Skip to content

Minifier doesn't inline arrow function parameter #10746

@mischnic

Description

@mischnic

Describe the bug

The minifier doesn't inline the message variable, it's still in the output (with a single use).

Input code

const ErrorResponse = (statusCode, message) => {
    return Response.json({
        message
    }, {
        status: statusCode
    });
}

export const unknownError = ErrorResponse(520, "Unknown error.");

or alternatively

let message;
export const unknownError = (message = "Unknown error.", Response.json({ message }, { status: 520 }));

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
      },
      "mangle": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.12.9&code=H4sIAAAAAAAAA1WOTQrCMBCF9znFo6sWQhHBjVI34gUED1DqICjOlJkEBendTROl%2BHaP98M3CFvAUVX0RDYmR%2BhQW%2BhDtINcyONBZv2VGnR7vB2SlEJUxm%2FQ3ky4LtGs7yD7yWMJyusWy3vpNDs3OUevUTRgyESR7yxPzmAJ6A%2Bw3qxXHtW5VEBz1lbp5AN36zRhzQAAAA%3D%3D&config=H4sIAAAAAAAAA41VwW7bMAy99ysCn3foimIY9gG77RsExaIcZbJoiJSboMi%2Fj1bsNG1oY5cg5tMjRfKRen%2Fa7Zojtc2v3bv8lY%2FBZoJ8%2BxYLnRPbk1gaaHtLbQ4DN98W9EgT5G0kqKbLFWnY5g64sujl%2BeV1ZjQRkWBhzLY%2BpODP9zFb7IcMRHc2sYrL0kNi%2BsyfsYxvE8C53Nv3iBFs2kCMJRMSQwdZc9xijHYgMKPNipfppjYHQi3EBBYGZ4aMg4onFzhgkpiPqAPrTIsOFChkaDmMoNEkltASSXpKPhV2sC9dV%2Fv8hQ2jjcWyEhNOtSVyW8XrAQOx8SVpJbyCKzW4gnNxvzKDNxm45PTIO2JIKz35CyAViJYo2R40v%2FWEFz2tsf0mMyQvkuWzgou%2BtSwTdFJUE4JXKjtVBjIHrZsZXGlhqmyrXWeGV8pHwYEB70Urimt6C9wetKB8HgC9Akh%2FrddUdQXMbQpX8GkgNuDfkiXrAptP9JYP6yid%2Bz3GjQA98AHdxgFpBeM6nGVLnIZ1vCQHIg1w6pFCFXhcAjIAjCbWffmgDRkP8Wi6iPuPNTEfuNz2cG9TV%2Bf9bl8yDhFGiGsy%2Fo8R2UTlbuOk6mWyH6YXfmqitDJ44fvzp2dDUnlafmtSTY%2Bu3CVUNXl9Tn40H4eWl2OpWhPoz0Ksdbr8AzzE8uLjBgAA

SWC Info output

No response

Expected behavior

export const unknownError=Response.json({message:"Unknown error."},{status:520});

Actual behavior

let message;export const unknownError=(message="Unknown error.",Response.json({message},{status:520}));

Version

1.12.9

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions