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: inlined variable declaration missing #8826

Closed
kryops opened this issue Apr 8, 2024 · 2 comments · Fixed by #8828
Closed

minify: inlined variable declaration missing #8826

kryops opened this issue Apr 8, 2024 · 2 comments · Fixed by #8828
Assignees
Labels
Milestone

Comments

@kryops
Copy link

kryops commented Apr 8, 2024

Describe the bug

Hi there,

I noticed a regression in the swc minifier between version 1.3.105 and 1.3.106 when minifying the source of monaco-editor.

Maybe caused by #8542 ?

Unfortunately, I could not really make a very small minimal reproduction, as the problem goes away if I delete too much code. I created a gist containing the smallest reproduction I could manage.

Input code

// NOTE: Not really minimal reproduction,
// see https://gist.github.com/kryops/7869c6cc91483e346b4f362a9048a9a2

export function createTypeChecker() {
  function getFlowTypeOfReference(
    reference,
    declaredType,
    initialType = declaredType,
    flowContainer,
    flowNode = (_a2 => (_a2 = tryCast(reference, canHaveFlowNode)) == null ? void 0 : _a2.flowNode)()
  ) {
    // ...     
  }

  getFlowTypeOfReference()
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2020",
    "loose": 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": 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": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.106&code=H4sIAAAAAAAAA3VQsW6DMBTc%2FRVvBCnCKUE0INEOqFGnRKqyV455gBVjI%2FNIi6r8e02SKkuz2L7zvTufOYftbv%2BWw9YSOBRaT9ApozqhPeydrUZJypoF4xwGRGiJ%2BiHnvFEDRY2idjxE0nb86CbbD%2Fx5nWYylTJ7StYrXCXpIalXaSyyZbIWmYgZw%2B%2FeOoJ6NBdjkD6VcD%2F1WLYoj%2BiCEH4Y3AUN0kbbr1mxqz%2BwRodGYuAl4J94g4sLrFBq4bCatVfGVyEl9ExA8c997Z1La0gog%2B5ObW0164NPEUPxctuB3FSKgYJ7Kkhh3sUJN7eZMISiADNqDa9wsqqCJeTgp6M%2F1zAIfcq1IoD%2F1CiK5hN4fGZ%2BeVA3ZGf2Cw7%2BC%2FutAQAA&config=H4sIAAAAAAAAA32UO5LbMAyG%2Bz2FR3WKnS1S5ADpcgYOLYIyHZLQEKDXmh3fPRAlP7KG3En48AMkAOLrbbfrjtR3v3Zf8ik%2Foy0E5fYvFpoy27NYOuiTpb6EkbsfV3qkGXkbCZrpspCObRmAm4o%2B3j%2FeV0UXEQmuitWWQg5%2BeszZYxoLED3YxCoha4LM9L9%2BZQU%2FZ8ClPtr3iBFsfkGMJRMywwBFC9xjjHYkMCdblCjzSW0JhFqKGVYGZ8aCo8qzCxwwS85n6sA606MDBYUCPYcTaDLJJbJMcj3lPg072NdhaH3%2BpoaTjdWykhPOrSVyWiXqAQOx8TVrJVzgRg0WuBb3uzJ4U4Bryc%2B6I4a80ZO%2FAFKBaImyTaDFbR5e5mlL7V8qQ%2FYysjwpXOZbu2WGQYpqQvBKZefKQOGgdbOAqz3Mle2146x4o3wUHBjwXmZFCU2fgfuDlpSnEdArQPprvTZVCzC3V7jB5wfxAv%2BWW7I%2BYKtHsnzYpjSlPcYXCRLwAd0LB2kF4zYusiXO4zav2YGMBjjVpVIDz0tAHgCjiW1fPs2GPA%2BJaIaI%2B%2FuaWB0utz2cbB7u731ZxW%2BrQ5fQ1QbXJT%2F3d1nNP7u703UL3w7eBfpzVbakl3%2F06T5bMAYAAA%3D%3D

SWC Info output

No response

Expected behavior

The code executes without error.

Actual behavior

Runtime exception:

2963.js:1 Uncaught (in promise) ReferenceError: _a2 is not defined
    at getFlowTypeOfReference (ts.worker.js:250:846376)
    at checkIdentifier (ts.worker.js:250:874614)
    at checkExpressionWorker (ts.worker.js:250:1053957)
    ...

Version

1.3.106

Additional context

At the very top, swc@1.3.105 creates a var _a2 statement, which is missing from 1.3.106 on, causing the above exception.

Thanks for looking into it!

@kryops kryops added the C-bug label Apr 8, 2024
@kdy1 kdy1 self-assigned this Apr 9, 2024
@kdy1 kdy1 added this to the Planned milestone Apr 9, 2024
@kdy1
Copy link
Member

kdy1 commented Apr 9, 2024

I'm investigating, and #8523 seems to be the cause

@kdy1 kdy1 closed this as completed in #8828 Apr 9, 2024
kdy1 added a commit that referenced this issue Apr 9, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.13 Apr 9, 2024
@swc-bot
Copy link
Collaborator

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