From 0a40615abde9b3094547a274deed0ae493c52715 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 18 Nov 2022 17:55:27 +0800 Subject: [PATCH 1/8] fix --- .../src/plugins/typescript/index.ts | 10 ++++ .../class/accessor-with-type/input.ts | 3 + .../class/accessor-with-type/options.json | 6 ++ .../class/accessor-with-type/output.json | 57 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index e83acac52cf7..cf49013d1307 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -3224,6 +3224,16 @@ export default (superClass: ClassWithMixin) => super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); } + pushClassAccessorProperty( + classBody: Undone, + prop: N.ClassAccessorProperty, + isPrivate: boolean, + ) { + const typeAnnotation = this.tsTryParseTypeAnnotation(); + if (typeAnnotation) prop.typeAnnotation = typeAnnotation; + super.pushClassAccessorProperty(classBody, prop, isPrivate); + } + declareClassPrivateMethodInScope( node: N.ClassPrivateMethod | N.EstreeMethodDefinition | N.TSDeclareMethod, kind: number, diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts new file mode 100644 index 000000000000..838f24163790 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts @@ -0,0 +1,3 @@ +class Foo { + accessor prop: number = 1; +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json new file mode 100644 index 000000000000..ceb6fe8e0820 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "typescript", + "decoratorAutoAccessors" + ] +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json new file mode 100644 index 000000000000..602557b79aa2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "program": { + "type": "Program", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":42,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":3,"column":1,"index":42}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":14,"end":40,"loc":{"start":{"line":2,"column":2,"index":14},"end":{"line":2,"column":28,"index":40}}, + "static": false, + "key": { + "type": "Identifier", + "start":23,"end":27,"loc":{"start":{"line":2,"column":11,"index":23},"end":{"line":2,"column":15,"index":27},"identifierName":"prop"}, + "name": "prop" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":27,"end":35,"loc":{"start":{"line":2,"column":15,"index":27},"end":{"line":2,"column":23,"index":35}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":29,"end":35,"loc":{"start":{"line":2,"column":17,"index":29},"end":{"line":2,"column":23,"index":35}} + } + }, + "value": { + "type": "NumericLiteral", + "start":38,"end":39,"loc":{"start":{"line":2,"column":26,"index":38},"end":{"line":2,"column":27,"index":39}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + ], + "directives": [] + } +} From 5f1d8239b6e586e14e1c21bbc99cba841f7f3c80 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sat, 19 Nov 2022 01:27:18 +0800 Subject: [PATCH 2/8] add tests --- .../class/accessor-with-type/input.ts | 3 + .../class/accessor-with-type/output.json | 96 ++++++++++++++++++- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts index 838f24163790..dc9bceae5851 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts @@ -1,3 +1,6 @@ class Foo { accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; } diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json index 602557b79aa2..9b91b672b3b6 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json @@ -1,15 +1,15 @@ { "type": "File", - "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, "program": { "type": "Program", - "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start":0,"end":42,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":42}}, + "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, "id": { "type": "Identifier", "start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9},"identifierName":"Foo"}, @@ -18,7 +18,7 @@ "superClass": null, "body": { "type": "ClassBody", - "start":10,"end":42,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":3,"column":1,"index":42}}, + "start":10,"end":142,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":6,"column":1,"index":142}}, "body": [ { "type": "ClassAccessorProperty", @@ -47,6 +47,94 @@ }, "value": 1 } + }, + { + "type": "ClassAccessorProperty", + "start":43,"end":77,"loc":{"start":{"line":3,"column":2,"index":43},"end":{"line":3,"column":36,"index":77}}, + "static": true, + "key": { + "type": "Identifier", + "start":59,"end":64,"loc":{"start":{"line":3,"column":18,"index":59},"end":{"line":3,"column":23,"index":64},"identifierName":"prop2"}, + "name": "prop2" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":64,"end":72,"loc":{"start":{"line":3,"column":23,"index":64},"end":{"line":3,"column":31,"index":72}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":66,"end":72,"loc":{"start":{"line":3,"column":25,"index":66},"end":{"line":3,"column":31,"index":72}} + } + }, + "value": { + "type": "NumericLiteral", + "start":75,"end":76,"loc":{"start":{"line":3,"column":34,"index":75},"end":{"line":3,"column":35,"index":76}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassAccessorProperty", + "start":80,"end":108,"loc":{"start":{"line":4,"column":2,"index":80},"end":{"line":4,"column":30,"index":108}}, + "static": false, + "key": { + "type": "PrivateName", + "start":89,"end":95,"loc":{"start":{"line":4,"column":11,"index":89},"end":{"line":4,"column":17,"index":95}}, + "id": { + "type": "Identifier", + "start":90,"end":95,"loc":{"start":{"line":4,"column":12,"index":90},"end":{"line":4,"column":17,"index":95},"identifierName":"prop3"}, + "name": "prop3" + } + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":95,"end":103,"loc":{"start":{"line":4,"column":17,"index":95},"end":{"line":4,"column":25,"index":103}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":97,"end":103,"loc":{"start":{"line":4,"column":19,"index":97},"end":{"line":4,"column":25,"index":103}} + } + }, + "value": { + "type": "NumericLiteral", + "start":106,"end":107,"loc":{"start":{"line":4,"column":28,"index":106},"end":{"line":4,"column":29,"index":107}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassAccessorProperty", + "start":111,"end":140,"loc":{"start":{"line":5,"column":2,"index":111},"end":{"line":5,"column":31,"index":140}}, + "static": false, + "key": { + "type": "Identifier", + "start":121,"end":126,"loc":{"start":{"line":5,"column":12,"index":121},"end":{"line":5,"column":17,"index":126},"identifierName":"prop4"}, + "name": "prop4" + }, + "computed": true, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":127,"end":135,"loc":{"start":{"line":5,"column":18,"index":127},"end":{"line":5,"column":26,"index":135}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":129,"end":135,"loc":{"start":{"line":5,"column":20,"index":129},"end":{"line":5,"column":26,"index":135}} + } + }, + "value": { + "type": "NumericLiteral", + "start":138,"end":139,"loc":{"start":{"line":5,"column":29,"index":138},"end":{"line":5,"column":30,"index":139}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } } ] } From 69726d96e5a0235ef55e3378c5a6f8e82c49e1f7 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sat, 19 Nov 2022 02:11:13 +0800 Subject: [PATCH 3/8] review --- .../class/accessor-with-type/input.ts | 5 +- .../class/accessor-with-type/output.json | 124 ++++++++++++++---- .../src/index.ts | 6 +- .../test/fixtures/class/accessor/input.ts | 9 ++ .../test/fixtures/class/accessor/options.json | 6 + .../test/fixtures/class/accessor/output.js | 8 ++ 6 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts index dc9bceae5851..3f2b87e28e07 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts @@ -1,6 +1,9 @@ -class Foo { +abstract class Foo { accessor prop: number = 1; static accessor prop2: number = 1; accessor #prop3: number = 1; accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + declare accessor prop7: number; } diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json index 9b91b672b3b6..bb206ee82cb8 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json @@ -1,46 +1,47 @@ { "type": "File", - "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, + "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, "program": { "type": "Program", - "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, + "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start":0,"end":142,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":6,"column":1,"index":142}}, + "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, + "abstract": true, "id": { "type": "Identifier", - "start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9},"identifierName":"Foo"}, + "start":15,"end":18,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":18,"index":18},"identifierName":"Foo"}, "name": "Foo" }, "superClass": null, "body": { "type": "ClassBody", - "start":10,"end":142,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":6,"column":1,"index":142}}, + "start":19,"end":258,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":9,"column":1,"index":258}}, "body": [ { "type": "ClassAccessorProperty", - "start":14,"end":40,"loc":{"start":{"line":2,"column":2,"index":14},"end":{"line":2,"column":28,"index":40}}, + "start":23,"end":49,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":28,"index":49}}, "static": false, "key": { "type": "Identifier", - "start":23,"end":27,"loc":{"start":{"line":2,"column":11,"index":23},"end":{"line":2,"column":15,"index":27},"identifierName":"prop"}, + "start":32,"end":36,"loc":{"start":{"line":2,"column":11,"index":32},"end":{"line":2,"column":15,"index":36},"identifierName":"prop"}, "name": "prop" }, "computed": false, "typeAnnotation": { "type": "TSTypeAnnotation", - "start":27,"end":35,"loc":{"start":{"line":2,"column":15,"index":27},"end":{"line":2,"column":23,"index":35}}, + "start":36,"end":44,"loc":{"start":{"line":2,"column":15,"index":36},"end":{"line":2,"column":23,"index":44}}, "typeAnnotation": { "type": "TSNumberKeyword", - "start":29,"end":35,"loc":{"start":{"line":2,"column":17,"index":29},"end":{"line":2,"column":23,"index":35}} + "start":38,"end":44,"loc":{"start":{"line":2,"column":17,"index":38},"end":{"line":2,"column":23,"index":44}} } }, "value": { "type": "NumericLiteral", - "start":38,"end":39,"loc":{"start":{"line":2,"column":26,"index":38},"end":{"line":2,"column":27,"index":39}}, + "start":47,"end":48,"loc":{"start":{"line":2,"column":26,"index":47},"end":{"line":2,"column":27,"index":48}}, "extra": { "rawValue": 1, "raw": "1" @@ -50,25 +51,25 @@ }, { "type": "ClassAccessorProperty", - "start":43,"end":77,"loc":{"start":{"line":3,"column":2,"index":43},"end":{"line":3,"column":36,"index":77}}, + "start":52,"end":86,"loc":{"start":{"line":3,"column":2,"index":52},"end":{"line":3,"column":36,"index":86}}, "static": true, "key": { "type": "Identifier", - "start":59,"end":64,"loc":{"start":{"line":3,"column":18,"index":59},"end":{"line":3,"column":23,"index":64},"identifierName":"prop2"}, + "start":68,"end":73,"loc":{"start":{"line":3,"column":18,"index":68},"end":{"line":3,"column":23,"index":73},"identifierName":"prop2"}, "name": "prop2" }, "computed": false, "typeAnnotation": { "type": "TSTypeAnnotation", - "start":64,"end":72,"loc":{"start":{"line":3,"column":23,"index":64},"end":{"line":3,"column":31,"index":72}}, + "start":73,"end":81,"loc":{"start":{"line":3,"column":23,"index":73},"end":{"line":3,"column":31,"index":81}}, "typeAnnotation": { "type": "TSNumberKeyword", - "start":66,"end":72,"loc":{"start":{"line":3,"column":25,"index":66},"end":{"line":3,"column":31,"index":72}} + "start":75,"end":81,"loc":{"start":{"line":3,"column":25,"index":75},"end":{"line":3,"column":31,"index":81}} } }, "value": { "type": "NumericLiteral", - "start":75,"end":76,"loc":{"start":{"line":3,"column":34,"index":75},"end":{"line":3,"column":35,"index":76}}, + "start":84,"end":85,"loc":{"start":{"line":3,"column":34,"index":84},"end":{"line":3,"column":35,"index":85}}, "extra": { "rawValue": 1, "raw": "1" @@ -78,29 +79,29 @@ }, { "type": "ClassAccessorProperty", - "start":80,"end":108,"loc":{"start":{"line":4,"column":2,"index":80},"end":{"line":4,"column":30,"index":108}}, + "start":89,"end":117,"loc":{"start":{"line":4,"column":2,"index":89},"end":{"line":4,"column":30,"index":117}}, "static": false, "key": { "type": "PrivateName", - "start":89,"end":95,"loc":{"start":{"line":4,"column":11,"index":89},"end":{"line":4,"column":17,"index":95}}, + "start":98,"end":104,"loc":{"start":{"line":4,"column":11,"index":98},"end":{"line":4,"column":17,"index":104}}, "id": { "type": "Identifier", - "start":90,"end":95,"loc":{"start":{"line":4,"column":12,"index":90},"end":{"line":4,"column":17,"index":95},"identifierName":"prop3"}, + "start":99,"end":104,"loc":{"start":{"line":4,"column":12,"index":99},"end":{"line":4,"column":17,"index":104},"identifierName":"prop3"}, "name": "prop3" } }, "computed": false, "typeAnnotation": { "type": "TSTypeAnnotation", - "start":95,"end":103,"loc":{"start":{"line":4,"column":17,"index":95},"end":{"line":4,"column":25,"index":103}}, + "start":104,"end":112,"loc":{"start":{"line":4,"column":17,"index":104},"end":{"line":4,"column":25,"index":112}}, "typeAnnotation": { "type": "TSNumberKeyword", - "start":97,"end":103,"loc":{"start":{"line":4,"column":19,"index":97},"end":{"line":4,"column":25,"index":103}} + "start":106,"end":112,"loc":{"start":{"line":4,"column":19,"index":106},"end":{"line":4,"column":25,"index":112}} } }, "value": { "type": "NumericLiteral", - "start":106,"end":107,"loc":{"start":{"line":4,"column":28,"index":106},"end":{"line":4,"column":29,"index":107}}, + "start":115,"end":116,"loc":{"start":{"line":4,"column":28,"index":115},"end":{"line":4,"column":29,"index":116}}, "extra": { "rawValue": 1, "raw": "1" @@ -110,31 +111,102 @@ }, { "type": "ClassAccessorProperty", - "start":111,"end":140,"loc":{"start":{"line":5,"column":2,"index":111},"end":{"line":5,"column":31,"index":140}}, + "start":120,"end":149,"loc":{"start":{"line":5,"column":2,"index":120},"end":{"line":5,"column":31,"index":149}}, "static": false, "key": { "type": "Identifier", - "start":121,"end":126,"loc":{"start":{"line":5,"column":12,"index":121},"end":{"line":5,"column":17,"index":126},"identifierName":"prop4"}, + "start":130,"end":135,"loc":{"start":{"line":5,"column":12,"index":130},"end":{"line":5,"column":17,"index":135},"identifierName":"prop4"}, "name": "prop4" }, "computed": true, "typeAnnotation": { "type": "TSTypeAnnotation", - "start":127,"end":135,"loc":{"start":{"line":5,"column":18,"index":127},"end":{"line":5,"column":26,"index":135}}, + "start":136,"end":144,"loc":{"start":{"line":5,"column":18,"index":136},"end":{"line":5,"column":26,"index":144}}, "typeAnnotation": { "type": "TSNumberKeyword", - "start":129,"end":135,"loc":{"start":{"line":5,"column":20,"index":129},"end":{"line":5,"column":26,"index":135}} + "start":138,"end":144,"loc":{"start":{"line":5,"column":20,"index":138},"end":{"line":5,"column":26,"index":144}} } }, "value": { "type": "NumericLiteral", - "start":138,"end":139,"loc":{"start":{"line":5,"column":29,"index":138},"end":{"line":5,"column":30,"index":139}}, + "start":147,"end":148,"loc":{"start":{"line":5,"column":29,"index":147},"end":{"line":5,"column":30,"index":148}}, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } + }, + { + "type": "ClassAccessorProperty", + "start":152,"end":187,"loc":{"start":{"line":6,"column":2,"index":152},"end":{"line":6,"column":37,"index":187}}, + "accessibility": "private", + "static": false, + "key": { + "type": "Identifier", + "start":169,"end":174,"loc":{"start":{"line":6,"column":19,"index":169},"end":{"line":6,"column":24,"index":174},"identifierName":"prop5"}, + "name": "prop5" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":174,"end":182,"loc":{"start":{"line":6,"column":24,"index":174},"end":{"line":6,"column":32,"index":182}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":176,"end":182,"loc":{"start":{"line":6,"column":26,"index":176},"end":{"line":6,"column":32,"index":182}} + } + }, + "value": { + "type": "NumericLiteral", + "start":185,"end":186,"loc":{"start":{"line":6,"column":35,"index":185},"end":{"line":6,"column":36,"index":186}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassAccessorProperty", + "start":190,"end":222,"loc":{"start":{"line":7,"column":2,"index":190},"end":{"line":7,"column":34,"index":222}}, + "abstract": true, + "static": false, + "key": { + "type": "Identifier", + "start":208,"end":213,"loc":{"start":{"line":7,"column":20,"index":208},"end":{"line":7,"column":25,"index":213},"identifierName":"prop6"}, + "name": "prop6" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":213,"end":221,"loc":{"start":{"line":7,"column":25,"index":213},"end":{"line":7,"column":33,"index":221}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":215,"end":221,"loc":{"start":{"line":7,"column":27,"index":215},"end":{"line":7,"column":33,"index":221}} + } + }, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":225,"end":256,"loc":{"start":{"line":8,"column":2,"index":225},"end":{"line":8,"column":33,"index":256}}, + "declare": true, + "static": false, + "key": { + "type": "Identifier", + "start":242,"end":247,"loc":{"start":{"line":8,"column":19,"index":242},"end":{"line":8,"column":24,"index":247},"identifierName":"prop7"}, + "name": "prop7" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":247,"end":255,"loc":{"start":{"line":8,"column":24,"index":247},"end":{"line":8,"column":32,"index":255}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":249,"end":255,"loc":{"start":{"line":8,"column":26,"index":249},"end":{"line":8,"column":32,"index":255}} + } + }, + "value": null } ] } diff --git a/packages/babel-plugin-transform-typescript/src/index.ts b/packages/babel-plugin-transform-typescript/src/index.ts index 5e094c60aa20..5f3bb975861d 100644 --- a/packages/babel-plugin-transform-typescript/src/index.ts +++ b/packages/babel-plugin-transform-typescript/src/index.ts @@ -120,7 +120,8 @@ export default declare((api, opts: Options) => { const classMemberVisitors = { field( path: NodePath< - (t.ClassPrivateProperty | t.ClassProperty) & ExtraNodeProps + (t.ClassPrivateProperty | t.ClassProperty | t.ClassAccessorProperty) & + ExtraNodeProps >, ) { const { node } = path; @@ -525,7 +526,8 @@ export default declare((api, opts: Options) => { } } else if ( child.isClassProperty() || - child.isClassPrivateProperty() + child.isClassPrivateProperty() || + child.isClassAccessorProperty() ) { classMemberVisitors.field(child); } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts new file mode 100644 index 000000000000..4d8bb46f5451 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts @@ -0,0 +1,9 @@ +abstract class Foo { + accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + declare accessor prop7: number +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json new file mode 100644 index 000000000000..7c035142f287 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [["transform-typescript", { "allowDeclareFields": true }]], + "parserOpts": { + "plugins": ["decoratorAutoAccessors"] + } +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js new file mode 100644 index 000000000000..1522c3c5cd3f --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js @@ -0,0 +1,8 @@ +class Foo { + accessor prop = 1; + static accessor prop2 = 1; + accessor #prop3 = 1; + accessor [prop4] = 1; + accessor prop5 = 1; + accessor prop6; +} From f3fe423497de4568f7a5779dc0f9cb3e162bef1b Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sat, 19 Nov 2022 05:34:09 +0800 Subject: [PATCH 4/8] review --- .../src/parse-error/standard-errors.ts | 1 + .../src/plugins/typescript/index.ts | 58 +++--- .../typescript/class/accessor/input.ts | 21 +++ .../options.json | 0 .../output.json | 177 +++++++++++++++++- .../input.ts | 8 +- .../options.json | 0 .../output.js | 14 ++ .../input.ts | 8 +- .../options.json | 6 + .../output.js | 2 +- 11 files changed, 262 insertions(+), 33 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts rename packages/babel-parser/test/fixtures/typescript/class/{accessor-with-type => accessor}/options.json (100%) rename packages/babel-parser/test/fixtures/typescript/class/{accessor-with-type => accessor}/output.json (54%) rename packages/{babel-parser/test/fixtures/typescript/class/accessor-with-type => babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false}/input.ts (60%) rename packages/babel-plugin-transform-typescript/test/fixtures/class/{accessor => accessor-allowDeclareFields-false}/options.json (100%) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/output.js rename packages/babel-plugin-transform-typescript/test/fixtures/class/{accessor => accessor-allowDeclareFields-true}/input.ts (60%) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json rename packages/babel-plugin-transform-typescript/test/fixtures/class/{accessor => accessor-allowDeclareFields-true}/output.js (88%) diff --git a/packages/babel-parser/src/parse-error/standard-errors.ts b/packages/babel-parser/src/parse-error/standard-errors.ts index 0db3966f6af8..d2e335b83ae4 100644 --- a/packages/babel-parser/src/parse-error/standard-errors.ts +++ b/packages/babel-parser/src/parse-error/standard-errors.ts @@ -35,6 +35,7 @@ export default { AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.", AwaitNotInAsyncFunction: "'await' is only allowed within async functions.", + // TODO: Accesor -> Accessor BadGetterArity: "A 'get' accesor must not have any formal parameters.", BadSetterArity: "A 'set' accesor must have exactly one formal parameter.", BadSetterRestParameter: diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index cf49013d1307..4b21e03dbcb3 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -90,12 +90,14 @@ const TSErrors = ParseErrorEnum`typescript`({ propertyName: string; }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`, - AccesorCannotDeclareThisParameter: + AccessorCannotBeOptional: + "An 'accessor' property cannot be declared optional.", + AccessorCannotDeclareThisParameter: "'get' and 'set' accessors cannot declare 'this' parameters.", - AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.", + AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.", ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.", ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.", - ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: + ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.", ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.", @@ -194,11 +196,11 @@ const TSErrors = ParseErrorEnum`typescript`({ "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `() => ...`.", ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.", - SetAccesorCannotHaveOptionalParameter: + SetAccessorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.", - SetAccesorCannotHaveRestParameter: + SetAccessorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.", - SetAccesorCannotHaveReturnType: + SetAccessorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.", SingleTypeParameterWithoutTrailingComma: ({ typeParameterName, @@ -835,7 +837,7 @@ export default (superClass: ClassWithMixin) => } const method: N.TsMethodSignature = nodeAny; if (method.kind && this.match(tt.lt)) { - this.raise(TSErrors.AccesorCannotHaveTypeParameters, { + this.raise(TSErrors.AccessorCannotHaveTypeParameters, { at: this.state.curPosition(), }); } @@ -851,7 +853,7 @@ export default (superClass: ClassWithMixin) => if (method[paramsKey].length > 0) { this.raise(Errors.BadGetterArity, { at: this.state.curPosition() }); if (this.isThisParam(method[paramsKey][0])) { - this.raise(TSErrors.AccesorCannotDeclareThisParameter, { + this.raise(TSErrors.AccessorCannotDeclareThisParameter, { at: this.state.curPosition(), }); } @@ -862,7 +864,7 @@ export default (superClass: ClassWithMixin) => } else { const firstParameter = method[paramsKey][0]; if (this.isThisParam(firstParameter)) { - this.raise(TSErrors.AccesorCannotDeclareThisParameter, { + this.raise(TSErrors.AccessorCannotDeclareThisParameter, { at: this.state.curPosition(), }); } @@ -870,18 +872,18 @@ export default (superClass: ClassWithMixin) => firstParameter.type === "Identifier" && firstParameter.optional ) { - this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, { + this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, { at: this.state.curPosition(), }); } if (firstParameter.type === "RestElement") { - this.raise(TSErrors.SetAccesorCannotHaveRestParameter, { + this.raise(TSErrors.SetAccessorCannotHaveRestParameter, { at: this.state.curPosition(), }); } } if (method[returnTypeKey]) { - this.raise(TSErrors.SetAccesorCannotHaveReturnType, { + this.raise(TSErrors.SetAccessorCannotHaveReturnType, { at: method[returnTypeKey], }); } @@ -2794,7 +2796,7 @@ export default (superClass: ClassWithMixin) => !isPossiblyLiteralEnum(init) ) { this.raise( - TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, + TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, { at: init }, ); } @@ -3124,10 +3126,14 @@ export default (superClass: ClassWithMixin) => } parseClassPropertyAnnotation( - node: N.ClassProperty | N.ClassPrivateProperty, + node: N.ClassProperty | N.ClassPrivateProperty | N.ClassAccessorProperty, ): void { - if (!node.optional && this.eat(tt.bang)) { - node.definite = true; + if (!node.optional) { + if (this.eat(tt.bang)) { + node.definite = true; + } else if (this.eat(tt.question)) { + node.optional = true; + } } const type = this.tsTryParseTypeAnnotation(); @@ -3181,6 +3187,16 @@ export default (superClass: ClassWithMixin) => return super.parseClassPrivateProperty(node); } + parseClassAccessorProperty( + node: N.ClassAccessorProperty, + ): N.ClassAccessorProperty { + this.parseClassPropertyAnnotation(node); + if (node.optional) { + this.raise(TSErrors.AccessorCannotBeOptional, { at: node }); + } + return super.parseClassAccessorProperty(node); + } + pushClassMethod( classBody: N.ClassBody, method: N.ClassMethod, @@ -3224,16 +3240,6 @@ export default (superClass: ClassWithMixin) => super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); } - pushClassAccessorProperty( - classBody: Undone, - prop: N.ClassAccessorProperty, - isPrivate: boolean, - ) { - const typeAnnotation = this.tsTryParseTypeAnnotation(); - if (typeAnnotation) prop.typeAnnotation = typeAnnotation; - super.pushClassAccessorProperty(classBody, prop, isPrivate); - } - declareClassPrivateMethodInScope( node: N.ClassPrivateMethod | N.EstreeMethodDefinition | N.TSDeclareMethod, kind: number, diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts new file mode 100644 index 000000000000..c6048a295b5f --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts @@ -0,0 +1,21 @@ +abstract class Foo { + accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + declare accessor prop7: number; + private accessor #p: any; + + accessor a!; + abstract accessor #s; + accessor #d?; + abstract accessor f = 1; + readonly accessor g; +} + +declare class C { + accessor x = 1; + #y = 1; +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json b/packages/babel-parser/test/fixtures/typescript/class/accessor/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/options.json rename to packages/babel-parser/test/fixtures/typescript/class/accessor/options.json diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json similarity index 54% rename from packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json rename to packages/babel-parser/test/fixtures/typescript/class/accessor/output.json index bb206ee82cb8..5ced919b9092 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json @@ -1,15 +1,18 @@ { "type": "File", - "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, + "start":0,"end":441,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":21,"column":1,"index":441}}, + "errors": [ + "SyntaxError: An 'accessor' property cannot be declared optional. (13:2)" + ], "program": { "type": "Program", - "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, + "start":0,"end":441,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":21,"column":1,"index":441}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start":0,"end":258,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":9,"column":1,"index":258}}, + "start":0,"end":392,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":16,"column":1,"index":392}}, "abstract": true, "id": { "type": "Identifier", @@ -19,7 +22,7 @@ "superClass": null, "body": { "type": "ClassBody", - "start":19,"end":258,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":9,"column":1,"index":258}}, + "start":19,"end":392,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":16,"column":1,"index":392}}, "body": [ { "type": "ClassAccessorProperty", @@ -207,6 +210,172 @@ } }, "value": null + }, + { + "type": "ClassAccessorProperty", + "start":259,"end":284,"loc":{"start":{"line":9,"column":2,"index":259},"end":{"line":9,"column":27,"index":284}}, + "accessibility": "private", + "static": false, + "key": { + "type": "PrivateName", + "start":276,"end":278,"loc":{"start":{"line":9,"column":19,"index":276},"end":{"line":9,"column":21,"index":278}}, + "id": { + "type": "Identifier", + "start":277,"end":278,"loc":{"start":{"line":9,"column":20,"index":277},"end":{"line":9,"column":21,"index":278},"identifierName":"p"}, + "name": "p" + } + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":278,"end":283,"loc":{"start":{"line":9,"column":21,"index":278},"end":{"line":9,"column":26,"index":283}}, + "typeAnnotation": { + "type": "TSAnyKeyword", + "start":280,"end":283,"loc":{"start":{"line":9,"column":23,"index":280},"end":{"line":9,"column":26,"index":283}} + } + }, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":288,"end":300,"loc":{"start":{"line":11,"column":2,"index":288},"end":{"line":11,"column":14,"index":300}}, + "static": false, + "key": { + "type": "Identifier", + "start":297,"end":298,"loc":{"start":{"line":11,"column":11,"index":297},"end":{"line":11,"column":12,"index":298},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "definite": true, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":303,"end":324,"loc":{"start":{"line":12,"column":2,"index":303},"end":{"line":12,"column":23,"index":324}}, + "abstract": true, + "static": false, + "key": { + "type": "PrivateName", + "start":321,"end":323,"loc":{"start":{"line":12,"column":20,"index":321},"end":{"line":12,"column":22,"index":323}}, + "id": { + "type": "Identifier", + "start":322,"end":323,"loc":{"start":{"line":12,"column":21,"index":322},"end":{"line":12,"column":22,"index":323},"identifierName":"s"}, + "name": "s" + } + }, + "computed": false, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":327,"end":340,"loc":{"start":{"line":13,"column":2,"index":327},"end":{"line":13,"column":15,"index":340}}, + "static": false, + "key": { + "type": "PrivateName", + "start":336,"end":338,"loc":{"start":{"line":13,"column":11,"index":336},"end":{"line":13,"column":13,"index":338}}, + "id": { + "type": "Identifier", + "start":337,"end":338,"loc":{"start":{"line":13,"column":12,"index":337},"end":{"line":13,"column":13,"index":338},"identifierName":"d"}, + "name": "d" + } + }, + "computed": false, + "optional": true, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":343,"end":367,"loc":{"start":{"line":14,"column":2,"index":343},"end":{"line":14,"column":26,"index":367}}, + "abstract": true, + "static": false, + "key": { + "type": "Identifier", + "start":361,"end":362,"loc":{"start":{"line":14,"column":20,"index":361},"end":{"line":14,"column":21,"index":362},"identifierName":"f"}, + "name": "f" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":365,"end":366,"loc":{"start":{"line":14,"column":24,"index":365},"end":{"line":14,"column":25,"index":366}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassAccessorProperty", + "start":370,"end":390,"loc":{"start":{"line":15,"column":2,"index":370},"end":{"line":15,"column":22,"index":390}}, + "readonly": true, + "static": false, + "key": { + "type": "Identifier", + "start":388,"end":389,"loc":{"start":{"line":15,"column":20,"index":388},"end":{"line":15,"column":21,"index":389},"identifierName":"g"}, + "name": "g" + }, + "computed": false, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start":394,"end":441,"loc":{"start":{"line":18,"column":0,"index":394},"end":{"line":21,"column":1,"index":441}}, + "declare": true, + "id": { + "type": "Identifier", + "start":408,"end":409,"loc":{"start":{"line":18,"column":14,"index":408},"end":{"line":18,"column":15,"index":409},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":410,"end":441,"loc":{"start":{"line":18,"column":16,"index":410},"end":{"line":21,"column":1,"index":441}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":414,"end":429,"loc":{"start":{"line":19,"column":2,"index":414},"end":{"line":19,"column":17,"index":429}}, + "static": false, + "key": { + "type": "Identifier", + "start":423,"end":424,"loc":{"start":{"line":19,"column":11,"index":423},"end":{"line":19,"column":12,"index":424},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":427,"end":428,"loc":{"start":{"line":19,"column":15,"index":427},"end":{"line":19,"column":16,"index":428}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start":432,"end":439,"loc":{"start":{"line":20,"column":2,"index":432},"end":{"line":20,"column":9,"index":439}}, + "static": false, + "key": { + "type": "PrivateName", + "start":432,"end":434,"loc":{"start":{"line":20,"column":2,"index":432},"end":{"line":20,"column":4,"index":434}}, + "id": { + "type": "Identifier", + "start":433,"end":434,"loc":{"start":{"line":20,"column":3,"index":433},"end":{"line":20,"column":4,"index":434},"identifierName":"y"}, + "name": "y" + } + }, + "value": { + "type": "NumericLiteral", + "start":437,"end":438,"loc":{"start":{"line":20,"column":7,"index":437},"end":{"line":20,"column":8,"index":438}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } } ] } diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/input.ts similarity index 60% rename from packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts rename to packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/input.ts index 3f2b87e28e07..b90f613a51bc 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor-with-type/input.ts +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/input.ts @@ -5,5 +5,11 @@ abstract class Foo { accessor [prop4]: number = 1; private accessor prop5: number = 1; abstract accessor prop6: number; - declare accessor prop7: number; + private accessor #p: any; + + accessor a!: any; + accessor aa!: any; + abstract accessor #s; + abstract accessor f = 1; + readonly accessor g; } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/options.json similarity index 100% rename from packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/options.json rename to packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/options.json diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/output.js new file mode 100644 index 000000000000..9a08c34e3c0b --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/output.js @@ -0,0 +1,14 @@ +class Foo { + accessor prop = 1; + static accessor prop2 = 1; + accessor #prop3 = 1; + accessor [prop4] = 1; + accessor prop5 = 1; + accessor prop6; + accessor #p; + accessor a; + accessor aa; + accessor #s; + accessor f = 1; + accessor g; +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/input.ts similarity index 60% rename from packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts rename to packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/input.ts index 4d8bb46f5451..b90f613a51bc 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/input.ts +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/input.ts @@ -5,5 +5,11 @@ abstract class Foo { accessor [prop4]: number = 1; private accessor prop5: number = 1; abstract accessor prop6: number; - declare accessor prop7: number + private accessor #p: any; + + accessor a!: any; + accessor aa!: any; + abstract accessor #s; + abstract accessor f = 1; + readonly accessor g; } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json new file mode 100644 index 000000000000..469441c53612 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [["transform-typescript", { "allowDeclareFields": false }]], + "parserOpts": { + "plugins": ["decoratorAutoAccessors"] + } +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js similarity index 88% rename from packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js rename to packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js index 1522c3c5cd3f..e78be3ff8e44 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor/output.js +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js @@ -4,5 +4,5 @@ class Foo { accessor #prop3 = 1; accessor [prop4] = 1; accessor prop5 = 1; - accessor prop6; + accessor f = 1; } From d9764c0bef6afe4d2191a23fd638d534db788c7b Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Sat, 19 Nov 2022 07:05:04 +0800 Subject: [PATCH 5/8] fix babel8 test --- .../input.ts | 15 +++++++++++++++ .../options.json | 7 +++++++ .../output.js | 8 ++++++++ .../accessor-allowDeclareFields-true/options.json | 3 ++- .../accessor-allowDeclareFields-true/output.js | 6 ++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/input.ts create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/options.json create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/output.js diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/input.ts new file mode 100644 index 000000000000..b90f613a51bc --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/input.ts @@ -0,0 +1,15 @@ +abstract class Foo { + accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + private accessor #p: any; + + accessor a!: any; + accessor aa!: any; + abstract accessor #s; + abstract accessor f = 1; + readonly accessor g; +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/options.json new file mode 100644 index 000000000000..06cd35701c66 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [["transform-typescript", { "allowDeclareFields": false }]], + "parserOpts": { + "plugins": ["decoratorAutoAccessors"] + }, + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/output.js new file mode 100644 index 000000000000..e78be3ff8e44 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true-babel-7/output.js @@ -0,0 +1,8 @@ +class Foo { + accessor prop = 1; + static accessor prop2 = 1; + accessor #prop3 = 1; + accessor [prop4] = 1; + accessor prop5 = 1; + accessor f = 1; +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json index 469441c53612..2ba2ad643858 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/options.json @@ -2,5 +2,6 @@ "plugins": [["transform-typescript", { "allowDeclareFields": false }]], "parserOpts": { "plugins": ["decoratorAutoAccessors"] - } + }, + "BABEL_8_BREAKING": true } diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js index e78be3ff8e44..9a08c34e3c0b 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js +++ b/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/output.js @@ -4,5 +4,11 @@ class Foo { accessor #prop3 = 1; accessor [prop4] = 1; accessor prop5 = 1; + accessor prop6; + accessor #p; + accessor a; + accessor aa; + accessor #s; accessor f = 1; + accessor g; } From 4845f74c9901c336586a1db85e4247a2a568fd22 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Tue, 22 Nov 2022 23:21:14 +0800 Subject: [PATCH 6/8] review --- .../class/accessor-invalid/input.ts | 15 ++ .../class/accessor-invalid/options.json | 6 + .../class/accessor-invalid/output.json | 220 ++++++++++++++++++ .../typescript/class/accessor/input.ts | 13 -- .../typescript/class/accessor/output.json | 198 +--------------- 5 files changed, 245 insertions(+), 207 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/options.json create mode 100644 packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/output.json diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/input.ts new file mode 100644 index 000000000000..8a2f8a1d63ab --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/input.ts @@ -0,0 +1,15 @@ +abstract class Foo { + declare accessor prop7: number; + private accessor #p: any; + + accessor a!; + abstract accessor #s; + accessor #d?; + abstract accessor f = 1; + readonly accessor g; +} + +declare class C { + accessor x = 1; + #y = 1; +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/options.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/options.json new file mode 100644 index 000000000000..ceb6fe8e0820 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "typescript", + "decoratorAutoAccessors" + ] +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/output.json new file mode 100644 index 000000000000..c1194e104c7b --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/output.json @@ -0,0 +1,220 @@ +{ + "type": "File", + "start":0,"end":239,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":15,"column":1,"index":239}}, + "errors": [ + "SyntaxError: An 'accessor' property cannot be declared optional. (7:2)" + ], + "program": { + "type": "Program", + "start":0,"end":239,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":15,"column":1,"index":239}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":190,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":10,"column":1,"index":190}}, + "abstract": true, + "id": { + "type": "Identifier", + "start":15,"end":18,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":18,"index":18},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":19,"end":190,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":10,"column":1,"index":190}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":23,"end":54,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":33,"index":54}}, + "declare": true, + "static": false, + "key": { + "type": "Identifier", + "start":40,"end":45,"loc":{"start":{"line":2,"column":19,"index":40},"end":{"line":2,"column":24,"index":45},"identifierName":"prop7"}, + "name": "prop7" + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":45,"end":53,"loc":{"start":{"line":2,"column":24,"index":45},"end":{"line":2,"column":32,"index":53}}, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start":47,"end":53,"loc":{"start":{"line":2,"column":26,"index":47},"end":{"line":2,"column":32,"index":53}} + } + }, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":57,"end":82,"loc":{"start":{"line":3,"column":2,"index":57},"end":{"line":3,"column":27,"index":82}}, + "accessibility": "private", + "static": false, + "key": { + "type": "PrivateName", + "start":74,"end":76,"loc":{"start":{"line":3,"column":19,"index":74},"end":{"line":3,"column":21,"index":76}}, + "id": { + "type": "Identifier", + "start":75,"end":76,"loc":{"start":{"line":3,"column":20,"index":75},"end":{"line":3,"column":21,"index":76},"identifierName":"p"}, + "name": "p" + } + }, + "computed": false, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start":76,"end":81,"loc":{"start":{"line":3,"column":21,"index":76},"end":{"line":3,"column":26,"index":81}}, + "typeAnnotation": { + "type": "TSAnyKeyword", + "start":78,"end":81,"loc":{"start":{"line":3,"column":23,"index":78},"end":{"line":3,"column":26,"index":81}} + } + }, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":86,"end":98,"loc":{"start":{"line":5,"column":2,"index":86},"end":{"line":5,"column":14,"index":98}}, + "static": false, + "key": { + "type": "Identifier", + "start":95,"end":96,"loc":{"start":{"line":5,"column":11,"index":95},"end":{"line":5,"column":12,"index":96},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "definite": true, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":101,"end":122,"loc":{"start":{"line":6,"column":2,"index":101},"end":{"line":6,"column":23,"index":122}}, + "abstract": true, + "static": false, + "key": { + "type": "PrivateName", + "start":119,"end":121,"loc":{"start":{"line":6,"column":20,"index":119},"end":{"line":6,"column":22,"index":121}}, + "id": { + "type": "Identifier", + "start":120,"end":121,"loc":{"start":{"line":6,"column":21,"index":120},"end":{"line":6,"column":22,"index":121},"identifierName":"s"}, + "name": "s" + } + }, + "computed": false, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":125,"end":138,"loc":{"start":{"line":7,"column":2,"index":125},"end":{"line":7,"column":15,"index":138}}, + "static": false, + "key": { + "type": "PrivateName", + "start":134,"end":136,"loc":{"start":{"line":7,"column":11,"index":134},"end":{"line":7,"column":13,"index":136}}, + "id": { + "type": "Identifier", + "start":135,"end":136,"loc":{"start":{"line":7,"column":12,"index":135},"end":{"line":7,"column":13,"index":136},"identifierName":"d"}, + "name": "d" + } + }, + "computed": false, + "optional": true, + "value": null + }, + { + "type": "ClassAccessorProperty", + "start":141,"end":165,"loc":{"start":{"line":8,"column":2,"index":141},"end":{"line":8,"column":26,"index":165}}, + "abstract": true, + "static": false, + "key": { + "type": "Identifier", + "start":159,"end":160,"loc":{"start":{"line":8,"column":20,"index":159},"end":{"line":8,"column":21,"index":160},"identifierName":"f"}, + "name": "f" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":163,"end":164,"loc":{"start":{"line":8,"column":24,"index":163},"end":{"line":8,"column":25,"index":164}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassAccessorProperty", + "start":168,"end":188,"loc":{"start":{"line":9,"column":2,"index":168},"end":{"line":9,"column":22,"index":188}}, + "readonly": true, + "static": false, + "key": { + "type": "Identifier", + "start":186,"end":187,"loc":{"start":{"line":9,"column":20,"index":186},"end":{"line":9,"column":21,"index":187},"identifierName":"g"}, + "name": "g" + }, + "computed": false, + "value": null + } + ] + } + }, + { + "type": "ClassDeclaration", + "start":192,"end":239,"loc":{"start":{"line":12,"column":0,"index":192},"end":{"line":15,"column":1,"index":239}}, + "declare": true, + "id": { + "type": "Identifier", + "start":206,"end":207,"loc":{"start":{"line":12,"column":14,"index":206},"end":{"line":12,"column":15,"index":207},"identifierName":"C"}, + "name": "C" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":208,"end":239,"loc":{"start":{"line":12,"column":16,"index":208},"end":{"line":15,"column":1,"index":239}}, + "body": [ + { + "type": "ClassAccessorProperty", + "start":212,"end":227,"loc":{"start":{"line":13,"column":2,"index":212},"end":{"line":13,"column":17,"index":227}}, + "static": false, + "key": { + "type": "Identifier", + "start":221,"end":222,"loc":{"start":{"line":13,"column":11,"index":221},"end":{"line":13,"column":12,"index":222},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "value": { + "type": "NumericLiteral", + "start":225,"end":226,"loc":{"start":{"line":13,"column":15,"index":225},"end":{"line":13,"column":16,"index":226}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start":230,"end":237,"loc":{"start":{"line":14,"column":2,"index":230},"end":{"line":14,"column":9,"index":237}}, + "static": false, + "key": { + "type": "PrivateName", + "start":230,"end":232,"loc":{"start":{"line":14,"column":2,"index":230},"end":{"line":14,"column":4,"index":232}}, + "id": { + "type": "Identifier", + "start":231,"end":232,"loc":{"start":{"line":14,"column":3,"index":231},"end":{"line":14,"column":4,"index":232},"identifierName":"y"}, + "name": "y" + } + }, + "value": { + "type": "NumericLiteral", + "start":235,"end":236,"loc":{"start":{"line":14,"column":7,"index":235},"end":{"line":14,"column":8,"index":236}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts b/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts index c6048a295b5f..2099b517a0f2 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor/input.ts @@ -5,17 +5,4 @@ abstract class Foo { accessor [prop4]: number = 1; private accessor prop5: number = 1; abstract accessor prop6: number; - declare accessor prop7: number; - private accessor #p: any; - - accessor a!; - abstract accessor #s; - accessor #d?; - abstract accessor f = 1; - readonly accessor g; -} - -declare class C { - accessor x = 1; - #y = 1; } diff --git a/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json b/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json index 5ced919b9092..b18d0badaa97 100644 --- a/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json +++ b/packages/babel-parser/test/fixtures/typescript/class/accessor/output.json @@ -1,18 +1,15 @@ { "type": "File", - "start":0,"end":441,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":21,"column":1,"index":441}}, - "errors": [ - "SyntaxError: An 'accessor' property cannot be declared optional. (13:2)" - ], + "start":0,"end":224,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":224}}, "program": { "type": "Program", - "start":0,"end":441,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":21,"column":1,"index":441}}, + "start":0,"end":224,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":224}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start":0,"end":392,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":16,"column":1,"index":392}}, + "start":0,"end":224,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":8,"column":1,"index":224}}, "abstract": true, "id": { "type": "Identifier", @@ -22,7 +19,7 @@ "superClass": null, "body": { "type": "ClassBody", - "start":19,"end":392,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":16,"column":1,"index":392}}, + "start":19,"end":224,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":8,"column":1,"index":224}}, "body": [ { "type": "ClassAccessorProperty", @@ -189,193 +186,6 @@ } }, "value": null - }, - { - "type": "ClassAccessorProperty", - "start":225,"end":256,"loc":{"start":{"line":8,"column":2,"index":225},"end":{"line":8,"column":33,"index":256}}, - "declare": true, - "static": false, - "key": { - "type": "Identifier", - "start":242,"end":247,"loc":{"start":{"line":8,"column":19,"index":242},"end":{"line":8,"column":24,"index":247},"identifierName":"prop7"}, - "name": "prop7" - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start":247,"end":255,"loc":{"start":{"line":8,"column":24,"index":247},"end":{"line":8,"column":32,"index":255}}, - "typeAnnotation": { - "type": "TSNumberKeyword", - "start":249,"end":255,"loc":{"start":{"line":8,"column":26,"index":249},"end":{"line":8,"column":32,"index":255}} - } - }, - "value": null - }, - { - "type": "ClassAccessorProperty", - "start":259,"end":284,"loc":{"start":{"line":9,"column":2,"index":259},"end":{"line":9,"column":27,"index":284}}, - "accessibility": "private", - "static": false, - "key": { - "type": "PrivateName", - "start":276,"end":278,"loc":{"start":{"line":9,"column":19,"index":276},"end":{"line":9,"column":21,"index":278}}, - "id": { - "type": "Identifier", - "start":277,"end":278,"loc":{"start":{"line":9,"column":20,"index":277},"end":{"line":9,"column":21,"index":278},"identifierName":"p"}, - "name": "p" - } - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start":278,"end":283,"loc":{"start":{"line":9,"column":21,"index":278},"end":{"line":9,"column":26,"index":283}}, - "typeAnnotation": { - "type": "TSAnyKeyword", - "start":280,"end":283,"loc":{"start":{"line":9,"column":23,"index":280},"end":{"line":9,"column":26,"index":283}} - } - }, - "value": null - }, - { - "type": "ClassAccessorProperty", - "start":288,"end":300,"loc":{"start":{"line":11,"column":2,"index":288},"end":{"line":11,"column":14,"index":300}}, - "static": false, - "key": { - "type": "Identifier", - "start":297,"end":298,"loc":{"start":{"line":11,"column":11,"index":297},"end":{"line":11,"column":12,"index":298},"identifierName":"a"}, - "name": "a" - }, - "computed": false, - "definite": true, - "value": null - }, - { - "type": "ClassAccessorProperty", - "start":303,"end":324,"loc":{"start":{"line":12,"column":2,"index":303},"end":{"line":12,"column":23,"index":324}}, - "abstract": true, - "static": false, - "key": { - "type": "PrivateName", - "start":321,"end":323,"loc":{"start":{"line":12,"column":20,"index":321},"end":{"line":12,"column":22,"index":323}}, - "id": { - "type": "Identifier", - "start":322,"end":323,"loc":{"start":{"line":12,"column":21,"index":322},"end":{"line":12,"column":22,"index":323},"identifierName":"s"}, - "name": "s" - } - }, - "computed": false, - "value": null - }, - { - "type": "ClassAccessorProperty", - "start":327,"end":340,"loc":{"start":{"line":13,"column":2,"index":327},"end":{"line":13,"column":15,"index":340}}, - "static": false, - "key": { - "type": "PrivateName", - "start":336,"end":338,"loc":{"start":{"line":13,"column":11,"index":336},"end":{"line":13,"column":13,"index":338}}, - "id": { - "type": "Identifier", - "start":337,"end":338,"loc":{"start":{"line":13,"column":12,"index":337},"end":{"line":13,"column":13,"index":338},"identifierName":"d"}, - "name": "d" - } - }, - "computed": false, - "optional": true, - "value": null - }, - { - "type": "ClassAccessorProperty", - "start":343,"end":367,"loc":{"start":{"line":14,"column":2,"index":343},"end":{"line":14,"column":26,"index":367}}, - "abstract": true, - "static": false, - "key": { - "type": "Identifier", - "start":361,"end":362,"loc":{"start":{"line":14,"column":20,"index":361},"end":{"line":14,"column":21,"index":362},"identifierName":"f"}, - "name": "f" - }, - "computed": false, - "value": { - "type": "NumericLiteral", - "start":365,"end":366,"loc":{"start":{"line":14,"column":24,"index":365},"end":{"line":14,"column":25,"index":366}}, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - { - "type": "ClassAccessorProperty", - "start":370,"end":390,"loc":{"start":{"line":15,"column":2,"index":370},"end":{"line":15,"column":22,"index":390}}, - "readonly": true, - "static": false, - "key": { - "type": "Identifier", - "start":388,"end":389,"loc":{"start":{"line":15,"column":20,"index":388},"end":{"line":15,"column":21,"index":389},"identifierName":"g"}, - "name": "g" - }, - "computed": false, - "value": null - } - ] - } - }, - { - "type": "ClassDeclaration", - "start":394,"end":441,"loc":{"start":{"line":18,"column":0,"index":394},"end":{"line":21,"column":1,"index":441}}, - "declare": true, - "id": { - "type": "Identifier", - "start":408,"end":409,"loc":{"start":{"line":18,"column":14,"index":408},"end":{"line":18,"column":15,"index":409},"identifierName":"C"}, - "name": "C" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start":410,"end":441,"loc":{"start":{"line":18,"column":16,"index":410},"end":{"line":21,"column":1,"index":441}}, - "body": [ - { - "type": "ClassAccessorProperty", - "start":414,"end":429,"loc":{"start":{"line":19,"column":2,"index":414},"end":{"line":19,"column":17,"index":429}}, - "static": false, - "key": { - "type": "Identifier", - "start":423,"end":424,"loc":{"start":{"line":19,"column":11,"index":423},"end":{"line":19,"column":12,"index":424},"identifierName":"x"}, - "name": "x" - }, - "computed": false, - "value": { - "type": "NumericLiteral", - "start":427,"end":428,"loc":{"start":{"line":19,"column":15,"index":427},"end":{"line":19,"column":16,"index":428}}, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - { - "type": "ClassPrivateProperty", - "start":432,"end":439,"loc":{"start":{"line":20,"column":2,"index":432},"end":{"line":20,"column":9,"index":439}}, - "static": false, - "key": { - "type": "PrivateName", - "start":432,"end":434,"loc":{"start":{"line":20,"column":2,"index":432},"end":{"line":20,"column":4,"index":434}}, - "id": { - "type": "Identifier", - "start":433,"end":434,"loc":{"start":{"line":20,"column":3,"index":433},"end":{"line":20,"column":4,"index":434},"identifierName":"y"}, - "name": "y" - } - }, - "value": { - "type": "NumericLiteral", - "start":437,"end":438,"loc":{"start":{"line":20,"column":7,"index":437},"end":{"line":20,"column":8,"index":438}}, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } } ] } From 1080dd1664575ac7970cf3ad71bc57788e6779da Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:48:02 +0800 Subject: [PATCH 7/8] review --- .../src/parse-error/standard-errors.ts | 7 ++--- .../src/plugins/typescript/index.ts | 29 ++++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/babel-parser/src/parse-error/standard-errors.ts b/packages/babel-parser/src/parse-error/standard-errors.ts index d2e335b83ae4..034db87f20ac 100644 --- a/packages/babel-parser/src/parse-error/standard-errors.ts +++ b/packages/babel-parser/src/parse-error/standard-errors.ts @@ -35,11 +35,10 @@ export default { AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.", AwaitNotInAsyncFunction: "'await' is only allowed within async functions.", - // TODO: Accesor -> Accessor - BadGetterArity: "A 'get' accesor must not have any formal parameters.", - BadSetterArity: "A 'set' accesor must have exactly one formal parameter.", + BadGetterArity: "A 'get' accessor must not have any formal parameters.", + BadSetterArity: "A 'set' accessor must have exactly one formal parameter.", BadSetterRestParameter: - "A 'set' accesor function argument must not be a rest parameter.", + "A 'set' accessor function argument must not be a rest parameter.", ConstructorClassField: "Classes may not have a field named 'constructor'.", ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.", diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index 4b21e03dbcb3..80db61b77bbf 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -90,14 +90,14 @@ const TSErrors = ParseErrorEnum`typescript`({ propertyName: string; }) => `Property '${propertyName}' cannot have an initializer because it is marked abstract.`, + AccesorCannotDeclareThisParameter: + "'get' and 'set' accessors cannot declare 'this' parameters.", + AccesorCannotHaveTypeParameters: "An accessor cannot have type parameters.", AccessorCannotBeOptional: "An 'accessor' property cannot be declared optional.", - AccessorCannotDeclareThisParameter: - "'get' and 'set' accessors cannot declare 'this' parameters.", - AccessorCannotHaveTypeParameters: "An accessor cannot have type parameters.", ClassMethodHasDeclare: "Class methods cannot have the 'declare' modifier.", ClassMethodHasReadonly: "Class methods cannot have the 'readonly' modifier.", - ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference: + ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference: "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.", ConstructorHasTypeParameters: "Type parameters cannot appear on a constructor declaration.", @@ -196,11 +196,12 @@ const TSErrors = ParseErrorEnum`typescript`({ "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `() => ...`.", ReservedTypeAssertion: "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.", - SetAccessorCannotHaveOptionalParameter: + // TODO: Accesor -> Accessor + SetAccesorCannotHaveOptionalParameter: "A 'set' accessor cannot have an optional parameter.", - SetAccessorCannotHaveRestParameter: + SetAccesorCannotHaveRestParameter: "A 'set' accessor cannot have rest parameter.", - SetAccessorCannotHaveReturnType: + SetAccesorCannotHaveReturnType: "A 'set' accessor cannot have a return type annotation.", SingleTypeParameterWithoutTrailingComma: ({ typeParameterName, @@ -837,7 +838,7 @@ export default (superClass: ClassWithMixin) => } const method: N.TsMethodSignature = nodeAny; if (method.kind && this.match(tt.lt)) { - this.raise(TSErrors.AccessorCannotHaveTypeParameters, { + this.raise(TSErrors.AccesorCannotHaveTypeParameters, { at: this.state.curPosition(), }); } @@ -853,7 +854,7 @@ export default (superClass: ClassWithMixin) => if (method[paramsKey].length > 0) { this.raise(Errors.BadGetterArity, { at: this.state.curPosition() }); if (this.isThisParam(method[paramsKey][0])) { - this.raise(TSErrors.AccessorCannotDeclareThisParameter, { + this.raise(TSErrors.AccesorCannotDeclareThisParameter, { at: this.state.curPosition(), }); } @@ -864,7 +865,7 @@ export default (superClass: ClassWithMixin) => } else { const firstParameter = method[paramsKey][0]; if (this.isThisParam(firstParameter)) { - this.raise(TSErrors.AccessorCannotDeclareThisParameter, { + this.raise(TSErrors.AccesorCannotDeclareThisParameter, { at: this.state.curPosition(), }); } @@ -872,18 +873,18 @@ export default (superClass: ClassWithMixin) => firstParameter.type === "Identifier" && firstParameter.optional ) { - this.raise(TSErrors.SetAccessorCannotHaveOptionalParameter, { + this.raise(TSErrors.SetAccesorCannotHaveOptionalParameter, { at: this.state.curPosition(), }); } if (firstParameter.type === "RestElement") { - this.raise(TSErrors.SetAccessorCannotHaveRestParameter, { + this.raise(TSErrors.SetAccesorCannotHaveRestParameter, { at: this.state.curPosition(), }); } } if (method[returnTypeKey]) { - this.raise(TSErrors.SetAccessorCannotHaveReturnType, { + this.raise(TSErrors.SetAccesorCannotHaveReturnType, { at: method[returnTypeKey], }); } @@ -2796,7 +2797,7 @@ export default (superClass: ClassWithMixin) => !isPossiblyLiteralEnum(init) ) { this.raise( - TSErrors.ConstInitializerMustBeStringOrNumericLiteralOrLiteralEnumReference, + TSErrors.ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference, { at: init }, ); } From 68312ffe576da92bf0374daa7d533b8f0729e9e1 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 16 Dec 2022 22:01:58 +0800 Subject: [PATCH 8/8] update tests --- .../core/object/invalid-setter/output.json | 2 +- .../class-methods/getter-signature/output.json | 2 +- .../es2015/uncategorised/347/output.json | 2 +- .../invalid-syntax/migrated_0075/output.json | 18 +++++++++--------- .../invalid-setter-rest/output.json | 2 +- .../object-method/invalid-setter/output.json | 4 ++-- .../typescript/getter-setter/output.json | 6 +++--- .../output.json | 2 +- .../invalid-getter-param-count/output.json | 2 +- .../invalid-setter-param-count/output.json | 2 +- .../invalid-setter-param-type/output.json | 2 +- .../this-annotation/this-getter/output.json | 2 +- .../this-setter-type/output.json | 2 +- .../output.json | 4 ++-- .../get-set-invalid-parameters/output.json | 4 ++-- .../output.json | 2 +- .../output.json | 2 +- 17 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-setter/output.json b/packages/babel-parser/test/fixtures/core/object/invalid-setter/output.json index ad8fc6967515..d4081be8c566 100644 --- a/packages/babel-parser/test/fixtures/core/object/invalid-setter/output.json +++ b/packages/babel-parser/test/fixtures/core/object/invalid-setter/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":15,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":15,"index":15}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (1:3)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (1:3)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/es2015/class-methods/getter-signature/output.json b/packages/babel-parser/test/fixtures/es2015/class-methods/getter-signature/output.json index 3b1fed887bf4..80366f9cebca 100644 --- a/packages/babel-parser/test/fixtures/es2015/class-methods/getter-signature/output.json +++ b/packages/babel-parser/test/fixtures/es2015/class-methods/getter-signature/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":31,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":31}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (2:2)" + "SyntaxError: A 'get' accessor must not have any formal parameters. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/347/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/347/output.json index 78a10d693c4f..7844fb183291 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/347/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/347/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":29,"index":29}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (1:10)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (1:10)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/output.json index 8af49750c8df..b91ae2b98296 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/output.json @@ -1,36 +1,36 @@ { "type": "File", - "start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}}, + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (1:3)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (1:3)" ], "program": { "type": "Program", - "start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}}, + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ExpressionStatement", - "start":0,"end":17,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":17,"index":17}}, + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, "expression": { "type": "ObjectExpression", - "start":1,"end":16,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":16,"index":16}}, + "start":1,"end":16,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":16}}, "properties": [ { "type": "Property", - "start":3,"end":14,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":14,"index":14}}, + "start":3,"end":14,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":14}}, "method": false, "key": { "type": "Identifier", - "start":7,"end":8,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":8,"index":8},"identifierName":"s"}, + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"s"}, "name": "s" }, "computed": false, "kind": "set", "value": { "type": "FunctionExpression", - "start":8,"end":14,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":14,"index":14}}, + "start":8,"end":14,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":14}}, "id": null, "generator": false, "async": false, @@ -38,7 +38,7 @@ "params": [], "body": { "type": "BlockStatement", - "start":11,"end":14,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":14,"index":14}}, + "start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}}, "body": [] } }, diff --git a/packages/babel-parser/test/fixtures/esprima/rest-parameter/invalid-setter-rest/output.json b/packages/babel-parser/test/fixtures/esprima/rest-parameter/invalid-setter-rest/output.json index e4e3fd9fc69d..00c1e1ae180d 100644 --- a/packages/babel-parser/test/fixtures/esprima/rest-parameter/invalid-setter-rest/output.json +++ b/packages/babel-parser/test/fixtures/esprima/rest-parameter/invalid-setter-rest/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":22,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":22,"index":22}}, "errors": [ - "SyntaxError: A 'set' accesor function argument must not be a rest parameter. (1:6)" + "SyntaxError: A 'set' accessor function argument must not be a rest parameter. (1:6)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json b/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json index a8870d027576..5a69a65bcfeb 100644 --- a/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json +++ b/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (1:3)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (1:3)" ], "program": { "type": "Program", @@ -53,4 +53,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/getter-setter/output.json b/packages/babel-parser/test/fixtures/estree/typescript/getter-setter/output.json index 082457acc226..92b27c4a8c55 100644 --- a/packages/babel-parser/test/fixtures/estree/typescript/getter-setter/output.json +++ b/packages/babel-parser/test/fixtures/estree/typescript/getter-setter/output.json @@ -2,8 +2,8 @@ "type": "File", "start":0,"end":85,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":18}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (3:3)", - "SyntaxError: A 'get' accesor must not have any formal parameters. (4:3)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (3:3)", + "SyntaxError: A 'get' accessor must not have any formal parameters. (4:3)" ], "program": { "type": "Program", @@ -200,4 +200,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json index 17f4fcc22b73..927cbb030fa7 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":37,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":37}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (2:2)" + "SyntaxError: A 'get' accessor must not have any formal parameters. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json index ebf265fb0830..898d5a829597 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":41,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":41}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (2:2)" + "SyntaxError: A 'get' accessor must not have any formal parameters. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json index 994feb0f0f6b..ed754c0d2753 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":29,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":29}}, "errors": [ - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (2:2)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json index c7ab11116cc8..ae80dbd53dd3 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":33,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":33}}, "errors": [ - "SyntaxError: A 'set' accesor function argument must not be a rest parameter. (2:2)" + "SyntaxError: A 'set' accessor function argument must not be a rest parameter. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json index 6950db1af795..4bccb996fcc0 100644 --- a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":40,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":40}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (2:2)", + "SyntaxError: A 'get' accessor must not have any formal parameters. (2:2)", "SyntaxError: A getter cannot have a `this` parameter. (2:10)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json index aaaf78efc008..775289cd0219 100644 --- a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json @@ -3,7 +3,7 @@ "start":0,"end":43,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":43}}, "errors": [ "SyntaxError: A setter cannot have a `this` parameter. (2:10)", - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (2:2)" + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (2:2)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters-babel-7/output.json index 4a7474d6cb50..b69c73a1849c 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters-babel-7/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters-babel-7/output.json @@ -2,8 +2,8 @@ "type": "File", "start":0,"end":56,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":56}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (3:5)", - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (4:1)" + "SyntaxError: A 'get' accessor must not have any formal parameters. (3:5)", + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (4:1)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters/output.json index 579d5da431f3..0cc4d4a0bcfa 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-parameters/output.json @@ -2,8 +2,8 @@ "type": "File", "start":0,"end":56,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":56}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (3:5)", - "SyntaxError: A 'set' accesor must have exactly one formal parameter. (4:1)" + "SyntaxError: A 'get' accessor must not have any formal parameters. (3:5)", + "SyntaxError: A 'set' accessor must have exactly one formal parameter. (4:1)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters-babel-7/output.json index 6cc80c73005b..514dd9d48381 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters-babel-7/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters-babel-7/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":61}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (3:5)", + "SyntaxError: A 'get' accessor must not have any formal parameters. (3:5)", "SyntaxError: 'get' and 'set' accessors cannot declare 'this' parameters. (3:5)", "SyntaxError: 'get' and 'set' accessors cannot declare 'this' parameters. (4:1)" ], diff --git a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters/output.json index ec6316aea846..fd2fbb02543c 100644 --- a/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters/output.json +++ b/packages/babel-parser/test/fixtures/typescript/interface/get-set-invalid-this-parameters/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":61,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":1,"index":61}}, "errors": [ - "SyntaxError: A 'get' accesor must not have any formal parameters. (3:5)", + "SyntaxError: A 'get' accessor must not have any formal parameters. (3:5)", "SyntaxError: 'get' and 'set' accessors cannot declare 'this' parameters. (3:5)", "SyntaxError: 'get' and 'set' accessors cannot declare 'this' parameters. (4:1)" ],