Found another interesting dead code elimination bug in the minifier.
Various other expression types, e.g. new Dead() will also trigger the behavior.
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2024",
"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,
"passes": 0
},
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
Describe the bug
Found another interesting dead code elimination bug in the minifier.
Replacing
Dead.xwithDead-> no reproRemove
extends Unknown-> no reproVarious other expression types, e.g.
new Dead()will also trigger the behavior.Input code
Config
{ "jsc": { "parser": { "syntax": "ecmascript", "jsx": false }, "target": "es2024", "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, "passes": 0 }, "mangle": false } }, "module": { "type": "es6" }, "minify": false, "isModule": true }Link to the code that reproduces this issue
https://play.swc.rs/?version=1.15.21&code=H4sIAAAAAAAAAyvOz011K81LLsnMz9NIgzIU0jQ0Faq5FIAgOSexuFjBJTUxRSG1oiQ1L6VYITQvOy%2B%2FPA%2BqAARyQcrBivQqrBVqweIQsii1pLQoT8HAmqtWEwAwssHDawAAAA%3D%3D&config=H4sIAAAAAAAAA32US27jMAyG9zlF4HUXRTHoYg7Q3ZxBUCTKUUYPQ6TSGEXuPrTspJmG9s7mx5%2BUSIpfu%2F2%2BO6Hpfu%2B%2F%2BJN%2FBl0Qyv2fLTgm0he2dGCiRlP8QN3LjZ5wQk4HhGa6zqQjXXqgpsK317dfi6ILOSPcFIst%2BuTd%2BJjT5DgUQHywsZVD1giJ8H%2F9wkr%2BnACV%2Bmg%2F5BxApw2iNCqfCHooUmCTQ9ADgjrrIkSZTqqLxyylmGAlsGooeRB5sp58TpzzmVrQVplsQUC%2BgCF%2FBknGuViWkK8n3KdhC4fa963PP9Rw1qFqEnLCpbWETytEPWaPpFxNUglnuFKDGS7F%2Fan0ThWgWtKz7pR9WunJXwCuQNCISUeQ4jYPx%2FO0pnabSp8cjyyNAuf5lm6ZoOeiKu%2BdUNmpMlDIS90sYKuBqbJGOs6CV8qH3oIC53hWhND46ckcpaQ0DpCdALi%2F2klTNQN1f4UrfHoQG%2FiDb0nygC0eUdNxneIYDzlsJIhAx2w3HLgVlNdx4S1xGdZ5TRZ4NMCKLhUbeF4C%2FAAoq9D25dNs8PPgiKoP%2BSCuiYHnvDXxdbFd78s56tR%2FL4F5P%2B8Why5mWxtcNv%2FU9Hlfv3ffTrfVfL9N5%2FHPTTmdZHf9B0LDrzJFBgAA
SWC Info output
No response
Expected behavior
The
class Deadexpression should be eliminated in its entirety, leaving at mostreturn Unknown, 0.Actual behavior
The entire
class Deaddefinition is retained.Version
1.15.21
Additional context
No response