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

Keep import assertions intact in targets that support it #2802

Closed
Mokshit06 opened this issue Nov 19, 2021 · 1 comment · Fixed by #3113
Closed

Keep import assertions intact in targets that support it #2802

Mokshit06 opened this issue Nov 19, 2021 · 1 comment · Fixed by #3113
Labels
Milestone

Comments

@Mokshit06
Copy link

Describe the bug

SWC removes import assertions from esm imports which isn't the expected result, since I am trying to run this file in the browser and it requires import assertions for json imports. I think the import assertions should be kept intact if jsc.parser.importAssertions is set to true and the target supports it

Input code

import json from './file.json' assert { type: "json" }

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false,
      "importAssertions": true
    },
    "target": "es2021",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.2.107&code=H4sIAAAAAAAAA8vMLcgvKlHIKs7PU0grys9VUFDX00%2FLzEnVAwmpKyQWF6cC5asVSioLUq0UlECiSgq1AMdd9yk3AAAA&config=H4sIAAAAAAAAA0WOsQ7DIAxE%2F8UzQ5uhQ7Z%2BQD8CUSeiAoxsRypC%2FHshSprNOt%2B7uwofcTBXyJYFeVxSktovzIAuWnHss4Lpti4tNgga8DET61M6oJ6SwKy8YTOgllfUgcp0m%2B4dC0SCfzD65JcyShzFzChyvWxaw%2BlsPSvSextCBS0Z98wHtCvj3CKvw7hv%2BAFPJhDn0AAAAA%3D%3D

Expected behavior

The import assertions should stay intact if the target environment is set to esnext, module system is esm and importAssertions in the config is set to true.

The expected output would be:

import json from  './file.json' assert { type: "json" }

Version

1.2.107

Additional context

No response

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants