Closed
Description
TypeScript Version: 3.9.2
Search Terms: static field, static class members, emit
Code
// @target: esnext
// @useDefineForClassFields: true
class C {
static x = 3;
}
Expected behavior:
Expected JS emit is:
class C {
static x = 3;
}
Actual behavior:
Actual JS emit gets wrapped in an unwanted IIFE.
let C = /** @class */ (() => {
class C {
static x = 3;
}
return C;
})();
Playground Link:
- Correct behavior in TypeScript 3.8.3
- Correct behavior in TypeScript 3.9.0-dev.20200214
- Incorrect behavior in TypeScript 3.9.0-dev.20200215
- Incorrect behavior in TypeScript 3.9.2
Related Issues: #38374
The bug is that classes with static fields are now getting wrapped in an IIFE. This undesirable bloat occurs unconditionally. There does not appear to be anyway to turn this off to get back to standard JS emit.
The emit change was introduced by #32011
Credit to @evmar for discovering this issue.