From 9f7cb552648829796ab4d6836d08246e95f16b9d Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 21:08:39 +1100 Subject: [PATCH] Add stray semicolons as class elements --- acorn.js | 3 ++- test/tests-harmony.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/acorn.js b/acorn.js index 4945981d59..6ba8f97d81 100644 --- a/acorn.js +++ b/acorn.js @@ -2524,6 +2524,8 @@ classBody.body = []; expect(_braceL); while (!eat(_braceR)) { + while (eat(_semi)); + if (tokType === _braceR) continue; var method = startNode(); var isGenerator = eat(_star); parsePropertyName(method); @@ -2546,7 +2548,6 @@ } method.value = parseMethod(isGenerator); classBody.body.push(finishNode(method, "MethodDefinition")); - eat(_semi); } node.body = finishNode(classBody, "ClassBody"); return finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); diff --git a/test/tests-harmony.js b/test/tests-harmony.js index eb8b8c5812..086d85216e 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -8859,6 +8859,42 @@ test("class A { foo() {} get foo() {} }",{ locations: true }); +test("class Semicolon { ; }", { + type: "Program", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 21} + }, + body: [{ + type: "ClassDeclaration", + loc: { + start: {line: 1, column: 0}, + end: {line: 1, column: 21} + }, + id: { + type: "Identifier", + loc: { + start: {line: 1, column: 6}, + end: {line: 1, column: 15} + }, + name: "Semicolon" + }, + superClass: null, + body: { + type: "ClassBody", + loc: { + start: {line: 1, column: 16}, + end: {line: 1, column: 21} + }, + body: [] + } + }] +}, { + ecmaVersion: 6, + ranges: true, + locations: true +}); + // ES6: Computed Properties test("({[x]: 10})", {