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:
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.
Yeah I don't have experience or opinions on them myself, but wanted to get ahead of any issue reports since it's already something that has come up in the upstream package.
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:
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 3Babel only supports these with the use of a parser plugin, either
importAttributes
orimportAssertions
. 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.