diff --git a/src/parser/statement.js b/src/parser/statement.js index c81550143f..1d5f112ab9 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -595,7 +595,7 @@ pp.parseClass = function (node, isStatement, optionalId) { }; pp.isClassProperty = function () { - return this.match(tt.eq) || this.match(tt.semi) || this.canInsertSemicolon(); + return this.match(tt.eq) || this.isLineTerminator(); }; pp.parseClassBody = function (node) { @@ -747,9 +747,7 @@ pp.parseClassProperty = function (node) { } else { node.value = null; } - if (!this.eat(tt.semi)) { - this.raise(node.value && node.value.end || node.key.end, "A semicolon is required after a class property"); - } + this.semicolon(); return this.finishNode(node, "ClassProperty"); }; diff --git a/test/fixtures/experimental/class-properties/asi-failure/actual.js b/test/fixtures/experimental/class-properties/asi-failure/actual.js new file mode 100644 index 0000000000..f2b5d0c2d1 --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-failure/actual.js @@ -0,0 +1,4 @@ +class Foo { + p = x + [m] () {} +} diff --git a/test/fixtures/experimental/class-properties/asi-failure/options.json b/test/fixtures/experimental/class-properties/asi-failure/options.json new file mode 100644 index 0000000000..0c58f8ded1 --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-failure/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Unexpected token (3:9)", + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/asi-success/actual.js b/test/fixtures/experimental/class-properties/asi-success/actual.js new file mode 100644 index 0000000000..2e57778bbb --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-success/actual.js @@ -0,0 +1,9 @@ +class Foo { + x + y +} + +class Foo { + p + [m] () {} +} diff --git a/test/fixtures/experimental/class-properties/asi-success/expected.json b/test/fixtures/experimental/class-properties/asi-success/expected.json new file mode 100644 index 0000000000..c78a521f9c --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-success/expected.json @@ -0,0 +1,289 @@ +{ + "type": "File", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "name": "x" + }, + "static": false, + "value": null + }, + { + "type": "ClassProperty", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "name": "y" + }, + "static": false, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 23, + "end": 52, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "name": "p" + }, + "static": false, + "value": null + }, + { + "type": "ClassMethod", + "start": 41, + "end": 50, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "computed": true, + "key": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "name": "m" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 48, + "end": 50, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/asi-success/options.json b/test/fixtures/experimental/class-properties/asi-success/options.json new file mode 100644 index 0000000000..9c27576d4a --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-success/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/semicolons-required-with-value/actual.js b/test/fixtures/experimental/class-properties/semicolons-required-with-value/actual.js deleted file mode 100644 index 51ecdbb104..0000000000 --- a/test/fixtures/experimental/class-properties/semicolons-required-with-value/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class A { - asdf = 1 -} diff --git a/test/fixtures/experimental/class-properties/semicolons-required-with-value/options.json b/test/fixtures/experimental/class-properties/semicolons-required-with-value/options.json deleted file mode 100644 index b8d8f0380c..0000000000 --- a/test/fixtures/experimental/class-properties/semicolons-required-with-value/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": "A semicolon is required after a class property (2:10)", - "plugins": ["classProperties"] -} diff --git a/test/fixtures/experimental/class-properties/semicolons-required-without-value/actual.js b/test/fixtures/experimental/class-properties/semicolons-required-without-value/actual.js deleted file mode 100644 index caa1ecf226..0000000000 --- a/test/fixtures/experimental/class-properties/semicolons-required-without-value/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class A { - asdf -} diff --git a/test/fixtures/experimental/class-properties/semicolons-required-without-value/options.json b/test/fixtures/experimental/class-properties/semicolons-required-without-value/options.json deleted file mode 100644 index 29c4aac831..0000000000 --- a/test/fixtures/experimental/class-properties/semicolons-required-without-value/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": "A semicolon is required after a class property (2:6)", - "plugins": ["classProperties"] -}