diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 7f848685aec36..c4a51b1b789a9 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -23,10 +23,10 @@ namespace ts { IsNamedExternalExport = 1 << 4, IsDefaultExternalExport = 1 << 5, IsDerivedClass = 1 << 6, + UseImmediatelyInvokedFunctionExpression = 1 << 7, HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators, NeedsName = HasStaticInitializedProperties | HasMemberDecorators, - UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties, IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport, } @@ -595,6 +595,10 @@ namespace ts { if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace; else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport; else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport; + if (facts & ClassFacts.HasAnyDecorators) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; + if (facts & ClassFacts.HasStaticInitializedProperties) { + if (languageVersion < ScriptTarget.ESNext || !compilerOptions.useDefineForClassFields) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; + } return facts; } diff --git a/tests/baselines/reference/thisInClassBodyStaticESNext.js b/tests/baselines/reference/thisInClassBodyStaticESNext.js index 6ad51b36a7385..7f061b12a4149 100644 --- a/tests/baselines/reference/thisInClassBodyStaticESNext.js +++ b/tests/baselines/reference/thisInClassBodyStaticESNext.js @@ -11,13 +11,10 @@ class Foo { //// [thisInClassBodyStaticESNext.js] // all are allowed with es-compliant class field emit -let Foo = /** @class */ (() => { - class Foo { - x = this; - static t = this; - static at = () => this; - static ft = function () { return this; }; - static mt() { return this; } - } - return Foo; -})(); +class Foo { + x = this; + static t = this; + static at = () => this; + static ft = function () { return this; }; + static mt() { return this; } +}