Skip to content

Static field emit is IIFE #38528

Closed
Closed
@robpalme

Description

@robpalme

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:

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.

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions