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

minifier: typeof <class> should be evaluated as "function", not "object" #9453

Closed
hyp3rflow opened this issue Aug 19, 2024 · 1 comment · Fixed by #9522
Closed

minifier: typeof <class> should be evaluated as "function", not "object" #9453

hyp3rflow opened this issue Aug 19, 2024 · 1 comment · Fixed by #9522

Comments

@hyp3rflow
Copy link
Sponsor Contributor

Describe the bug

typeof <class> should be evaluated as a "function" because classes have [[Call]] internal slot like a function. MDN reference also noted this behavior.

Input code

"use strict";
class x {}
console.log(typeof x);

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "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
    },
    "externalHelpers": true
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.12&code=H4sIAAAAAAAAA1MqLU5VKC4pykwuUbLmSs5JLC5WqFCoruVKzs8rzs9J1cvJT9coqSxIzU9TqNC0BgDpvrE7LwAAAA%3D%3D&config=H4sIAAAAAAAAA32VO5LbMAyG%2B5zCozpFxkWKHCCzTc7AoUlQppcPDQF6rdnx3QNR8mPXkDoLH36ABED488du153QdH92n%2FyTPwZdEMr9my04JtIXtnRgokZT%2FEDdzxs94YScDgjNdJ1JR7r0QE2F%2B1%2F7%2FaLoQs4IN8Viiz55Nz7nNDkOBRCfbGzlkDVCIvyqX1jJHxOgUp%2Fth5wD6LRBlEblE0EPRQpscgh6QFBnXYQo00l18ZilFBOsBFYNJQ8iT9aTz4lzvlIL2iqTLQjIFzDkzyDJOBfLEvL1hPs0bOFQ%2B771%2BZsazjpUTUJOuLSW8GmFqMfskZSrSSrhDFdqMMOluN%2BV3qkCVEt61Z2yTys9eQfgCgSNmHQEKW7zcDxPa2q3qfTJ8cjSKHCeb%2BmWCXouqvLeCZWdKgOFvNTNArYamCprpOMseKV86C0ocI5nRQiNH57MUUpK4wDZCYD7q500VTNQ91e4wqcHsYH%2F8i1JHrDFI2o6rlMc4yGHjQQR6JjthgO3gvI6LrwlLsM6r8kCjwZY0aViA69LgB8AZRXavnyZDX4eHFH1IR8ea2JxuN73cNSpf7z3L6sYLgSFV8wbhAHKU4Tm0MVsa1Mu%2FwBT8%2Be9%2Fbt7ON1W9P1Wncd%2FN%2BWc8%2FofsXtHPU4GAAA%3D

SWC Info output

No response

Expected behavior

class x {}
console.log("function");

Actual behavior

class x {}
console.log("object");

Version

1.7.12

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Aug 19, 2024
@mischnic
Copy link
Contributor

Decl::Class(..) => {
self.typeofs.insert(i.to_id(), "object".into());
}

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