fix: assure left bracket is not consumed after dot (#13695)
* fix: assure left bracket is not consumed after dot * address review comments
This commit is contained in:
parent
e0c3969a24
commit
976bfbbf69
@ -701,6 +701,7 @@ export default class ExpressionParser extends LValParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let optional = false;
|
let optional = false;
|
||||||
|
|
||||||
if (this.match(tt.questionDot)) {
|
if (this.match(tt.questionDot)) {
|
||||||
if (noCalls && this.lookaheadCharCode() === charCodes.leftParenthesis) {
|
if (noCalls && this.lookaheadCharCode() === charCodes.leftParenthesis) {
|
||||||
// stop at `?.` when parsing `new a?.()`
|
// stop at `?.` when parsing `new a?.()`
|
||||||
@ -719,11 +720,21 @@ export default class ExpressionParser extends LValParser {
|
|||||||
state,
|
state,
|
||||||
optional,
|
optional,
|
||||||
);
|
);
|
||||||
} else if (optional || this.match(tt.bracketL) || this.eat(tt.dot)) {
|
|
||||||
return this.parseMember(base, startPos, startLoc, state, optional);
|
|
||||||
} else {
|
} else {
|
||||||
state.stop = true;
|
const computed = this.eat(tt.bracketL);
|
||||||
return base;
|
if (computed || optional || this.eat(tt.dot)) {
|
||||||
|
return this.parseMember(
|
||||||
|
base,
|
||||||
|
startPos,
|
||||||
|
startLoc,
|
||||||
|
state,
|
||||||
|
computed,
|
||||||
|
optional,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
state.stop = true;
|
||||||
|
return base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -736,10 +747,10 @@ export default class ExpressionParser extends LValParser {
|
|||||||
startPos: number,
|
startPos: number,
|
||||||
startLoc: Position,
|
startLoc: Position,
|
||||||
state: N.ParseSubscriptState,
|
state: N.ParseSubscriptState,
|
||||||
|
computed: boolean,
|
||||||
optional: boolean,
|
optional: boolean,
|
||||||
): N.OptionalMemberExpression | N.MemberExpression {
|
): N.OptionalMemberExpression | N.MemberExpression {
|
||||||
const node = this.startNodeAt(startPos, startLoc);
|
const node = this.startNodeAt(startPos, startLoc);
|
||||||
const computed = this.eat(tt.bracketL);
|
|
||||||
node.object = base;
|
node.object = base;
|
||||||
node.computed = computed;
|
node.computed = computed;
|
||||||
const privateName =
|
const privateName =
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
a.[b]
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (1:2)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user