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

Bad emit for mangled private fields/methods #2086

Closed
Lodin opened this issue Aug 15, 2021 · 1 comment · Fixed by #2089
Closed

Bad emit for mangled private fields/methods #2086

Lodin opened this issue Aug 15, 2021 · 1 comment · Fixed by #2089
Labels
Milestone

Comments

@Lodin
Copy link

Lodin commented Aug 15, 2021

Describe the bug
When I run mangling for private fields or methods, the declaration is mangled while the usage is not. It leads to the unknown field/method usage.

Input code

export default class Test {
  #element: HTMLElement;

  constructor(element: HTMLElement) {
    this.#element = element;
  }

  #run() {
    setTimeout(() => {
      this.#element.textContent = 'TESTED';
    }, 1000);
  }

  run() {
    this.#run();
  }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "dynamicImport": true,
      "decorators": true,
      "importAssertions": true
    },
    "transform": {
      "legacyDecorator": true,
      "optimizer": {
        "jsonify": {
          "minCost": 0
        }
      }
    },
    "target": "es2020",
    "loose": true,
    "externalHelpers": false,
    "keepClassNames": false,
    "minify": {
      "compress": {
        "comparisons": false,
        "inline": 2
      },
      "mangle": true
    }
  },
  "minify": true,
  "sourceMaps": true
}

Expected behavior
Usage of the private field/method should be the same as the declaration.

Version
The version of @swc/core: 1.2.77

Additional context
Result code:

export default class Test {
  #a;

  constructor(a) {
    this.#element = a;
  }

  #b() {
    setTimeout(() => {
      this.#element.textContent = 'TESTED';
    }, 1e3);
  }

  run() {
    this.#run();
  }
}
@Lodin Lodin added the C-bug label Aug 15, 2021
@kdy1 kdy1 added this to the v1.2.78 milestone Aug 16, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 16, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 16, 2021
kdy1 added a commit that referenced this issue Aug 16, 2021
swc_ecma_minifier:
 - Expose hygiene optimizer.
 - `mangle_names`: Handle private names in member expressions. (#2086)

swc_visit:
 - Make `Optional::new` const function.

swc:
 - Make `es3` optional via cargo feature.
 - Ensure that #1554 is already fixed. (#1554)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 22, 2022

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 Oct 22, 2022
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