Skip to content

Incorrect "JSC_USED_GLOBAL_THIS" warning on this in class field initializer #4230

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

Open
lauraharker opened this issue Mar 26, 2025 · 1 comment
Assignees

Comments

@lauraharker
Copy link
Contributor

As noted in #2731 - the compiler incorrectly reports "[JSC_USED_GLOBAL_THIS] dangerous use of the global this object" on the this.y reference below.

class Foo {
  x = () => this.y;
  y = 3;
}

this in a non-static class field initializer will refer to the class instance.

To reproduce -

closure-compiler-debugger

@lauraharker
Copy link
Contributor Author

This also repros when this is not wrapped in an arrow function.

@trevorade trevorade self-assigned this Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants