Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(ts) Throw for abstract methods in a non-abstract class (#12686)
- Loading branch information
1 parent
463cb33
commit 45fdde0
Showing
10 changed files
with
244 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
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
...el-parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-1/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 @@ | ||
class Foo { | ||
abstract method(); | ||
} |
49 changes: 49 additions & 0 deletions
49
...parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-1/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,49 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Abstract methods can only appear within an abstract class. (2:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":34,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":14,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":20}}, | ||
"abstract": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":23,"end":29,"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": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...el-parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-2/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,7 @@ | ||
abstract class Foo { | ||
method() { | ||
return class { | ||
abstract m(); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-2/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,89 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Abstract methods can only appear within an abstract class. (4:6)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":84,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"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":84,"loc":{"start":{"line":1,"column":19},"end":{"line":7,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":23,"end":82,"loc":{"start":{"line":2,"column":2},"end":{"line":6,"column":3}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":23,"end":29,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":8},"identifierName":"method"}, | ||
"name": "method" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":32,"end":82,"loc":{"start":{"line":2,"column":11},"end":{"line":6,"column":3}}, | ||
"body": [ | ||
{ | ||
"type": "ReturnStatement", | ||
"start":38,"end":78,"loc":{"start":{"line":3,"column":4},"end":{"line":5,"column":5}}, | ||
"argument": { | ||
"type": "ClassExpression", | ||
"start":45,"end":78,"loc":{"start":{"line":3,"column":11},"end":{"line":5,"column":5}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":51,"end":78,"loc":{"start":{"line":3,"column":17},"end":{"line":5,"column":5}}, | ||
"body": [ | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":59,"end":72,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":19}}, | ||
"abstract": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":68,"end":69,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":16},"identifierName":"m"}, | ||
"name": "m" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...el-parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-3/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 @@ | ||
abstract class C { p = class { abstract method() } } |
73 changes: 73 additions & 0 deletions
73
...parser/test/fixtures/typescript/class/abstract-method-in-non-abstract-class-3/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":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, | ||
"errors": [ | ||
"SyntaxError: Abstract methods can only appear within an abstract class. (1:31)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":52}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":17,"end":52,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":52}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":19,"end":50,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":50}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20},"identifierName":"p"}, | ||
"name": "p" | ||
}, | ||
"computed": false, | ||
"value": { | ||
"type": "ClassExpression", | ||
"start":23,"end":50,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":50}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":29,"end":50,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":50}}, | ||
"body": [ | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":31,"end":48,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":48}}, | ||
"abstract": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":40,"end":46,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":46},"identifierName":"method"}, | ||
"name": "method" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/babel-parser/test/fixtures/typescript/class/generator-method-with-modifiers/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
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