Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(ts) Raise syntax error for abstract methods with a body (#12687)
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
0d9ad43
commit b416847
Showing
6 changed files
with
147 additions
and
1 deletion.
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
3 changes: 3 additions & 0 deletions
3
...s/babel-parser/test/fixtures/typescript/class/abstract-method-with-body-computed/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,3 @@ | ||
abstract class Foo { | ||
abstract [foo()]() {} | ||
} |
61 changes: 61 additions & 0 deletions
61
...abel-parser/test/fixtures/typescript/class/abstract-method-with-body-computed/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,61 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Method '[foo()]' cannot have an implementation because it is marked abstract. (2:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":18,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":18},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":19,"end":46,"loc":{"start":{"line":1,"column":19},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":23,"end":44,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":23}}, | ||
"abstract": true, | ||
"static": false, | ||
"computed": true, | ||
"key": { | ||
"type": "CallExpression", | ||
"start":33,"end":38,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":17}}, | ||
"callee": { | ||
"type": "Identifier", | ||
"start":33,"end":36,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"arguments": [] | ||
}, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":42,"end":44,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":23}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/class/abstract-method-with-body/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,3 @@ | ||
abstract class Foo { | ||
abstract method() {} | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/babel-parser/test/fixtures/typescript/class/abstract-method-with-body/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,56 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Method 'method' cannot have an implementation because it is marked abstract. (2:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":18,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":18},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":19,"end":45,"loc":{"start":{"line":1,"column":19},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":23,"end":43,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":22}}, | ||
"abstract": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":32,"end":38,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":17},"identifierName":"method"}, | ||
"name": "method" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":41,"end":43,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":22}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
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