-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for import attributes (#174)
There are three styles of import assertions/attributes that have been proposed over the years and made it to various stages of TC-39. Here's a bit of [history](https://github.com/tc39/proposal-import-attributes#history): 1) `import x from 'x' with type: "json"` - original proposal, made it to stage 2 2) `import x from 'x' assert { type: 'json' };` - import "assertion", got to stage 3, then found problems 3) `import x from 'x' with { type: 'json' };` - import "attribute", current proposal, stage 3 Babel only supports these with the use of a parser plugin, either `importAttributes` or `importAssertions`. Also, babel/generator has to be told which style to generate. Upstream has a PR, https://github.com/trivago/prettier-plugin-sort-imports/pull/273/files, which adds another user-level option to control this. Instead, I've taken the stance here that we should only generate the latest "import attribute" style code. So, not only does this PR add support for import attributes/assertions, this has the side-effect of converting deprecated import assertions to import attributes. Maybe there's some reason someone would want to stick with the old style, but I can't think of one, and I personally would appreciate getting updated to the latest format.
- Loading branch information
Showing
8 changed files
with
62 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import z from 'z-assert' assert { type: 'json' }; | ||
import x from 'x-with' with { type: 'json' }; | ||
|
||
// import y from 'y-legacy' with type: "json" // <-- this format is from a very old proposal, and is not supported |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import z from 'z-assert' assert { type: 'json' }; | ||
import x from 'x-with' with { type: 'json' }; | ||
|
||
// import y from 'y-legacy' with type: "json" // <-- this format is from a very old proposal, and is not supported |
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