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

Drop empty constructors during minification #8177

Closed
NullVoxPopuli opened this issue Oct 24, 2023 · 5 comments
Closed

Drop empty constructors during minification #8177

NullVoxPopuli opened this issue Oct 24, 2023 · 5 comments
Labels

Comments

@NullVoxPopuli
Copy link

Describe the bug

empty constructor remains in minified output

Input code

import { IS_DEV_MODE } from "debug";

function ifDev(callback: () => void) {
  if (IS_DEV_MODE) {
    callback();
  }
}

export class Foo {
  constructor() {
    ifDev(() => {
      Object.defineProperties({
        hello: {
          enumerable: true,
          get x() { return 1; }
        }
      })
    })
  }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": 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,
    },
    "transform": {
      "constModules": {"globals": {"debug": {"IS_DEV_MODE": "false"}}}
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.94-nightly-20231016.1&code=H4sIAAAAAAAAA01PQWrDMBC8G%2FyHIScZQqFXm%2FbkFHooKRR6Dba8TtTK2rCWQiD474mixPi0w8zszK4ZjiweF3z%2B7OrN7%2B5rW28woRcesOqoDftVlWd51genvWEH09d0Urqxtm30fwlV4O0dJzZdgUue4WaAWoQ9WOC5oooqElOeTTGYzvcDtG3GER%2FMya7ZjV6C9ixqTkjVqfBBAdv2j7R%2F6ag3jr6FjyTe0KhmA3Aga7nEggHIhYGkaS2VuBXReinuyeMceyHkgzi8VvHepzzDqUgozfjRFW4uVnlPAQAA&config=H4sIAAAAAAAAA31VPY%2FbMAzd71cEmjsUGTp0vivQIehQ4FZBsShHV1kyRCqXIPB%2FLy07H5fQ2Sw%2BPlLix%2FPpZbVSH9ion6sTf%2FKhNxkhX85swWMkc2CLomMP2GTfk%2Fp2RglHyJmAUE3DhCgyuQUaWYDr7%2Bv1zFAhJYQzY7Z1Pnp3vM3ZpK7PgHhjYyuHLB1Ewq%2F8GcvpcwQol1v7NqUAJj5BtEHtI0ELWQrcpBBMj6D3JgtRxpua7DFJKUawEFjd59SLeLSefIqc8xG1YKxukgUB8hka8nuQaJyLaRH5ecJ7KmxhW9q29vmODXsTiiEhJxxqS%2Fi2QtRd8kjalSiVcAIXajCBc3Hvmd7pDFRyfOR9JB8XevIPgCsQDGI0HUhxq4fjeVpiu6dMHx2PLB0FnOdbemWElouqvXdCZcfKQCYvdTODLQ2MlW2k68zwQvnQW9DgHM%2BKEBo%2FPTU7Kem46MkJAPfXOGmqJkBftnABHxfiCfyLX0nygM0enaHdMorHbpvCkwQd0C7ZJw7cCkrLcGaVOPTLeIkWeDTAii4FK%2FAoArwAlHSoevkwG7weHFG3IW2vMjE7DBcd7kxs7%2Ff9osWZZc6l3H2VWE67SbaEOgEndU1wUlUf6tfvv%2Fr17V1v%2Fry%2BjWJeo6thGKYEL3MS1dVA19%2FIOEGT%2BP9QV6ezzl%2FuqDxuzsz6rOE%2FQnOQmpIGAAA%3D

SWC Info output

No response

Expected behavior

constructor is removed as it does nothing

Actual behavior

constructor remains

Version

1.3.94-nightly-20231016.1

Additional context

No response

@kdy1
Copy link
Member

kdy1 commented Oct 24, 2023

I don't expect this rule to have a noticeable effect on real-world code.

@NullVoxPopuli
Copy link
Author

NullVoxPopuli commented Oct 24, 2023

It compounds for projects that have a lot of class definitions, and is pretty similar to the empty static block removal, yeah?

@kwonoj
Copy link
Member

kwonoj commented Oct 25, 2023

In either case, I really don't think it's worth to separate issue from existing similar variant issues, especially if you already aware those issue exists. Please consolidate your suggestions into existing one.

Core team may evaluate the suggestions, but as noted in original issue we don't track this as high priority at this moment.

@kwonoj kwonoj closed this as completed Oct 25, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 24, 2023

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 Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants