-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
static variable causes typescript lowering #1480
Comments
I believe in this case the issue is that the official TypeScript compiler defaults to
then that code is not lowered. Specifically when |
Thank you for so detailed answer. As of TypeScript default behavior, it is not even a bundler —— ❯ cat a.ts
class A {
static C = 1;
#a;
f() { this.#a ??= A.C }
}
❯ tsc a.ts --target esnext --outFile /dev/stdout
class A {
static C = 1;
#a;
f() { this.#a ??= A.C; }
} |
Update: I found typescript has a simple transform api, while its default behavior is targetting commonjs and es5. const ts = require('typescript')
let start = performance.now()
let result = ts.transpileModule(`
class A { a = 1 }
`, {
compilerOptions: {
target: 99 // esnext, if not set this, it will output es5
}
})
let elapsed = performance.now() - start
console.log(result.outputText)
console.log(`[Finished in ${elapsed.toFixed(2)}ms]`) Output: class A {
a = 1;
}
[Finished in 36.37ms] |
Since it was resolved in 0.14.0 (you can use |
I've noticed lowering always occurs in
--target=esnext
when there is static variable in class and the loader ists
ortsx
(js
andjsx
are not affected). For example, this code:will always be lowered to something include
__privateGet
. while this code is not lowered when the loader isjs
.Is this an intentional behavior?
Related issue: #1418 (comment)
Live example
The text was updated successfully, but these errors were encountered: