Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
babel-parser(ts): Raise recoverable error for abstract interface (#12771
) * Support parsing abstract interface * Address review Address reviews Address reviews * Fix types * Add hasFollowingLineBreak
- Loading branch information
1 parent
4778e32
commit d242ea0
Showing
8 changed files
with
190 additions
and
17 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
packages/babel-parser/test/fixtures/typescript/interface/abstract/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 interface Foo { | ||
foo: string; | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/babel-parser/test/fixtures/typescript/interface/abstract/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,50 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'abstract' modifier can only appear on a class, method, or property declaration. (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":19,"end":22,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":22},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":23,"end":41,"loc":{"start":{"line":1,"column":23},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":27,"end":39,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":27,"end":30,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":30,"end":38,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":13}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":32,"end":38,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":13}} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
...es/babel-parser/test/fixtures/typescript/interface/export-abstract-interface/options.json
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
...ges/babel-parser/test/fixtures/typescript/interface/export-abstract-interface/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,38 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'abstract' modifier can only appear on a class, method, or property declaration. (1:7)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExportNamedDeclaration", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"exportKind": "type", | ||
"specifiers": [], | ||
"source": null, | ||
"declaration": { | ||
"type": "TSInterfaceDeclaration", | ||
"start":7,"end":32,"loc":{"start":{"line":1,"column":7},"end":{"line":3,"column":1}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":26,"end":27,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":27},"identifierName":"I"}, | ||
"name": "I" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":28,"end":32,"loc":{"start":{"line":1,"column":28},"end":{"line":3,"column":1}}, | ||
"body": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/fixtures/typescript/interface/invalid-abstract-interface/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,2 @@ | ||
abstract interface | ||
Foo {} |
50 changes: 50 additions & 0 deletions
50
...es/babel-parser/test/fixtures/typescript/interface/invalid-abstract-interface/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,50 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":6}}, | ||
"errors": [ | ||
"SyntaxError: Missing semicolon (1:8)", | ||
"SyntaxError: Missing semicolon (2:3)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":6}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8},"identifierName":"abstract"}, | ||
"name": "abstract" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18},"identifierName":"interface"}, | ||
"name": "interface" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":19,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":19,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
} | ||
}, | ||
{ | ||
"type": "BlockStatement", | ||
"start":23,"end":25,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":6}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |