-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: preserve tokensLength in tryParse #13326
Conversation
@@ -0,0 +1 @@ | |||
<div propA={[key: value]} /> |
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.
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
.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46182/ |
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:
|
Co-authored-by: Brian Ng <bng412@gmail.com>
In this PR we preserve
state.tokensLength
(derived fromthis.tokens
) on raising errors whenerrorRecovery: true
, because the parser will parse remaining tokens. We do not reset the parser state whentryParse
successfully returns, so whenerrorRecovery
istrue
, we should not resetstate.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.