From 78b43e7cc1a838fadcbdccd5715d2ad79a24604c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 4 Dec 2025 09:25:35 -0800 Subject: [PATCH] Fix canHaveLiteralInitializer misport --- internal/transformers/declarations/util.go | 2 +- .../submodule/compiler/computedEnumTypeWidening.js | 2 +- .../compiler/computedEnumTypeWidening.js.diff | 11 +---------- .../compiler/declarationEmitConstantNoWidening.js | 2 +- .../declarationEmitConstantNoWidening.js.diff | 8 -------- .../declarationEmitEnumReadonlyProperty.js | 2 +- .../declarationEmitEnumReadonlyProperty.js.diff | 9 --------- .../declarationEmitPrivateReadonlyLiterals.js | 8 ++++---- .../declarationEmitPrivateReadonlyLiterals.js.diff | 12 +----------- .../compiler/initializerWithThisPropertyAccess.js | 4 ++-- .../initializerWithThisPropertyAccess.js.diff | 13 ------------- .../isolatedDeclarationErrorsExpressions.js | 14 +++++++------- .../isolatedDeclarationErrorsExpressions.js.diff | 14 +++++++------- .../compiler/isolatedDeclarationsAddUndefined.js | 4 ++-- .../isolatedDeclarationsAddUndefined.js.diff | 4 ++-- 15 files changed, 30 insertions(+), 79 deletions(-) diff --git a/internal/transformers/declarations/util.go b/internal/transformers/declarations/util.go index b716a1b338..3f0c22f4f8 100644 --- a/internal/transformers/declarations/util.go +++ b/internal/transformers/declarations/util.go @@ -14,7 +14,7 @@ func canHaveLiteralInitializer(host DeclarationEmitHost, node *ast.Node) bool { switch node.Kind { case ast.KindPropertyDeclaration, ast.KindPropertySignature: - return host.GetEffectiveDeclarationFlags(node, ast.ModifierFlagsPrivate) != 0 + return host.GetEffectiveDeclarationFlags(node, ast.ModifierFlagsPrivate) == 0 case ast.KindParameter, ast.KindVariableDeclaration: return true diff --git a/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js b/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js index 5c613f080d..90143e71ec 100644 --- a/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js +++ b/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js @@ -178,7 +178,7 @@ declare let v2: E.B; declare class C { p1: E; p2: E.B; - readonly p3: E; + readonly p3 = E.B; readonly p4: E.B; } declare enum MyEnum { diff --git a/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js.diff b/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js.diff index c8c9a8d25a..9d27aebdce 100644 --- a/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js.diff +++ b/testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js.diff @@ -35,13 +35,4 @@ + p4 = E.B; } // Repro from #52531 - var MyEnum; -@@= skipped -45, +43 lines =@@ - declare class C { - p1: E; - p2: E.B; -- readonly p3 = E.B; -+ readonly p3: E; - readonly p4: E.B; - } - declare enum MyEnum { \ No newline at end of file + var MyEnum; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js b/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js index 322a5aee9e..a0fba17283 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js @@ -20,5 +20,5 @@ exports.Bar = Bar; //// [declarationEmitConstantNoWidening.d.ts] export declare const FOO = "FOO"; export declare class Bar { - readonly type: string; + readonly type = "FOO"; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js.diff index d1cae2cb33..3d84fb01fb 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js.diff @@ -10,11 +10,3 @@ + type = exports.FOO; // Should be widening literal "FOO" - so either `typeof "FOO"` or = "FOO" } exports.Bar = Bar; - -@@= skipped -10, +8 lines =@@ - //// [declarationEmitConstantNoWidening.d.ts] - export declare const FOO = "FOO"; - export declare class Bar { -- readonly type = "FOO"; -+ readonly type: string; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js b/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js index 745886c952..3a12e628d5 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js @@ -30,6 +30,6 @@ declare enum E { B = "b" } declare class C { - readonly type: E; + readonly type = E.A; } declare let x: E.A; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js.diff index 1f78ab5775..077c43cec8 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js.diff @@ -10,12 +10,3 @@ + type = E.A; } let x = new C().type; - -@@= skipped -13, +11 lines =@@ - B = "b" - } - declare class C { -- readonly type = E.A; -+ readonly type: E; - } - declare let x: E.A; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js b/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js index cdad7571e5..115fba5d06 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js @@ -20,8 +20,8 @@ class Foo { //// [declarationEmitPrivateReadonlyLiterals.d.ts] declare class Foo { - private static readonly A = "a"; - private readonly B = "b"; - private static readonly C = 42; - private readonly D = 42; + private static readonly A; + private readonly B; + private static readonly C; + private readonly D; } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js.diff index f75495e4f1..b1743df64a 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js.diff @@ -17,14 +17,4 @@ -Foo.C = 42; - //// [declarationEmitPrivateReadonlyLiterals.d.ts] - declare class Foo { -- private static readonly A; -- private readonly B; -- private static readonly C; -- private readonly D; -+ private static readonly A = "a"; -+ private readonly B = "b"; -+ private static readonly C = 42; -+ private readonly D = 42; - } \ No newline at end of file + //// [declarationEmitPrivateReadonlyLiterals.d.ts] \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js b/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js index 1d9c86ac69..da9b5a7f9f 100644 --- a/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js +++ b/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js @@ -83,9 +83,9 @@ declare class C { } declare class Foo { private bar; - readonly barProp: boolean; + readonly barProp = false; constructor(); } declare class Bar { - readonly prop: boolean; + readonly prop = false; } diff --git a/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js.diff b/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js.diff index a3cb0f2fdb..46d1ac8db8 100644 --- a/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js.diff +++ b/testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js.diff @@ -45,16 +45,3 @@ + prop = false; } - -@@= skipped -49, +45 lines =@@ - } - declare class Foo { - private bar; -- readonly barProp = false; -+ readonly barProp: boolean; - constructor(); - } - declare class Bar { -- readonly prop = false; -+ readonly prop: boolean; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js index 95f0b751ff..d810e8e0f2 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js @@ -292,18 +292,18 @@ export declare class Exported { templateLetOk2: string; templateLetOk3: string; templateLetOk4: string; - readonly numberConst: number; + readonly numberConst = 1; readonly numberConstBad1: number; readonly numberConstBad2: number; - readonly numberConstBad3: number; - readonly bigIntConst: bigint; + readonly numberConstBad3 = 1; + readonly bigIntConst = 1n; readonly bigIntConstBad1: bigint; readonly bigIntConstBad2: bigint; - readonly bigIntConstBad3: bigint; - readonly stringConst: string; + readonly bigIntConstBad3 = 1n; + readonly stringConst = "s"; readonly stringConstBad: string; - readonly templateConstOk1: string; - readonly templateConstNotOk2: string; + readonly templateConstOk1 = "s"; + readonly templateConstNotOk2 = "s1 - S"; readonly templateConstNotOk3: string; readonly templateConstNotOk4: string; numberLetAsConst: 1; diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js.diff index 6105d1f7c4..e802d469fd 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsExpressions.js.diff @@ -61,18 +61,18 @@ + templateLetOk2: string; + templateLetOk3: string; + templateLetOk4: string; -+ readonly numberConst: number; ++ readonly numberConst = 1; + readonly numberConstBad1: number; + readonly numberConstBad2: number; -+ readonly numberConstBad3: number; -+ readonly bigIntConst: bigint; ++ readonly numberConstBad3 = 1; ++ readonly bigIntConst = 1n; + readonly bigIntConstBad1: bigint; + readonly bigIntConstBad2: bigint; -+ readonly bigIntConstBad3: bigint; -+ readonly stringConst: string; ++ readonly bigIntConstBad3 = 1n; ++ readonly stringConst = "s"; + readonly stringConstBad: string; -+ readonly templateConstOk1: string; -+ readonly templateConstNotOk2: string; ++ readonly templateConstOk1 = "s"; ++ readonly templateConstNotOk2 = "s1 - S"; + readonly templateConstNotOk3: string; + readonly templateConstNotOk4: string; + numberLetAsConst: 1; diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js index 362662292c..b4dcdcc13f 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js @@ -50,13 +50,13 @@ exports.Bar2 = Bar2; export declare class Bar { c?: readonly [1] | undefined; c3?: 1 | undefined; - readonly r: number; + readonly r = 1; f: number; } //// [file2.d.ts] export declare function foo(p?: (ip: number | undefined, v: number) => void): void; export declare function foo2(p?: (ip: number | undefined, v: number) => void): void; export declare class Bar2 { - readonly r: number; + readonly r = 1; f: number; } diff --git a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js.diff b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js.diff index f80a112b47..67c9cf5b29 100644 --- a/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js.diff +++ b/testdata/baselines/reference/submodule/compiler/isolatedDeclarationsAddUndefined.js.diff @@ -41,13 +41,13 @@ -} -export {}; + c3?: 1 | undefined; -+ readonly r: number; ++ readonly r = 1; + f: number; +} +//// [file2.d.ts] +export declare function foo(p?: (ip: number | undefined, v: number) => void): void; +export declare function foo2(p?: (ip: number | undefined, v: number) => void): void; +export declare class Bar2 { -+ readonly r: number; ++ readonly r = 1; + f: number; +} \ No newline at end of file