Skip to content
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

feat(es/ast): Support import attributes proposal #7868

Merged
merged 27 commits into from
Aug 28, 2023
Merged

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Aug 25, 2023

Description:

Related issue:

@kdy1 kdy1 added this to the Planned milestone Aug 25, 2023
@kdy1 kdy1 self-assigned this Aug 25, 2023
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-bump:

  • swc_ecma_ast --breaking

@kdy1 kdy1 marked this pull request as ready for review August 27, 2023 23:51
@kdy1 kdy1 enabled auto-merge (squash) August 27, 2023 23:51
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit 4d3fcb8 into swc-project:main Aug 28, 2023
128 checks passed
@kdy1 kdy1 deleted the issue-7179 branch August 28, 2023 00:29
@kdy1 kdy1 modified the milestones: Planned, v1.3.81 Aug 30, 2023
@chentsulin
Copy link

chentsulin commented Sep 1, 2023

Hi @kdy1, I use @swc/core 1.3.82 with ts-node and have some problems due to this feature.

This feature transforms the assert keyword to the with keyword, like below:

import data from "./data.json" assert { type: "json" };

https://github.com/kdy1/swc/blob/c6a477d528a5e844680f85606a2f146d9a41f8d0/crates/swc_ecma_codegen/tests/fixture/issues/3110/input.js

import data from "./data.json" with {
    type: "json"
};

https://github.com/kdy1/swc/blob/c6a477d528a5e844680f85606a2f146d9a41f8d0/crates/swc_ecma_codegen/tests/fixture/issues/3110/output.js

However, there are a lot of environments (including our node 18/20) only support import assertions and not import attributes. So it causes a SyntaxError:

SyntaxError: Unexpected token 'with'
           at CustomizedModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18)
           at CustomizedModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14)
           at async link (node:internal/modules/esm/module_job:67:21)

Is it as expected?

@kdy1
Copy link
Member Author

kdy1 commented Sep 1, 2023

I didn't expect it

@chentsulin
Copy link

chentsulin commented Sep 1, 2023

There is a babel plugin supporting transform from with to assert: https://babeljs.io/docs/babel-plugin-proposal-import-attributes-to-assertions

However, in my case, avoiding transform from assert to with is enough.

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Sep 1, 2023

The status currently is that:

  • V8 supports with behind a --harmony-import-attributes flag (so does Chrome dev, Deno when it will upgrade swc, and Node.js when it will upgrade V8), and it supports assert
  • JSC only supports with, but I do not think it's in safari TP yet
  • SpiderMonkey is implementing with

Our goal is to only have babeljs.io/docs/babel-plugin-proposal-import-attributes-to-assertions as a temporary plugin, and deprecate it as soon as it's feasible to do so.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

import '...' with {...}
4 participants