Skip to content

Commit

Permalink
Add support for function return type
Browse files Browse the repository at this point in the history
Summary: Now we can get all of the type nodes of a function decalaration, we will use them for relay schema generation.

Reviewed By: captbaritone

Differential Revision: D54521748

fbshipit-source-id: 63b6d13fd998580913c2039015b4da292d7096de
  • Loading branch information
tyao1 authored and facebook-github-bot committed Mar 7, 2024
1 parent dfdc43f commit 2a57eeb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"body": {
"type": "Option<FunctionBody>"
},
"return_type": {
"type": "Option<TypeAnnotation>",
"rename": "returnType",
"optional": true
},
"is_generator": {
"type": "bool",
"optional": true,
Expand Down Expand Up @@ -1160,8 +1165,9 @@
"type": "Option<FunctionTypeParam>",
"optional": true
},
"returnType": {
"type": "FlowTypeAnnotation"
"return_type": {
"type": "FlowTypeAnnotation",
"rename": "returnType"
},
"rest": {
"type": "Option<FunctionTypeParam>",
Expand Down
19 changes: 19 additions & 0 deletions unsupported/hermes/crates/hermes_parser/src/generated_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use hermes::parser::hermes_get_ArrowFunctionExpression_body;
use hermes::parser::hermes_get_ArrowFunctionExpression_expression;
use hermes::parser::hermes_get_ArrowFunctionExpression_id;
use hermes::parser::hermes_get_ArrowFunctionExpression_params;
use hermes::parser::hermes_get_ArrowFunctionExpression_returnType;
use hermes::parser::hermes_get_ClassDeclaration_body;
use hermes::parser::hermes_get_ClassDeclaration_id;
use hermes::parser::hermes_get_ClassDeclaration_superClass;
Expand All @@ -23,11 +24,13 @@ use hermes::parser::hermes_get_FunctionDeclaration_body;
use hermes::parser::hermes_get_FunctionDeclaration_generator;
use hermes::parser::hermes_get_FunctionDeclaration_id;
use hermes::parser::hermes_get_FunctionDeclaration_params;
use hermes::parser::hermes_get_FunctionDeclaration_returnType;
use hermes::parser::hermes_get_FunctionExpression_async;
use hermes::parser::hermes_get_FunctionExpression_body;
use hermes::parser::hermes_get_FunctionExpression_generator;
use hermes::parser::hermes_get_FunctionExpression_id;
use hermes::parser::hermes_get_FunctionExpression_params;
use hermes::parser::hermes_get_FunctionExpression_returnType;
use hermes::parser::hermes_get_Property_computed;
use hermes::parser::hermes_get_Property_key;
use hermes::parser::hermes_get_Property_kind;
Expand Down Expand Up @@ -63,6 +66,7 @@ use hermes_estree::Pattern;
use hermes_estree::SourceRange;
use hermes_estree::TemplateElement;
use hermes_estree::TemplateElementValue;
use hermes_estree::TypeAnnotation;
use juno_support::NullTerminatedBuf;
use serde::Serialize;

Expand Down Expand Up @@ -220,6 +224,10 @@ impl FromHermes for FunctionDeclaration {
|node| Pattern::convert(cx, node),
);
let body = FunctionBody::convert(cx, unsafe { hermes_get_FunctionDeclaration_body(node) });
let return_type = convert_option(
unsafe { hermes_get_FunctionDeclaration_returnType(node) },
|node| TypeAnnotation::convert(cx, node),
);
let is_generator = unsafe { hermes_get_FunctionDeclaration_generator(node) };
let is_async = unsafe { hermes_get_FunctionDeclaration_async(node) };
let loc = None;
Expand All @@ -229,6 +237,7 @@ impl FromHermes for FunctionDeclaration {
id,
params,
body: Some(body),
return_type,
is_generator,
is_async,
loc: loc.clone(),
Expand All @@ -250,6 +259,10 @@ impl FromHermes for FunctionExpression {
|node| Pattern::convert(cx, node),
);
let body = FunctionBody::convert(cx, unsafe { hermes_get_FunctionExpression_body(node) });
let return_type = convert_option(
unsafe { hermes_get_FunctionExpression_returnType(node) },
|node| TypeAnnotation::convert(cx, node),
);
let is_generator = unsafe { hermes_get_FunctionExpression_generator(node) };
let is_async = unsafe { hermes_get_FunctionExpression_async(node) };
let loc = None;
Expand All @@ -259,6 +272,7 @@ impl FromHermes for FunctionExpression {
id,
params,
body: Some(body),
return_type,
is_generator,
is_async,
loc: loc.clone(),
Expand All @@ -282,6 +296,10 @@ impl FromHermes for ArrowFunctionExpression {
);
let body =
FunctionBody::convert(cx, unsafe { hermes_get_ArrowFunctionExpression_body(node) });
let return_type = convert_option(
unsafe { hermes_get_ArrowFunctionExpression_returnType(node) },
|node| TypeAnnotation::convert(cx, node),
);
let is_generator = unsafe { hermes_get_FunctionExpression_generator(node) };
let is_async = unsafe { hermes_get_ArrowFunctionExpression_async(node) };
let is_expression = unsafe { hermes_get_ArrowFunctionExpression_expression(node) };
Expand All @@ -292,6 +310,7 @@ impl FromHermes for ArrowFunctionExpression {
id,
params,
body: Some(body),
return_type,
is_generator,
is_async,
loc: loc.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

/* TODO:
function field(user: User): string {
return "Hello";
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

let BooleanTypeAnnotation: boolean;
Expand Down

0 comments on commit 2a57eeb

Please sign in to comment.