New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Import Assertions for re-export statement #12249
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea90583
Add assertions property for ExportNamedDeclaration
sosukesuzuki 965b83b
Add tests
sosukesuzuki 4f4ff5a
Support importAssertions for re-export statement on babel-generator
sosukesuzuki 3723517
Add assrttions to AST spec
sosukesuzuki bbcb4a8
Add more tests for babel-parser
sosukesuzuki f7320ee
Supoort generation of import assertions for ExportAllDeclaration
sosukesuzuki fa83ccb
Fix type definition
sosukesuzuki dd4b991
Extract to printAssertions
sosukesuzuki File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion
5
packages/babel-generator/test/fixtures/types/ImportAssertion/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 |
---|---|---|
@@ -1 +1,4 @@ | ||
import foo from "foo.json" assert { type: "json" }; | ||
import foo1 from "foo.json" assert { type: "json" }; | ||
export { foo2 } from "foo.json" assert { type: "json" }; | ||
export * from "foo.json" assert { type: "json" }; | ||
export * as foo3 from "foo.json" assert { type: "json" }; |
5 changes: 4 additions & 1 deletion
5
packages/babel-generator/test/fixtures/types/ImportAssertion/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 |
---|---|---|
@@ -1 +1,4 @@ | ||
import foo from "foo.json" assert { type: "json" }; | ||
import foo1 from "foo.json" assert { type: "json" }; | ||
export { foo2 } from "foo.json" assert { type: "json" }; | ||
export * from "foo.json" assert { type: "json" }; | ||
export * as foo3 from "foo.json" assert { type: "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
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
...ental/import-assertions/invalid-syntax-export-with-and-attributes-multiple-lines/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,2 @@ | ||
export { x } from "foo" assert | ||
{ type: "json" } |
63 changes: 63 additions & 0 deletions
63
...al/import-assertions/invalid-syntax-export-with-and-attributes-multiple-lines/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,63 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExportNamedDeclaration", | ||
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ExportSpecifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}}, | ||
"local": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"exported": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":18,"end":23,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":23}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
}, | ||
"declaration": null, | ||
"assertions": [ | ||
{ | ||
"type": "ImportAttribute", | ||
"start":33,"end":45,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":33,"end":37,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6},"identifierName":"type"}, | ||
"name": "type" | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":39,"end":45,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":14}}, | ||
"extra": { | ||
"rawValue": "json", | ||
"raw": "\"json\"" | ||
}, | ||
"value": "json" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...perimental/import-assertions/invalid-syntax-export-without-attributes-identifier/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 @@ | ||
export { x } from "foo" assert; |
5 changes: 5 additions & 0 deletions
5
...mental/import-assertions/invalid-syntax-export-without-attributes-identifier/options.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,5 @@ | ||
{ | ||
"plugins": [["importAssertions"]], | ||
"sourceType": "module", | ||
"throws": "Unexpected token (1:30)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/experimental/import-assertions/string-literal/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import foo from "foo.json" assert { for: "for" } | ||
export { foo } from "foo.json" assert { for: "for" } |
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
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import foo from "foo" assert { type: "json", } | ||
export { foo } from "foo" assert { type: "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
1 change: 1 addition & 0 deletions
1
...tures/experimental/import-assertions/valid-syntax-export-star-as-with-attributes/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 @@ | ||
export * as foo from "foo.json" assert { type: "json" }; |
57 changes: 57 additions & 0 deletions
57
...es/experimental/import-assertions/valid-syntax-export-star-as-with-attributes/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,57 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":56}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":56}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExportNamedDeclaration", | ||
"start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":56}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ExportNamespaceSpecifier", | ||
"start":7,"end":15,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":15}}, | ||
"exported": { | ||
"type": "Identifier", | ||
"start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":21,"end":31,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":31}}, | ||
"extra": { | ||
"rawValue": "foo.json", | ||
"raw": "\"foo.json\"" | ||
}, | ||
"value": "foo.json" | ||
}, | ||
"assertions": [ | ||
{ | ||
"type": "ImportAttribute", | ||
"start":41,"end":53,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":53}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":41,"end":45,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":45},"identifierName":"type"}, | ||
"name": "type" | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":47,"end":53,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":53}}, | ||
"extra": { | ||
"rawValue": "json", | ||
"raw": "\"json\"" | ||
}, | ||
"value": "json" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add type information to
packages/babel-parser/src/types.js
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fa83ccb 👍