This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional property to Identifier node
Summary: Hermes currently parses optional function parameters (e.g. `function foo(a?) {}` or `(a?: string) => {}`), however it does not store whether a parameter is optional in the AST. Flow and Babel store this information as a boolean `optional` property on `Identifier` nodes which is `true` if the identifier is an optional function parameter, otherwise `optional` is false. Let's update Hermes' AST definition to now store an `optional` property on identifiers, just like Flow and Babel. Almost all places where `IdentifierNodes` are created, optional is set to be false. In fact the only place where an `IdentifierNode` is directly created with `optional` set to true is within `parseBindingIdentifier` when we encounter a question mark directly following the identifier. There is only one other path through which optional identifiers are created: when reparsing arrow function parameters. To handle this case we also need to add an optional property to the `CoverTypedIdentifierNode`. Then when unwrapping a `CoverTypedIdentifierNode` in `reparseAssignmentPattern`, we pass the value of `optional` from the `CoverTypedIdentifierNode` to the `IdentifierNode`. In addition, as per avp's suggestion we now allow declaring `ESTREE_IGNORE_IF_EMPTY` on boolean node properties. If the boolean is false, such as the new `optional` property for non-optional identifiers, then it will not be included in the JSON output. Without this we would have to update every single parser test that contains an identifier, instead of only the tests that contain optional parameters. Reviewed By: avp Differential Revision: D24210171 fbshipit-source-id: 2bb860ba2876d28100f17286bbb74e46dabf3cbc
- Loading branch information
1 parent
d91e0e3
commit a7f424c
Showing
10 changed files
with
180 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.