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

Invalid code produced via Minify/Compress in 1.4.1+ #8737

Closed
marcusdarmstrong opened this issue Mar 12, 2024 · 1 comment · Fixed by #8738
Closed

Invalid code produced via Minify/Compress in 1.4.1+ #8737

marcusdarmstrong opened this issue Mar 12, 2024 · 1 comment · Fixed by #8738
Assignees
Labels
Milestone

Comments

@marcusdarmstrong
Copy link

marcusdarmstrong commented Mar 12, 2024

Describe the bug

Regression from 1.4.0, code yields a reference error. "dead_code" or "hoist_props" minifier options set to false mitigate the issue.

Input code

d(() => {
  var obj = {
    key: "some string",
  };
  
  var b = () => {
    switch (a) {
      default:
        break;
    }
    return obj.key;
  };
  return () => b;
});

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

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.6&code=H4sIAAAAAAAAA0WNUQqDMBBE%2Fz3F4FcCxQO42LskdbXWVmETFZHc3Zim9GdgHrP7WqU0mjuOAliNYLYvNKkBI%2B81Sjd%2FGM7LMPXlLfJAMfLaxu3%2FHnDb4B9PKKMzAFruzPL2da6AFTYjpRpSCvtFpstcRSP9FBl%2F31sqgqYT2Fivw60AAAA%3D&config=H4sIAAAAAAAAA32US3LbMAyG9zmFR%2Bts20UPkF3PwKFJUKbDh4YAHWsyvnshSrLdGNJOwocfIAEQ32%2BHQ3dG0%2F05fPMn%2Fwy6IJT7P1twTKSvbOnARI2m%2BIG695WecUJOB4Rmus2kI116oKbCX4t7F3JGWN0XW%2FTJu%2FE5oclxKID4ZGMrx6sREuH%2F%2BoWV%2FDUBKvXZfsw5gE47RGlUPhH0UKTAJoegBwR10UWIMp1UF49ZSjHBSmDVUPIg8mQ9%2BZw45yu1oK0y2YKAfAFD%2FgKSjHOxLCFfT7hPwxaOte9bk3%2Bo4aJD1STkhGtrCZ9WiHrKHkm5mqQSznCjBjNcivtT6Z0qQLWkV905%2B7TRk08ArkDQiElHkOI2D8fztKV2u0qfHI8sjQLn%2BZZumaDnoirvnVDZqTJQyEvdLGCrgamyRjrOgjfKh96CAud4VoTQ%2BOXJnKSkNA6QnQC4v9pJUzUDdX%2BFG3x6EDv4g29J8oAtHlHTaZviGI857CSIQKdsdxy4FZS3ceEtcR22eU0WeDTAii4VG3hdAvwAKKvQluXLbPDz4IiqD%2Fn4WBOLw%2B2%2BhKNO%2FeO9z3v4bXHoYra1wWXDT%2F2d9%2FLv7uG0buH1BJ3Hv6uw5bz9A1EN%2Bh8sBgAA

SWC Info output

No response

Expected behavior

d(function(){var b=function(){return a,"some string"};return function(){return b}});

Actual behavior

d(function(){var b=function(){return a,obj.key};return function(){return b}});

Version

1.4.6

Additional context

Modifying pass count reveals the intermediate error, with the key failure being in pass 2:
Pass 1: d(function(){var obj={key:"some string"},b=function(){return a,obj.key};return function(){return b}});
Pass 2: d(function(){var obj_key="some string",b=function(){return a,obj.key};return function(){return b}});
Pass 3: d(function(){var b=function(){return a,obj.key};return function(){return b}});

@marcusdarmstrong marcusdarmstrong changed the title Invalid code produced via Minify/Compress in 1.4.x Invalid code produced via Minify/Compress in 1.4.1+ Mar 12, 2024
@kdy1 kdy1 self-assigned this Mar 13, 2024
@kdy1 kdy1 added this to the Planned milestone Mar 13, 2024
kdy1 added a commit that referenced this issue Mar 13, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.7 Mar 13, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 12, 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 Apr 12, 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