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

Minification removed function decl incorrectly #7287

Closed
JSerFeng opened this issue Apr 18, 2023 · 4 comments · Fixed by #7288
Closed

Minification removed function decl incorrectly #7287

JSerFeng opened this issue Apr 18, 2023 · 4 comments · Fixed by #7288
Assignees
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

JSerFeng commented Apr 18, 2023

Describe the bug

f has been removed incorrectly. only happens using:

  • isModule: false
  • target above ES5

Input code

(function () {

    const r = f();
    console.log(r)
  
    function f() {
      console.log("REQUIRE")
      return 1
    }
  })();

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": false,
        "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": true
    },
    "externalHelpers": true,
    "target": "es2022"
  },
  "minify": true,
  "isModule": false,
  "module": {
    "type": "commonjs"
  },
}

Playground link

https://play.swc.rs/?version=1.3.51&code=H4sIAAAAAAAAA9NIK81LLsnMz1PQ0FSo5uJSAILk%2FLziEoUiBVuFNA1Na7hQfk6qXk5%2BukaRJlAILArXmwbWrKCArlQpyDUw1DPIVUkTKlmUWlJalKdgCObWAslaTYgVAAKlCLGIAAAA&config=H4sIAAAAAAAAA32VS5LiMAxA930KyuteTLGcA3TNZs7gMrEczDhWypJpUl3cfeQQPgUKO6Knn%2FXj52OzMQfqzO%2FNj%2FyUj9EVgnL7FglNmd1JJIanEagrcWTzeaUeOiyOsZBocKkwg%2FOFmyHmGKZHbx0OYwGiB5lIXenrAJmbOLhE8PnICn5fvT%2FId4gJXH5DrCMbM0MPRXPcYUpuJLBHVxQvLVNXIqEWosHK4O1YcFR59pEjZon5Sj04bzv0oGTlY4GO4xE0OwkmdpnkfZppwx52te%2FnFj5Zw9Gl6hgUcpp7IukqXvcYiW2oWavhBa4U4QKX6j5bxmALcC351e6AMa805R%2BAVCA5ouwG0PzOGkEGas06vLWMOcjM8qTwhOorM%2FRSVBtjUCrbKgOFo9bNAr520CrbaekseKV8FD1YCEFmRXFN35G7vRa07TAGBUh%2FXdCm6gLsbQ1XeNuIN%2FhLXsn6gC0ag%2BP9OqVp2GF6E2AA3qN%2FoyCtYFzHRc7EaVznNXuQ0QCvqlSawesVkAVgtAlYmw1ZD%2FFo%2B4S7%2B51YFM63Ezu43L%2FuuxnQ1wRGubpwYihyef5AGuFpiwzLaszZGKDtr%2B3WfCyG92N91TaR%2Fl6D3GLf4y7%2FGG2imjsZgAHzgRaH5%2F96NNeqXAYAAA%3D%3D

Expected behavior

f should present

Actual behavior

No response

Version

1.3.51

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Apr 18, 2023
@JSerFeng
Copy link
Contributor Author

Do you have any clue ? You can leave this to me.

@JSerFeng JSerFeng changed the title Minify remove function decl incorrectly Minification remove function decl incorrectly Apr 18, 2023
@JSerFeng JSerFeng changed the title Minification remove function decl incorrectly Minification removed function decl incorrectly Apr 18, 2023
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Apr 18, 2023
@kdy1 kdy1 added this to the Planned milestone Apr 18, 2023
@kdy1 kdy1 self-assigned this Apr 18, 2023
@kdy1
Copy link
Member

kdy1 commented Apr 18, 2023

I fixed it.
#7288

@JSerFeng
Copy link
Contributor Author

Thanks !

kdy1 added a commit that referenced this issue Apr 19, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.52 Apr 19, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented May 20, 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 May 20, 2023
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