diff --git a/src/parser/statement.js b/src/parser/statement.js index 676920fff4..8de2368093 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -618,8 +618,12 @@ pp.parseClass = function (node, isStatement, optionalId) { return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); }; -pp.isClassProperty = function () { - return this.match(tt.eq) || this.isLineTerminator(); +pp.isInitializedClassProperty = function () { + return this.match(tt.eq); +}; + +pp.isUninitializedClassProperty = function () { + return this.match(tt.semi) || (this.canInsertSemicolon() && !this.match(tt.parenL)); }; pp.isClassMutatorStarter = function () { @@ -666,7 +670,9 @@ pp.parseClassBody = function (node) { this.parsePropertyName(method); - method.static = isMaybeStatic && !this.match(tt.parenL); + let isMaybeGetSet = !method.computed && (method.key.name === "get" || method.key.name === "set"); + + method.static = isMaybeStatic && !this.match(tt.parenL) && !(this.match(tt.braceR) && this.hasPlugin("classProperties")); if (method.static) { if (isGenerator) this.unexpected(); isGenerator = this.eat(tt.star); @@ -674,9 +680,11 @@ pp.parseClassBody = function (node) { } if (!isGenerator) { - if (this.isClassProperty()) { - classBody.body.push(this.parseClassProperty(method)); - continue; + if (this.isInitializedClassProperty() || (this.isUninitializedClassProperty() && !(isMaybeGetSet && this.match(tt.name)))) { + if (this.hasPlugin("classProperties") || this.hasPlugin("flow")) { + classBody.body.push(this.parseClassProperty(method)); + continue; + } } if (method.key.type === "Identifier" && !method.computed && this.hasPlugin("classConstructorCall") && method.key.name === "call" && this.match(tt.name) && this.state.value === "constructor") { @@ -692,6 +700,9 @@ pp.parseClassBody = function (node) { this.parsePropertyName(method); } + // Do this again because we may have updated `method` + isMaybeGetSet = !method.computed && (method.key.name === "get" || method.key.name === "set"); + method.kind = "method"; if (!method.computed) { @@ -699,7 +710,7 @@ pp.parseClassBody = function (node) { // handle get/set methods // eg. class Foo { get bar() {} set bar() {} } - if (!isAsync && !isGenerator && !this.isClassMutatorStarter() && key.type === "Identifier" && !this.match(tt.parenL) && (key.name === "get" || key.name === "set")) { + if (!isAsync && !isGenerator && !this.isClassMutatorStarter() && key.type === "Identifier" && !this.match(tt.parenL) && isMaybeGetSet) { isGetSet = true; method.kind = key.name; key = this.parsePropertyName(method); @@ -775,7 +786,9 @@ pp.parseClassProperty = function (node) { } else { node.value = null; } - this.semicolon(); + if (!this.isLineTerminator()) { + this.semicolon(); + } return this.finishNode(node, "ClassProperty"); }; diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 7063b24283..24e1d13f03 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -979,8 +979,15 @@ export default function (instance) { }; }); - // determine whether or not we're currently in the position where a class property would appear - instance.extend("isClassProperty", function (inner) { + // determine whether or not we're currently in the position where an initialized class property would appear + instance.extend("isInitializedClassProperty", function (inner) { + return function () { + return this.match(tt.colon) || inner.call(this); + }; + }); + + // determine whether or not we're currently in the position where an uninitialized class property would appear + instance.extend("isUninitializedClassProperty", function (inner) { return function () { return this.match(tt.colon) || inner.call(this); }; diff --git a/test/fixtures/experimental/class-properties/at-end-async/actual.js b/test/fixtures/experimental/class-properties/at-end-async/actual.js new file mode 100644 index 0000000000..07a467b333 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-async/actual.js @@ -0,0 +1 @@ +class A { async } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-async/expected.json b/test/fixtures/experimental/class-properties/at-end-async/expected.json new file mode 100644 index 0000000000..72490474ec --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-async/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "async" + }, + "name": "async" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-computed/actual.js b/test/fixtures/experimental/class-properties/at-end-computed/actual.js new file mode 100644 index 0000000000..35b22e6f94 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-computed/actual.js @@ -0,0 +1 @@ +class A { [Symbol.foo] } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-computed/expected.json b/test/fixtures/experimental/class-properties/at-end-computed/expected.json new file mode 100644 index 0000000000..516cf495fb --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-computed/expected.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "computed": true, + "key": { + "type": "MemberExpression", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "object": { + "type": "Identifier", + "start": 11, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "Symbol" + }, + "name": "Symbol" + }, + "property": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-get/actual.js b/test/fixtures/experimental/class-properties/at-end-get/actual.js new file mode 100644 index 0000000000..e0bc574c1f --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-get/actual.js @@ -0,0 +1 @@ +class A { get } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-get/expected.json b/test/fixtures/experimental/class-properties/at-end-get/expected.json new file mode 100644 index 0000000000..28243d8ecd --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-get/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "get" + }, + "name": "get" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-set/actual.js b/test/fixtures/experimental/class-properties/at-end-set/actual.js new file mode 100644 index 0000000000..541faf7126 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-set/actual.js @@ -0,0 +1 @@ +class A { set } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-set/expected.json b/test/fixtures/experimental/class-properties/at-end-set/expected.json new file mode 100644 index 0000000000..86426b2926 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-set/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "set" + }, + "name": "set" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-static/actual.js b/test/fixtures/experimental/class-properties/at-end-static/actual.js new file mode 100644 index 0000000000..605e80cb80 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-static/actual.js @@ -0,0 +1 @@ +class A { static } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end-static/expected.json b/test/fixtures/experimental/class-properties/at-end-static/expected.json new file mode 100644 index 0000000000..e24483fd8a --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end-static/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "static" + }, + "name": "static" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end/actual.js b/test/fixtures/experimental/class-properties/at-end/actual.js new file mode 100644 index 0000000000..0ac1506aa9 --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end/actual.js @@ -0,0 +1 @@ +class A { x } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/at-end/expected.json b/test/fixtures/experimental/class-properties/at-end/expected.json new file mode 100644 index 0000000000..d8ef7c9c3d --- /dev/null +++ b/test/fixtures/experimental/class-properties/at-end/expected.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/computed/options.json b/test/fixtures/experimental/class-properties/computed/options.json deleted file mode 100644 index 9c27576d4a..0000000000 --- a/test/fixtures/experimental/class-properties/computed/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classProperties"] -} diff --git a/test/fixtures/experimental/class-properties/constructor/actual.js b/test/fixtures/experimental/class-properties/constructor/actual.js new file mode 100644 index 0000000000..df24bca852 --- /dev/null +++ b/test/fixtures/experimental/class-properties/constructor/actual.js @@ -0,0 +1,8 @@ +class A { + +constructor +( a +, b +) { +} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/constructor/expected.json b/test/fixtures/experimental/class-properties/constructor/expected.json new file mode 100644 index 0000000000..af84ec7004 --- /dev/null +++ b/test/fixtures/experimental/class-properties/constructor/expected.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 11, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 11, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "static": false, + "kind": "constructor", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "body": { + "type": "BlockStatement", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-get/actual.js b/test/fixtures/experimental/class-properties/method-get/actual.js new file mode 100644 index 0000000000..541b96dd01 --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-get/actual.js @@ -0,0 +1,4 @@ +class A { + get + x(){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-get/expected.json b/test/fixtures/experimental/class-properties/method-get/expected.json new file mode 100644 index 0000000000..f6e3e49156 --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-get/expected.json @@ -0,0 +1,141 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "kind": "get", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-named-static/actual.js b/test/fixtures/experimental/class-properties/method-named-static/actual.js new file mode 100644 index 0000000000..7b9cc2fede --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-named-static/actual.js @@ -0,0 +1,4 @@ +class A { + static + (){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-named-static/expected.json b/test/fixtures/experimental/class-properties/method-named-static/expected.json new file mode 100644 index 0000000000..b0ad0014ac --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-named-static/expected.json @@ -0,0 +1,140 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-no-asi/actual.js b/test/fixtures/experimental/class-properties/method-no-asi/actual.js new file mode 100644 index 0000000000..b0b90da3ef --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-no-asi/actual.js @@ -0,0 +1,4 @@ +class A { + 'x' + (){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-no-asi/expected.json b/test/fixtures/experimental/class-properties/method-no-asi/expected.json new file mode 100644 index 0000000000..ffbbd76c9b --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-no-asi/expected.json @@ -0,0 +1,144 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "computed": false, + "key": { + "type": "StringLiteral", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "extra": { + "rawValue": "x", + "raw": "'x'" + }, + "value": "x" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-set/actual.js b/test/fixtures/experimental/class-properties/method-set/actual.js new file mode 100644 index 0000000000..f495aac6c7 --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-set/actual.js @@ -0,0 +1,4 @@ +class A { + set + x(value){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/method-set/expected.json b/test/fixtures/experimental/class-properties/method-set/expected.json new file mode 100644 index 0000000000..86b0a43132 --- /dev/null +++ b/test/fixtures/experimental/class-properties/method-set/expected.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "kind": "set", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "value" + }, + "name": "value" + } + ], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "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/options.json similarity index 100% rename from test/fixtures/experimental/class-properties/asi-success/options.json rename to test/fixtures/experimental/class-properties/options.json diff --git a/test/fixtures/experimental/class-properties/prop-named-async/actual.js b/test/fixtures/experimental/class-properties/prop-named-async/actual.js new file mode 100644 index 0000000000..4c91d98d7a --- /dev/null +++ b/test/fixtures/experimental/class-properties/prop-named-async/actual.js @@ -0,0 +1,4 @@ +class C { + async + x(){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/prop-named-async/expected.json b/test/fixtures/experimental/class-properties/prop-named-async/expected.json new file mode 100644 index 0000000000..7b2e533726 --- /dev/null +++ b/test/fixtures/experimental/class-properties/prop-named-async/expected.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 12, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "static": false, + "value": null + }, + { + "type": "ClassMethod", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/props-named-get-set/actual.js b/test/fixtures/experimental/class-properties/props-named-get-set/actual.js new file mode 100644 index 0000000000..226ecf830f --- /dev/null +++ b/test/fixtures/experimental/class-properties/props-named-get-set/actual.js @@ -0,0 +1,4 @@ +class C { + get; + set; +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/props-named-get-set/expected.json b/test/fixtures/experimental/class-properties/props-named-get-set/expected.json new file mode 100644 index 0000000000..32ca6de2c7 --- /dev/null +++ b/test/fixtures/experimental/class-properties/props-named-get-set/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "get" + }, + "name": "get" + }, + "static": false, + "value": null + }, + { + "type": "ClassProperty", + "start": 19, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "set" + }, + "name": "set" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/same-line/actual.js b/test/fixtures/experimental/class-properties/same-line/actual.js new file mode 100644 index 0000000000..209db641c0 --- /dev/null +++ b/test/fixtures/experimental/class-properties/same-line/actual.js @@ -0,0 +1 @@ +class A { a; b=2; c; } \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/same-line/expected.json b/test/fixtures/experimental/class-properties/same-line/expected.json new file mode 100644 index 0000000000..c1a6be0ffc --- /dev/null +++ b/test/fixtures/experimental/class-properties/same-line/expected.json @@ -0,0 +1,208 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "static": false, + "value": null + }, + { + "type": "ClassProperty", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "b" + }, + "name": "b" + }, + "static": false, + "value": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + { + "type": "ClassProperty", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "c" + }, + "name": "c" + }, + "static": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/no-class-properties/error-flow-initialized/actual.js b/test/fixtures/experimental/no-class-properties/error-flow-initialized/actual.js new file mode 100644 index 0000000000..222e5a1190 --- /dev/null +++ b/test/fixtures/experimental/no-class-properties/error-flow-initialized/actual.js @@ -0,0 +1,3 @@ +class A { + a = 1; +} \ No newline at end of file diff --git a/test/fixtures/experimental/no-class-properties/error-flow-initialized/options.json b/test/fixtures/experimental/no-class-properties/error-flow-initialized/options.json new file mode 100644 index 0000000000..7c52546da9 --- /dev/null +++ b/test/fixtures/experimental/no-class-properties/error-flow-initialized/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["flow"], + "throws": "Unexpected token (2:4)" +} \ No newline at end of file diff --git a/test/fixtures/experimental/no-class-properties/error-without-plugins/actual.js b/test/fixtures/experimental/no-class-properties/error-without-plugins/actual.js new file mode 100644 index 0000000000..881ddc003a --- /dev/null +++ b/test/fixtures/experimental/no-class-properties/error-without-plugins/actual.js @@ -0,0 +1,3 @@ +class A { + a; b; +} \ No newline at end of file diff --git a/test/fixtures/experimental/no-class-properties/error-without-plugins/options.json b/test/fixtures/experimental/no-class-properties/error-without-plugins/options.json new file mode 100644 index 0000000000..8870c994d6 --- /dev/null +++ b/test/fixtures/experimental/no-class-properties/error-without-plugins/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "Unexpected token, expected ( (2:3)" +} \ No newline at end of file