diff --git a/packages/babel-parser/ast/spec.md b/packages/babel-parser/ast/spec.md index 1c934c1ba129..73833ef71b4d 100644 --- a/packages/babel-parser/ast/spec.md +++ b/packages/babel-parser/ast/spec.md @@ -1212,6 +1212,29 @@ interface ClassPrivateProperty <: Node { } ``` +## ClassAccessorProperty + +```js +interface ClassAccessorProperty <: Node { + type: "ClassAccessorProperty"; + key: Expression; + value: Expression; + static: boolean; + computed: boolean; +} +``` + +## ClassPrivateAccessorProperty + +```js +interface ClassPrivateAccessorProperty <: Node { + type: "ClassPrivateAccessorProperty"; + key: PrivateName; + value: Expression; + static: boolean; +} +``` + ## StaticBlock ```js diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 71bbb711bd1d..4934e0790111 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -1379,6 +1379,7 @@ export default class StatementParser extends ExpressionParser { prop.computed = false; prop.key = key; prop.static = false; + classBody.body.push(this.parseClassProperty(prop)); return true; } @@ -1415,8 +1416,11 @@ export default class StatementParser extends ExpressionParser { ) { const publicMethod: $FlowSubtype = member; const privateMethod: $FlowSubtype = member; - const publicProp: $FlowSubtype = member; - const privateProp: $FlowSubtype = member; + const publicProp: $FlowSubtype = member; + const privateProp: $FlowSubtype = member; + const publicAccessorProp: $FlowSubtype = member; + const privateAccessorProp: $FlowSubtype = + member; const method: typeof publicMethod | typeof privateMethod = publicMethod; const publicMember: typeof publicMethod | typeof publicProp = publicMethod; @@ -1569,6 +1573,24 @@ export default class StatementParser extends ExpressionParser { } this.checkGetterSetterParams(publicMethod); + } else if ( + isContextual && + key.name === "accessor" && + this.hasPlugin("decorators") && + this.getPluginOption("decorators", "version") === "modern" && + !this.isLineTerminator() + ) { + this.resetPreviousNodeTrailingComments(key); + + // The so-called parsed name would have been "get/set": get the real name. + const isPrivate = this.match(tt.privateName); + this.parseClassElementName(publicProp); + + if (isPrivate) { + this.pushClassPrivateAccessorProperty(classBody, privateAccessorProp); + } else { + this.pushClassAccessorProperty(classBody, publicAccessorProp); + } } else if (this.isLineTerminator()) { // an uninitialized class property (due to ASI, since we don't otherwise recognize the next token) if (isPrivate) { @@ -1650,6 +1672,36 @@ export default class StatementParser extends ExpressionParser { ); } + pushClassAccessorProperty( + classBody: N.ClassBody, + prop: N.ClassAccessorProperty, + ) { + if ( + !prop.computed && + (prop.key.name === "constructor" || prop.key.value === "constructor") + ) { + // Non-computed field, which is either an identifier named "constructor" + // or a string literal named "constructor" + this.raise(prop.key.start, Errors.ConstructorClassField); + } + + classBody.body.push(this.parseClassAccessorProperty(prop)); + } + + pushClassPrivateAccessorProperty( + classBody: N.ClassBody, + prop: N.ClassPrivateAccessorProperty, + ) { + const node = this.parseClassPrivateAccessorProperty(prop); + classBody.body.push(node); + + this.classScope.declarePrivateName( + this.getPrivateNameSV(node.key), + CLASS_ELEMENT_OTHER, + node.key.start, + ); + } + pushClassMethod( classBody: N.ClassBody, method: N.ClassMethod, @@ -1727,6 +1779,22 @@ export default class StatementParser extends ExpressionParser { return this.finishNode(node, "ClassProperty"); } + parseClassPrivateAccessorProperty( + node: N.ClassPrivateAccessorProperty, + ): N.ClassPrivateAccessorProperty { + this.parseInitializer(node); + this.semicolon(); + return this.finishNode(node, "ClassPrivateAccessorProperty"); + } + + parseClassAccessorProperty( + node: N.ClassAccessorProperty, + ): N.ClassAccessorProperty { + this.parseInitializer(node); + this.semicolon(); + return this.finishNode(node, "ClassAccessorProperty"); + } + // https://tc39.es/proposal-class-fields/#prod-Initializer parseInitializer(node: N.ClassProperty | N.ClassPrivateProperty): void { this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index e747abc6b5f5..c4181eb09663 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -849,6 +849,37 @@ export type ClassPrivateProperty = NodeBase & { override?: true, }; +export type ClassAccessorProperty = ClassMemberBase & + DeclarationBase & { + type: "ClassAccesorProperty", + key: Expression, + init?: Expression, // TODO: Not in spec that this is nullable. + + typeAnnotation?: ?TypeAnnotationBase, // TODO: Not in spec + variance?: ?FlowVariance, // TODO: Not in spec + + // TypeScript only: (TODO: Not in spec) + readonly?: true, + definite?: true, + }; + +export type ClassPrivateAccessorProperty = NodeBase & { + type: "ClassPrivateAccessorProperty", + key: PrivateName, + init?: Expression, // TODO: Not in spec that this is nullable. + static: boolean, + computed: false, + + // Flow and Typescript + typeAnnotation?: ?TypeAnnotationBase, + + // TypeScript only + optional?: true, + definite?: true, + readonly?: true, + override?: true, +}; + export type OptClassDeclaration = ClassBase & DeclarationBase & HasDecorators & { diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/input.js new file mode 100644 index 000000000000..fa4a4b67422e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor constructor; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/output.json new file mode 100644 index 000000000000..6860810b0dda --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/accessor-named-constructor/output.json @@ -0,0 +1,44 @@ +{ + "type": "File", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: Classes may not have a field named 'constructor'. (2:11)" + ], + "program": { + "type": "Program", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":37,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":35,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":23}}, + "static": false, + "key": { + "type": "Identifier", + "start":23,"end":34,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":22},"identifierName":"constructor"}, + "name": "constructor" + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/input.js new file mode 100644 index 000000000000..735a7a78e304 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor bar; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/output.json new file mode 100644 index 000000000000..378b00ee57ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/basic-accessor/output.json @@ -0,0 +1,41 @@ +{ + "type": "File", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, + "static": false, + "key": { + "type": "Identifier", + "start":23,"end":26,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/input.js new file mode 100644 index 000000000000..27dd24f5bb98 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor ["constructor"]; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/output.json new file mode 100644 index 000000000000..2705e4929c5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor-named-constructor/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":41,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":39,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":27}}, + "static": false, + "key": { + "type": "StringLiteral", + "start":24,"end":37,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":25}}, + "extra": { + "rawValue": "constructor", + "raw": "\"constructor\"" + }, + "value": "constructor" + }, + "computed": true, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/input.js new file mode 100644 index 000000000000..f77d3f867281 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor ["bar"]; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/output.json new file mode 100644 index 000000000000..d15e333f0317 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-accessor/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":33,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}}, + "static": false, + "key": { + "type": "StringLiteral", + "start":24,"end":29,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":17}}, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + }, + "computed": true, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/input.js new file mode 100644 index 000000000000..03a1bfe9b8d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/input.js @@ -0,0 +1,3 @@ +class Foo { + static accessor ["bar"]; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/output.json new file mode 100644 index 000000000000..709fa0b48133 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/computed-static-accesor/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":40,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":38,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":26}}, + "static": true, + "key": { + "type": "StringLiteral", + "start":31,"end":36,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":24}}, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + }, + "computed": true, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/input.js new file mode 100644 index 000000000000..fba4a91f8875 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor = 123; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/output.json new file mode 100644 index 000000000000..6f6c5d059cc5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/field-named-accessor/output.json @@ -0,0 +1,49 @@ +{ + "type": "File", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":31,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassProperty", + "start":14,"end":29,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}}, + "static": false, + "key": { + "type": "Identifier", + "start":14,"end":22,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10},"identifierName":"accessor"}, + "name": "accessor" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":25,"end":28,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/input.js new file mode 100644 index 000000000000..d4092463f89a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/output.json new file mode 100644 index 000000000000..b55c19130b12 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/method-named-accessor/output.json @@ -0,0 +1,51 @@ +{ + "type": "File", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":14,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, + "static": false, + "key": { + "type": "Identifier", + "start":14,"end":22,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10},"identifierName":"accessor"}, + "name": "accessor" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":25,"end":27,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":15}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/input.js new file mode 100644 index 000000000000..4e41f3511da0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/input.js @@ -0,0 +1,5 @@ +class Foo { + accessor bar() { + + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/options.json new file mode 100644 index 000000000000..a1c98245e1ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/not-allowed-on-methods/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/options.json new file mode 100644 index 000000000000..20edf62c0edf --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["decorators", { "decoratorsBeforeExport": false, "version": "modern" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/input.js new file mode 100644 index 000000000000..9127772fc36b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + accessor #bar; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/output.json new file mode 100644 index 000000000000..14d271d0366b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-accessor/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":30,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassPrivateAccessorProperty", + "start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, + "static": false, + "key": { + "type": "PrivateName", + "start":23,"end":27,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":15}}, + "id": { + "type": "Identifier", + "start":24,"end":27,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"bar"}, + "name": "bar" + } + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/input.js new file mode 100644 index 000000000000..eda1665ae885 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + static accessor #bar; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/output.json new file mode 100644 index 000000000000..a0d3a0ed0a01 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/private-static-accessor/output.json @@ -0,0 +1,45 @@ +{ + "type": "File", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":37,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassPrivateAccessorProperty", + "start":14,"end":35,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":23}}, + "static": true, + "key": { + "type": "PrivateName", + "start":30,"end":34,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":22}}, + "id": { + "type": "Identifier", + "start":31,"end":34,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":22},"identifierName":"bar"}, + "name": "bar" + } + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/input.js new file mode 100644 index 000000000000..10777835cd1c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/input.js @@ -0,0 +1,3 @@ +class Foo { + static accessor bar; +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/output.json new file mode 100644 index 000000000000..ca4c9c4e761e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-modern/static-accessor/output.json @@ -0,0 +1,41 @@ +{ + "type": "File", + "start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":36,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":34,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":22}}, + "static": true, + "key": { + "type": "Identifier", + "start":30,"end":33,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":21},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file