Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: raise `SyntaxError` for `declare` before getter/setter * fix: allow `declare` when class property name is `get` or `set`
- Loading branch information
Showing
5 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/class/declare-accessor/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Foo { | ||
declare get foo() | ||
declare set foo(v) | ||
} |
73 changes: 73 additions & 0 deletions
73
packages/babel-parser/test/fixtures/typescript/class/declare-accessor/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'declare' is not allowed in getters. (2:2)", | ||
"SyntaxError: 'declare' is not allowed in setters. (3:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"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":54,"loc":{"start":{"line":1,"column":10},"end":{"line":4,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":14,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":26,"end":29,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":17},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"computed": false, | ||
"kind": "get", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [] | ||
}, | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":34,"end":52,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":20}}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":46,"end":49,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":17},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"computed": false, | ||
"kind": "set", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":50,"end":51,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":19},"identifierName":"v"}, | ||
"name": "v" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/class/declare-get-set-field/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class C { | ||
declare get: string | ||
declare set: string; | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/babel-parser/test/fixtures/typescript/class/declare-get-set-field/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":8,"end":56,"loc":{"start":{"line":1,"column":8},"end":{"line":4,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":12,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":21}}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":20,"end":23,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13},"identifierName":"get"}, | ||
"name": "get" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":23,"end":31,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":21}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":25,"end":31,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":21}} | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassProperty", | ||
"start":34,"end":54,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":22}}, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":42,"end":45,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13},"identifierName":"set"}, | ||
"name": "set" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":45,"end":53,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":21}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":47,"end":53,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":21}} | ||
} | ||
}, | ||
"value": null | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |