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

"typeof" is not transformed to working with Symbol polyfill #8971

Closed
j-sen opened this issue May 23, 2024 · 1 comment · Fixed by #8976
Closed

"typeof" is not transformed to working with Symbol polyfill #8971

j-sen opened this issue May 23, 2024 · 1 comment · Fixed by #8976
Assignees
Labels
Milestone

Comments

@j-sen
Copy link

j-sen commented May 23, 2024

Describe the bug

"typeof" is not transformed to working with Symbol polyfill

Input code

export function f () {
  return [
    typeof a === 'object', /* if a is a polyfilled symbol the result is wrong */
    typeof b === 'symbol',
    typeof c
  ]
}

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": true,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true
      },
      "mangle": false
    },
    "externalHelpers": true
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.8&code=H4sIAAAAAAAAA02MTQrDIBCF9znF29mGQE7gSUoX1Y6pxTqiI42U3j2GbLJ5vD8%2BWhNngavRiucIh8sVvwHIJDVH3LoFpCVihwe01lBs3mRFTZhH%2BL31pUvi0JwPgZ4o7WM4QF7UMaUG2R%2FfzHHBOJ%2BB5gAefzWdJ9vDffhvgvmsEaAAAAA%3D&config=H4sIAAAAAAAAA32UzZLbIAzH732KjM%2B9toc%2BQKeXfQaGgHDIYuRBIhvPTt69MnY%2BdiPnZuunvwSS0OeP3a47kuv%2B7D7lU35GWwjK7V8sNGW2Z7F04AZLrsSRu59XeqQZBZsImumykI5t6YGbin6t7l1CJLi6r7Yh5himx4QOh7EA0YNNrBKvDpCZvupXVvBjBlzqo32PmMDmF8RYMjEz9FC0wA5TsiOBOdmiRJlPaksk1FLMsDJ4MxYcVZ595IhZcj5TD9Ybhx4UFAs4jifQZJJLZJnkesp9Gvawr33fmvxNDSebqmUlJ5xbS%2BS0StQDRmITatZKuMCNGixwLe53ZQymANeSn3VHjHmjJ%2B8AUoFkibIdQIvbPILM05Y6vFTGHGRkeVK4zLd2ywy9FNXEGJTKzpWBwlHrZgFfHcyVddpxVrxRPooeDIQgs6KEpo%2FI7qAl5WkEDAqQ%2FtqgTdUCzO0VbvD5QbzAf%2BWWrA%2FY6jFYPmxTmoY9ak%2FpqgY%2BoH9xAOkE4zYusiTO4zav2YNMBnjVpVIDzztA5p%2FRpLYrn0ZDXodENH3C%2FX1LrA6X2w4ebO7vz%2F3LGoYzQ5EN8w%2FSCOUhQnPoBvS1KdftP%2Fd%2B2dm%2Fu7vTdUPfbtVFersqW7zLf5CLpVVJBgAA

SWC Info output

`
Operating System:
Platform: win32
Arch: x64
Machine Type: x86_64
Version: Windows 11 Pro for Workstations
CPU: (12 cores)
Models: AMD Ryzen 5 5600U with Radeon Graphics

Binaries:
    Node: 21.5.0
    npm: N/A
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: N/A
    @swc/helpers: N/A
    @swc/types: N/A
    typescript: 5.4.5

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A`

Expected behavior

The result from babel.js:

import _typeof from "@babel/runtime/helpers/typeof";
export function f() {
  return [
    (typeof a === "undefined" ? "undefined" : _typeof(a)) ===
      "object",
    (typeof b === "undefined" ? "undefined" : _typeof(b)) === "symbol",
    typeof c === "undefined" ? "undefined" : _typeof(c)
  ];
}

Actual behavior

import { _ as _type_of } from "@swc/helpers/_/_type_of";
export function f() {
    return [
        'object' == typeof a, /* if a is a polyfilled symbol the result is wrong */
        ("undefined" == typeof b ? "undefined" : _type_of(b)) === 'symbol',
        "undefined" == typeof c ? "undefined" : _type_of(c)
    ];
}

Version

1.5.8

Additional context

No response

@j-sen j-sen added the C-bug label May 23, 2024
@kdy1 kdy1 added this to the Planned milestone May 23, 2024
@kdy1 kdy1 self-assigned this May 23, 2024
kdy1 added a commit that referenced this issue May 26, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.5.9 May 28, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Jun 27, 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 27, 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.

3 participants