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

Incorrect compilation of Object Literal with Special Characters #8940

Closed
t-k opened this issue May 9, 2024 · 7 comments · Fixed by #8941
Closed

Incorrect compilation of Object Literal with Special Characters #8940

t-k opened this issue May 9, 2024 · 7 comments · Fixed by #8941
Assignees
Labels
Milestone

Comments

@t-k
Copy link

t-k commented May 9, 2024

Describe the bug

Since version 1.4.12, when constructing an object containing keys with special characters such as "" (U+30FB KATAKANA MIDDLE DOT), it will be converted to a format with no quotes.

This leads to a "Uncaught SyntaxError: Invalid or unexpected token" error during execution.

Input code

console.log({
  "あ": 1,
  "あ・あ": 1,
  "・あ": 1,
  "・": 1,
  "あ・": 1,
})

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": true,
        "hoist_vars": false,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": true,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": false,
        "unsafe_arrows": false,
        "unsafe_comps": false,
        "unsafe_Function": false,
        "unsafe_math": false,
        "unsafe_symbols": false,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.12&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP16jmUlBQetzYpGSlYKgDZT9u3o0igsFFUwzh1moCABZnot9YAAAA&config=H4sIAAAAAAAAA32UO5LbMAxA%2Bz2FR3XapMgBtssZODQJytxQhIYAvdbs%2BO4BJfmTNaROwsOP%2BH29HQ7dB7nu9%2BFLPuVntIWg3P9FQlNmexFJx9MI5Eocuftxo0wNBZsIZtF1IR3b0gM3K6Cfq3qXEAlu6qtsiDmG6Tmgw2EsQPQkE6n4qwNkpv%2FtV1bwswEu9Vl%2BRExg8w4xlkzMDD0UzbHDlOxIYM62KF5aprZEQi1Eg5XBm7HgqPLsI0fMEvOVerDeOPSgoFjAcTyDZiaxxCyTPE95z4w9HGvfz03%2BZg1nm6plJSZc5pZItorXE0ZiE2rWSrjAjRoscC3ud8sYTAGuJb%2FafWDMGz35CyAVSJYo2wE0v7NGkHnasg67ljEHGVmeFC7zrb0yQy9FNTEGpbKtMlA4at0s4KuDVlmnpbPijfJR9GAgBJkVxTV9RnYnLWjbcgwKkP7aoE3VAsx9Czd4W4gd%2FC6vZH3AVo3B8mmb0jQcMe0EGIBP6HcUpBWM27jIlbiM27xmDzIa4FWVSjN4PQKyAIwmzcfyZTZkPcSj6RMeH2diVbjej%2FBgc%2F%2FY9%2BUOv60K3YC%2BznC98K2%2Fy13%2B1T2Ublf4nngX6c%2FNcg56%2FQckCXpSLQYAAA%3D%3D

SWC Info output

No response

Expected behavior

console.log({
    : 1,
    "あ・あ": 1,
    "・あ": 1,
    "・": 1,
    "あ・": 1
});

Actual behavior

console.log({
    : 1,
    あ・あ: 1,
    "・あ": 1,
    "・": 1,
    あ・: 1
});

Version

Version 1.4.12 and above

Additional context

No response

@t-k t-k added the C-bug label May 9, 2024
@kdy1 kdy1 self-assigned this May 9, 2024
@kdy1 kdy1 added this to the Planned milestone May 9, 2024
@kdy1
Copy link
Member

kdy1 commented May 9, 2024

cc @Boshen It seems like #8785 introduced a regression. Any ideas about the difference?

@Boshen
Copy link
Contributor

Boshen commented May 9, 2024

@kdy1 Can you point me to where you're dropping the quotes? I want to check whether it's using the correct functions or not.

@kdy1
Copy link
Member

kdy1 commented May 9, 2024

@Boshen

if s.value.is_reserved()
|| s.value.is_reserved_in_es3()
|| is_valid_identifier(&s.value, false)
{
self.changed = true;
report_change!("misc: Optimizing string property name");
*name = PropName::Ident(Ident {
span: s.span,
sym: s.value.clone(),
optional: false,
});
return;
}

@Boshen
Copy link
Contributor

Boshen commented May 9, 2024

I found part of the problem:

U+30FB was added to ID_Continue from Unicode version 14 to 15, but v8 is using an older version of unicode ... which I can't find the exact version.

I spent 2 hours searching for all the missing pieces, I give up.

Let me back port unicode version 14.

@Boshen
Copy link
Contributor

Boshen commented May 9, 2024

@kdy1 Can you change and pin the version (perhaps with the comment as well so we are clear which version of unicode we are targeting.)

unicode-id-start = "=1.0.4" # Unicode 14.0.0

kdy1 added a commit that referenced this issue May 10, 2024
**Description:**

#8940 (comment)

> I found part of the problem:
> 
> U+30FB was added to `ID_Continue` from Unicode version 14 to 15, but v8 is using an older version of unicode ... which I can't find the exact version.
> 
> I spent 2 hours searching for all the missing pieces, I give up.
> 
> Let me back port unicode version 14.

**Related issue:**

 - Closes #8940
@kdy1 kdy1 modified the milestones: Planned, v1.5.6 May 14, 2024
@t-k
Copy link
Author

t-k commented May 14, 2024

@kdy1 @Boshen I have confirmed the fix in v1.5.6. Thank you for your quick response!

@swc-bot
Copy link
Collaborator

swc-bot commented Jun 13, 2024

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 Jun 13, 2024
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