Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts): parse multiline declarations correctly (#12776)
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
4462eea
commit 8e9143f
Showing
15 changed files
with
426 additions
and
19 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
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/fixtures/typescript/class/declare-new-line-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,2 @@ | ||
declare abstract | ||
class A {} |
49 changes: 49 additions & 0 deletions
49
packages/babel-parser/test/fixtures/typescript/class/declare-new-line-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,49 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":10}}, | ||
"errors": [ | ||
"SyntaxError: Missing semicolon (1:7)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":10}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"declare"}, | ||
"name": "declare" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":8,"end":16,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":16}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":8,"end":16,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":16},"identifierName":"abstract"}, | ||
"name": "abstract" | ||
} | ||
}, | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":17,"end":27,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":10}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":23,"end":24,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":25,"end":27,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":10}}, | ||
"body": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/enum/declare-new-line/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 @@ | ||
declare enum | ||
E | ||
{} |
24 changes: 24 additions & 0 deletions
24
packages/babel-parser/test/fixtures/typescript/enum/declare-new-line/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,24 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSEnumDeclaration", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":13,"end":14,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":1},"identifierName":"E"}, | ||
"name": "E" | ||
}, | ||
"members": [], | ||
"declare": true | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/interface/declare-new-line/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 @@ | ||
declare interface | ||
I | ||
{} |
49 changes: 49 additions & 0 deletions
49
packages/babel-parser/test/fixtures/typescript/interface/declare-new-line/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":22,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, | ||
"errors": [ | ||
"SyntaxError: Missing semicolon (1:7)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"declare"}, | ||
"name": "declare" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"interface"}, | ||
"name": "interface" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":18,"end":19,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":1}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":18,"end":19,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":1},"identifierName":"I"}, | ||
"name": "I" | ||
} | ||
}, | ||
{ | ||
"type": "BlockStatement", | ||
"start":20,"end":22,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":2}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...s/babel-parser/test/fixtures/typescript/module-namespace/module-declare-new-line/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,8 @@ | ||
declare | ||
module | ||
'foo' | ||
{} | ||
|
||
declare module | ||
'bar' | ||
{} |
90 changes: 90 additions & 0 deletions
90
...abel-parser/test/fixtures/typescript/module-namespace/module-declare-new-line/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,90 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":2}}, | ||
"errors": [ | ||
"SyntaxError: Missing semicolon (6:7)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":2}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7},"identifierName":"declare"}, | ||
"name": "declare" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":8,"end":14,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":8,"end":14,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6},"identifierName":"module"}, | ||
"name": "module" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":15,"end":20,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":5}}, | ||
"expression": { | ||
"type": "StringLiteral", | ||
"start":15,"end":20,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":5}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "'foo'" | ||
}, | ||
"value": "foo" | ||
} | ||
}, | ||
{ | ||
"type": "BlockStatement", | ||
"start":21,"end":23,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":2}}, | ||
"body": [], | ||
"directives": [] | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":25,"end":32,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":7}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":25,"end":32,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":7},"identifierName":"declare"}, | ||
"name": "declare" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":33,"end":39,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":14}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":33,"end":39,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":14},"identifierName":"module"}, | ||
"name": "module" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":40,"end":45,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":5}}, | ||
"expression": { | ||
"type": "StringLiteral", | ||
"start":40,"end":45,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":5}}, | ||
"extra": { | ||
"rawValue": "bar", | ||
"raw": "'bar'" | ||
}, | ||
"value": "bar" | ||
} | ||
}, | ||
{ | ||
"type": "BlockStatement", | ||
"start":46,"end":48,"loc":{"start":{"line":8,"column":0},"end":{"line":8,"column":2}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/typescript/module-namespace/module-new-line/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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module | ||
Foo | ||
{} | ||
|
||
module | ||
'm' | ||
{} |
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
8 changes: 8 additions & 0 deletions
8
...abel-parser/test/fixtures/typescript/module-namespace/namespace-declare-new-line/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,8 @@ | ||
declare | ||
namespace | ||
foofoo | ||
{} | ||
|
||
declare namespace | ||
barbar | ||
{} |
Oops, something went wrong.