Skip to content

Commit 950fe02

Browse files
committed
Always wrap classes with decorators or static properties in an IIFE
Currently only script targets less than or equal to ES5 will wrap classes. However, the wrapping is also crucial to file size optimizations for ES2015+ as well. Without the IIFE wrapper, minification tools do not elide the class. This is due to references to the class being present within the downlevelled decorator and static property code. This change represents the full completion of issue #15857
1 parent cd371da commit 950fe02

File tree

1 file changed

+2
-4
lines changed
  • src/compiler/transformers

1 file changed

+2
-4
lines changed

src/compiler/transformers/ts.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ namespace ts {
2323
IsNamedExternalExport = 1 << 4,
2424
IsDefaultExternalExport = 1 << 5,
2525
IsDerivedClass = 1 << 6,
26-
UseImmediatelyInvokedFunctionExpression = 1 << 7,
2726

2827
HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
2928
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
30-
MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
29+
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
3130
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
3231
}
3332

@@ -587,7 +586,6 @@ namespace ts {
587586
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
588587
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
589588
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
590-
if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
591589
return facts;
592590
}
593591

@@ -666,7 +664,7 @@ namespace ts {
666664
/*type*/ undefined,
667665
iife
668666
)
669-
])
667+
], languageVersion > ScriptTarget.ES5 ? NodeFlags.Let : undefined)
670668
);
671669

672670
setOriginalNode(varStatement, node);

0 commit comments

Comments
 (0)