Skip to content

Error when compiling typescript in target es2022 #16330

@orangebokov

Description

@orangebokov

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions