refactor: add parse*Literal parser routines#13333
Merged
JLHwung merged 8 commits intobabel:mainfrom May 19, 2021
Merged
Conversation
Collaborator
|
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:
|
fedeci
approved these changes
May 19, 2021
| "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)" |
Contributor
Author
There was a problem hiding this comment.
Nope, I forgot to add sourceType module to options.json😬
Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
00dbbfe to
7214721
Compare
nicolo-ribaudo
approved these changes
May 19, 2021
| return this.finishNode<T>(node, type); | ||
| } | ||
|
|
||
| parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { |
Member
There was a problem hiding this comment.
Maybe one of these works:
Suggested change
| parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { | |
| parseLiteral<T: N.Literal>(value: any, type: $PropertyType<T, "kind">): T { |
Suggested change
| parseLiteral<T: N.Literal>(value: any, type: /*T["kind"]*/ string): T { | |
| parseLiteral<T: N.Literal>(value: any, type: $ElementType<T, "kind">): T { |
nicolo-ribaudo
approved these changes
May 19, 2021
fedeci
approved these changes
May 19, 2021
This was referenced Jun 10, 2021
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR should be reviewed by commits.
Currently we handle the
StringLiteral->Literalconversion inparseExprAtom, however, in the scenarios like module string names or import assertions, we can not callparseExprAtomsince only a limited set of PrimaryExpression (namelyStringLiteralandIdentifier) are accepted in the grammar, thus theStringLiteralin such places is not converted to aLiteralas expected from theestreeplugin.Thus the goal of this PR is to break the conversion logic of
parseExprAtomto more granularparseSomeLiteral, so whenever a string literal is created fromparseStringLiteral, theestreeplugin can handle it via subclassedparseStringLiteralmethod.This PR also simplifies the interface of
parseLiteral: It turns out the optional position input is only used by Flow plugin when it parses-1as a dedicated NumberTypeAnnotation, thus we can remove the branch logic ofparseLiteral.