-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: add parse*Literal parser routines #13333
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46273/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4205780:
|
"type": "File", | ||
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}}, | ||
"errors": [ | ||
"SyntaxError: 'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we testing this error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I forgot to add sourceType module to options.json😬
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
00dbbfe
to
7214721
Compare
return this.finishNode<T>(node, type); | ||
} | ||
|
||
parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe one of these works:
parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { | |
parseLiteral<T: N.Literal>(value: any, type: $PropertyType<T, "kind">): T { |
parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { | |
parseLiteral<T: N.Literal>(value: any, type: $ElementType<T, "kind">): T { |
This PR should be reviewed by commits.
Currently we handle the
StringLiteral
->Literal
conversion inparseExprAtom
, however, in the scenarios like module string names or import assertions, we can not callparseExprAtom
since only a limited set of PrimaryExpression (namelyStringLiteral
andIdentifier
) are accepted in the grammar, thus theStringLiteral
in such places is not converted to aLiteral
as expected from theestree
plugin.Thus the goal of this PR is to break the conversion logic of
parseExprAtom
to more granularparseSomeLiteral
, so whenever a string literal is created fromparseStringLiteral
, theestree
plugin can handle it via subclassedparseStringLiteral
method.This PR also simplifies the interface of
parseLiteral
: It turns out the optional position input is only used by Flow plugin when it parses-1
as a dedicated NumberTypeAnnotation, thus we can remove the branch logic ofparseLiteral
.