Skip to content

Commit fb0c169

Browse files
authored
Fix canHaveLiteralInitializer misport (#2219)
1 parent a37a257 commit fb0c169

15 files changed

+30
-79
lines changed

internal/transformers/declarations/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func canHaveLiteralInitializer(host DeclarationEmitHost, node *ast.Node) bool {
1414
switch node.Kind {
1515
case ast.KindPropertyDeclaration,
1616
ast.KindPropertySignature:
17-
return host.GetEffectiveDeclarationFlags(node, ast.ModifierFlagsPrivate) != 0
17+
return host.GetEffectiveDeclarationFlags(node, ast.ModifierFlagsPrivate) == 0
1818
case ast.KindParameter,
1919
ast.KindVariableDeclaration:
2020
return true

testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ declare let v2: E.B;
178178
declare class C {
179179
p1: E;
180180
p2: E.B;
181-
readonly p3: E;
181+
readonly p3 = E.B;
182182
readonly p4: E.B;
183183
}
184184
declare enum MyEnum {

testdata/baselines/reference/submodule/compiler/computedEnumTypeWidening.js.diff

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,4 @@
3535
+ p4 = E.B;
3636
}
3737
// Repro from #52531
38-
var MyEnum;
39-
@@= skipped -45, +43 lines =@@
40-
declare class C {
41-
p1: E;
42-
p2: E.B;
43-
- readonly p3 = E.B;
44-
+ readonly p3: E;
45-
readonly p4: E.B;
46-
}
47-
declare enum MyEnum {
38+
var MyEnum;

testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ exports.Bar = Bar;
2020
//// [declarationEmitConstantNoWidening.d.ts]
2121
export declare const FOO = "FOO";
2222
export declare class Bar {
23-
readonly type: string;
23+
readonly type = "FOO";
2424
}

testdata/baselines/reference/submodule/compiler/declarationEmitConstantNoWidening.js.diff

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,3 @@
1010
+ type = exports.FOO; // Should be widening literal "FOO" - so either `typeof "FOO"` or = "FOO"
1111
}
1212
exports.Bar = Bar;
13-
14-
@@= skipped -10, +8 lines =@@
15-
//// [declarationEmitConstantNoWidening.d.ts]
16-
export declare const FOO = "FOO";
17-
export declare class Bar {
18-
- readonly type = "FOO";
19-
+ readonly type: string;
20-
}

testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ declare enum E {
3030
B = "b"
3131
}
3232
declare class C {
33-
readonly type: E;
33+
readonly type = E.A;
3434
}
3535
declare let x: E.A;

testdata/baselines/reference/submodule/compiler/declarationEmitEnumReadonlyProperty.js.diff

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,3 @@
1010
+ type = E.A;
1111
}
1212
let x = new C().type;
13-
14-
@@= skipped -13, +11 lines =@@
15-
B = "b"
16-
}
17-
declare class C {
18-
- readonly type = E.A;
19-
+ readonly type: E;
20-
}
21-
declare let x: E.A;

testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Foo {
2020

2121
//// [declarationEmitPrivateReadonlyLiterals.d.ts]
2222
declare class Foo {
23-
private static readonly A = "a";
24-
private readonly B = "b";
25-
private static readonly C = 42;
26-
private readonly D = 42;
23+
private static readonly A;
24+
private readonly B;
25+
private static readonly C;
26+
private readonly D;
2727
}

testdata/baselines/reference/submodule/compiler/declarationEmitPrivateReadonlyLiterals.js.diff

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,4 @@
1717
-Foo.C = 42;
1818

1919

20-
//// [declarationEmitPrivateReadonlyLiterals.d.ts]
21-
declare class Foo {
22-
- private static readonly A;
23-
- private readonly B;
24-
- private static readonly C;
25-
- private readonly D;
26-
+ private static readonly A = "a";
27-
+ private readonly B = "b";
28-
+ private static readonly C = 42;
29-
+ private readonly D = 42;
30-
}
20+
//// [declarationEmitPrivateReadonlyLiterals.d.ts]

testdata/baselines/reference/submodule/compiler/initializerWithThisPropertyAccess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ declare class C {
8383
}
8484
declare class Foo {
8585
private bar;
86-
readonly barProp: boolean;
86+
readonly barProp = false;
8787
constructor();
8888
}
8989
declare class Bar {
90-
readonly prop: boolean;
90+
readonly prop = false;
9191
}

0 commit comments

Comments
 (0)