-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add parser support for type only imports in TS Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Raja Sekar <rajasekarm.dev@gmail.com> Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Kai Cataldo <kai@kaicataldo.com> * Add transform and printer test for type only imports in TS Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Raja Sekar <rajasekarm.dev@gmail.com> Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Kai Cataldo <kai@kaicataldo.com> * Update packages/babel-parser/src/plugins/typescript/index.js * Fix flow Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Raja Sekar <rajasekar.murugan@omio.com> Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
- Loading branch information
1 parent
0018881
commit ed2af92
Showing
17 changed files
with
571 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/typescript/import-type/input.js
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 @@ | ||
import type T from './mod'; | ||
import type { A, B } from './mod'; | ||
import type * as Types from './mod'; |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/typescript/import-type/output.js
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 @@ | ||
import type T from './mod'; | ||
import type { A, B } from './mod'; | ||
import type * as Types from './mod'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ | |
"column": 27 | ||
} | ||
}, | ||
"importKind": "value", | ||
"specifiers": [ | ||
{ | ||
"type": "ImportNamespaceSpecifier", | ||
|
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"column": 38 | ||
} | ||
}, | ||
"importKind": "value", | ||
"specifiers": [ | ||
{ | ||
"type": "ImportDefaultSpecifier", | ||
|
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/types/import-type-declaration-error/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 @@ | ||
import type FooDefault, { Bar, Baz } from "module"; |
206 changes: 206 additions & 0 deletions
206
...ges/babel-parser/test/fixtures/typescript/types/import-type-declaration-error/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,206 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 51, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 51 | ||
} | ||
}, | ||
"errors": [ | ||
"SyntaxError: A type-only import can specify a default import or named bindings, but not both. (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 51, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 51 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start": 0, | ||
"end": 51, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 51 | ||
} | ||
}, | ||
"importKind": "type", | ||
"specifiers": [ | ||
{ | ||
"type": "ImportDefaultSpecifier", | ||
"start": 12, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 22 | ||
} | ||
}, | ||
"local": { | ||
"type": "Identifier", | ||
"start": 12, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 22 | ||
}, | ||
"identifierName": "FooDefault" | ||
}, | ||
"name": "FooDefault" | ||
} | ||
}, | ||
{ | ||
"type": "ImportSpecifier", | ||
"start": 26, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 26 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29 | ||
} | ||
}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start": 26, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 26 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29 | ||
}, | ||
"identifierName": "Bar" | ||
}, | ||
"name": "Bar" | ||
}, | ||
"local": { | ||
"type": "Identifier", | ||
"start": 26, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 26 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29 | ||
}, | ||
"identifierName": "Bar" | ||
}, | ||
"name": "Bar" | ||
} | ||
}, | ||
{ | ||
"type": "ImportSpecifier", | ||
"start": 31, | ||
"end": 34, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 31 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 34 | ||
} | ||
}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start": 31, | ||
"end": 34, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 31 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 34 | ||
}, | ||
"identifierName": "Baz" | ||
}, | ||
"name": "Baz" | ||
}, | ||
"local": { | ||
"type": "Identifier", | ||
"start": 31, | ||
"end": 34, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 31 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 34 | ||
}, | ||
"identifierName": "Baz" | ||
}, | ||
"name": "Baz" | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start": 42, | ||
"end": 50, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 42 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 50 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": "module", | ||
"raw": "\"module\"" | ||
}, | ||
"value": "module" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/types/import-type-declaration/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 @@ | ||
import type T from './mod'; | ||
import type { A, B } from './mod'; | ||
import type * as Types from './mod'; |
Oops, something went wrong.