From ce87518e662a3193521bba2e93ee61c1cc258229 Mon Sep 17 00:00:00 2001 From: Karl Cheng Date: Sat, 2 Sep 2017 01:18:01 +1000 Subject: [PATCH] Change Identifier to PrivateName, ban #constructor, fix error position --- src/parser/expression.js | 27 ++-- src/parser/statement.js | 113 ++++++---------- src/parser/util.js | 8 +- .../async-generator/expected.json | 25 +++- .../class-private-methods/async/expected.json | 25 +++- .../combined/expected.json | 100 +++++++++++--- .../failure-name-constructor/actual.js | 3 + .../failure-name-constructor/options.json | 7 + .../failure-no-plugin/options.json | 2 +- .../generator/expected.json | 24 +++- .../get-set/expected.json | 50 +++++-- .../method/expected.json | 24 +++- .../asi-success/expected.json | 52 +++++-- .../failure-name-constructor/actual.js | 3 + .../failure-name-constructor/options.json | 7 + .../inline/expected.json | 102 +++++++++++--- .../nested/expected.json | 128 +++++++++++++----- .../pbn-success/expected.json | 64 ++++++--- .../static/expected.json | 52 +++++-- 19 files changed, 576 insertions(+), 240 deletions(-) create mode 100644 test/fixtures/experimental/class-private-methods/failure-name-constructor/actual.js create mode 100644 test/fixtures/experimental/class-private-methods/failure-name-constructor/options.json create mode 100644 test/fixtures/experimental/class-private-properties/failure-name-constructor/actual.js create mode 100644 test/fixtures/experimental/class-private-properties/failure-name-constructor/options.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 407b7c1ef1..6e7cdd587c 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -1398,35 +1398,28 @@ export default class ExpressionParser extends LValParser { } parsePropertyName( - prop: N.ObjectOrClassMember | N.TsNamedTypeElementBase, - ): N.Expression { + prop: N.ObjectOrClassMember | N.ClassPrivateProperty | N.ClassPrivateMethod | N.TsNamedTypeElementBase, + ): N.Expression | N.Identifier { if (this.eat(tt.bracketL)) { prop.computed = true; prop.key = this.parseMaybeAssign(); this.expect(tt.bracketR); } else { - 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; - } + : this.parseMaybePrivateName(); - return prop.key; - } + // TODO: if no plugin and is PrivateName, should error be handled here or elsewhere? + if (prop.key.type !== "PrivateName") { + // ClassPrivateProperty is never computed, so we don't assign in that case. + prop.computed = false; + } - // FIXME: does this make sense separate? - parseClassPrivateName( - prop: N.ClassPrivateProperty | N.ClassPrivateMethod, - ): N.Expression { - prop.computed = false; - const oldInPropertyName = this.state.inPropertyName; - this.state.inPropertyName = true; - prop.key = this.parseIdentifier(true); - this.state.inPropertyName = oldInPropertyName; + this.state.inPropertyName = oldInPropertyName; + } return prop.key; } diff --git a/src/parser/statement.js b/src/parser/statement.js index f97c561672..655ddae32f 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -978,12 +978,11 @@ export default class StatementParser extends ExpressionParser { if (this.eat(tt.star)) { // a generator method.kind = "method"; + this.parseClassPropertyName(method); - if (this.match(tt.hash)) { - this.expectPlugin("classPrivateMethods"); - this.next(); + if (method.key.type === "PrivateName") { + this.expectPlugin("classPrivateMethods", method.key.start); // Private generator method - this.parseClassPrivateName(method); this.parseClassPrivateMethod( classBody, method, @@ -994,21 +993,10 @@ export default class StatementParser extends ExpressionParser { return; } - this.parsePropertyName(method); - if (this.isNonstaticConstructor(method)) { this.raise(method.key.start, "Constructor can't be a generator"); } - 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", - ); - } + this.parseClassMethod( classBody, method, @@ -1016,20 +1004,23 @@ export default class StatementParser extends ExpressionParser { false, /* isConstructor */ false, ); + return; } - const isPrivate = this.match(tt.hash); - if (isPrivate) { - this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); - // Skip over the hash. - this.next(); - } + const key = this.parseClassPropertyName(methodOrProp); + let isPrivate = key.type === "PrivateName"; + const isSimple = !isPrivate && !key.computed; - const isSimple = this.match(tt.name); - const key = isPrivate - ? this.parseClassPrivateName(methodOrProp) - : this.parseClassPropertyName(methodOrProp); + const handleClassProperty = () => { + if (isPrivate) { + this.expectPlugin("classPrivateProperties", key.start); + // Private property + classBody.body.push(this.parseClassPrivateProperty(prop)); + } else { + this.pushClassProperty(classBody, prop); + } + }; this.parsePostMemberNameModifiers(methodOrProp); @@ -1037,9 +1028,7 @@ export default class StatementParser extends ExpressionParser { method.kind = "method"; if (isPrivate) { - // TODO: seems a bit inconsistent error throwing: in some cases we've already - // eaten the #, but in other cases we haven't. How to solve? - this.expectPlugin("classPrivateMethods"); + this.expectPlugin("classPrivateMethods", key.start); this.parseClassPrivateMethod( classBody, method, @@ -1072,13 +1061,7 @@ export default class StatementParser extends ExpressionParser { this.parseClassMethod(classBody, method, false, false, isConstructor); } else if (this.isClassProperty()) { - if (isPrivate) { - this.expectPlugin("classPrivateProperties"); - // Private property - classBody.body.push(this.parseClassPrivateProperty(prop)); - } else { - this.pushClassProperty(classBody, prop); - } + handleClassProperty(); } else if (isSimple && key.name === "async" && !this.isLineTerminator()) { // an async method let isGenerator = false; @@ -1088,14 +1071,12 @@ export default class StatementParser extends ExpressionParser { isGenerator = true; } method.kind = "method"; + // The so-called parsed name would have been "async": get the real name. + this.parseClassPropertyName(method); - if (this.match(tt.hash)) { + if (method.key.type === "PrivateName") { + this.expectPlugin("classPrivateMethods", method.key.start); // private async method - this.expectPlugin("classPrivateMethods"); - // The private # wouldn't have been eaten yet as the "async" was in front of it. - this.next(); - // The so-called parsed name would have been "async": get the real name. - this.parseClassPrivateName(method); this.parseClassPrivateMethod( classBody, method, @@ -1104,7 +1085,6 @@ export default class StatementParser extends ExpressionParser { /* isConstructor */ false, ); } else { - this.parsePropertyName(method); if (this.isNonstaticConstructor(method)) { this.raise( method.key.start, @@ -1127,14 +1107,12 @@ export default class StatementParser extends ExpressionParser { // `get\n*` is an uninitialized property named 'get' followed by a generator. // a getter or setter method.kind = key.name; + // The so-called parsed name would have been "get/set": get the real name. + this.parseClassPropertyName(method); - if (this.match(tt.hash)) { + if (method.key.type === "PrivateName") { + this.expectPlugin("classPrivateMethods", method.key.start); // private getter/setter - this.expectPlugin("classPrivateMethods"); - // The private # wouldn't have been eaten yet as the "get/set" was in front of it. - this.next(); - // The so-called parsed name would have been "get/set": get the real name. - this.parseClassPrivateName(method); this.parseClassPrivateMethod( classBody, method, @@ -1143,7 +1121,6 @@ export default class StatementParser extends ExpressionParser { /* isConstructor */ false, ); } else { - this.parsePropertyName(method); if (this.isNonstaticConstructor(method)) { this.raise( method.key.start, @@ -1162,43 +1139,37 @@ export default class StatementParser extends ExpressionParser { this.checkGetterSetterParamCount(method); } else if (this.isLineTerminator()) { // an uninitialized class property (due to ASI, since we don't otherwise recognize the next token) - if (isPrivate) { - this.expectPlugin("classPrivateProperties"); - // Private property - classBody.body.push(this.parseClassPrivateProperty(prop)); - } else { - if (this.isNonstaticConstructor(prop)) { - this.raise( - prop.key.start, - "Classes may not have a non-static field named 'constructor'", - ); - } - classBody.body.push(this.parseClassProperty(prop)); - } + handleClassProperty(); } else { this.unexpected(); } } parseClassPropertyName( - methodOrProp: N.ClassMethod | N.ClassProperty, - ): N.Expression { + methodOrProp: N.ClassMethod | N.ClassProperty | N.ClassPrivateProperty | N.ClassPrivateMethod, + ): N.Expression | N.Identifier { const key = this.parsePropertyName(methodOrProp); if ( !methodOrProp.computed && methodOrProp.static && - (methodOrProp.key.name === "prototype" || - methodOrProp.key.value === "prototype") + (key.name === "prototype" || key.value === "prototype") ) { this.raise( - methodOrProp.key.start, + key.start, "Classes may not have static property named prototype", ); } + if (key.type === 'PrivateName' && key.id.name === 'constructor') { + this.raise( + key.start, + "Classes may not have a private field named '#constructor'", + ); + } return key; } pushClassProperty(classBody: N.ClassBody, prop: N.ClassProperty) { + // FIXME: inconsistent placement? if (this.isNonstaticConstructor(prop)) { this.raise( prop.key.start, @@ -1223,10 +1194,7 @@ export default class StatementParser extends ExpressionParser { node: N.ClassPrivateProperty, ): N.ClassPrivateProperty { this.state.inClassProperty = true; - - if (node.computed !== undefined) node.computed = undefined; node.value = this.eat(tt.eq) ? this.parseMaybeAssign() : null; - this.semicolon(); this.state.inClassProperty = false; return this.finishNode(node, "ClassPrivateProperty"); @@ -1275,14 +1243,13 @@ export default class StatementParser extends ExpressionParser { method: N.ClassMethod, isGenerator: boolean, isAsync: boolean, - isConstructor: boolean, ): void { classBody.body.push( this.parseMethod( method, isGenerator, isAsync, - isConstructor, + /* isConstructor */ false, "ClassPrivateMethod", ), ); diff --git a/src/parser/util.js b/src/parser/util.js index 52587e3322..d17bad782b 100644 --- a/src/parser/util.js +++ b/src/parser/util.js @@ -110,20 +110,20 @@ export default class UtilParser extends Tokenizer { throw this.raise(pos != null ? pos : this.state.start, messageOrType); } - expectPlugin(name: string): void { + expectPlugin(name: string, pos?: ?number): void { if (!this.hasPlugin(name)) { throw this.raise( - this.state.start, + pos != null ? pos : this.state.start, `This experimental syntax requires enabling the parser plugin: '${name}'`, [name], ); } } - expectOnePlugin(names: Array): void { + expectOnePlugin(names: Array, pos?: ?number): void { if (!names.some(n => this.hasPlugin(n))) { throw this.raise( - this.state.start, + pos != null ? pos : this.state.start, `This experimental syntax requires enabling one of the following parser plugin(s): '${names.join( ", ", )}'`, diff --git a/test/fixtures/experimental/class-private-methods/async-generator/expected.json b/test/fixtures/experimental/class-private-methods/async-generator/expected.json index eb4c865fb7..a222170f1b 100644 --- a/test/fixtures/experimental/class-private-methods/async-generator/expected.json +++ b/test/fixtures/experimental/class-private-methods/async-generator/expected.json @@ -90,9 +90,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 22, "end": 31, "loc": { @@ -103,11 +102,27 @@ "end": { "line": 2, "column": 19 - }, - "identifierName": "readLines" + } }, - "name": "readLines" + "id": { + "type": "Identifier", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "readLines" + }, + "name": "readLines" + } }, + "computed": false, "kind": "method", "id": null, "generator": true, diff --git a/test/fixtures/experimental/class-private-methods/async/expected.json b/test/fixtures/experimental/class-private-methods/async/expected.json index e4abcf4800..434f6f5b98 100644 --- a/test/fixtures/experimental/class-private-methods/async/expected.json +++ b/test/fixtures/experimental/class-private-methods/async/expected.json @@ -90,9 +90,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 23, "end": 27, "loc": { @@ -103,11 +102,27 @@ "end": { "line": 2, "column": 13 - }, - "identifierName": "evil" + } }, - "name": "evil" + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "evil" + }, + "name": "evil" + } }, + "computed": false, "kind": "method", "id": null, "generator": false, diff --git a/test/fixtures/experimental/class-private-methods/combined/expected.json b/test/fixtures/experimental/class-private-methods/combined/expected.json index 14830f2dde..c46bfafaf5 100644 --- a/test/fixtures/experimental/class-private-methods/combined/expected.json +++ b/test/fixtures/experimental/class-private-methods/combined/expected.json @@ -90,7 +90,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 14, @@ -108,6 +107,7 @@ }, "name": "a" }, + "computed": false, "value": { "type": "NumericLiteral", "start": 18, @@ -145,9 +145,8 @@ }, "static": false, "kind": "method", - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 26, "end": 27, "loc": { @@ -158,10 +157,25 @@ "end": { "line": 4, "column": 5 - }, - "identifierName": "a" + } }, - "name": "a" + "id": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + } }, "id": null, "generator": true, @@ -267,7 +281,7 @@ }, "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 57, "end": 58, "loc": { @@ -278,10 +292,25 @@ "end": { "line": 8, "column": 4 - }, - "identifierName": "b" + } }, - "name": "b" + "id": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 4 + }, + "identifierName": "b" + }, + "name": "b" + } }, "value": { "type": "NumericLiteral", @@ -319,7 +348,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 71, @@ -337,6 +365,7 @@ }, "name": "b" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -412,9 +441,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 99, "end": 100, "loc": { @@ -425,11 +453,27 @@ "end": { "line": 11, "column": 8 - }, - "identifierName": "c" + } }, - "name": "c" + "id": { + "type": "Identifier", + "start": 99, + "end": 100, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + }, + "identifierName": "c" + }, + "name": "c" + } }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -520,9 +564,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 122, "end": 123, "loc": { @@ -533,10 +576,25 @@ "end": { "line": 13, "column": 4 - }, - "identifierName": "d" + } }, - "name": "d" + "id": { + "type": "Identifier", + "start": 122, + "end": 123, + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 4 + }, + "identifierName": "d" + }, + "name": "d" + } }, "kind": "method", "id": null, diff --git a/test/fixtures/experimental/class-private-methods/failure-name-constructor/actual.js b/test/fixtures/experimental/class-private-methods/failure-name-constructor/actual.js new file mode 100644 index 0000000000..9b37f57c33 --- /dev/null +++ b/test/fixtures/experimental/class-private-methods/failure-name-constructor/actual.js @@ -0,0 +1,3 @@ +class Foo { + #constructor() {}; +} diff --git a/test/fixtures/experimental/class-private-methods/failure-name-constructor/options.json b/test/fixtures/experimental/class-private-methods/failure-name-constructor/options.json new file mode 100644 index 0000000000..14e0bd1888 --- /dev/null +++ b/test/fixtures/experimental/class-private-methods/failure-name-constructor/options.json @@ -0,0 +1,7 @@ +{ + "throws": "Classes may not have a private field named '#constructor' (2:3)", + "plugins": [ + "classProperties", + "classPrivateMethods" + ] +} diff --git a/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json b/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json index d58523e2f6..284a3b1ef7 100644 --- a/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json +++ b/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json @@ -1,4 +1,4 @@ { - "throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:5)", + "throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:3)", "plugins": ["classProperties", "classPrivateProperties"] } diff --git a/test/fixtures/experimental/class-private-methods/generator/expected.json b/test/fixtures/experimental/class-private-methods/generator/expected.json index 16b9237c1d..13d9f1a2fa 100644 --- a/test/fixtures/experimental/class-private-methods/generator/expected.json +++ b/test/fixtures/experimental/class-private-methods/generator/expected.json @@ -91,9 +91,8 @@ }, "static": false, "kind": "method", - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 18, "end": 22, "loc": { @@ -104,10 +103,25 @@ "end": { "line": 2, "column": 8 - }, - "identifierName": "evil" + } }, - "name": "evil" + "id": { + "type": "Identifier", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "evil" + }, + "name": "evil" + } }, "id": null, "generator": true, diff --git a/test/fixtures/experimental/class-private-methods/get-set/expected.json b/test/fixtures/experimental/class-private-methods/get-set/expected.json index fa89661094..f8cbfe8346 100644 --- a/test/fixtures/experimental/class-private-methods/get-set/expected.json +++ b/test/fixtures/experimental/class-private-methods/get-set/expected.json @@ -90,9 +90,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 21, "end": 25, "loc": { @@ -103,11 +102,27 @@ "end": { "line": 2, "column": 11 - }, - "identifierName": "evil" + } }, - "name": "evil" + "id": { + "type": "Identifier", + "start": 21, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "evil" + }, + "name": "evil" + } }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -196,9 +211,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 60, "end": 64, "loc": { @@ -209,11 +223,27 @@ "end": { "line": 5, "column": 11 - }, - "identifierName": "evil" + } }, - "name": "evil" + "id": { + "type": "Identifier", + "start": 60, + "end": 64, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 11 + }, + "identifierName": "evil" + }, + "name": "evil" + } }, + "computed": false, "kind": "set", "id": null, "generator": false, diff --git a/test/fixtures/experimental/class-private-methods/method/expected.json b/test/fixtures/experimental/class-private-methods/method/expected.json index d08ac3d90b..211e15b7ac 100644 --- a/test/fixtures/experimental/class-private-methods/method/expected.json +++ b/test/fixtures/experimental/class-private-methods/method/expected.json @@ -90,9 +90,8 @@ } }, "static": false, - "computed": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 17, "end": 26, "loc": { @@ -103,10 +102,25 @@ "end": { "line": 2, "column": 12 - }, - "identifierName": "getBanned" + } }, - "name": "getBanned" + "id": { + "type": "Identifier", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "getBanned" + }, + "name": "getBanned" + } }, "kind": "method", "id": null, 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 22a8ec7990..b3201d11ae 100644 --- a/test/fixtures/experimental/class-private-properties/asi-success/expected.json +++ b/test/fixtures/experimental/class-private-properties/asi-success/expected.json @@ -89,8 +89,9 @@ "column": 4 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 15, "end": 16, "loc": { @@ -101,12 +102,26 @@ "end": { "line": 2, "column": 4 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": null }, { @@ -123,8 +138,9 @@ "column": 4 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 20, "end": 21, "loc": { @@ -135,12 +151,26 @@ "end": { "line": 3, "column": 4 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": null } ] @@ -149,4 +179,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-private-properties/failure-name-constructor/actual.js b/test/fixtures/experimental/class-private-properties/failure-name-constructor/actual.js new file mode 100644 index 0000000000..d72b6a9a8d --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-name-constructor/actual.js @@ -0,0 +1,3 @@ +class Foo { + #constructor; +} diff --git a/test/fixtures/experimental/class-private-properties/failure-name-constructor/options.json b/test/fixtures/experimental/class-private-properties/failure-name-constructor/options.json new file mode 100644 index 0000000000..faa50232dd --- /dev/null +++ b/test/fixtures/experimental/class-private-properties/failure-name-constructor/options.json @@ -0,0 +1,7 @@ +{ + "throws": "Classes may not have a private field named '#constructor' (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 2ebb392b10..98c21df819 100644 --- a/test/fixtures/experimental/class-private-properties/inline/expected.json +++ b/test/fixtures/experimental/class-private-properties/inline/expected.json @@ -89,8 +89,9 @@ "column": 13 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 11, "end": 12, "loc": { @@ -101,12 +102,26 @@ "end": { "line": 1, "column": 12 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": null }, { @@ -123,8 +138,9 @@ "column": 17 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 15, "end": 16, "loc": { @@ -135,12 +151,26 @@ "end": { "line": 1, "column": 16 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": null } ] @@ -207,8 +237,9 @@ "column": 17 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 32, "end": 33, "loc": { @@ -219,12 +250,26 @@ "end": { "line": 3, "column": 12 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 36, @@ -260,8 +305,9 @@ "column": 25 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 40, "end": 41, "loc": { @@ -272,12 +318,26 @@ "end": { "line": 3, "column": 20 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 44, @@ -305,4 +365,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/test/fixtures/experimental/class-private-properties/nested/expected.json b/test/fixtures/experimental/class-private-properties/nested/expected.json index c2cd3363c2..d5d64806a6 100644 --- a/test/fixtures/experimental/class-private-properties/nested/expected.json +++ b/test/fixtures/experimental/class-private-properties/nested/expected.json @@ -89,8 +89,9 @@ "column": 9 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 17, "end": 18, "loc": { @@ -101,12 +102,26 @@ "end": { "line": 2, "column": 4 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 21, @@ -142,8 +157,9 @@ "column": 9 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 27, "end": 28, "loc": { @@ -154,12 +170,26 @@ "end": { "line": 3, "column": 4 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 31, @@ -196,7 +226,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 37, @@ -214,6 +243,7 @@ }, "name": "constructor" }, + "computed": false, "kind": "constructor", "id": null, "generator": false, @@ -724,8 +754,9 @@ "column": 13 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 132, "end": 133, "loc": { @@ -736,12 +767,26 @@ "end": { "line": 10, "column": 8 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 132, + "end": 133, + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 136, @@ -777,8 +822,9 @@ "column": 13 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 146, "end": 147, "loc": { @@ -789,12 +835,26 @@ "end": { "line": 11, "column": 8 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 150, @@ -831,7 +891,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 160, @@ -849,6 +908,7 @@ }, "name": "constructor" }, + "computed": false, "kind": "constructor", "id": null, "generator": false, @@ -1256,7 +1316,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 251, @@ -1274,6 +1333,7 @@ }, "name": "x" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -1392,7 +1452,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 284, @@ -1410,6 +1469,7 @@ }, "name": "x" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -1599,7 +1659,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 325, @@ -1617,6 +1676,7 @@ }, "name": "y" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -1735,7 +1795,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 358, @@ -1753,6 +1812,7 @@ }, "name": "y" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -1942,7 +2002,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 395, @@ -1960,6 +2019,7 @@ }, "name": "equals" }, + "computed": false, "kind": "method", "id": null, "generator": false, @@ -2337,7 +2397,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 460, @@ -2355,6 +2414,7 @@ }, "name": "toString" }, + "computed": false, "kind": "method", "id": null, "generator": false, @@ -2624,7 +2684,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 535, @@ -2642,6 +2701,7 @@ }, "name": "x" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -2760,7 +2820,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 564, @@ -2778,6 +2837,7 @@ }, "name": "x" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -2967,7 +3027,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 601, @@ -2985,6 +3044,7 @@ }, "name": "y" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -3103,7 +3163,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 630, @@ -3121,6 +3180,7 @@ }, "name": "y" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -3310,7 +3370,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 663, @@ -3328,6 +3387,7 @@ }, "name": "equals" }, + "computed": false, "kind": "method", "id": null, "generator": false, @@ -3705,7 +3765,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 724, @@ -3723,6 +3782,7 @@ }, "name": "toString" }, + "computed": false, "kind": "method", "id": null, "generator": false, 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 8e832903dc..420f3f9619 100644 --- a/test/fixtures/experimental/class-private-properties/pbn-success/expected.json +++ b/test/fixtures/experimental/class-private-properties/pbn-success/expected.json @@ -89,8 +89,9 @@ "column": 9 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 17, "end": 18, "loc": { @@ -101,12 +102,26 @@ "end": { "line": 2, "column": 4 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 21, @@ -142,8 +157,9 @@ "column": 9 } }, + "static": false, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 27, "end": 28, "loc": { @@ -154,12 +170,26 @@ "end": { "line": 3, "column": 4 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": false, "value": { "type": "NumericLiteral", "start": 31, @@ -196,7 +226,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 37, @@ -214,6 +243,7 @@ }, "name": "constructor" }, + "computed": false, "kind": "constructor", "id": null, "generator": false, @@ -621,7 +651,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 112, @@ -639,6 +668,7 @@ }, "name": "x" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -757,7 +787,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 141, @@ -775,6 +804,7 @@ }, "name": "x" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -964,7 +994,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 178, @@ -982,6 +1011,7 @@ }, "name": "y" }, + "computed": false, "kind": "get", "id": null, "generator": false, @@ -1100,7 +1130,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 207, @@ -1118,6 +1147,7 @@ }, "name": "y" }, + "computed": false, "kind": "set", "id": null, "generator": false, @@ -1307,7 +1337,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 240, @@ -1325,6 +1354,7 @@ }, "name": "equals" }, + "computed": false, "kind": "method", "id": null, "generator": false, @@ -1702,7 +1732,6 @@ } }, "static": false, - "computed": false, "key": { "type": "Identifier", "start": 301, @@ -1720,6 +1749,7 @@ }, "name": "toString" }, + "computed": false, "kind": "method", "id": null, "generator": false, diff --git a/test/fixtures/experimental/class-private-properties/static/expected.json b/test/fixtures/experimental/class-private-properties/static/expected.json index 9d7c840f64..ac66240967 100644 --- a/test/fixtures/experimental/class-private-properties/static/expected.json +++ b/test/fixtures/experimental/class-private-properties/static/expected.json @@ -89,8 +89,9 @@ "column": 12 } }, + "static": true, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 20, "end": 21, "loc": { @@ -101,12 +102,26 @@ "end": { "line": 2, "column": 11 - }, - "identifierName": "x" + } }, - "name": "x" + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } }, - "static": true, "value": null }, { @@ -123,8 +138,9 @@ "column": 16 } }, + "static": true, "key": { - "type": "Identifier", + "type": "PrivateName", "start": 33, "end": 34, "loc": { @@ -135,12 +151,26 @@ "end": { "line": 3, "column": 11 - }, - "identifierName": "y" + } }, - "name": "y" + "id": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + } }, - "static": true, "value": { "type": "NumericLiteral", "start": 37, @@ -168,4 +198,4 @@ ], "directives": [] } -} +} \ No newline at end of file