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

Variable named as NaN cannot be resolved #7685

Closed
magic-akari opened this issue Jul 20, 2023 · 4 comments · Fixed by #7893
Closed

Variable named as NaN cannot be resolved #7685

magic-akari opened this issue Jul 20, 2023 · 4 comments · Fixed by #7893
Labels
Milestone

Comments

@magic-akari
Copy link
Member

magic-akari commented Jul 20, 2023

Describe the bug

Variable NaN is incorrectly renamed.

Input code

{
    let NaN = 1;
    console.log(NaN);
}

Config

{
  "jsc": {
    "minify": {
      "compress": false
    },
    "parser": {
      "syntax": "ecmascript"
    },
    "target": "es2022"
  }
}

Playground link

playground

Expected behavior

The output should be exactly the same as the input.

Actual behavior

{
    let NaN1 = 1;
    console.log(NaN);
}

Version

1.3.70

Additional context

No response

@magic-akari
Copy link
Member Author

// NaN always points the globals
if *sym == js_word!("NaN") {
return Some(self.config.unresolved_mark);
}

I don't think this is true.

@kdy1 kdy1 added this to the Planned milestone Jul 20, 2023
@kdy1
Copy link
Member

kdy1 commented Jul 20, 2023

Ah...

{
    let NaN = 1;
    console.log(NaN);
}

prints 1

and


{
    var NaN = 1;
    console.log(NaN);
}

prints NaN, so yeah, the code is wrong.

@Austaras
Copy link
Member

NaN can be shadowed in non strict mode, but cannot be overridden.

kdy1 pushed a commit that referenced this issue Aug 31, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.82 Sep 1, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 1, 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 1, 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.

4 participants