diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index e3b6eae99a0b..d88bf86266d0 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -606,7 +606,7 @@ export default class ExpressionParser extends LValParser { ? this.parseExpression() : optional ? this.parseIdentifier(true) - : this.parseMaybePrivateName(); + : this.parseMaybePrivateName(true); node.computed = computed; if (node.property.type === "PrivateName") { @@ -1131,11 +1131,19 @@ export default class ExpressionParser extends LValParser { return this.finishNode(node, "BooleanLiteral"); } - parseMaybePrivateName(): N.PrivateName | N.Identifier { + parseMaybePrivateName( + isPrivateNameAllowed: boolean, + ): N.PrivateName | N.Identifier { const isPrivate = this.match(tt.hash); if (isPrivate) { this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); + if (!isPrivateNameAllowed) { + this.raise( + this.state.pos, + "Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p).", + ); + } const node = this.startNode(); this.next(); this.assertNoSpace("Unexpected space between # and identifier"); @@ -1596,12 +1604,12 @@ export default class ExpressionParser extends LValParser { } const containsEsc = this.state.containsEsc; - this.parsePropertyName(prop); + this.parsePropertyName(prop, /* isPrivateNameAllowed */ false); if (!isPattern && !containsEsc && !isGenerator && this.isAsyncProp(prop)) { isAsync = true; isGenerator = this.eat(tt.star); - this.parsePropertyName(prop); + this.parsePropertyName(prop, /* isPrivateNameAllowed */ false); } else { isAsync = false; } @@ -1688,7 +1696,7 @@ export default class ExpressionParser extends LValParser { if (!containsEsc && this.isGetterOrSetterMethod(prop, isPattern)) { if (isGenerator || isAsync) this.unexpected(); prop.kind = prop.key.name; - this.parsePropertyName(prop); + this.parsePropertyName(prop, /* isPrivateNameAllowed */ false); this.parseMethod( prop, /* isGenerator */ false, @@ -1780,6 +1788,7 @@ export default class ExpressionParser extends LValParser { parsePropertyName( prop: N.ObjectOrClassMember | N.ClassMember | N.TsNamedTypeElementBase, + isPrivateNameAllowed: boolean, ): N.Expression | N.Identifier { if (this.eat(tt.bracketL)) { (prop: $FlowSubtype).computed = true; @@ -1792,7 +1801,7 @@ export default class ExpressionParser extends LValParser { (prop: $FlowFixMe).key = this.match(tt.num) || this.match(tt.string) || this.match(tt.bigint) ? this.parseExprAtom() - : this.parseMaybePrivateName(); + : this.parseMaybePrivateName(isPrivateNameAllowed); if (prop.key.type !== "PrivateName") { // ClassPrivateProperty is never computed, so we don't assign in that case. diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 7a5bc33c9541..85e177564676 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -1474,7 +1474,7 @@ export default class StatementParser extends ExpressionParser { } parseClassPropertyName(member: N.ClassMember): N.Expression | N.Identifier { - const key = this.parsePropertyName(member); + const key = this.parsePropertyName(member, /* isPrivateNameAllowed */ true); if ( !member.computed && diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index 72ed92b6c276..42f864a2069d 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -2266,9 +2266,10 @@ export default (superClass: Class): Class => parsePropertyName( node: N.ObjectOrClassMember | N.ClassMember | N.TsNamedTypeElementBase, + isPrivateNameAllowed: boolean, ): N.Identifier { const variance = this.flowParseVariance(); - const key = super.parsePropertyName(node); + const key = super.parsePropertyName(node, isPrivateNameAllowed); // $FlowIgnore ("variance" not defined on TsNamedTypeElementBase) node.variance = variance; return key; diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 0c740b2c9bdd..b53dca72d61c 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -507,7 +507,7 @@ export default (superClass: Class): Class => return idx; } - this.parsePropertyName(node); + this.parsePropertyName(node, /* isPrivateNameAllowed */ false); return this.tsParsePropertyOrMethodSignature(node, readonly); } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/input.js new file mode 100644 index 000000000000..efc69f1bc6eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/input.js @@ -0,0 +1,4 @@ +class C { + #x = 1; + #p = ({ #x: x }) => {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/output.json new file mode 100644 index 000000000000..d8c6109cf982 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring-arguments/output.json @@ -0,0 +1,324 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (3:11)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "p" + }, + "name": "p" + } + }, + "value": { + "type": "ArrowFunctionExpression", + "start": 27, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 28, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 30, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "method": false, + "key": { + "type": "PrivateName", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "shorthand": false, + "value": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/input.js new file mode 100644 index 000000000000..980a785949d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/input.js @@ -0,0 +1,6 @@ +class C { + #x = 1; + m() { + const {#x: x} = this; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/output.json new file mode 100644 index 000000000000..73b7c2579453 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-destructuring/output.json @@ -0,0 +1,344 @@ +{ + "type": "File", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (4:12)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassMethod", + "start": 22, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "m" + }, + "name": "m" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 26, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 32, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 38, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "id": { + "type": "ObjectPattern", + "start": 38, + "end": 45, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "method": false, + "key": { + "type": "PrivateName", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "shorthand": false, + "value": { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + }, + "init": { + "type": "ThisExpression", + "start": 48, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 24 + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/input.js new file mode 100644 index 000000000000..234c9a49371e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/input.js @@ -0,0 +1,3 @@ +class C { + #p = ({ #x: 42 }); +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/options.json new file mode 100644 index 000000000000..f26e916957c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/output.json new file mode 100644 index 000000000000..7a5716ee676d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-object-method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:11)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "C" + }, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "p" + }, + "name": "p" + } + }, + "value": { + "type": "ObjectExpression", + "start": 18, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "method": false, + "key": { + "type": "PrivateName", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 17 + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/input.js new file mode 100644 index 000000000000..dd79bd88301a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/input.js @@ -0,0 +1,3 @@ +interface I { + #p: string +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/options.json new file mode 100644 index 000000000000..cb835ce4233c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "typescript"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/output.json new file mode 100644 index 000000000000..3422be4603b9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/invalid-ts-type-literal/output.json @@ -0,0 +1,164 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p). (2:3)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TSInterfaceDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "I" + }, + "name": "I" + }, + "body": { + "type": "TSInterfaceBody", + "start": 12, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSPropertySignature", + "start": 16, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "p" + }, + "name": "p" + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/scripts/parser-tests/test262/whitelist.txt b/scripts/parser-tests/test262/whitelist.txt index d7a38c2104cf..8b137891791f 100644 --- a/scripts/parser-tests/test262/whitelist.txt +++ b/scripts/parser-tests/test262/whitelist.txt @@ -1,16 +1 @@ -language/expressions/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(default) -language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-async-gen.js(default) -language/expressions/object/method-definition/private-name-early-error-async-gen.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(default) -language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-gen.js(default) -language/expressions/object/method-definition/private-name-early-error-gen.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(default) -language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(strict mode) -language/expressions/object/method-definition/private-name-early-error-method.js(default) -language/expressions/object/method-definition/private-name-early-error-method.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(default) -language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) +