Skip to content
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

fix: preserve tokensLength in tryParse #13326

Merged
merged 2 commits into from
May 17, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 17, 2021

Q                       A
Fixed Issues? Fixes #13322
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we preserve state.tokensLength (derived from this.tokens) on raising errors when errorRecovery: true, because the parser will parse remaining tokens. We do not reset the parser state when tryParse successfully returns, so when errorRecovery is true, we should not reset state.tokensLength, too.

Technically #13256 does not introduce this regression but it reveals the fact that the parser unexpectedly eats tokens when errors are thrown in recovery mode.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser labels May 17, 2021
@@ -0,0 +1 @@
<div propA={[key: value]} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the tokens of parsed AST is a length-14 array

[ tt.jsxTagStart, tt.name, undefined, undefined, ... , tt.eof]

babel7Compat thus throws because the tokens unexpectedly includes undefined.

@babel-bot
Copy link
Collaborator

babel-bot commented May 17, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 17, 2021

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 6f84912:

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

Co-authored-by: Brian Ng <bng412@gmail.com>
@JLHwung JLHwung merged commit 0d0950f into babel:main May 17, 2021
@JLHwung JLHwung deleted the preserve-tokens-length-on-error-recovery branch May 17, 2021 19:32
@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 Aug 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 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: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unexpected error thrown
4 participants