diff --git a/src/parser/statement.js b/src/parser/statement.js index 179be68b76..840ea098e2 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -625,11 +625,18 @@ pp.parseClass = function (node, isStatement, optionalId) { }; pp.isClassProperty = function () { - return this.match(tt.eq) || this.isLineTerminator(); + return this.match(tt.eq) || this.match(tt.semi) || this.match(tt.braceR); }; -pp.isClassMutatorStarter = function () { - return false; +pp.isClassMethod = function () { + return this.match(tt.parenL); +}; + +pp.isNonstaticConstructor = function (method) { + return !method.computed && !method.static && ( + (method.key.name === "constructor") || // Identifier + (method.key.value === "constructor") // Literal + ); }; pp.parseClassBody = function (node) { @@ -664,92 +671,102 @@ pp.parseClassBody = function (node) { decorators = []; } - let isConstructorCall = false; - const isMaybeStatic = this.match(tt.name) && this.state.value === "static"; - let isGenerator = this.eat(tt.star); - let isGetSet = false; - let isAsync = false; - - this.parsePropertyName(method); - - method.static = isMaybeStatic && !this.match(tt.parenL); - if (method.static) { - isGenerator = this.eat(tt.star); - this.parsePropertyName(method); - } - - if (!isGenerator) { - if (this.isClassProperty()) { + method.static = false; + if (this.match(tt.name) && this.state.value === "static") { + const key = this.parseIdentifier(true); // eats 'static' + if (this.isClassMethod()) { + // a method named 'static' + method.kind = "method"; + method.computed = false; + method.key = key; + this.parseClassMethod(classBody, method, false, false); + continue; + } else if (this.isClassProperty()) { + // a property named 'static' + method.computed = false; + method.key = key; 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") { - isConstructorCall = true; - this.parsePropertyName(method); - } + // otherwise something static + method.static = true; } - const isAsyncMethod = !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async"; - if (isAsyncMethod) { - if (this.hasPlugin("asyncGenerators") && this.eat(tt.star)) isGenerator = true; - isAsync = true; + if (this.eat(tt.star)) { + // a generator + method.kind = "method"; this.parsePropertyName(method); - } - - method.kind = "method"; - - if (!method.computed) { - let { key } = method; - - // 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")) { - isGetSet = true; - method.kind = key.name; - key = this.parsePropertyName(method); + if (this.isNonstaticConstructor(method)) { + this.raise(method.key.start, "Constructor can't be a generator"); } - - // disallow invalid constructors - const isConstructor = !isConstructorCall && !method.static && ( - (key.name === "constructor") || // Identifier - (key.value === "constructor") // Literal - ); - if (isConstructor) { - if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class"); - if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier"); - if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); - if (isAsync) this.raise(key.start, "Constructor can't be an async function"); - method.kind = "constructor"; - hadConstructor = true; + if (!method.computed && method.static && (method.key.name === "prototype" || method.key.value === "prototype")) { + this.raise(method.key.start, "Classes may not have static property named prototype"); } - - // disallow static prototype method - const isStaticPrototype = method.static && ( - (key.name === "prototype") || // Identifier - (key.value === "prototype") // Literal - ); - if (isStaticPrototype) { - this.raise(key.start, "Classes may not have static property named prototype"); + this.parseClassMethod(classBody, method, true, false); + } else { + const isSimple = this.match(tt.name); + const key = this.parsePropertyName(method); + if (!method.computed && method.static && (method.key.name === "prototype" || method.key.value === "prototype")) { + this.raise(method.key.start, "Classes may not have static property named prototype"); + } + if (this.isClassMethod()) { + // a normal method + if (this.isNonstaticConstructor(method)) { + if (hadConstructor) { + this.raise(key.start, "Duplicate constructor in the same class"); + } else if (method.decorators) { + this.raise(method.start, "You can't attach decorators to a class constructor"); + } + hadConstructor = true; + method.kind = "constructor"; + } else { + method.kind = "method"; + } + this.parseClassMethod(classBody, method, false, false); + } else if (this.isClassProperty()) { + // a normal property + if (this.isNonstaticConstructor(method)) { + this.raise(method.key.start, "Classes may not have a non-static field named 'constructor'"); + } + classBody.body.push(this.parseClassProperty(method)); + } else if (isSimple && key.name === "async" && !this.isLineTerminator()) { + // an async method + const isGenerator = this.hasPlugin("asyncGenerators") && this.eat(tt.star); + method.kind = "method"; + this.parsePropertyName(method); + if (this.isNonstaticConstructor(method)) { + this.raise(method.key.start, "Constructor can't be an async function"); + } + this.parseClassMethod(classBody, method, isGenerator, true); + } else if (isSimple && (key.name === "get" || key.name === "set") && !(this.isLineTerminator() && this.match(tt.star))) { // `get\n*` is an uninitialized property named 'get' followed by a generator. + // a getter or setter + method.kind = key.name; + this.parsePropertyName(method); + if (this.isNonstaticConstructor(method)) { + this.raise(method.key.start, "Constructor can't have get/set modifier"); + } + this.parseClassMethod(classBody, method, false, false); + this.checkGetterSetterParamCount(method); + } else if (this.hasPlugin("classConstructorCall") && isSimple && key.name === "call" && this.match(tt.name) && this.state.value === "constructor") { + // a (deprecated) call constructor + if (hadConstructorCall) { + this.raise(method.start, "Duplicate constructor call in the same class"); + } else if (method.decorators) { + this.raise(method.start, "You can't attach decorators to a class constructor"); + } + hadConstructorCall = true; + method.kind = "constructorCall"; + this.parsePropertyName(method); // consume "constructor" and make it the method's name + this.parseClassMethod(classBody, method, false, false); + } else if (this.isLineTerminator()) { + // an uninitialized class property (due to ASI, since we don't otherwise recognize the next token) + if (this.isNonstaticConstructor(method)) { + this.raise(method.key.start, "Classes may not have a non-static field named 'constructor'"); + } + classBody.body.push(this.parseClassProperty(method)); + } else { + this.unexpected(); } - } - - // convert constructor to a constructor call - if (isConstructorCall) { - if (hadConstructorCall) this.raise(method.start, "Duplicate constructor call in the same class"); - method.kind = "constructorCall"; - hadConstructorCall = true; - } - - // disallow decorators on class constructors - if ((method.kind === "constructor" || method.kind === "constructorCall") && method.decorators) { - this.raise(method.start, "You can't attach decorators to a class constructor"); - } - - this.parseClassMethod(classBody, method, isGenerator, isAsync); - - if (isGetSet) { - this.checkGetterSetterParamCount(method); } } diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 14f5b48562..21f55e1ca6 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -1120,6 +1120,13 @@ export default function (instance) { }; }); + // determine whether or not we're currently in the position where a class method would appear + instance.extend("isClassMethod", function (inner) { + return function () { + return this.isRelational("<") || inner.call(this); + }; + }); + // determine whether or not we're currently in the position where a class property would appear instance.extend("isClassProperty", function (inner) { return function () { @@ -1450,14 +1457,4 @@ export default function (instance) { return this.match(tt.colon) || inner.call(this); }; }); - - instance.extend("isClassMutatorStarter", function (inner) { - return function () { - if (this.isRelational("<")) { - return true; - } else { - return inner.call(this); - } - }; - }); } diff --git a/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/actual.js b/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/actual.js new file mode 100644 index 0000000000..d96088851c --- /dev/null +++ b/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/actual.js @@ -0,0 +1,3 @@ +class A { + static *prototype() {} +} \ No newline at end of file diff --git a/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/options.json b/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/options.json new file mode 100644 index 0000000000..00c025e551 --- /dev/null +++ b/test/fixtures/es2015/class-methods/disallow-static-generator-prototype/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Classes may not have static property named prototype (2:10)" +} \ No newline at end of file diff --git a/test/fixtures/es2015/class-methods/linebreaks/actual.js b/test/fixtures/es2015/class-methods/linebreaks/actual.js new file mode 100644 index 0000000000..4c68e68f03 --- /dev/null +++ b/test/fixtures/es2015/class-methods/linebreaks/actual.js @@ -0,0 +1,42 @@ +class A { + get + a + () {} + + set + a + (a) {} + + constructor + () {} + + a + () {} + + * + a + () {} + + static + get + a + () {} + + static + set + a + (a) {} + + static + constructor + () {} + + static + a + () {} + + static + * + a + () {} +} \ No newline at end of file diff --git a/test/fixtures/es2015/class-methods/linebreaks/expected.json b/test/fixtures/es2015/class-methods/linebreaks/expected.json new file mode 100644 index 0000000000..62dcad3c53 --- /dev/null +++ b/test/fixtures/es2015/class-methods/linebreaks/expected.json @@ -0,0 +1,690 @@ +{ + "type": "File", + "start": 0, + "end": 239, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 42, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 239, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 42, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 239, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 42, + "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": 239, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 42, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "static": false, + "kind": "get", + "computed": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 31, + "end": 47, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "static": false, + "kind": "set", + "computed": false, + "key": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + } + ], + "body": { + "type": "BlockStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 51, + "end": 70, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 51, + "end": 62, + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 13 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "kind": "constructor", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 68, + "end": 70, + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 74, + "end": 83, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 74, + "end": 75, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 81, + "end": 83, + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 87, + "end": 100, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 91, + "end": 92, + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 98, + "end": 100, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 104, + "end": 128, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 23, + "column": 7 + } + }, + "static": true, + "kind": "get", + "computed": false, + "key": { + "type": "Identifier", + "start": 119, + "end": 120, + "loc": { + "start": { + "line": 22, + "column": 2 + }, + "end": { + "line": 22, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 126, + "end": 128, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 132, + "end": 157, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 28, + "column": 8 + } + }, + "static": true, + "kind": "set", + "computed": false, + "key": { + "type": "Identifier", + "start": 147, + "end": 148, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 27, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 152, + "end": 153, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + } + ], + "body": { + "type": "BlockStatement", + "start": 155, + "end": 157, + "loc": { + "start": { + "line": 28, + "column": 6 + }, + "end": { + "line": 28, + "column": 8 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 161, + "end": 189, + "loc": { + "start": { + "line": 30, + "column": 2 + }, + "end": { + "line": 32, + "column": 7 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 170, + "end": 181, + "loc": { + "start": { + "line": 31, + "column": 2 + }, + "end": { + "line": 31, + "column": 13 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 187, + "end": 189, + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 193, + "end": 211, + "loc": { + "start": { + "line": 34, + "column": 2 + }, + "end": { + "line": 36, + "column": 7 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 202, + "end": 203, + "loc": { + "start": { + "line": 35, + "column": 2 + }, + "end": { + "line": 35, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 209, + "end": 211, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 215, + "end": 237, + "loc": { + "start": { + "line": 38, + "column": 2 + }, + "end": { + "line": 41, + "column": 7 + } + }, + "static": true, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 228, + "end": 229, + "loc": { + "start": { + "line": 40, + "column": 2 + }, + "end": { + "line": 40, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 235, + "end": 237, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 7 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/class-methods/tricky-names/actual.js b/test/fixtures/es2015/class-methods/tricky-names/actual.js new file mode 100644 index 0000000000..35e8ddeefe --- /dev/null +++ b/test/fixtures/es2015/class-methods/tricky-names/actual.js @@ -0,0 +1,45 @@ +class A { + get + () {} + + set + () {} + + static + () {} + + async + () {} + + + static + get + () {} + + static + set + () {} + + static + static + () {} + + static + async + () {} + + static + a + () {} + + + get + async + () {} + + + static + get + static + () {} +} \ No newline at end of file diff --git a/test/fixtures/es2015/class-methods/tricky-names/expected.json b/test/fixtures/es2015/class-methods/tricky-names/expected.json new file mode 100644 index 0000000000..27b74a271b --- /dev/null +++ b/test/fixtures/es2015/class-methods/tricky-names/expected.json @@ -0,0 +1,711 @@ +{ + "type": "File", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 45, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 45, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 45, + "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": 257, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 45, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "get" + }, + "name": "get" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 27, + "end": 38, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 27, + "end": 30, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "set" + }, + "name": "set" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 42, + "end": 56, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 42, + "end": 48, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 54, + "end": 56, + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 60, + "end": 73, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 60, + "end": 65, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 71, + "end": 73, + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 78, + "end": 98, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "static": true, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 87, + "end": 90, + "loc": { + "start": { + "line": 16, + "column": 2 + }, + "end": { + "line": 16, + "column": 5 + }, + "identifierName": "get" + }, + "name": "get" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 96, + "end": 98, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 102, + "end": 122, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 21, + "column": 7 + } + }, + "static": true, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 111, + "end": 114, + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + }, + "identifierName": "set" + }, + "name": "set" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 120, + "end": 122, + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 126, + "end": 149, + "loc": { + "start": { + "line": 23, + "column": 2 + }, + "end": { + "line": 25, + "column": 7 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 135, + "end": 141, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 147, + "end": 149, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 153, + "end": 175, + "loc": { + "start": { + "line": 27, + "column": 2 + }, + "end": { + "line": 29, + "column": 7 + } + }, + "static": true, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 162, + "end": 167, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 28, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 173, + "end": 175, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 179, + "end": 197, + "loc": { + "start": { + "line": 31, + "column": 2 + }, + "end": { + "line": 33, + "column": 7 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 188, + "end": 189, + "loc": { + "start": { + "line": 32, + "column": 2 + }, + "end": { + "line": 32, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 195, + "end": 197, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 202, + "end": 221, + "loc": { + "start": { + "line": 36, + "column": 2 + }, + "end": { + "line": 38, + "column": 7 + } + }, + "static": false, + "kind": "get", + "computed": false, + "key": { + "type": "Identifier", + "start": 208, + "end": 213, + "loc": { + "start": { + "line": 37, + "column": 2 + }, + "end": { + "line": 37, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 219, + "end": 221, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 7 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 226, + "end": 255, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 44, + "column": 7 + } + }, + "static": true, + "kind": "get", + "computed": false, + "key": { + "type": "Identifier", + "start": 241, + "end": 247, + "loc": { + "start": { + "line": 43, + "column": 2 + }, + "end": { + "line": 43, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 253, + "end": 255, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 7 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2017/async-functions/no-method-asi/actual.js b/test/fixtures/es2017/async-functions/no-method-asi/actual.js new file mode 100644 index 0000000000..3ed61ad65f --- /dev/null +++ b/test/fixtures/es2017/async-functions/no-method-asi/actual.js @@ -0,0 +1,4 @@ +class A { + async + a(){} +} \ No newline at end of file diff --git a/test/fixtures/es2017/async-functions/no-method-asi/options.json b/test/fixtures/es2017/async-functions/no-method-asi/options.json new file mode 100644 index 0000000000..af38bd1530 --- /dev/null +++ b/test/fixtures/es2017/async-functions/no-method-asi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" +} diff --git a/test/fixtures/esprima/invalid-syntax/migrated_0268/options.json b/test/fixtures/esprima/invalid-syntax/migrated_0268/options.json index 021ac49e5f..89bfc2d73f 100644 --- a/test/fixtures/esprima/invalid-syntax/migrated_0268/options.json +++ b/test/fixtures/esprima/invalid-syntax/migrated_0268/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected ( (1:10)" + "throws": "Unexpected token (1:10)" } diff --git a/test/fixtures/esprima/invalid-syntax/migrated_0275/options.json b/test/fixtures/esprima/invalid-syntax/migrated_0275/options.json index 609492567c..cb6c66081e 100644 --- a/test/fixtures/esprima/invalid-syntax/migrated_0275/options.json +++ b/test/fixtures/esprima/invalid-syntax/migrated_0275/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected ( (1:11)" + "throws": "Unexpected token (1:11)" } diff --git a/test/fixtures/esprima/invalid-syntax/migrated_0276/options.json b/test/fixtures/esprima/invalid-syntax/migrated_0276/options.json index cd71808039..562afcef48 100644 --- a/test/fixtures/esprima/invalid-syntax/migrated_0276/options.json +++ b/test/fixtures/esprima/invalid-syntax/migrated_0276/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected ( (1:23)" + "throws": "Unexpected token (1:23)" } diff --git a/test/fixtures/experimental/async-generators/class-method-2/actual.js b/test/fixtures/experimental/async-generators/class-method-2/actual.js new file mode 100644 index 0000000000..fd3dc7f8ae --- /dev/null +++ b/test/fixtures/experimental/async-generators/class-method-2/actual.js @@ -0,0 +1,4 @@ +class A { + async * + a(){} +} diff --git a/test/fixtures/experimental/async-generators/class-method-2/expected.json b/test/fixtures/experimental/async-generators/class-method-2/expected.json new file mode 100644 index 0000000000..d0dfc49fa8 --- /dev/null +++ b/test/fixtures/experimental/async-generators/class-method-2/expected.json @@ -0,0 +1,141 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 29, + "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": 29, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": true, + "expression": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "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/async-generators/class-method-no-asi/actual.js b/test/fixtures/experimental/async-generators/class-method-no-asi/actual.js new file mode 100644 index 0000000000..4b42b64210 --- /dev/null +++ b/test/fixtures/experimental/async-generators/class-method-no-asi/actual.js @@ -0,0 +1,4 @@ +class A { + async + * a(){} +} diff --git a/test/fixtures/experimental/async-generators/class-method-no-asi/options.json b/test/fixtures/experimental/async-generators/class-method-no-asi/options.json new file mode 100644 index 0000000000..af38bd1530 --- /dev/null +++ b/test/fixtures/experimental/async-generators/class-method-no-asi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" +} diff --git a/test/fixtures/experimental/class-constructor-call/disallow-decorator/actual.js b/test/fixtures/experimental/class-constructor-call/disallow-decorator/actual.js new file mode 100644 index 0000000000..c63f1e9880 --- /dev/null +++ b/test/fixtures/experimental/class-constructor-call/disallow-decorator/actual.js @@ -0,0 +1,4 @@ +class Foo { + @dec + call constructor() {} +} diff --git a/test/fixtures/experimental/class-constructor-call/disallow-decorator/options.json b/test/fixtures/experimental/class-constructor-call/disallow-decorator/options.json new file mode 100644 index 0000000000..75152c7974 --- /dev/null +++ b/test/fixtures/experimental/class-constructor-call/disallow-decorator/options.json @@ -0,0 +1,4 @@ +{ + "throws": "You can't attach decorators to a class constructor (3:2)", + "plugins": ["classConstructorCall", "decorators"] +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-constructor-call/disallow-duplicate/actual.js b/test/fixtures/experimental/class-constructor-call/disallow-duplicate/actual.js new file mode 100644 index 0000000000..6fd5dd7d11 --- /dev/null +++ b/test/fixtures/experimental/class-constructor-call/disallow-duplicate/actual.js @@ -0,0 +1,4 @@ +class Foo { + call constructor() {} + call constructor() {} +} diff --git a/test/fixtures/experimental/class-constructor-call/disallow-duplicate/options.json b/test/fixtures/experimental/class-constructor-call/disallow-duplicate/options.json new file mode 100644 index 0000000000..e13cd0e258 --- /dev/null +++ b/test/fixtures/experimental/class-constructor-call/disallow-duplicate/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Duplicate constructor call in the same class (3:2)" +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-constructor-call/illegal-key/options.json b/test/fixtures/experimental/class-constructor-call/illegal-key/options.json index 606cbed9d9..4e84114247 100644 --- a/test/fixtures/experimental/class-constructor-call/illegal-key/options.json +++ b/test/fixtures/experimental/class-constructor-call/illegal-key/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected ( (2:7)" + "throws": "Unexpected token (2:7)" } diff --git a/test/fixtures/experimental/class-properties/asi-failure-inline/actual.js b/test/fixtures/experimental/class-properties/asi-failure-inline/actual.js new file mode 100644 index 0000000000..efddc05595 --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-failure-inline/actual.js @@ -0,0 +1,3 @@ +class Foo { + x y +} diff --git a/test/fixtures/experimental/class-properties/asi-failure-inline/options.json b/test/fixtures/experimental/class-properties/asi-failure-inline/options.json new file mode 100644 index 0000000000..2a11366381 --- /dev/null +++ b/test/fixtures/experimental/class-properties/asi-failure-inline/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Unexpected token (2:4)", + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/edge-cases/actual.js b/test/fixtures/experimental/class-properties/edge-cases/actual.js new file mode 100644 index 0000000000..539a3ccff8 --- /dev/null +++ b/test/fixtures/experimental/class-properties/edge-cases/actual.js @@ -0,0 +1,50 @@ +class A1 { + static + a + static +} + +class A2 { a } +class A3 { get } +class A4 { set } +class A5 { static } +class A6 { async } + +class A7 { + get + *a(){} +} + +class A8 { + static + *a(){} +} + +class A9 { + async + a(){} +} + +class A10 { + static + async + a +} + +class A11 { static; } + +class A12 { + static = 0; +} + +class A13 { + get + ['a'](){} +} + +class A14 { + static + get + static + (){} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/edge-cases/expected.json b/test/fixtures/experimental/class-properties/edge-cases/expected.json new file mode 100644 index 0000000000..3a41800a0b --- /dev/null +++ b/test/fixtures/experimental/class-properties/edge-cases/expected.json @@ -0,0 +1,1496 @@ +{ + "type": "File", + "start": 0, + "end": 381, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 381, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "A1" + }, + "name": "A1" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 9, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 13, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": null + }, + { + "type": "ClassProperty", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 36, + "end": 50, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 8 + }, + "identifierName": "A2" + }, + "name": "A2" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 45, + "end": 50, + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 51, + "end": 67, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 57, + "end": 59, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 8 + }, + "identifierName": "A3" + }, + "name": "A3" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 60, + "end": 67, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 16 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 62, + "end": 65, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 62, + "end": 65, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 14 + }, + "identifierName": "get" + }, + "name": "get" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 68, + "end": 84, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 74, + "end": 76, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 8 + }, + "identifierName": "A4" + }, + "name": "A4" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 77, + "end": 84, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 16 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 79, + "end": 82, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 14 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 79, + "end": 82, + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 14 + }, + "identifierName": "set" + }, + "name": "set" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 85, + "end": 104, + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 91, + "end": 93, + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 8 + }, + "identifierName": "A5" + }, + "name": "A5" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 94, + "end": 104, + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 96, + "end": 102, + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 10, + "column": 17 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 96, + "end": 102, + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 10, + "column": 17 + }, + "identifierName": "static" + }, + "name": "static" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 105, + "end": 123, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 111, + "end": 113, + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 8 + }, + "identifierName": "A6" + }, + "name": "A6" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 114, + "end": 123, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 18 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 116, + "end": 121, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 116, + "end": 121, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 16 + }, + "identifierName": "async" + }, + "name": "async" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 125, + "end": 152, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 131, + "end": 133, + "loc": { + "start": { + "line": 13, + "column": 6 + }, + "end": { + "line": 13, + "column": 8 + }, + "identifierName": "A7" + }, + "name": "A7" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 134, + "end": 152, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 138, + "end": 141, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 138, + "end": 141, + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 5 + }, + "identifierName": "get" + }, + "name": "get" + }, + "value": null + }, + { + "type": "ClassMethod", + "start": 144, + "end": 150, + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "static": false, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 145, + "end": 146, + "loc": { + "start": { + "line": 15, + "column": 3 + }, + "end": { + "line": 15, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 148, + "end": 150, + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 154, + "end": 184, + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 21, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 160, + "end": 162, + "loc": { + "start": { + "line": 18, + "column": 6 + }, + "end": { + "line": 18, + "column": 8 + }, + "identifierName": "A8" + }, + "name": "A8" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 163, + "end": 184, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 21, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 167, + "end": 182, + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 20, + "column": 8 + } + }, + "static": true, + "kind": "method", + "computed": false, + "key": { + "type": "Identifier", + "start": 177, + "end": 178, + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 180, + "end": 182, + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 8 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 186, + "end": 214, + "loc": { + "start": { + "line": 23, + "column": 0 + }, + "end": { + "line": 26, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 192, + "end": 194, + "loc": { + "start": { + "line": 23, + "column": 6 + }, + "end": { + "line": 23, + "column": 8 + }, + "identifierName": "A9" + }, + "name": "A9" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 195, + "end": 214, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 26, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 199, + "end": 204, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 7 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 199, + "end": 204, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "value": null + }, + { + "type": "ClassMethod", + "start": 207, + "end": 212, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 7 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 207, + "end": 208, + "loc": { + "start": { + "line": 25, + "column": 2 + }, + "end": { + "line": 25, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 210, + "end": 212, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 7 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 216, + "end": 250, + "loc": { + "start": { + "line": 28, + "column": 0 + }, + "end": { + "line": 32, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 222, + "end": 225, + "loc": { + "start": { + "line": 28, + "column": 6 + }, + "end": { + "line": 28, + "column": 9 + }, + "identifierName": "A10" + }, + "name": "A10" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 226, + "end": 250, + "loc": { + "start": { + "line": 28, + "column": 10 + }, + "end": { + "line": 32, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 230, + "end": 244, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 30, + "column": 7 + } + }, + "static": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 239, + "end": 244, + "loc": { + "start": { + "line": 30, + "column": 2 + }, + "end": { + "line": 30, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "value": null + }, + { + "type": "ClassProperty", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 31, + "column": 2 + }, + "end": { + "line": 31, + "column": 3 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 31, + "column": 2 + }, + "end": { + "line": 31, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 252, + "end": 273, + "loc": { + "start": { + "line": 34, + "column": 0 + }, + "end": { + "line": 34, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 258, + "end": 261, + "loc": { + "start": { + "line": 34, + "column": 6 + }, + "end": { + "line": 34, + "column": 9 + }, + "identifierName": "A11" + }, + "name": "A11" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 262, + "end": 273, + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 21 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 264, + "end": 271, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 19 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 264, + "end": 270, + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 18 + }, + "identifierName": "static" + }, + "name": "static" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 275, + "end": 302, + "loc": { + "start": { + "line": 36, + "column": 0 + }, + "end": { + "line": 38, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 281, + "end": 284, + "loc": { + "start": { + "line": 36, + "column": 6 + }, + "end": { + "line": 36, + "column": 9 + }, + "identifierName": "A12" + }, + "name": "A12" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 285, + "end": 302, + "loc": { + "start": { + "line": 36, + "column": 10 + }, + "end": { + "line": 38, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 289, + "end": 300, + "loc": { + "start": { + "line": 37, + "column": 2 + }, + "end": { + "line": 37, + "column": 13 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 289, + "end": 295, + "loc": { + "start": { + "line": 37, + "column": 2 + }, + "end": { + "line": 37, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "value": { + "type": "NumericLiteral", + "start": 298, + "end": 299, + "loc": { + "start": { + "line": 37, + "column": 11 + }, + "end": { + "line": 37, + "column": 12 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 304, + "end": 335, + "loc": { + "start": { + "line": 40, + "column": 0 + }, + "end": { + "line": 43, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 310, + "end": 313, + "loc": { + "start": { + "line": 40, + "column": 6 + }, + "end": { + "line": 40, + "column": 9 + }, + "identifierName": "A13" + }, + "name": "A13" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 314, + "end": 335, + "loc": { + "start": { + "line": 40, + "column": 10 + }, + "end": { + "line": 43, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 318, + "end": 333, + "loc": { + "start": { + "line": 41, + "column": 2 + }, + "end": { + "line": 42, + "column": 11 + } + }, + "static": false, + "kind": "get", + "computed": true, + "key": { + "type": "StringLiteral", + "start": 325, + "end": 328, + "loc": { + "start": { + "line": 42, + "column": 3 + }, + "end": { + "line": 42, + "column": 6 + } + }, + "extra": { + "rawValue": "a", + "raw": "'a'" + }, + "value": "a" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 331, + "end": 333, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 11 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 337, + "end": 381, + "loc": { + "start": { + "line": 45, + "column": 0 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 343, + "end": 346, + "loc": { + "start": { + "line": 45, + "column": 6 + }, + "end": { + "line": 45, + "column": 9 + }, + "identifierName": "A14" + }, + "name": "A14" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 347, + "end": 381, + "loc": { + "start": { + "line": 45, + "column": 10 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 351, + "end": 379, + "loc": { + "start": { + "line": 46, + "column": 2 + }, + "end": { + "line": 49, + "column": 6 + } + }, + "static": true, + "kind": "get", + "computed": false, + "key": { + "type": "Identifier", + "start": 366, + "end": 372, + "loc": { + "start": { + "line": 48, + "column": 2 + }, + "end": { + "line": 48, + "column": 8 + }, + "identifierName": "static" + }, + "name": "static" + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 377, + "end": 379, + "loc": { + "start": { + "line": 49, + "column": 4 + }, + "end": { + "line": 49, + "column": 6 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/edge-cases/options.json b/test/fixtures/experimental/class-properties/edge-cases/options.json new file mode 100644 index 0000000000..9c27576d4a --- /dev/null +++ b/test/fixtures/experimental/class-properties/edge-cases/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/inline/actual.js b/test/fixtures/experimental/class-properties/inline/actual.js new file mode 100644 index 0000000000..615a25ab4e --- /dev/null +++ b/test/fixtures/experimental/class-properties/inline/actual.js @@ -0,0 +1,3 @@ +class A { x; y; } + +class B { x = 0; y = 1; } diff --git a/test/fixtures/experimental/class-properties/inline/expected.json b/test/fixtures/experimental/class-properties/inline/expected.json new file mode 100644 index 0000000000..d5369121bb --- /dev/null +++ b/test/fixtures/experimental/class-properties/inline/expected.json @@ -0,0 +1,312 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "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": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": null + }, + { + "type": "ClassProperty", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start": 19, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "B" + }, + "name": "B" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 27, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 29, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassProperty", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "NumericLiteral", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/inline/options.json b/test/fixtures/experimental/class-properties/inline/options.json new file mode 100644 index 0000000000..9c27576d4a --- /dev/null +++ b/test/fixtures/experimental/class-properties/inline/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/no-ctor/actual.js b/test/fixtures/experimental/class-properties/no-ctor/actual.js new file mode 100644 index 0000000000..581943685f --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-ctor/actual.js @@ -0,0 +1,3 @@ +class Foo { + constructor +} diff --git a/test/fixtures/experimental/class-properties/no-ctor/options.json b/test/fixtures/experimental/class-properties/no-ctor/options.json new file mode 100644 index 0000000000..9884529d32 --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-ctor/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Classes may not have a non-static field named 'constructor' (2:2)", + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/no-static-prototype-2/actual.js b/test/fixtures/experimental/class-properties/no-static-prototype-2/actual.js new file mode 100644 index 0000000000..a7eb328656 --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-static-prototype-2/actual.js @@ -0,0 +1,4 @@ +class Foo { + static prototype + *x(){} +} diff --git a/test/fixtures/experimental/class-properties/no-static-prototype-2/options.json b/test/fixtures/experimental/class-properties/no-static-prototype-2/options.json new file mode 100644 index 0000000000..5bde2716eb --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-static-prototype-2/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Classes may not have static property named prototype (2:9)", + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/class-properties/no-static-prototype/actual.js b/test/fixtures/experimental/class-properties/no-static-prototype/actual.js new file mode 100644 index 0000000000..f7a9f68dfe --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-static-prototype/actual.js @@ -0,0 +1,3 @@ +class Foo { + static prototype +} diff --git a/test/fixtures/experimental/class-properties/no-static-prototype/options.json b/test/fixtures/experimental/class-properties/no-static-prototype/options.json new file mode 100644 index 0000000000..5bde2716eb --- /dev/null +++ b/test/fixtures/experimental/class-properties/no-static-prototype/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Classes may not have static property named prototype (2:9)", + "plugins": ["classProperties"] +} diff --git a/test/fixtures/experimental/decorators/export-decorators-on-class/actual.js b/test/fixtures/experimental/decorators/export-decorators-on-class/actual.js new file mode 100644 index 0000000000..51804c6056 --- /dev/null +++ b/test/fixtures/experimental/decorators/export-decorators-on-class/actual.js @@ -0,0 +1,2 @@ +@foo +export default class {} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/export-decorators-on-class/expected.json b/test/fixtures/experimental/decorators/export-decorators-on-class/expected.json new file mode 100644 index 0000000000..343060fcaf --- /dev/null +++ b/test/fixtures/experimental/decorators/export-decorators-on-class/expected.json @@ -0,0 +1,116 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 5, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "declaration": { + "type": "ClassDeclaration", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "body": [] + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/export-decorators-on-class/options.json b/test/fixtures/experimental/decorators/export-decorators-on-class/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/experimental/decorators/export-decorators-on-class/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators/no-constructor-decorators/actual.js b/test/fixtures/experimental/decorators/no-constructor-decorators/actual.js new file mode 100644 index 0000000000..4387084bbf --- /dev/null +++ b/test/fixtures/experimental/decorators/no-constructor-decorators/actual.js @@ -0,0 +1,4 @@ +class Foo { + @abc + constructor(){} +} diff --git a/test/fixtures/experimental/decorators/no-constructor-decorators/options.json b/test/fixtures/experimental/decorators/no-constructor-decorators/options.json new file mode 100644 index 0000000000..c0baef5996 --- /dev/null +++ b/test/fixtures/experimental/decorators/no-constructor-decorators/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can't attach decorators to a class constructor (3:2)" +} diff --git a/test/fixtures/experimental/decorators/no-export-decorators-without-class/actual.js b/test/fixtures/experimental/decorators/no-export-decorators-without-class/actual.js new file mode 100644 index 0000000000..c5a55d643f --- /dev/null +++ b/test/fixtures/experimental/decorators/no-export-decorators-without-class/actual.js @@ -0,0 +1,2 @@ +@foo +export default function f(){}; \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json b/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json new file mode 100644 index 0000000000..61c2c23daa --- /dev/null +++ b/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json @@ -0,0 +1,4 @@ +{ + "throws": "You can only use decorators on an export when exporting a class (2:0)", + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators/no-export-decorators/actual.js b/test/fixtures/experimental/decorators/no-export-decorators/actual.js new file mode 100644 index 0000000000..4630d555a4 --- /dev/null +++ b/test/fixtures/experimental/decorators/no-export-decorators/actual.js @@ -0,0 +1,2 @@ +@foo +export default 0; \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/no-export-decorators/options.json b/test/fixtures/experimental/decorators/no-export-decorators/options.json new file mode 100644 index 0000000000..61c2c23daa --- /dev/null +++ b/test/fixtures/experimental/decorators/no-export-decorators/options.json @@ -0,0 +1,4 @@ +{ + "throws": "You can only use decorators on an export when exporting a class (2:0)", + "sourceType": "module" +}