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
Simplify token context #13450
Simplify token context #13450
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46803/ |
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 112e1f8:
|
// a template quasi `${` or other tokens containing `{`: | ||
// namely tt.braceL `{` and tt.braceHashL `#{` | ||
// The token context is used to track whether the apostrophe "`" | ||
// starts or ends a string template |
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.
I wonder if we could completely remove context and just use a this.state.inTemplateLiteral
boolean flag, that we manage with oldInTemplateLiteral = this.state.inTemplateLiteral; this.state.inTemplateLiteral = true
similarly to how we manage the other boolean variables.
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.
We are close to remove the whole token context. However the token context also records preserveSpace
, to instruct whether tokenizer should skip space in nextToken
. This feature is also used in JSX expressions so it can't be replaced by state.inTemplateLiteral
.
* refactor: unify tc.brace and tc.templateQuasi * refactor: remove unused context check * perf: reduce arrayPrototype call and hoist variables
This PR continues efforts on #13431. When I am working on #13449 I realize that
tc.brace
andtc.templateQuasi
are unifiable, they were separated before when we havebraceIsBlock
logic ontc.brace
but not the other. Now that parsing RegExp no longer depends onstate.exprAllowed
andbraceIsBlock
is removed, we can further simplify the token context by unifying these two contexts into one context.The other commits are cleanup and micro-optimizations.