Skip to content

Simplify token context#13450

Merged
JLHwung merged 3 commits into
babel:mainfrom
JLHwung:simplify-token-context
Jun 21, 2021
Merged

Simplify token context#13450
JLHwung merged 3 commits into
babel:mainfrom
JLHwung:simplify-token-context

Conversation

@JLHwung

@JLHwung JLHwung commented Jun 10, 2021

Copy link
Copy Markdown
Contributor
Q                       A
License MIT

This PR continues efforts on #13431. When I am working on #13449 I realize that tc.brace and tc.templateQuasi are unifiable, they were separated before when we have braceIsBlock logic on tc.brace but not the other. Now that parsing RegExp no longer depends on state.exprAllowed and braceIsBlock 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.

@JLHwung JLHwung added PR: Internal 🏠 A type of pull request used for our changelog categories pkg: parser labels Jun 10, 2021
@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46803/

@codesandbox-ci

Copy link
Copy Markdown

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

// 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

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@JLHwung JLHwung merged commit 5145c98 into babel:main Jun 21, 2021
@JLHwung JLHwung deleted the simplify-token-context branch June 21, 2021 14:51
nicolo-ribaudo pushed a commit to nicolo-ribaudo/babel that referenced this pull request Jul 30, 2021
* refactor: unify tc.brace and tc.templateQuasi

* refactor: remove unused context check

* perf: reduce arrayPrototype call and hoist variables
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 21, 2021
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants