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

Large numeric literals are emitted as Infinity / -Infinity instead of remaining as they are. #9223

Closed
lucacasonato opened this issue Jul 12, 2024 · 3 comments · Fixed by #9226

Comments

@lucacasonato
Copy link
Contributor

Describe the bug

Roundtripping an AST containing the code below, the output contains -Infinity instead of -1e999. I think the output should remain as -1e999.

Input code

const x = -1e999;

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "transform": {
      "react": {
        "importSource": "npm:react",
        "runtime": "automatic"
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA0vOzysuUahQsFXQNUy1tLS0BgAenTgBEQAAAA%3D%3D&config=H4sIAAAAAAAAA21QOw7CMAzde4rKMwPqwMAdmDiBFVwU1HxkOxJV1buTtA0tEksUv4%2Bf7alpW3iJgWs75W8uIrIQf%2BuMyOgV3xkBHSOJYRsVTpVVKVSPg9ACzSsDivwkLS6S7tx1mwOGEISqY8Oc9bYfj5kmuMgk8issUvTPgf4nMnrpA7tjIyY0egAyZF0MrPeQ2JRG4KO7rrLTLuLk1bqFx6TBoVoDGz039V2iwYVHWmbaTljOtC5%2BgV1Ud%2FzuA1Zu1amcqJk%2FtsEHsI4BAAA%3D

SWC Info output

No response

Expected behavior

const x = -1e999;

Actual behavior

const x = -Infinity;

Version

1.6.7

Additional context

No response

@magic-akari
Copy link
Member

Are you currently writing custom DTS codegen?
I believe you can extract data from the raw data of the Number.

SWC AST Viewer

image

@kdy1
Copy link
Member

kdy1 commented Jul 12, 2024

Guide for GFI

The problematic logic is

// Handle infinity
if num.value.is_infinite() {
if num.value.is_sign_negative() {
self.wr.write_str_lit(num.span, "-")?;
}
self.wr.write_str_lit(num.span, "Infinity")?;
return Ok(false);
}

We can move code for using raw before the code checking infinity

@imranbarbhuiya
Copy link
Contributor

imranbarbhuiya commented Jul 12, 2024

Guide for GFI

The problematic logic is

// Handle infinity
if num.value.is_infinite() {
if num.value.is_sign_negative() {
self.wr.write_str_lit(num.span, "-")?;
}
self.wr.write_str_lit(num.span, "Infinity")?;
return Ok(false);
}

We can move code for using raw before the code checking infinity

Hi, I'm working on this, how can I test the changes in windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants