From 06b9c8c21c0b37d3284f34f51c788e28f675a19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E6=98=AF=E5=96=9C=E6=AC=A2=E9=99=88=E7=B2=92?= Date: Tue, 24 Aug 2021 15:54:36 +0800 Subject: [PATCH] Make sequence expression's end location correct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FIX: Fix wrong end locations stored on SequenceExpression nodes. Co-authored-by: 成仕伟 --- acorn/src/expression.js | 2 +- test/tests.js | 116 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 10d4a6931..139edac0b 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -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)) { diff --git a/test/tests.js b/test/tests.js index 9d1d97543..ec784f067 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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 }) +}