refactor: raise AwaitNotInAsyncContext when an AwaitExpression will be parsed (#12716)

* refactor: raise AwaitNotInAsyncContext when an AwaitExpression will be parsed

* tweak logic

* early exit when errors are before thrown error position

* fix: always return true in assert.throws callback

See https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message

* update test fixtures

* fix flow error
This commit is contained in:
Huáng Jùnliàng
2021-02-01 10:46:43 -05:00
committed by GitHub
parent 8cf0a757d5
commit 108564fdad
15 changed files with 158 additions and 38 deletions

View File

@@ -6,6 +6,7 @@ import { Position } from "../util/location";
import { types as ct, type TokContext } from "./context";
import { types as tt, type TokenType } from "./types";
import type { ParsingError } from "../parser/error";
type TopicContextState = {
// When a topic binding has been currently established,
@@ -37,7 +38,7 @@ export default class State {
this.startLoc = this.endLoc = this.curPosition();
}
errors: SyntaxError[] = [];
errors: ParsingError[] = [];
// Used to signify the start of a potential arrow function
potentialArrowAt: number = -1;
@@ -155,9 +156,6 @@ export default class State {
// Tokens length in token store
tokensLength: number = 0;
// Positions of invalid await errors
invalidAwaitErrors: Set<number> = new Set();
curPosition(): Position {
return new Position(this.curLine, this.pos - this.lineStart);
}