Skip to content

Commit 06b9c8c

Browse files
Lucian-4a25成仕伟
andauthored
Make sequence expression's end location correct
FIX: Fix wrong end locations stored on SequenceExpression nodes. Co-authored-by: 成仕伟 <[email protected]>
1 parent cce777a commit 06b9c8c

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

acorn/src/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ pp.parseParenAndDistinguishExpression = function(canBeArrow) {
582582
exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem))
583583
}
584584
}
585-
let innerEndPos = this.start, innerEndLoc = this.startLoc
585+
let innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc
586586
this.expect(tt.parenR)
587587

588588
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {

test/tests.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29490,3 +29490,119 @@ test("for (; function () {} / 1;);", {}, {ecmaVersion: 6})
2949029490
test("for (; class {} / 1;);", {}, {ecmaVersion: 6})
2949129491
test("for (;; function () {} / 1);", {}, {ecmaVersion: 6})
2949229492
test("for (;; class {} / 1);", {}, {ecmaVersion: 6})
29493+
29494+
for (const ecmaVersion of [5, 6]) {
29495+
test("a = (\r\n b,\r\n c\r\n)", {
29496+
type: "Program",
29497+
start: 0,
29498+
end: 19,
29499+
loc: {
29500+
start: {
29501+
line: 1,
29502+
column: 0
29503+
},
29504+
end: {
29505+
line: 4,
29506+
column: 1
29507+
}
29508+
},
29509+
body: [
29510+
{
29511+
type: "ExpressionStatement",
29512+
start: 0,
29513+
end: 19,
29514+
loc: {
29515+
start: {
29516+
line: 1,
29517+
column: 0
29518+
},
29519+
end: {
29520+
line: 4,
29521+
column: 1
29522+
}
29523+
},
29524+
expression: {
29525+
type: "AssignmentExpression",
29526+
start: 0,
29527+
end: 19,
29528+
loc: {
29529+
start: {
29530+
line: 1,
29531+
column: 0
29532+
},
29533+
end: {
29534+
line: 4,
29535+
column: 1
29536+
}
29537+
},
29538+
operator: "=",
29539+
left: {
29540+
type: "Identifier",
29541+
start: 0,
29542+
end: 1,
29543+
loc: {
29544+
start: {
29545+
line: 1,
29546+
column: 0
29547+
},
29548+
end: {
29549+
line: 1,
29550+
column: 1
29551+
}
29552+
},
29553+
name: "a"
29554+
},
29555+
right: {
29556+
type: "SequenceExpression",
29557+
start: 9,
29558+
end: 16,
29559+
loc: {
29560+
start: {
29561+
line: 2,
29562+
column: 2
29563+
},
29564+
end: {
29565+
line: 3,
29566+
column: 3
29567+
}
29568+
},
29569+
expressions: [
29570+
{
29571+
type: "Identifier",
29572+
start: 9,
29573+
end: 10,
29574+
loc: {
29575+
start: {
29576+
line: 2,
29577+
column: 2
29578+
},
29579+
end: {
29580+
line: 2,
29581+
column: 3
29582+
}
29583+
},
29584+
name: "b"
29585+
},
29586+
{
29587+
type: "Identifier",
29588+
start: 15,
29589+
end: 16,
29590+
loc: {
29591+
start: {
29592+
line: 3,
29593+
column: 2
29594+
},
29595+
end: {
29596+
line: 3,
29597+
column: 3
29598+
}
29599+
},
29600+
name: "c"
29601+
}
29602+
]
29603+
}
29604+
}
29605+
}
29606+
],
29607+
}, { ecmaVersion, locations: true })
29608+
}

0 commit comments

Comments
 (0)