Correctly disambiguate / after async fuctions (#10475)
* Correctly disambiguate / after async fuctions
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser
|
||||
|
||||
import { types as tt, type TokenType } from "../tokenizer/types";
|
||||
import { types as ct } from "../tokenizer/context";
|
||||
import * as N from "../types";
|
||||
import LValParser from "./lval";
|
||||
import {
|
||||
@@ -970,6 +971,19 @@ export default class ExpressionParser extends LValParser {
|
||||
this.match(tt._function) &&
|
||||
!this.canInsertSemicolon()
|
||||
) {
|
||||
const last = this.state.context.length - 1;
|
||||
if (this.state.context[last] !== ct.functionStatement) {
|
||||
// Since "async" is an identifier and normally identifiers
|
||||
// can't be followed by expression, the tokenizer assumes
|
||||
// that "function" starts a statement.
|
||||
// Fixing it in the tokenizer would mean tracking not only the
|
||||
// previous token ("async"), but also the one before to know
|
||||
// its beforeExpr value.
|
||||
// It's easier and more efficient to adjust the context here.
|
||||
throw new Error("Internal error");
|
||||
}
|
||||
this.state.context[last] = ct.functionExpression;
|
||||
|
||||
this.next();
|
||||
return this.parseFunction(node, undefined, true);
|
||||
} else if (
|
||||
|
||||
Reference in New Issue
Block a user