Repository: acornjs/acorn (JavaScript)

Issue:
Incorrect location for multiline group in class extends
```
class C extends (
  a,
  c
) {
}
```

This parses just fine, of course. The AST contains this part for the `extends`:

```
      superClass: {
        type: 'SequenceExpression',
        loc:{start:{line:2,column:2},end:{line:3,column:3},source:''},
```

I think this is reasonable because the contents of the sequence starts at the `a` and ends immediately after the `c`. (In a CST the parenthesis would get special care, I think Estree has some extensible options for this).

Acorn and Babel will report this for loc:
```
loc:{start:{line:2,column:2},end:{line:4,column:0}},
```

So they agree that the expression starts at `a` but that it ends before the closing parenthesis, rather than immediately after the `c`.

A simpler case (which would be a different bug in my parser) is this input:

```
a = (
  b,
  c
) 
```

Where the same location symptom appears.


Discussion:

Patch:
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)) {


Test patch:
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 })
+}