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

Minifier removes parens around optional chain followed by member access #6154

Closed
jridgewell opened this issue Oct 14, 2022 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@jridgewell
Copy link
Contributor

jridgewell commented Oct 14, 2022

Describe the bug

The minifier is removing the parens in (a?.b).c.

The parens around (a?.b).c have a semantic meaning that prevents the short-circuiting behavior of later chaining. Eg, (null?.b).c will throw a TypeError, because the .c access is not optional.

Input code

(a?.b).c

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2020",
    "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": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.7&code=H4sIAAAAAAAAA9NItNdL0tRLBgDvvqKQCAAAAA%3D%3D&config=H4sIAAAAAAAAA22TQXLDIAxF7%2BJ1F50ue4DuegaGgHBIAXmQSOPJ5O4Vjg1x0p31%2FCXEl7gOJzLD53WYdCbI9YvmxPoyfA48T0Am%2B4mHt4FJkNOB4CaBziOwSIA%2B3j%2Fe5XdAJFgFb0P0ybu5FjMYpwxE9VuSSoTE1HQ6Z%2FyVkHOR6IAYQKeXWGlSPjGMkHuqwRD0RKDOOreMeprOnjDtUGGwaso4PdBkPXtMUmxjFrRVBi004DMY9mfoEqkhkkTSWOtkgRYOZRyrgXclnHUomlstuCw2yIkt74ieWLmS6AntOr2j%2ByVXlXcqA5ecNs0Jfdr58AMgfQZNlHSEnrlwJ3PYK90%2FKp%2BcDJHnRmXCvasEo1xOee%2FaDWvXkNl3tzLYYqDe0PTiK9xdiLwFBc6J2y2Zfj2bYy9WlxFdC8U17foM7qHa9mlP6wq8wC%2Fpih%2FHsfKo%2BfjMaI4HDC8lIvAR7QsWIxifYZbtvUzPtCQLYjPYhx%2BFatjWVIbPqEJ9bZvPshCSo8aAh7a%2B8iijTmNby1sFaEsF18U8ea1iRMR0ouHWn%2Bi2U%2FS9qpdqfzFN4fsXBAAA

Expected behavior

(a?.b).c

Actual behavior

a?.b.c

Version

1.3.7

Additional context

Re: #5332

@jridgewell
Copy link
Contributor Author

Fixed by #6639

@kdy1 kdy1 modified the milestones: Planned, 1.3.24 Dec 21, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Jan 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 Jan 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