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

Reference to class name in body of class expression is replaced with reference to import when class name shadows import name #16763

Closed
dasa opened this issue Feb 28, 2023 · 0 comments · Fixed by #17233
Labels

Comments

@dasa
Copy link

dasa commented Feb 28, 2023

Bug report

What is the current behavior?

The calls to static members of the class fail inside the class body when the name of the class in a class expression shadow a import name.

If the current behavior is a bug, please provide the steps to reproduce.

a.mjs:

export const a = 1;

index.mjs:

import { a as C } from "./a.mjs"

let CV = class C {
  static name = "test";
  static test() {
    console.log(C.name);
  }
}

console.log(C);
CV.test();

Bundled code snippet in none mode:

let CV = class C {
  static name = "test";
  static test() {
    console.log(_a_mjs__WEBPACK_IMPORTED_MODULE_0__.a.name);
  }
}

console.log(_a_mjs__WEBPACK_IMPORTED_MODULE_0__.a);
CV.test();

})();

Bundled code in production mode:

(()=>{"use strict";console.log(1),class{static name="test";static test(){console.log(1..name)}}.test()})();

Running dist output in either mode:

> node dist/index.js
1
undefined

What is the expected behavior?

Running src code:

> node src/index.mjs
1
test

Other relevant information:
webpack version: 5.75.0
Node.js version: 19.7.0
Operating System:
Additional tools:

This code pattern came about as a result of the changes in Rollup PR rollup/rollup#4827 and how Terser will shadow the import when possible when mangling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

3 participants