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

emitAssertForImportAttributes does not emit assert for import attributes #7928

Closed
isaacs opened this issue Sep 7, 2023 · 3 comments · Fixed by #7936
Closed

emitAssertForImportAttributes does not emit assert for import attributes #7928

isaacs opened this issue Sep 7, 2023 · 3 comments · Fixed by #7936
Assignees
Labels
Milestone

Comments

@isaacs
Copy link

isaacs commented Sep 7, 2023

Describe the bug

#7914 added an option to emit assert for import attributes.

However, it does not do that. It emits with for import attributes.

This is even verified by the tests, you can observe the same output in both cases, regardless of whether the emitAssertForImportAttributes is set.

As far as I can tell, it does nothing.

Input code

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

console.log(packageJSON)

Config

{
    "$schema": "https://json.schemastore.org/swcrc",
    "jsc": {
        "parser": {
            "syntax": "typescript"
        },
        "target": "es2022",
        "experimental": {
            "keepImportAttributes": true,
            "emitAssertForImportAttributes": true
        }
    },
    "module": {
        "type": "es6"
    },
    "isModule": true
}

Playground link

No response

SWC Info output

No response

Expected behavior

Expect emitAssertForImportAttributes to emit assert for import attributes.

Actual behavior

Emits with for import attributes, regardless of whether emitAssertForImportAttributes is set or not.

Version

1.3.83

Additional context

I realize that this is an experimental feature. I am reporting the results of the experiment, that it clearly either does not work as intended, or if the intent of emitAssertForImportAttributes to do something other than emit assert for import assertions, then that is a very bad name for the flag.

@kdy1
Copy link
Member

kdy1 commented Sep 9, 2023

Yeah, I didn't realize that the test is wrong. I was too busy at that times due to a talk I did yesterday. I'm now not too busy, so I will be able to do it correctly. 😄

@isaacs
Copy link
Author

isaacs commented Sep 9, 2023

@kdy1 Fantastic! I'm not too familiar with your normal project timelines, any idea when we might expect it to be moved out of experimental status? It would be nice to have a way for ts-node users to import JSON from es modules, but you'll probably fix the flag long before V8 support import/with 😅

kdy1 added a commit that referenced this issue Sep 11, 2023
**Description:**

 - Add `format.emitAssertForImportAttributes` to `minify()`
 - Use `jsc.experimental. emitAssertForImportAttributes`.

**Related issue (if exists):**

 - Closes #7926
 - Closes #7928
@kdy1 kdy1 modified the milestones: Planned, v1.3.85 Sep 11, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 12, 2023

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 12, 2023
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