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 strip method in object that should exist #9148

Closed
JSerFeng opened this issue Jul 5, 2024 · 3 comments · Fixed by #9339
Closed

Minify strip method in object that should exist #9148

JSerFeng opened this issue Jul 5, 2024 · 3 comments · Fixed by #9339
Assignees
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

JSerFeng commented Jul 5, 2024

Describe the bug

Remove class member that is accessed by another class member

Input code

function foo() {
  const obj = {
    clear: function () {
      console.log('clear')
    },
    start: function () {
      setTimeout(function () {
        this.clear();
      });
    }
  };
  return () => obj.start()
};

foo()

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },

    "target": "es2022",
    "transform": {
      "decoratorMetadata": true,
    },
    "externalHelpers": true,
    "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": false,
  "isModule": "unknown"
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.6&code=H4sIAAAAAAAAA21POw7DIAzdOYW3GKniAI3SU%2FQCaWQaKoolMFPF3UMsumXx53388TVtEjiBZ0YLPwOwcSoC%2FPrAon1HIq35Dv6vHUKlupgjuchvnFQ3WaXaTVORNcu1tZA8w5e4Cl7RALKH4nQm2nmgbVStx3aWmaRmNS6P82inG9Gazhp96gCae6CK4wAAAA%3D%3D&config=H4sIAAAAAAAAA32VO47jMAxA%2B5wicD3FYoot9gCLbeYMAmNRjmZk0RCpfDDI3Ze2FSeTyOliPv5JMd%2Bb7bb55Lb5s%2F3Wn%2FoxQGJMy7dK%2BBwFTipp5Dwgt8kP0rxdqfCIJGVcRBZbSiCUuJAJXN42cwSB1KGM%2FpDff72%2FF1%2BNJIjsKPX3wRdfHyhgQeBHsEsxxZNgihD%2BYRhwCVtgIGJUkYPAV1nvo3fn%2B0At9UNC5juZSjXV3GMU%2FmlfWKIjPxSv8h1RQC1lnRhg46NgN%2Bf66LilEGBgNAdIFS9jppA8Uy3ECLOgNUOiocqj9eJJm1WhFsGalixWkE%2FYij9gzUxjqVlkLa9Sz4Qt7nLXTZv1YI0HCBmkEhNP00g024rXPXkW43KstXCGKz2YYWnuo6V3JqHkFJ%2FtPsnHlZl8IWoHAjBH6LHmd9Jwuk9r1u6lpY9OV1bOFa77XasyYqdNNd67SmfHzmASX5tmQptbHDvb1tIpeKV97C0adE53peKaj17afS3oeFrIVYDOF1xtq2Zglle4wscH8QL%2F1SqlvmBFowfZr1M%2B9zsKLwL0KHuyLxR0FELrOOmVOA3rPEeLuhpoqyqZJ%2FB8BPQBCJkw3eGn3dDnoR5NF2h3OxNF4bKc%2BR5id3vv8z3eFIWmJ5snWP5WxvnOJ%2F93c1O6XuEl8cbzx9VS0%2F%2BKdIzN5vIfIdZH36cGAAA%3D

SWC Info output

No response

Expected behavior

obj.clear should exist in output, as it is accessed by another member in the object

Actual behavior

clear method is removed

Version

1.6.6

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Jul 5, 2024
@kdy1 kdy1 added this to the Planned milestone Jul 5, 2024
@kdy1 kdy1 self-assigned this Jul 5, 2024
@kdy1
Copy link
Member

kdy1 commented Jul 24, 2024

I think it's fine to remove clear here.

function foo() {
  const obj = {
    clear: function () {
      console.log('clear')
    },
    start: function () {
      setTimeout(function () { // <- this belongs to function here
        this.clear();
      });
    }
  };
  return () => obj.start()
};

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2024
@JSerFeng
Copy link
Contributor Author

image

This also fails

@kdy1 kdy1 reopened this Jul 24, 2024
kdy1 added a commit that referenced this issue Jul 29, 2024
@JSerFeng
Copy link
Contributor Author

Thank you !

@kdy1 kdy1 modified the milestones: Planned, v1.7.4 Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants