Skip to content

Commit 710136b

Browse files
committed
fix wrapping classes when targeting ESNext
1 parent 7171125 commit 710136b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/compiler/transformers/ts.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ namespace ts {
2323
IsNamedExternalExport = 1 << 4,
2424
IsDefaultExternalExport = 1 << 5,
2525
IsDerivedClass = 1 << 6,
26+
UseImmediatelyInvokedFunctionExpression = 1 << 7,
2627

2728
HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
2829
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
29-
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
3030
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
3131
}
3232

@@ -595,6 +595,11 @@ namespace ts {
595595
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
596596
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
597597
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
598+
if (facts & ClassFacts.HasAnyDecorators) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
599+
if (facts & ClassFacts.HasStaticInitializedProperties) {
600+
if (languageVersion < ScriptTarget.ESNext) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
601+
else if (languageVersion === ScriptTarget.ESNext && !compilerOptions.useDefineForClassFields) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
602+
}
598603
return facts;
599604
}
600605

tests/baselines/reference/thisInClassBodyStaticESNext.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ class Foo {
1111

1212
//// [thisInClassBodyStaticESNext.js]
1313
// all are allowed with es-compliant class field emit
14-
let Foo = /** @class */ (() => {
15-
class Foo {
16-
x = this;
17-
static t = this;
18-
static at = () => this;
19-
static ft = function () { return this; };
20-
static mt() { return this; }
21-
}
22-
return Foo;
23-
})();
14+
class Foo {
15+
x = this;
16+
static t = this;
17+
static at = () => this;
18+
static ft = function () { return this; };
19+
static mt() { return this; }
20+
}

0 commit comments

Comments
 (0)