swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.22k stars 1.23k forks source link

Minifier evaluates the code point of the character instead of char code for `charCodeAt`. #8943

Closed hyp3rflow closed 6 months ago

hyp3rflow commented 6 months ago

Describe the bug

Code point is differ from char code which is returned by String.prototype.charCodeAt. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt#description

Input code

"use strict";
const k = (() => {
    return "👨‍👩‍👦".charCodeAt(0);
})

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": 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": "commonjs"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.5&code=H4sIAAAAAAAAA1MqLU5VKC4pykwuUbLmSs7PKy5RyFawVdDQ0FSwtVOo5lIAgqLUktKiPAWlD%2FMnrnjU0AukVkKoZUp6yRmJRc75KamOJRoGmtZctZoAAHg2xlIAAAA%3D&config=H4sIAAAAAAAAA32UO5LbMAyG%2Bz2FR3XaNDlAupyBQ5OgTIckNATotWbHdw%2F08CNrSJ2EDz9AAiC%2BPg6H7kyu%2B3X4kk%2F5GWwlqI9%2FsdBY2F7F0oHLllyNA3c%2F7vRMEwo2Ecym20I6trUHnlX0c3XvEiLB3X215VhiGF8TOsxDBaIXm1glXstQmP7Xr6zi5wS4tlf7ETGBLTvEWDKxMPRQtcAOU7IDgbnYqkSZTmprJNRSTLAxeDNUHFRefOSIRXK%2BUw%2FWG4ceFBQrOI4X0GSSS2SF5HrKfWbs4dj6fm7yNzVcbGqWlZxwnVsip1WinjASm9CKVsIFbtRggWtxvytjMBW41fKuO2MsGz35CyAVSJao2Axa3NkjyDxtqcOuMpYgI8ujwmW%2BtVsW6KWoJsagVHaqDFSOWjcr%2BOZgqqzTjrPijfJR9GAgBJkVJTR9RnYnLSmPA2BQgPTXBm2qFmAer3CDTw9iB%2F%2BWW7I%2BYKtHtnzapjTmI6adBBn4hH7HQVrBuI2rbInrsM1b8SCjAV51aTSD9yUgD4DRpHlZvs2GPA%2BJaPqEx%2BeaWB1ujyWcbemf733Zwx%2BrQ5fRtxmuG37q77SXpR0Zy5m6p%2Bd9FT9O30X6c5cvsW%2F%2FAHrujcQzBgAA

SWC Info output

No response

Expected behavior

the char code of the first character of "👨‍👩‍👦" is 55357.

Actual behavior

minifier evaluates it as 128104, which is the code point of the first character.

Version

1.5.5

Additional context

No response

swc-bot commented 5 months ago

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.