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

Minify failed when meet some webpack comment #9823

Closed
Tracked by #8846
JSerFeng opened this issue Dec 31, 2024 · 3 comments · Fixed by #9853
Closed
Tracked by #8846

Minify failed when meet some webpack comment #9823

JSerFeng opened this issue Dec 31, 2024 · 3 comments · Fixed by #9853
Assignees
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

Describe the bug

webpack use some strategy to help minifier minimize more bundle size.

// transform
foo // unused
// into
null && foo;

But swc failed to transform this, while it can be minimized without null && foo

You can remove comment in line 11

Input code

(() => {
  "use strict";
  class Element { }
  class PointElement extends Element {
    static id = 'point';
    constructor(cfg) {
      super();
    }
  }

  // var chart_elements = /*#__PURE__*/ Object.freeze({
  // PointElement: PointElement
  // });

  var chart_elements = /*#__PURE__*/(null && (Object.freeze({
    PointElement: PointElement
  })));

  const registerables = null && ([
    chart_elements,
    chart_plugins,
  ]);
})()
  ;

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "externalHelpers": true,
    "transform": {
      "react": {
        "development": true,
        "runtime": "automatic"
      }
    },
    "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": true,
        "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,
        "passes": 999
      },
      "mangle": false,
      "inlineSourcesContent": false
    },
    "loose": false
  },
  "minify": false,
  "isModule": true,
  "module": {
    "type": "es6"
  },
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.1&code=H4sIAAAAAAAAA5WQT0vEMBDF7%2FspHivsJkXs3bLe9uwieBIp2XS2RmJa8kfE0u%2FutFHpIihewmTmzbzfjBASuxsMK2CdAiFEb3RcV%2FzXVoWAvaUXchEDxu%2FcoTMufhXoLZJrFkKWgeeoaDRMgx22%2FaTfVnNBd449ko6dF%2FrUyk89d6SevJBZNXmNK37KEq%2FKQz8pH2vKFoFnlsVFXR%2Fu7%2FZ1XZS4PT6TjlcnT%2FROYsh9S8rrs1%2Buj%2BzF0d%2FjRVkgOb5Ogz554o17TyGYzqHzmRsM4ZK12GwgftLgd5hRyswyHweeWhMieXW0NMH81%2F8hH%2Fpsp8tFrrepNW5OPU7GoxSS4%2BoDVgwMRAwCAAA%3D&config=H4sIAAAAAAAAA32Vy64aMQxA9%2F0KNOu7qO6iEt1Wqrrpqh8QhcQZQvNS7HBBV%2Fx7PQ%2FoAB52jI%2FfNs7nl82mO6Dpvm8%2B%2BSd%2FFF0R6u2bJXhOpE8s6cBEjab6Qt3blR5wQE4HhFF0mUhHuvZAoxW%2Bf31%2Fny06OBHUpMMvCAUqsgLVBlejqhO6XOMyfgVtaCFgkYUjhFwiJLpzMOm3RD7CEFo3ylGTN92ML3c5Rp%2B8Oy9jmRxLBcT7cFxKG2LhtdK3Jav5A5%2Bz2OUcgKtZJ0qj8omgn9rw6NjkEHRBUEddBS9Dprp6zFKIATYCq0rNReTJevKZ5yBQC9oqky0IyFcw5I8gmXEsNkvI5Qn1jNjCrvX9uF8P1nDUoWkSYsJpHAlnK3jdZ4%2BkXEtSCye40oMJzs19tPROVaBW07PdIfu0MpO%2FANyBoBGTjiD5HTUc79OatXtp6ZPjlaWzwEMWq0zQc1OV907o7NAZqOSlaVawzcDQWSOlM%2BOV9qG3oMA53hXBNX54MnspKJ0LZCcAnq%2BWKpjk6vYnfExk5sP%2F4QX%2ByUWSvF%2BzBh%2BR%2FTrFc9zl8CJABNpn%2B0KBJ0F5HVc%2BEqeyzluywJsBVlRpOILnG8D7T1kFEI5o4dNC7FH1Ie%2FEK1F4zccZbrfb63W9vQpRp%2F75CnQ%2BBfb5J7dqAH9kPn7jAX9%2BPXibERZklP%2B%2F1zevncff2bawXI0uXiXzkzZs1fQQfesmX5d%2Fv%2FQpRfgGAAA%3D

SWC Info output

No response

Expected behavior

should be minimized

Actual behavior

No response

Version

1.10.1

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Dec 31, 2024
@kdy1 kdy1 added this to the Planned milestone Dec 31, 2024
@kdy1 kdy1 self-assigned this Dec 31, 2024
@kdy1
Copy link
Member

kdy1 commented Jan 8, 2025

Wow. It's an interesting edge case. I forgot that I implemented a rule to remove unused class declarations.

@JSerFeng
Copy link
Contributor Author

JSerFeng commented Jan 9, 2025

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants