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

self reference in static block is not working well on rename #4811

Closed
nicolashenry opened this issue Jan 19, 2023 · 5 comments · Fixed by #4827
Closed

self reference in static block is not working well on rename #4811

nicolashenry opened this issue Jan 19, 2023 · 5 comments · Fixed by #4827

Comments

@nicolashenry
Copy link

Rollup Version

3.10.0

Operating System (or Browser)

Chrome

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=3.10.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMiUyRiolMjBUUkVFLVNIQUtJTkclMjAqJTJGJTVDbmltcG9ydCUyMCU3QiUyMFRlc3QlMjAlN0QlMjBmcm9tJTIwJy4lMkZ0ZXN0MS5qcyclM0IlNUNuaW1wb3J0JTIwJTdCJTIwVGVzdCUyMGFzJTIwVGVzdDIlMjAlN0QlMjBmcm9tJTIwJy4lMkZ0ZXN0Mi5qcyclM0IlNUNuY29uc29sZS5sb2coVGVzdC50ZXN0JTJDJTIwVGVzdDIudGVzdCklMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCUyQyU3QiUyMm5hbWUlMjIlM0ElMjJ0ZXN0MS5qcyUyMiUyQyUyMmNvZGUlMjIlM0ElMjIlNUNuZXhwb3J0JTIwY2xhc3MlMjBUZXN0JTIwJTdCJTVDbiUyMCUyMHN0YXRpYyUyMHRlc3QlMjAlM0QlMjAnVGVzdDEnJTNCJTVDbiUyMCUyMHN0YXRpYyUyMCU3QiUyMGNvbnNvbGUubG9nKFRlc3QudGVzdCklM0IlMjAlN0QlNUNuJTdEJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTdEJTJDJTdCJTIybmFtZSUyMiUzQSUyMnRlc3QyLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMiU1Q25leHBvcnQlMjBjbGFzcyUyMFRlc3QlMjAlN0IlNUNuJTIwJTIwc3RhdGljJTIwdGVzdCUyMCUzRCUyMCdUZXN0MiclM0IlNUNuJTIwJTIwc3RhdGljJTIwJTdCJTIwY29uc29sZS5sb2coVGVzdC50ZXN0KSUzQiUyMCU3RCU1Q24lN0QlMjIlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyZXMlMjIlMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==

Expected Behaviour

When running, it should give the following in console.

Test1
Test2
Test1 Test2

Actual Behaviour

Currently it give an error:

VM93:3 Uncaught ReferenceError: Test$1 is not defined
    at <static_initializer> (<anonymous>:3:24)
    at <anonymous>:1:14
@TrickyPi
Copy link
Member

TrickyPi commented Jan 27, 2023

@lukastaegert I'm wondering if this is a right way to solve this problem, using the class name instead of renderName in the static block, as shown in the following code.

let Test$1 = class Test {
  static test = 'Test1';
  static { console.log(Test.test); }
};

@lukastaegert
Copy link
Member

Yes, I think that should work.

@nicolashenry
Copy link
Author

I realized that keeping name on static block is maybe not enough, it should probably be kept on non-static block also. For example would give this as a result if the fix is done only on static block (so an error would be raised):

let Test$1 = class Test {
  constructor() {
    console.log(Test$1.test);
  }
  static test = 'Test1';
  static {
    console.log(Test.test);
    new Test();
  }
};

The name should probably be also be kept everywhere inside the class:

let Test$1 = class Test {
  constructor() {
    console.log(Test.test);
  }
  static test = 'Test1';
  static {
    console.log(Test.test);
    new Test();
  }
};

I am not sure that the PR is taking this into account.

@TrickyPi
Copy link
Member

Oh, thanks! I didn't take this into account, I'll fix it later in the PR.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4827 as part of rollup@3.12.1. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants