From 69cba43f82fd0257329ea8f202453a92658bcb65 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 6 Jun 2017 17:42:07 +0200 Subject: [PATCH] Fix parsing of private fields (#566) The computed key is not part of the spec. key for ClassProperties is an Expression Do not parse computed and literal keys for PrivateClassProperties --- ast/spec.md | 2 +- src/parser/expression.js | 7 +- src/parser/statement.js | 5 +- src/plugins/flow.js | 1 - src/types.js | 6 +- .../asi-success/expected.json | 4 +- .../actual.js | 2 +- .../options.json | 2 +- .../failure-method/actual.js | 4 + .../options.json | 1 + .../failure-numeric-literal/actual.js | 3 + .../failure-numeric-literal/options.json | 7 + .../failure-string-literal/actual.js | 3 + .../failure-string-literal/options.json | 7 + .../inline/expected.json | 6 +- .../pbn-success.1/actual.js | 19 - .../pbn-success.1/expected.json | 1874 ----------------- .../pbn-success/expected.json | 4 +- 18 files changed, 38 insertions(+), 1919 deletions(-) rename test/fixtures/experimental/class-private-properties/{asi-failure-computed => failure-computed}/actual.js (63%) rename test/fixtures/experimental/class-private-properties/{asi-failure-computed => failure-computed}/options.json (60%) create mode 100644 test/fixtures/experimental/class-private-properties/failure-method/actual.js rename test/fixtures/experimental/class-private-properties/{pbn-success.1 => failure-method}/options.json (55%) create mode 100644 test/fixtures/experimental/class-private-properties/failure-numeric-literal/actual.js create mode 100644 test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json create mode 100644 test/fixtures/experimental/class-private-properties/failure-string-literal/actual.js create mode 100644 test/fixtures/experimental/class-private-properties/failure-string-literal/options.json delete mode 100644 test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js delete mode 100644 test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json diff --git a/ast/spec.md b/ast/spec.md index b5d6517184..f8c675c8c1 100644 --- a/ast/spec.md +++ b/ast/spec.md @@ -1054,7 +1054,7 @@ interface ClassMethod <: Function { ```js interface ClassProperty <: Node { type: "ClassProperty"; - key: Identifier; + key: Expression; value: Expression; computed: boolean; } diff --git a/src/parser/expression.js b/src/parser/expression.js index c66f8cebcd..2e0a22e857 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -578,7 +578,7 @@ export default class ExpressionParser extends LValParser { if (this.hasPlugin("classPrivateProperties")) { return this.parseMaybePrivateName(); } else { - this.unexpected(); + throw this.unexpected(); } case tt._new: @@ -1011,20 +1011,19 @@ export default class ExpressionParser extends LValParser { if (!node) this.unexpected(); } - parsePropertyName(prop: N.ObjectOrClassMember): N.Identifier { + parsePropertyName(prop: N.ObjectOrClassMember): N.Expression { if (this.eat(tt.bracketL)) { - // $FlowFixMe (ClassPrivateMember shouldn't be allowed to be computed!) prop.computed = true; prop.key = this.parseMaybeAssign(); this.expect(tt.bracketR); } else { - // $FlowFixMe (ClassPrivateMember shouldn't be allowed to be computed!) prop.computed = false; const oldInPropertyName = this.state.inPropertyName; this.state.inPropertyName = true; prop.key = (this.match(tt.num) || this.match(tt.string)) ? this.parseExprAtom() : this.parseIdentifier(true); this.state.inPropertyName = oldInPropertyName; } + return prop.key; } diff --git a/src/parser/statement.js b/src/parser/statement.js index 6db7b133cf..610f7b4f53 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -642,9 +642,7 @@ export default class StatementParser extends ExpressionParser { isNonstaticConstructor(method: N.ClassMethod | N.ClassProperty): boolean { return !method.computed && !method.static && ( - // $FlowFixMe ('key' downcasting) (method.key.name === "constructor") || // Identifier - // $FlowFixMe ('key' downcasting) (method.key.value === "constructor") // Literal ); } @@ -707,7 +705,7 @@ export default class StatementParser extends ExpressionParser { if (this.hasPlugin("classPrivateProperties") && this.match(tt.hash)) { // Private property this.next(); const privateProp: N.ClassPrivateProperty = memberAny; - this.parsePropertyName(privateProp); + privateProp.key = this.parseIdentifier(true); classBody.body.push(this.parsePrivateClassProperty(privateProp)); return; } @@ -749,7 +747,6 @@ export default class StatementParser extends ExpressionParser { const isSimple = this.match(tt.name); const key = this.parsePropertyName(methodOrProp); - // $FlowFixMe ('key' downcasting) if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) { this.raise(methodOrProp.key.start, "Classes may not have static property named prototype"); } diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 29e61d2732..5329fef875 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -1294,7 +1294,6 @@ export default (superClass: Class): Class => class extends super parsePropertyName(node: N.ObjectOrClassMember): N.Identifier { const variance = this.flowParseVariance(); const key = super.parsePropertyName(node); - // $FlowFixMe (variance not defined on ClassPrivateProperty) node.variance = variance; return key; } diff --git a/src/types.js b/src/types.js index 23597835fd..950c2fdc6f 100644 --- a/src/types.js +++ b/src/types.js @@ -339,7 +339,7 @@ export type ObjectExpression = NodeBase & { properties: $ReadOnlyArray; }; -export type ObjectOrClassMember = ClassMethod | ClassProperty | ClassPrivateProperty | ObjectMember; +export type ObjectOrClassMember = ClassMethod | ClassProperty | ObjectMember; export type ObjectMember = ObjectProperty | ObjectMethod; @@ -359,7 +359,7 @@ export type ObjectProperty = ObjectMemberBase & { shorthand: boolean; }; -export type ObjectMethod = ObjectMemberBase & MethodBase & { +export type ObjectMethod = ObjectMemberBase & MethodBase & { type: "ObjectMethod"; kind: "get" | "set" | "method"; // Never "constructor" }; @@ -579,7 +579,7 @@ export type ClassMethod = MethodBase & ClassMemberBase & { export type ClassProperty = ClassMemberBase & { type: "ClassProperty"; - key: Identifier; + key: Expression; value: ?Expression; // TODO: Not in spec that this is nullable. typeAnnotation?: ?FlowTypeAnnotation; // TODO: Not in spec diff --git a/test/fixtures/experimental/class-private-properties/asi-success/expected.json b/test/fixtures/experimental/class-private-properties/asi-success/expected.json index 8aa723ae03..d9b6ffff9c 100644 --- a/test/fixtures/experimental/class-private-properties/asi-success/expected.json +++ b/test/fixtures/experimental/class-private-properties/asi-success/expected.json @@ -89,7 +89,6 @@ "column": 4 } }, - "computed": false, "key": { "type": "Identifier", "start": 15, @@ -123,7 +122,6 @@ "column": 4 } }, - "computed": false, "key": { "type": "Identifier", "start": 20, @@ -149,4 +147,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-private-properties/asi-failure-computed/actual.js b/test/fixtures/experimental/class-private-properties/failure-computed/actual.js similarity index 63% rename from test/fixtures/experimental/class-private-properties/asi-failure-computed/actual.js rename to test/fixtures/experimental/class-private-properties/failure-computed/actual.js index 0fb2172e4d..14786041ca 100644 --- a/test/fixtures/experimental/class-private-properties/asi-failure-computed/actual.js +++ b/test/fixtures/experimental/class-private-properties/failure-computed/actual.js @@ -1,4 +1,4 @@ class Foo { #p = x - [#m] () {} + #[m] = 1 } diff --git a/test/fixtures/experimental/class-private-properties/asi-failure-computed/options.json b/test/fixtures/experimental/class-private-properties/failure-computed/options.json similarity index 60% rename from test/fixtures/experimental/class-private-properties/asi-failure-computed/options.json rename to test/fixtures/experimental/class-private-properties/failure-computed/options.json index 31d89fa474..5e6d8d079a 100644 --- a/test/fixtures/experimental/class-private-properties/asi-failure-computed/options.json +++ b/test/fixtures/experimental/class-private-properties/failure-computed/options.json @@ -1,5 +1,5 @@ { - "throws": "Unexpected token, expected ; (3:10)", + "throws": "Unexpected token (3:3)", "plugins": [ "classProperties", "classPrivateProperties" diff --git a/test/fixtures/experimental/class-private-properties/failure-method/actual.js b/test/fixtures/experimental/class-private-properties/failure-method/actual.js new file mode 100644 index 0000000000..2d0523cd43 --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-method/actual.js @@ -0,0 +1,4 @@ +class Foo { + #p = x + #m () {} +} diff --git a/test/fixtures/experimental/class-private-properties/pbn-success.1/options.json b/test/fixtures/experimental/class-private-properties/failure-method/options.json similarity index 55% rename from test/fixtures/experimental/class-private-properties/pbn-success.1/options.json rename to test/fixtures/experimental/class-private-properties/failure-method/options.json index 19c38d2996..6110b91af1 100644 --- a/test/fixtures/experimental/class-private-properties/pbn-success.1/options.json +++ b/test/fixtures/experimental/class-private-properties/failure-method/options.json @@ -1,3 +1,4 @@ { + "throws": "Unexpected token, expected ; (3:5)", "plugins": ["classProperties", "classPrivateProperties"] } diff --git a/test/fixtures/experimental/class-private-properties/failure-numeric-literal/actual.js b/test/fixtures/experimental/class-private-properties/failure-numeric-literal/actual.js new file mode 100644 index 0000000000..82864c6391 --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-numeric-literal/actual.js @@ -0,0 +1,3 @@ +class Foo { + #2 = y +} diff --git a/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json b/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json new file mode 100644 index 0000000000..2ca966904a --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json @@ -0,0 +1,7 @@ +{ + "throws": "Unexpected token (2:3)", + "plugins": [ + "classProperties", + "classPrivateProperties" + ] +} diff --git a/test/fixtures/experimental/class-private-properties/failure-string-literal/actual.js b/test/fixtures/experimental/class-private-properties/failure-string-literal/actual.js new file mode 100644 index 0000000000..3d1db965c1 --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-string-literal/actual.js @@ -0,0 +1,3 @@ +class Foo { + #"p" = x +} diff --git a/test/fixtures/experimental/class-private-properties/failure-string-literal/options.json b/test/fixtures/experimental/class-private-properties/failure-string-literal/options.json new file mode 100644 index 0000000000..2ca966904a --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-string-literal/options.json @@ -0,0 +1,7 @@ +{ + "throws": "Unexpected token (2:3)", + "plugins": [ + "classProperties", + "classPrivateProperties" + ] +} diff --git a/test/fixtures/experimental/class-private-properties/inline/expected.json b/test/fixtures/experimental/class-private-properties/inline/expected.json index abb56c7d32..79e5aa820a 100644 --- a/test/fixtures/experimental/class-private-properties/inline/expected.json +++ b/test/fixtures/experimental/class-private-properties/inline/expected.json @@ -89,7 +89,6 @@ "column": 13 } }, - "computed": false, "key": { "type": "Identifier", "start": 11, @@ -123,7 +122,6 @@ "column": 17 } }, - "computed": false, "key": { "type": "Identifier", "start": 15, @@ -207,7 +205,6 @@ "column": 17 } }, - "computed": false, "key": { "type": "Identifier", "start": 32, @@ -260,7 +257,6 @@ "column": 25 } }, - "computed": false, "key": { "type": "Identifier", "start": 40, @@ -305,4 +301,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js b/test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js deleted file mode 100644 index 457eaabf1a..0000000000 --- a/test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js +++ /dev/null @@ -1,19 +0,0 @@ -class Point { - #x; - #y; - - constructor(x = 0, y = 0) { - #x = +x; - #y = +y; - } - - get x() { return this.#x } - set x(value) { this.#x = +value } - - get y() { return this.#y } - set y(value) { this.#y = +value } - - equals(p) { return this.#x === p.#x && this.#y === p.#y } - - toString() { return `Point<${ this.#x },${ this.#y }>` } -} diff --git a/test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json b/test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json deleted file mode 100644 index b462f3ed7a..0000000000 --- a/test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json +++ /dev/null @@ -1,1874 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 369, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 19, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 369, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 19, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 369, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 19, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 11 - }, - "identifierName": "Point" - }, - "name": "Point" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 12, - "end": 369, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 19, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateProperty", - "start": 18, - "end": 21, - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "computed": false, - "key": { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "x" - }, - "name": "x" - }, - "value": null - }, - { - "type": "ClassPrivateProperty", - "start": 26, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 7 - } - }, - "computed": false, - "key": { - "type": "Identifier", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 6 - }, - "identifierName": "y" - }, - "name": "y" - }, - "value": null - }, - { - "type": "ClassMethod", - "start": 35, - "end": 102, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 8, - "column": 5 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 35, - "end": 46, - "loc": { - "start": { - "line": 5, - "column": 4 - }, - "end": { - "line": 5, - "column": 15 - }, - "identifierName": "constructor" - }, - "name": "constructor" - }, - "kind": "constructor", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [ - { - "type": "AssignmentPattern", - "start": 47, - "end": 52, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 21 - } - }, - "left": { - "type": "Identifier", - "start": 47, - "end": 48, - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 17 - }, - "identifierName": "x" - }, - "name": "x" - }, - "right": { - "type": "NumericLiteral", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 5, - "column": 20 - }, - "end": { - "line": 5, - "column": 21 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - } - }, - { - "type": "AssignmentPattern", - "start": 54, - "end": 59, - "loc": { - "start": { - "line": 5, - "column": 23 - }, - "end": { - "line": 5, - "column": 28 - } - }, - "left": { - "type": "Identifier", - "start": 54, - "end": 55, - "loc": { - "start": { - "line": 5, - "column": 23 - }, - "end": { - "line": 5, - "column": 24 - }, - "identifierName": "y" - }, - "name": "y" - }, - "right": { - "type": "NumericLiteral", - "start": 58, - "end": 59, - "loc": { - "start": { - "line": 5, - "column": 27 - }, - "end": { - "line": 5, - "column": 28 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - } - } - ], - "body": { - "type": "BlockStatement", - "start": 61, - "end": 102, - "loc": { - "start": { - "line": 5, - "column": 30 - }, - "end": { - "line": 8, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 71, - "end": 79, - "loc": { - "start": { - "line": 6, - "column": 8 - }, - "end": { - "line": 6, - "column": 16 - } - }, - "expression": { - "type": "AssignmentExpression", - "start": 71, - "end": 78, - "loc": { - "start": { - "line": 6, - "column": 8 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "operator": "=", - "left": { - "type": "PrivateName", - "start": 72, - "end": 73, - "loc": { - "start": { - "line": 6, - "column": 9 - }, - "end": { - "line": 6, - "column": 10 - } - }, - "name": { - "type": "Identifier", - "start": 72, - "end": 73, - "loc": { - "start": { - "line": 6, - "column": 9 - }, - "end": { - "line": 6, - "column": 10 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "right": { - "type": "UnaryExpression", - "start": 76, - "end": 78, - "loc": { - "start": { - "line": 6, - "column": 13 - }, - "end": { - "line": 6, - "column": 15 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "Identifier", - "start": 77, - "end": 78, - "loc": { - "start": { - "line": 6, - "column": 14 - }, - "end": { - "line": 6, - "column": 15 - }, - "identifierName": "x" - }, - "name": "x" - }, - "extra": { - "parenthesizedArgument": false - } - } - } - }, - { - "type": "ExpressionStatement", - "start": 88, - "end": 96, - "loc": { - "start": { - "line": 7, - "column": 8 - }, - "end": { - "line": 7, - "column": 16 - } - }, - "expression": { - "type": "AssignmentExpression", - "start": 88, - "end": 95, - "loc": { - "start": { - "line": 7, - "column": 8 - }, - "end": { - "line": 7, - "column": 15 - } - }, - "operator": "=", - "left": { - "type": "PrivateName", - "start": 89, - "end": 90, - "loc": { - "start": { - "line": 7, - "column": 9 - }, - "end": { - "line": 7, - "column": 10 - } - }, - "name": { - "type": "Identifier", - "start": 89, - "end": 90, - "loc": { - "start": { - "line": 7, - "column": 9 - }, - "end": { - "line": 7, - "column": 10 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "right": { - "type": "UnaryExpression", - "start": 93, - "end": 95, - "loc": { - "start": { - "line": 7, - "column": 13 - }, - "end": { - "line": 7, - "column": 15 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "Identifier", - "start": 94, - "end": 95, - "loc": { - "start": { - "line": 7, - "column": 14 - }, - "end": { - "line": 7, - "column": 15 - }, - "identifierName": "y" - }, - "name": "y" - }, - "extra": { - "parenthesizedArgument": false - } - } - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 108, - "end": 134, - "loc": { - "start": { - "line": 10, - "column": 4 - }, - "end": { - "line": 10, - "column": 30 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 112, - "end": 113, - "loc": { - "start": { - "line": 10, - "column": 8 - }, - "end": { - "line": 10, - "column": 9 - }, - "identifierName": "x" - }, - "name": "x" - }, - "kind": "get", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 116, - "end": 134, - "loc": { - "start": { - "line": 10, - "column": 12 - }, - "end": { - "line": 10, - "column": 30 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 118, - "end": 132, - "loc": { - "start": { - "line": 10, - "column": 14 - }, - "end": { - "line": 10, - "column": 28 - } - }, - "argument": { - "type": "MemberExpression", - "start": 125, - "end": 132, - "loc": { - "start": { - "line": 10, - "column": 21 - }, - "end": { - "line": 10, - "column": 28 - } - }, - "object": { - "type": "ThisExpression", - "start": 125, - "end": 129, - "loc": { - "start": { - "line": 10, - "column": 21 - }, - "end": { - "line": 10, - "column": 25 - } - } - }, - "property": { - "type": "PrivateName", - "start": 131, - "end": 132, - "loc": { - "start": { - "line": 10, - "column": 27 - }, - "end": { - "line": 10, - "column": 28 - } - }, - "name": { - "type": "Identifier", - "start": 131, - "end": 132, - "loc": { - "start": { - "line": 10, - "column": 27 - }, - "end": { - "line": 10, - "column": 28 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 139, - "end": 172, - "loc": { - "start": { - "line": 11, - "column": 4 - }, - "end": { - "line": 11, - "column": 37 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 143, - "end": 144, - "loc": { - "start": { - "line": 11, - "column": 8 - }, - "end": { - "line": 11, - "column": 9 - }, - "identifierName": "x" - }, - "name": "x" - }, - "kind": "set", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 145, - "end": 150, - "loc": { - "start": { - "line": 11, - "column": 10 - }, - "end": { - "line": 11, - "column": 15 - }, - "identifierName": "value" - }, - "name": "value" - } - ], - "body": { - "type": "BlockStatement", - "start": 152, - "end": 172, - "loc": { - "start": { - "line": 11, - "column": 17 - }, - "end": { - "line": 11, - "column": 37 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 154, - "end": 170, - "loc": { - "start": { - "line": 11, - "column": 19 - }, - "end": { - "line": 11, - "column": 35 - } - }, - "expression": { - "type": "AssignmentExpression", - "start": 154, - "end": 170, - "loc": { - "start": { - "line": 11, - "column": 19 - }, - "end": { - "line": 11, - "column": 35 - } - }, - "operator": "=", - "left": { - "type": "MemberExpression", - "start": 154, - "end": 161, - "loc": { - "start": { - "line": 11, - "column": 19 - }, - "end": { - "line": 11, - "column": 26 - } - }, - "object": { - "type": "ThisExpression", - "start": 154, - "end": 158, - "loc": { - "start": { - "line": 11, - "column": 19 - }, - "end": { - "line": 11, - "column": 23 - } - } - }, - "property": { - "type": "PrivateName", - "start": 160, - "end": 161, - "loc": { - "start": { - "line": 11, - "column": 25 - }, - "end": { - "line": 11, - "column": 26 - } - }, - "name": { - "type": "Identifier", - "start": 160, - "end": 161, - "loc": { - "start": { - "line": 11, - "column": 25 - }, - "end": { - "line": 11, - "column": 26 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false - }, - "right": { - "type": "UnaryExpression", - "start": 164, - "end": 170, - "loc": { - "start": { - "line": 11, - "column": 29 - }, - "end": { - "line": 11, - "column": 35 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "Identifier", - "start": 165, - "end": 170, - "loc": { - "start": { - "line": 11, - "column": 30 - }, - "end": { - "line": 11, - "column": 35 - }, - "identifierName": "value" - }, - "name": "value" - }, - "extra": { - "parenthesizedArgument": false - } - } - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 178, - "end": 204, - "loc": { - "start": { - "line": 13, - "column": 4 - }, - "end": { - "line": 13, - "column": 30 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 182, - "end": 183, - "loc": { - "start": { - "line": 13, - "column": 8 - }, - "end": { - "line": 13, - "column": 9 - }, - "identifierName": "y" - }, - "name": "y" - }, - "kind": "get", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 186, - "end": 204, - "loc": { - "start": { - "line": 13, - "column": 12 - }, - "end": { - "line": 13, - "column": 30 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 188, - "end": 202, - "loc": { - "start": { - "line": 13, - "column": 14 - }, - "end": { - "line": 13, - "column": 28 - } - }, - "argument": { - "type": "MemberExpression", - "start": 195, - "end": 202, - "loc": { - "start": { - "line": 13, - "column": 21 - }, - "end": { - "line": 13, - "column": 28 - } - }, - "object": { - "type": "ThisExpression", - "start": 195, - "end": 199, - "loc": { - "start": { - "line": 13, - "column": 21 - }, - "end": { - "line": 13, - "column": 25 - } - } - }, - "property": { - "type": "PrivateName", - "start": 201, - "end": 202, - "loc": { - "start": { - "line": 13, - "column": 27 - }, - "end": { - "line": 13, - "column": 28 - } - }, - "name": { - "type": "Identifier", - "start": 201, - "end": 202, - "loc": { - "start": { - "line": 13, - "column": 27 - }, - "end": { - "line": 13, - "column": 28 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "computed": false - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 209, - "end": 242, - "loc": { - "start": { - "line": 14, - "column": 4 - }, - "end": { - "line": 14, - "column": 37 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 213, - "end": 214, - "loc": { - "start": { - "line": 14, - "column": 8 - }, - "end": { - "line": 14, - "column": 9 - }, - "identifierName": "y" - }, - "name": "y" - }, - "kind": "set", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 215, - "end": 220, - "loc": { - "start": { - "line": 14, - "column": 10 - }, - "end": { - "line": 14, - "column": 15 - }, - "identifierName": "value" - }, - "name": "value" - } - ], - "body": { - "type": "BlockStatement", - "start": 222, - "end": 242, - "loc": { - "start": { - "line": 14, - "column": 17 - }, - "end": { - "line": 14, - "column": 37 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 224, - "end": 240, - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 35 - } - }, - "expression": { - "type": "AssignmentExpression", - "start": 224, - "end": 240, - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 35 - } - }, - "operator": "=", - "left": { - "type": "MemberExpression", - "start": 224, - "end": 231, - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 26 - } - }, - "object": { - "type": "ThisExpression", - "start": 224, - "end": 228, - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 23 - } - } - }, - "property": { - "type": "PrivateName", - "start": 230, - "end": 231, - "loc": { - "start": { - "line": 14, - "column": 25 - }, - "end": { - "line": 14, - "column": 26 - } - }, - "name": { - "type": "Identifier", - "start": 230, - "end": 231, - "loc": { - "start": { - "line": 14, - "column": 25 - }, - "end": { - "line": 14, - "column": 26 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "computed": false - }, - "right": { - "type": "UnaryExpression", - "start": 234, - "end": 240, - "loc": { - "start": { - "line": 14, - "column": 29 - }, - "end": { - "line": 14, - "column": 35 - } - }, - "operator": "+", - "prefix": true, - "argument": { - "type": "Identifier", - "start": 235, - "end": 240, - "loc": { - "start": { - "line": 14, - "column": 30 - }, - "end": { - "line": 14, - "column": 35 - }, - "identifierName": "value" - }, - "name": "value" - }, - "extra": { - "parenthesizedArgument": false - } - } - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 248, - "end": 305, - "loc": { - "start": { - "line": 16, - "column": 4 - }, - "end": { - "line": 16, - "column": 61 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 248, - "end": 254, - "loc": { - "start": { - "line": 16, - "column": 4 - }, - "end": { - "line": 16, - "column": 10 - }, - "identifierName": "equals" - }, - "name": "equals" - }, - "kind": "method", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 255, - "end": 256, - "loc": { - "start": { - "line": 16, - "column": 11 - }, - "end": { - "line": 16, - "column": 12 - }, - "identifierName": "p" - }, - "name": "p" - } - ], - "body": { - "type": "BlockStatement", - "start": 258, - "end": 305, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 61 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 260, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 16 - }, - "end": { - "line": 16, - "column": 59 - } - }, - "argument": { - "type": "LogicalExpression", - "start": 267, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 59 - } - }, - "left": { - "type": "BinaryExpression", - "start": 267, - "end": 283, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 39 - } - }, - "left": { - "type": "MemberExpression", - "start": 267, - "end": 274, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 30 - } - }, - "object": { - "type": "ThisExpression", - "start": 267, - "end": 271, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 27 - } - } - }, - "property": { - "type": "PrivateName", - "start": 273, - "end": 274, - "loc": { - "start": { - "line": 16, - "column": 29 - }, - "end": { - "line": 16, - "column": 30 - } - }, - "name": { - "type": "Identifier", - "start": 273, - "end": 274, - "loc": { - "start": { - "line": 16, - "column": 29 - }, - "end": { - "line": 16, - "column": 30 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false - }, - "operator": "===", - "right": { - "type": "MemberExpression", - "start": 279, - "end": 283, - "loc": { - "start": { - "line": 16, - "column": 35 - }, - "end": { - "line": 16, - "column": 39 - } - }, - "object": { - "type": "Identifier", - "start": 279, - "end": 280, - "loc": { - "start": { - "line": 16, - "column": 35 - }, - "end": { - "line": 16, - "column": 36 - }, - "identifierName": "p" - }, - "name": "p" - }, - "property": { - "type": "PrivateName", - "start": 282, - "end": 283, - "loc": { - "start": { - "line": 16, - "column": 38 - }, - "end": { - "line": 16, - "column": 39 - } - }, - "name": { - "type": "Identifier", - "start": 282, - "end": 283, - "loc": { - "start": { - "line": 16, - "column": 38 - }, - "end": { - "line": 16, - "column": 39 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false - } - }, - "operator": "&&", - "right": { - "type": "BinaryExpression", - "start": 287, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 43 - }, - "end": { - "line": 16, - "column": 59 - } - }, - "left": { - "type": "MemberExpression", - "start": 287, - "end": 294, - "loc": { - "start": { - "line": 16, - "column": 43 - }, - "end": { - "line": 16, - "column": 50 - } - }, - "object": { - "type": "ThisExpression", - "start": 287, - "end": 291, - "loc": { - "start": { - "line": 16, - "column": 43 - }, - "end": { - "line": 16, - "column": 47 - } - } - }, - "property": { - "type": "PrivateName", - "start": 293, - "end": 294, - "loc": { - "start": { - "line": 16, - "column": 49 - }, - "end": { - "line": 16, - "column": 50 - } - }, - "name": { - "type": "Identifier", - "start": 293, - "end": 294, - "loc": { - "start": { - "line": 16, - "column": 49 - }, - "end": { - "line": 16, - "column": 50 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "computed": false - }, - "operator": "===", - "right": { - "type": "MemberExpression", - "start": 299, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 55 - }, - "end": { - "line": 16, - "column": 59 - } - }, - "object": { - "type": "Identifier", - "start": 299, - "end": 300, - "loc": { - "start": { - "line": 16, - "column": 55 - }, - "end": { - "line": 16, - "column": 56 - }, - "identifierName": "p" - }, - "name": "p" - }, - "property": { - "type": "PrivateName", - "start": 302, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 58 - }, - "end": { - "line": 16, - "column": 59 - } - }, - "name": { - "type": "Identifier", - "start": 302, - "end": 303, - "loc": { - "start": { - "line": 16, - "column": 58 - }, - "end": { - "line": 16, - "column": 59 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "computed": false - } - } - } - } - ], - "directives": [] - } - }, - { - "type": "ClassMethod", - "start": 311, - "end": 367, - "loc": { - "start": { - "line": 18, - "column": 4 - }, - "end": { - "line": 18, - "column": 60 - } - }, - "static": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 311, - "end": 319, - "loc": { - "start": { - "line": 18, - "column": 4 - }, - "end": { - "line": 18, - "column": 12 - }, - "identifierName": "toString" - }, - "name": "toString" - }, - "kind": "method", - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 322, - "end": 367, - "loc": { - "start": { - "line": 18, - "column": 15 - }, - "end": { - "line": 18, - "column": 60 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 324, - "end": 365, - "loc": { - "start": { - "line": 18, - "column": 17 - }, - "end": { - "line": 18, - "column": 58 - } - }, - "argument": { - "type": "TemplateLiteral", - "start": 331, - "end": 365, - "loc": { - "start": { - "line": 18, - "column": 24 - }, - "end": { - "line": 18, - "column": 58 - } - }, - "expressions": [ - { - "type": "MemberExpression", - "start": 341, - "end": 348, - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 41 - } - }, - "object": { - "type": "ThisExpression", - "start": 341, - "end": 345, - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 38 - } - } - }, - "property": { - "type": "PrivateName", - "start": 347, - "end": 348, - "loc": { - "start": { - "line": 18, - "column": 40 - }, - "end": { - "line": 18, - "column": 41 - } - }, - "name": { - "type": "Identifier", - "start": 347, - "end": 348, - "loc": { - "start": { - "line": 18, - "column": 40 - }, - "end": { - "line": 18, - "column": 41 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false - }, - { - "type": "MemberExpression", - "start": 354, - "end": 361, - "loc": { - "start": { - "line": 18, - "column": 47 - }, - "end": { - "line": 18, - "column": 54 - } - }, - "object": { - "type": "ThisExpression", - "start": 354, - "end": 358, - "loc": { - "start": { - "line": 18, - "column": 47 - }, - "end": { - "line": 18, - "column": 51 - } - } - }, - "property": { - "type": "PrivateName", - "start": 360, - "end": 361, - "loc": { - "start": { - "line": 18, - "column": 53 - }, - "end": { - "line": 18, - "column": 54 - } - }, - "name": { - "type": "Identifier", - "start": 360, - "end": 361, - "loc": { - "start": { - "line": 18, - "column": 53 - }, - "end": { - "line": 18, - "column": 54 - }, - "identifierName": "y" - }, - "name": "y" - } - }, - "computed": false - } - ], - "quasis": [ - { - "type": "TemplateElement", - "start": 332, - "end": 338, - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 31 - } - }, - "value": { - "raw": "Point<", - "cooked": "Point<" - }, - "tail": false - }, - { - "type": "TemplateElement", - "start": 350, - "end": 351, - "loc": { - "start": { - "line": 18, - "column": 43 - }, - "end": { - "line": 18, - "column": 44 - } - }, - "value": { - "raw": ",", - "cooked": "," - }, - "tail": false - }, - { - "type": "TemplateElement", - "start": 363, - "end": 364, - "loc": { - "start": { - "line": 18, - "column": 56 - }, - "end": { - "line": 18, - "column": 57 - } - }, - "value": { - "raw": ">", - "cooked": ">" - }, - "tail": true - } - ] - } - } - ], - "directives": [] - } - } - ] - } - } - ], - "directives": [] - } -} diff --git a/test/fixtures/experimental/class-private-properties/pbn-success/expected.json b/test/fixtures/experimental/class-private-properties/pbn-success/expected.json index 837f95fee8..b8a4aa6558 100644 --- a/test/fixtures/experimental/class-private-properties/pbn-success/expected.json +++ b/test/fixtures/experimental/class-private-properties/pbn-success/expected.json @@ -89,7 +89,6 @@ "column": 7 } }, - "computed": false, "key": { "type": "Identifier", "start": 19, @@ -123,7 +122,6 @@ "column": 7 } }, - "computed": false, "key": { "type": "Identifier", "start": 27, @@ -1623,4 +1621,4 @@ ], "directives": [] } -} +} \ No newline at end of file