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.
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.
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.braceandtc.templateQuasiare unifiable, they were separated before when we havebraceIsBlocklogic ontc.bracebut not the other. Now that parsing RegExp no longer depends onstate.exprAllowedandbraceIsBlockis removed, we can further simplify the token context by unifying these two contexts into one context.The other commits are cleanup and micro-optimizations.