Skip to content

Commit

Permalink
Make sequence expression's end location correct
Browse files Browse the repository at this point in the history
FIX: Fix wrong end locations stored on SequenceExpression nodes.

Co-authored-by: 成仕伟 <[email protected]>
  • Loading branch information
Lucian-4a25 and 成仕伟 authored Aug 24, 2021
1 parent cce777a commit 06b9c8c
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ pp.parseParenAndDistinguishExpression = function(canBeArrow) {
exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem))
}
}
let innerEndPos = this.start, innerEndLoc = this.startLoc
let innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc
this.expect(tt.parenR)

if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
Expand Down
116 changes: 116 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29490,3 +29490,119 @@ test("for (; function () {} / 1;);", {}, {ecmaVersion: 6})
test("for (; class {} / 1;);", {}, {ecmaVersion: 6})
test("for (;; function () {} / 1);", {}, {ecmaVersion: 6})
test("for (;; class {} / 1);", {}, {ecmaVersion: 6})

for (const ecmaVersion of [5, 6]) {
test("a = (\r\n b,\r\n c\r\n)", {
type: "Program",
start: 0,
end: 19,
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 1
}
},
body: [
{
type: "ExpressionStatement",
start: 0,
end: 19,
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 1
}
},
expression: {
type: "AssignmentExpression",
start: 0,
end: 19,
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 1
}
},
operator: "=",
left: {
type: "Identifier",
start: 0,
end: 1,
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 1
}
},
name: "a"
},
right: {
type: "SequenceExpression",
start: 9,
end: 16,
loc: {
start: {
line: 2,
column: 2
},
end: {
line: 3,
column: 3
}
},
expressions: [
{
type: "Identifier",
start: 9,
end: 10,
loc: {
start: {
line: 2,
column: 2
},
end: {
line: 2,
column: 3
}
},
name: "b"
},
{
type: "Identifier",
start: 15,
end: 16,
loc: {
start: {
line: 3,
column: 2
},
end: {
line: 3,
column: 3
}
},
name: "c"
}
]
}
}
}
],
}, { ecmaVersion, locations: true })
}

0 comments on commit 06b9c8c

Please sign in to comment.