diff --git a/src/parser/expression.js b/src/parser/expression.js index cfc8442f91..1e1e36cfda 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -1049,11 +1049,14 @@ export default class ExpressionParser extends LValParser { if (this.eat(tt.dot)) { const metaProp = this.parseMetaProperty(node, meta, "target"); - if (!this.state.inFunction) { - this.raise( - metaProp.property.start, - "new.target can only be used in functions", - ); + if (!this.state.inFunction && !this.state.inClassProperty) { + let error = "new.target can only be used in functions"; + + if (this.hasPlugin("classProperties")) { + error += " or class properties"; + } + + this.raise(metaProp.start, error); } return metaProp; diff --git a/test/fixtures/es2015/meta-properties/new-target-invalid/options.json b/test/fixtures/es2015/meta-properties/new-target-invalid/options.json index abb78cbdb2..092a825444 100644 --- a/test/fixtures/es2015/meta-properties/new-target-invalid/options.json +++ b/test/fixtures/es2015/meta-properties/new-target-invalid/options.json @@ -1,3 +1,3 @@ { - "throws": "new.target can only be used in functions (1:4)" + "throws": "new.target can only be used in functions (1:0)" } diff --git a/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json b/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json index 44194382de..a8a536e737 100644 --- a/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json +++ b/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json @@ -1,3 +1,3 @@ { - "throws": "new.target can only be used in functions (1:12)" + "throws": "new.target can only be used in functions (1:8)" } diff --git a/test/fixtures/experimental/class-properties/new-target-invalid/actual.js b/test/fixtures/experimental/class-properties/new-target-invalid/actual.js new file mode 100644 index 0000000000..46b13d0e56 --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target-invalid/actual.js @@ -0,0 +1 @@ +var x = new.target; diff --git a/test/fixtures/experimental/class-properties/new-target-invalid/options.json b/test/fixtures/experimental/class-properties/new-target-invalid/options.json new file mode 100644 index 0000000000..8d36a47b9f --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target-invalid/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["classProperties"], + "throws": "new.target can only be used in functions or class properties (1:8)" +} diff --git a/test/fixtures/experimental/class-properties/new-target-with-flow/actual.js b/test/fixtures/experimental/class-properties/new-target-with-flow/actual.js new file mode 100644 index 0000000000..eaa88bdc31 --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target-with-flow/actual.js @@ -0,0 +1,10 @@ +class X { + static a = new.target; + static b = (foo = 1 + bar(new.target)); + static c = () => new.target; + static d = (foo = new.target) => {}; + e = new.target; + f = (foo = 1 + bar(new.target)); + g = () => new.target; + h = (foo = new.target) => {}; +} diff --git a/test/fixtures/experimental/class-properties/new-target-with-flow/expected.json b/test/fixtures/experimental/class-properties/new-target-with-flow/expected.json new file mode 100644 index 0000000000..2f28593957 --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target-with-flow/expected.json @@ -0,0 +1,1150 @@ +{ + "type": "File", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "X" + }, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 12, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "variance": null, + "value": { + "type": "MetaProperty", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "meta": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "target" + }, + "name": "target" + } + } + }, + { + "type": "ClassProperty", + "start": 37, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false, + "variance": null, + "value": { + "type": "AssignmentExpression", + "start": 49, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "BinaryExpression", + "start": 55, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "left": { + "type": "NumericLiteral", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "CallExpression", + "start": 59, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "callee": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 27 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "arguments": [ + { + "type": "MetaProperty", + "start": 63, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "meta": { + "type": "Identifier", + "start": 63, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 31 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 67, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 38 + }, + "identifierName": "target" + }, + "name": "target" + } + } + ] + } + }, + "extra": { + "parenthesized": true, + "parenStart": 48 + } + } + }, + { + "type": "ClassProperty", + "start": 79, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 30 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 86, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "c" + }, + "name": "c" + }, + "computed": false, + "variance": null, + "value": { + "type": "ArrowFunctionExpression", + "start": 90, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "MetaProperty", + "start": 96, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "meta": { + "type": "Identifier", + "start": 96, + "end": 99, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 22 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 100, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 29 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + }, + { + "type": "ClassProperty", + "start": 110, + "end": 146, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 38 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + }, + "identifierName": "d" + }, + "name": "d" + }, + "computed": false, + "variance": null, + "value": { + "type": "ArrowFunctionExpression", + "start": 121, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 122, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 122, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "MetaProperty", + "start": 128, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "meta": { + "type": "Identifier", + "start": 128, + "end": 131, + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 23 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 132, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 30 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 143, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 35 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ClassProperty", + "start": 149, + "end": 164, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "e" + }, + "name": "e" + }, + "computed": false, + "variance": null, + "value": { + "type": "MetaProperty", + "start": 153, + "end": 163, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "meta": { + "type": "Identifier", + "start": 153, + "end": 156, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 157, + "end": 163, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 16 + }, + "identifierName": "target" + }, + "name": "target" + } + } + }, + { + "type": "ClassProperty", + "start": 167, + "end": 199, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 167, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + }, + "identifierName": "f" + }, + "name": "f" + }, + "computed": false, + "variance": null, + "value": { + "type": "AssignmentExpression", + "start": 172, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 172, + "end": 175, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 10 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "BinaryExpression", + "start": 178, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "left": { + "type": "NumericLiteral", + "start": 178, + "end": 179, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "CallExpression", + "start": 182, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "callee": { + "type": "Identifier", + "start": 182, + "end": 185, + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "arguments": [ + { + "type": "MetaProperty", + "start": 186, + "end": 196, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "meta": { + "type": "Identifier", + "start": 186, + "end": 189, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 24 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 190, + "end": 196, + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 31 + }, + "identifierName": "target" + }, + "name": "target" + } + } + ] + } + }, + "extra": { + "parenthesized": true, + "parenStart": 171 + } + } + }, + { + "type": "ClassProperty", + "start": 202, + "end": 223, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 202, + "end": 203, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + }, + "identifierName": "g" + }, + "name": "g" + }, + "computed": false, + "variance": null, + "value": { + "type": "ArrowFunctionExpression", + "start": 206, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "MetaProperty", + "start": 212, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "meta": { + "type": "Identifier", + "start": 212, + "end": 215, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 216, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 22 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + }, + { + "type": "ClassProperty", + "start": 226, + "end": 255, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 226, + "end": 227, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + }, + "identifierName": "h" + }, + "name": "h" + }, + "computed": false, + "variance": null, + "value": { + "type": "ArrowFunctionExpression", + "start": 230, + "end": 254, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 231, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 231, + "end": 234, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 10 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "MetaProperty", + "start": 237, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "meta": { + "type": "Identifier", + "start": 237, + "end": 240, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 241, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 23 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 252, + "end": 254, + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/new-target-with-flow/options.json b/test/fixtures/experimental/class-properties/new-target-with-flow/options.json new file mode 100644 index 0000000000..eabd25e1b5 --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target-with-flow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classProperties", "flow"] +} diff --git a/test/fixtures/experimental/class-properties/new-target/actual.js b/test/fixtures/experimental/class-properties/new-target/actual.js new file mode 100644 index 0000000000..eaa88bdc31 --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target/actual.js @@ -0,0 +1,10 @@ +class X { + static a = new.target; + static b = (foo = 1 + bar(new.target)); + static c = () => new.target; + static d = (foo = new.target) => {}; + e = new.target; + f = (foo = 1 + bar(new.target)); + g = () => new.target; + h = (foo = new.target) => {}; +} diff --git a/test/fixtures/experimental/class-properties/new-target/expected.json b/test/fixtures/experimental/class-properties/new-target/expected.json new file mode 100644 index 0000000000..0f9788579b --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target/expected.json @@ -0,0 +1,1142 @@ +{ + "type": "File", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "X" + }, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 257, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "body": [ + { + "type": "ClassProperty", + "start": 12, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "value": { + "type": "MetaProperty", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "meta": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "target" + }, + "name": "target" + } + } + }, + { + "type": "ClassProperty", + "start": 37, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false, + "value": { + "type": "AssignmentExpression", + "start": 49, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "BinaryExpression", + "start": 55, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "left": { + "type": "NumericLiteral", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "CallExpression", + "start": 59, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "callee": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 27 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "arguments": [ + { + "type": "MetaProperty", + "start": 63, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "meta": { + "type": "Identifier", + "start": 63, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 31 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 67, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 38 + }, + "identifierName": "target" + }, + "name": "target" + } + } + ] + } + }, + "extra": { + "parenthesized": true, + "parenStart": 48 + } + } + }, + { + "type": "ClassProperty", + "start": 79, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 30 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 86, + "end": 87, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "c" + }, + "name": "c" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 90, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "MetaProperty", + "start": 96, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "meta": { + "type": "Identifier", + "start": 96, + "end": 99, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 22 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 100, + "end": 106, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 29 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + }, + { + "type": "ClassProperty", + "start": 110, + "end": 146, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 38 + } + }, + "static": true, + "key": { + "type": "Identifier", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + }, + "identifierName": "d" + }, + "name": "d" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 121, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 122, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 122, + "end": 125, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "MetaProperty", + "start": 128, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "meta": { + "type": "Identifier", + "start": 128, + "end": 131, + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 23 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 132, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 30 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 143, + "end": 145, + "loc": { + "start": { + "line": 5, + "column": 35 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ClassProperty", + "start": 149, + "end": 164, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 149, + "end": 150, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "e" + }, + "name": "e" + }, + "computed": false, + "value": { + "type": "MetaProperty", + "start": 153, + "end": 163, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "meta": { + "type": "Identifier", + "start": 153, + "end": 156, + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 157, + "end": 163, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 16 + }, + "identifierName": "target" + }, + "name": "target" + } + } + }, + { + "type": "ClassProperty", + "start": 167, + "end": 199, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 34 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 167, + "end": 168, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + }, + "identifierName": "f" + }, + "name": "f" + }, + "computed": false, + "value": { + "type": "AssignmentExpression", + "start": 172, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 172, + "end": 175, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 10 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "BinaryExpression", + "start": 178, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "left": { + "type": "NumericLiteral", + "start": 178, + "end": 179, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "CallExpression", + "start": 182, + "end": 197, + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "callee": { + "type": "Identifier", + "start": 182, + "end": 185, + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "arguments": [ + { + "type": "MetaProperty", + "start": 186, + "end": 196, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "meta": { + "type": "Identifier", + "start": 186, + "end": 189, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 24 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 190, + "end": 196, + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 31 + }, + "identifierName": "target" + }, + "name": "target" + } + } + ] + } + }, + "extra": { + "parenthesized": true, + "parenStart": 171 + } + } + }, + { + "type": "ClassProperty", + "start": 202, + "end": 223, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 202, + "end": 203, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + }, + "identifierName": "g" + }, + "name": "g" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 206, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [], + "body": { + "type": "MetaProperty", + "start": 212, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 22 + } + }, + "meta": { + "type": "Identifier", + "start": 212, + "end": 215, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 216, + "end": 222, + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 22 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + }, + { + "type": "ClassProperty", + "start": 226, + "end": 255, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 226, + "end": 227, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + }, + "identifierName": "h" + }, + "name": "h" + }, + "computed": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 230, + "end": 254, + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 231, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 231, + "end": 234, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 10 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "MetaProperty", + "start": 237, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "meta": { + "type": "Identifier", + "start": 237, + "end": 240, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 241, + "end": 247, + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 23 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 252, + "end": 254, + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-properties/new-target/options.json b/test/fixtures/experimental/class-properties/new-target/options.json new file mode 100644 index 0000000000..9c27576d4a --- /dev/null +++ b/test/fixtures/experimental/class-properties/new-target/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classProperties"] +}