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
JSON modules should be imported with default #14668
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1783104
fix: JSON module must be imported with default
JLHwung 748fb52
update test fixutres
JLHwung fa9cff9
fix broken tests
JLHwung 1bace41
fix flow error
JLHwung 220a907
Update packages/babel-parser/src/parse-error/standard-errors.js
JLHwung f4a6e41
add assert {} test
JLHwung 09b8b33
update test fixtures
JLHwung 840740f
address review comment
JLHwung 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
2 changes: 1 addition & 1 deletion
2
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,4 +1,4 @@ | ||
import foo1 from "foo.json" assert { type: "json" }; | ||
export { foo2 } from "foo.json" assert { type: "json" }; | ||
export { default as foo2 } from "foo.json" assert { type: "json" }; | ||
export * from "foo.json" assert { type: "json" }; | ||
export * as foo3 from "foo.json" assert { type: "json" }; |
2 changes: 1 addition & 1 deletion
2
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,4 +1,4 @@ | ||
import foo1 from "foo.json" assert { type: "json" }; | ||
export { foo2 } from "foo.json" assert { type: "json" }; | ||
export { default as 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
1 change: 1 addition & 0 deletions
1
...fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-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 @@ | ||
export { default as foo } from "foo.json" assert { type: "json", type: "html" }; |
84 changes: 84 additions & 0 deletions
84
...tures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/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,84 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, | ||
"errors": [ | ||
"SyntaxError: Duplicate key \"type\" is not allowed in module attributes. (1:65)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExportNamedDeclaration", | ||
"start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ExportSpecifier", | ||
"start":9,"end":23,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":23,"index":23}}, | ||
"local": { | ||
"type": "Identifier", | ||
"start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, | ||
"name": "default" | ||
}, | ||
"exported": { | ||
"type": "Identifier", | ||
"start":20,"end":23,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":23,"index":23},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":31,"end":41,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":41,"index":41}}, | ||
"extra": { | ||
"rawValue": "foo.json", | ||
"raw": "\"foo.json\"" | ||
}, | ||
"value": "foo.json" | ||
}, | ||
"declaration": null, | ||
"assertions": [ | ||
{ | ||
"type": "ImportAttribute", | ||
"start":51,"end":63,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":63,"index":63}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":51,"end":55,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":55,"index":55},"identifierName":"type"}, | ||
"name": "type" | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":57,"end":63,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":63,"index":63}}, | ||
"extra": { | ||
"rawValue": "json", | ||
"raw": "\"json\"" | ||
}, | ||
"value": "json" | ||
} | ||
}, | ||
{ | ||
"type": "ImportAttribute", | ||
"start":65,"end":77,"loc":{"start":{"line":1,"column":65,"index":65},"end":{"line":1,"column":77,"index":77}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":65,"end":69,"loc":{"start":{"line":1,"column":65,"index":65},"end":{"line":1,"column":69,"index":69},"identifierName":"type"}, | ||
"name": "type" | ||
}, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":71,"end":77,"loc":{"start":{"line":1,"column":71,"index":71},"end":{"line":1,"column":77,"index":77}}, | ||
"extra": { | ||
"rawValue": "html", | ||
"raw": "\"html\"" | ||
}, | ||
"value": "html" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
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,2 +1,2 @@ | ||
import foo from "foo" assert { type: "json", } | ||
export { foo } from "foo" assert { type: "json", } | ||
export { default as 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
.../babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/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 @@ | ||
import "foo" assert {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant specifically, |
28 changes: 28 additions & 0 deletions
28
...bel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/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,28 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":0,"end":23,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":23,"index":23}}, | ||
"specifiers": [], | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":7,"end":12,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":12,"index":12}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
}, | ||
"assertions": [] | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...imental/import-assertions/valid-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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { x } from "foo" assert | ||
export { default as x } 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
2 changes: 1 addition & 1 deletion
2
...res/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/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,2 +1,2 @@ | ||
export { x } from "foo" assert { type: "json" } | ||
export { "default" as x } from "foo" assert { type: "json" } | ||
[0] |
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.
Currently import assertions only allow
type: "json"
, soisJSONModuleImport
always returntrue
. If more import assertions are supported, then we should differentiate each assertions/attributes.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.
We can add a test where
node.assertions
is not null but it does not returntrue
:import { foo } from "bar" asserts {};