fix: preserve tokensLength in tryParse (#13326)

* fix: preserve tokensLength in tryParse

* Apply suggestions from code review

Co-authored-by: Brian Ng <bng412@gmail.com>

Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
Huáng Jùnliàng
2021-05-17 15:32:12 -04:00
committed by GitHub
parent 9d620c2d42
commit 0d0950f341
4 changed files with 301 additions and 0 deletions

View File

@@ -216,6 +216,10 @@ export default class UtilParser extends Tokenizer {
if (this.state.errors.length > oldState.errors.length) {
const failState = this.state;
this.state = oldState;
// tokensLength should be preserved during error recovery mode
// since the parser does not halt and will instead parse the
// remaining tokens
this.state.tokensLength = failState.tokensLength;
return {
node,
error: (failState.errors[oldState.errors.length]: SyntaxError),