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

Error when compiling typescript in target es2022 #16330

Closed
orangebokov opened this issue Oct 3, 2022 · 9 comments · Fixed by #17233
Closed

Error when compiling typescript in target es2022 #16330

orangebokov opened this issue Oct 3, 2022 · 9 comments · Fixed by #17233

Comments

@orangebokov
Copy link

orangebokov commented Oct 3, 2022

Bug report

What is the current behavior?
Error when compiling typescript in target es2022

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

{
   ...
   "compilerOptions" {
       ...
       "target": "ES2022",
       ...
   }
    ...
}

module1.ts

export let userId = document.body.getAttribute("data-user-id")!

module2.ts

import { userId } from "./module1"; 

export class Theme {
    private constructor() {}
    private static Change(isCallback: boolean) {
        localStorage.removeItem('lightTheme_'+userId)
    }
    static {
        localStorage.getItem('lightTheme_'+userId) && this.Change(false)
    }
}

Compiling produces the following file:

...
;// CONCATENATED MODULE: ../ts/module1.ts
let module1_userId = document.body.getAttribute("data-user-id");

;// CONCATENATED MODULE: ../ts/module2.ts

class Theme {
    constructor() { }
    static Change(isCallback) {
        localStorage.removeItem('lightTheme_' + userId);
    }
    static {
        localStorage.getItem('lightTheme_' + module1_userId) && this.Change(false);
    }
}
...

the userId that is in the static block is renamed to module1_userId, and the userId that is in the Change function is not renamed

if you remove static, then all the same, userId will not be renamed inside the class.
In the global context it is renamed normally

What is the expected behavior?
userId must not be renamed to module1_userId. At least this behavior is observed with target = es2021

Other relevant information:
webpack version: 5.74.0
webpack cli version: 4.10.0
Node.js version: 14.19.0
Operating System: Mac Os Mojave 10.14.6
Additional tools:

@LP1994
Copy link

LP1994 commented Oct 4, 2022

There are also errors when compiling type scripts in target esnext.

@LP1994
Copy link

LP1994 commented Oct 4, 2022

I found that replacing "this.Change" with "Theme.Change" would eliminate the above problems.
But, The class name or "this" can be used inside the static block to refer to the current class.

https://github.com/tc39/proposal-class-static-block#semantics
image

It's a strange phenomenon.

@alexander-akait
Copy link
Member

I think related to #16054

@alexander-akait
Copy link
Member

Confirmed, this is bug, workaround (bad workaround):

optimization: {
    usedExports: false,
}

Feel free to send a fix

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@TheLarkInn
Copy link
Member

Bumping this for relevance, and labelling into our backlog. This definitely should be addressed.

Also is this related to #16763?

@alexander-akait
Copy link
Member

alexander-akait commented Mar 8, 2023

@TheLarkInn Yeah, looks like the same, I think we can merge them just move example for future tests

@alexander-akait
Copy link
Member

Weird should be fixed here 8bfcb69...

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

Successfully merging a pull request may close this issue.

5 participants