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

Unicode Code Point Escape syntax is not transpiled #1227

Closed
wessberg opened this issue Nov 23, 2020 · 7 comments · Fixed by #1300
Closed

Unicode Code Point Escape syntax is not transpiled #1227

wessberg opened this issue Nov 23, 2020 · 7 comments · Fixed by #1300
Labels
Milestone

Comments

@wessberg
Copy link
Contributor

wessberg commented Nov 23, 2020

Describe the bug

Unicode Code Point Escape syntax is not being transformed to ES5-compatible syntax when es5 is the target.

It would seem that swc is always assuming traditional unicode escape sequences of on the form \u followed by four digits and simply doesn't parse code point escape syntax.

Input code
Please see this repro.

In it, you'll find that output.js is the result of running swc index.js -o output.js with es5 as the target for the following input:

const foo = "\u{a0}";

The output is:

var foo = "\u";

Which is incorrect.

Config
You'll find it in the repro, but here it is:

{
  "jsc": {
    "target": "es5"
  }
}

Expected behavior
Unicode Code Point Escape syntax should be transpiled into syntax that legacy environments can understand.

Here's how babel would have rewritten the example from the repro:

var foo = "\xA0";

Version
The version of @swc/core: 1.2.39

@wessberg wessberg added the C-bug label Nov 23, 2020
@kdy1 kdy1 added this to the v1.2.40 milestone Nov 29, 2020
@kdy1 kdy1 self-assigned this Nov 29, 2020
This was referenced Nov 29, 2020
@kdy1 kdy1 removed this from the v1.2.40 milestone Dec 3, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 3, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 3, 2020
@kdy1 kdy1 removed their assignment Dec 10, 2020
@kdy1 kdy1 self-assigned this Dec 29, 2020
@kdy1 kdy1 added this to the v1.2.43 milestone Dec 29, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 29, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 29, 2020
@kdy1 kdy1 mentioned this issue Dec 29, 2020
4 tasks
@kdy1 kdy1 modified the milestones: v1.2.43, v1.2.44 Dec 30, 2020
@kdy1 kdy1 modified the milestones: v1.2.44, v1.2.45 Jan 11, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jan 14, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jan 14, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jan 14, 2021
kdy1 added a commit that referenced this issue Jan 14, 2021
swc_ecma_codegen:
 - Handle unicode escape sequences when target is es5. (#1227, #1326)

swc_ecma_transforms_compat:
 - Handle template literals correctly. (#1314)
 - Handle private class properties correctly. (#1306)

swc:
 - Don't panic on `export * as foo from 'foo'`. (#1307)
@wessberg
Copy link
Contributor Author

wessberg commented Mar 9, 2021

This issue has been marked as closed, but the issue haven't been resolved. Please reopen this issue and see the updated repro.

It is correct that the example from the my original repro now produce the correct output, but the following code snippet will still produce invalid code:

For the following input:

const foo = [
        "\u{660}",
        "\u{661}",
        "\u{662}",
        "\u{663}",
        "\u{664}",
        "\u{665}",
        "\u{666}",
        "\u{667}",
        "\u{668}",
        "\u{669}"
    ];

swc v1.2.50 will produce the following output when targeting es5:

var foo = [
    "\u{660}",
    "\u{661}",
    "\u{662}",
    "\u{663}",
    "\u{664}",
    "\u{665}",
    "\u{666}",
    "\u{667}",
    "\u{668}",
    "\u{669}"
];

This is still incorrect.

@wessberg
Copy link
Contributor Author

wessberg commented May 17, 2021

Can this issue please be reopened? See my comment above. You can verify this behavior in the repro.

@vertic4l
Copy link

vertic4l commented Jun 1, 2021

Ran into this issue as well while testing webpack 5 + swc-loader (which gives create build performance) and was checking the produced bundle within IE11.

Encountered syntax errors due to the above mentioned problem.

@kdy1 kdy1 removed this from the v1.2.45 milestone Mar 6, 2022
@kdy1 kdy1 added this to the v1.2.150 milestone Mar 6, 2022
@kdy1 kdy1 removed their assignment Mar 6, 2022
@kdy1 kdy1 modified the milestones: v1.2.150, Planned Mar 6, 2022
@kdy1
Copy link
Member

kdy1 commented Mar 18, 2022

@kdy1 kdy1 closed this as completed Mar 18, 2022
@kdy1 kdy1 modified the milestones: Planned, v1.2.157 Mar 18, 2022
@kdy1
Copy link
Member

kdy1 commented Apr 7, 2022 via email

@wessberg
Copy link
Contributor Author

wessberg commented Apr 7, 2022

You're right, I deleted my comment after running the repro example again. Thanks!

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 16, 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 16, 2022
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