Skip to content

Commit

Permalink
fix: Correctly set position for @(a.b)() (#17013)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
liuxingbaoyu authored Dec 10, 2024
1 parent a2d1da8 commit ad0f525
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions packages/babel-parser/src/parser/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ export default abstract class StatementParser extends ExpressionParser {
expr = this.wrapParenthesis(startLoc, expr);

const paramsStartLoc = this.state.startLoc;
node.expression = this.parseMaybeDecoratorArguments(expr);
node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
if (
this.getPluginOption("decorators", "allowCallParenthesized") ===
false &&
Expand Down Expand Up @@ -801,17 +801,21 @@ export default abstract class StatementParser extends ExpressionParser {
expr = this.finishNode(node, "MemberExpression");
}

node.expression = this.parseMaybeDecoratorArguments(expr);
node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
}
} else {
node.expression = this.parseExprSubscripts();
}
return this.finishNode(node, "Decorator");
}

parseMaybeDecoratorArguments(this: Parser, expr: N.Expression): N.Expression {
parseMaybeDecoratorArguments(
this: Parser,
expr: N.Expression,
startLoc: Position,
): N.Expression {
if (this.eat(tt.parenL)) {
const node = this.startNodeAtNode<N.CallExpression>(expr);
const node = this.startNodeAt<N.CallExpression>(startLoc);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR);
this.toReferencedList(node.arguments);
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-parser/src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3756,14 +3756,18 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
return super.parseBindingAtom();
}

parseMaybeDecoratorArguments(expr: N.Expression): N.Expression {
parseMaybeDecoratorArguments(
expr: N.Expression,
startLoc: Position,
): N.Expression {
// handles `@f<<T>`
if (this.match(tt.lt) || this.match(tt.bitShiftL)) {
const typeArguments = this.tsParseTypeArgumentsInExpression();

if (this.match(tt.parenL)) {
const call = super.parseMaybeDecoratorArguments(
expr,
startLoc,
) as N.CallExpression;
call.typeParameters = typeArguments;
return call;
Expand All @@ -3772,7 +3776,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
this.unexpected(null, tt.parenL);
}

return super.parseMaybeDecoratorArguments(expr);
return super.parseMaybeDecoratorArguments(expr, startLoc);
}

checkCommaAfterRest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"start":14,"end":30,"loc":{"start":{"line":2,"column":2,"index":14},"end":{"line":2,"column":18,"index":30}},
"expression": {
"type": "CallExpression",
"start":16,"end":30,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":18,"index":30}},
"start":15,"end":30,"loc":{"start":{"line":2,"column":3,"index":15},"end":{"line":2,"column":18,"index":30}},
"callee": {
"type": "MemberExpression",
"start":16,"end":24,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":12,"index":24}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start":14,"end":30,"loc":{"start":{"line":2,"column":2,"index":14},"end":{"line":2,"column":18,"index":30}},
"expression": {
"type": "CallExpression",
"start":16,"end":30,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":18,"index":30}},
"start":15,"end":30,"loc":{"start":{"line":2,"column":3,"index":15},"end":{"line":2,"column":18,"index":30}},
"callee": {
"type": "MemberExpression",
"start":16,"end":24,"loc":{"start":{"line":2,"column":4,"index":16},"end":{"line":2,"column":12,"index":24}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"start":93,"end":109,"loc":{"start":{"line":7,"column":2,"index":93},"end":{"line":7,"column":18,"index":109}},
"expression": {
"type": "CallExpression",
"start":95,"end":109,"loc":{"start":{"line":7,"column":4,"index":95},"end":{"line":7,"column":18,"index":109}},
"start":94,"end":109,"loc":{"start":{"line":7,"column":3,"index":94},"end":{"line":7,"column":18,"index":109}},
"callee": {
"type": "MemberExpression",
"start":95,"end":103,"loc":{"start":{"line":7,"column":4,"index":95},"end":{"line":7,"column":12,"index":103}},
Expand Down

0 comments on commit ad0f525

Please sign in to comment.