Skip to content

Commit cc36cfc

Browse files
authored
Merge pull request #24050 from Microsoft/fix-js-initializer-merging
Fix js initializer merging
2 parents bdc0a3e + 2792ff9 commit cc36cfc

File tree

5 files changed

+79
-52
lines changed

5 files changed

+79
-52
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ namespace ts {
892892
function mergeSymbol(target: Symbol, source: Symbol) {
893893
if (!(target.flags & getExcludedSymbolFlags(source.flags)) ||
894894
(source.flags | target.flags) & SymbolFlags.JSContainer) {
895+
Debug.assert(!!(target.flags & SymbolFlags.Transient));
895896
// Javascript static-property-assignment declarations always merge, even though they are also values
896897
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
897898
// reset flag when merging instantiated module into value module that has only const enums
@@ -915,8 +916,12 @@ namespace ts {
915916
}
916917
if ((source.flags | target.flags) & SymbolFlags.JSContainer) {
917918
const sourceInitializer = getJSInitializerSymbol(source);
918-
const targetInitializer = getJSInitializerSymbol(target);
919+
let targetInitializer = getJSInitializerSymbol(target);
919920
if (sourceInitializer !== source || targetInitializer !== target) {
921+
if (!(targetInitializer.flags & SymbolFlags.Transient)) {
922+
const mergedInitializer = getMergedSymbol(targetInitializer);
923+
targetInitializer = mergedInitializer === targetInitializer ? cloneSymbol(targetInitializer) : mergedInitializer;
924+
}
920925
mergeSymbol(targetInitializer, sourceInitializer);
921926
}
922927
}
@@ -19452,7 +19457,7 @@ namespace ts {
1945219457
}
1945319458

1945419459
const links = getNodeLinks(node);
19455-
const type = getTypeOfSymbol(node.symbol);
19460+
const type = getTypeOfSymbol(getMergedSymbol(node.symbol));
1945619461
if (isTypeAny(type)) {
1945719462
return type;
1945819463
}

tests/baselines/reference/typeFromPropertyAssignment10.types

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
=== tests/cases/conformance/salsa/module.js ===
22
var Outer = Outer || {};
3-
>Outer : typeof __object
4-
>Outer || {} : typeof __object
5-
>Outer : typeof __object
6-
>{} : typeof __object
3+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
4+
>Outer || {} : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
5+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
6+
>{} : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
77

88
Outer.app = Outer.app || {};
9-
>Outer.app = Outer.app || {} : typeof __object
10-
>Outer.app : typeof __object
11-
>Outer : typeof __object
12-
>app : typeof __object
13-
>Outer.app || {} : typeof __object
14-
>Outer.app : typeof __object
15-
>Outer : typeof __object
16-
>app : typeof __object
17-
>{} : typeof __object
9+
>Outer.app = Outer.app || {} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
10+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
11+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
12+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
13+
>Outer.app || {} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
14+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
15+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
16+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
17+
>{} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
1818

1919
=== tests/cases/conformance/salsa/someview.js ===
2020
Outer.app.SomeView = (function () {
2121
>Outer.app.SomeView = (function () { var SomeView = function() { var me = this; } return SomeView;})() : () => void
2222
>Outer.app.SomeView : () => void
23-
>Outer.app : typeof __object
24-
>Outer : typeof __object
25-
>app : typeof __object
23+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
24+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
25+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
2626
>SomeView : () => void
2727
>(function () { var SomeView = function() { var me = this; } return SomeView;})() : () => void
2828
>(function () { var SomeView = function() { var me = this; } return SomeView;}) : () => () => void
@@ -43,9 +43,9 @@ Outer.app.SomeView = (function () {
4343
Outer.app.Inner = class {
4444
>Outer.app.Inner = class { constructor() { /** @type {number} */ this.y = 12; }} : typeof Inner
4545
>Outer.app.Inner : typeof Inner
46-
>Outer.app : typeof __object
47-
>Outer : typeof __object
48-
>app : typeof __object
46+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
47+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
48+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
4949
>Inner : typeof Inner
5050
>class { constructor() { /** @type {number} */ this.y = 12; }} : typeof Inner
5151

@@ -63,9 +63,9 @@ var example = new Outer.app.Inner();
6363
>example : Inner
6464
>new Outer.app.Inner() : Inner
6565
>Outer.app.Inner : typeof Inner
66-
>Outer.app : typeof __object
67-
>Outer : typeof __object
68-
>app : typeof __object
66+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
67+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
68+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
6969
>Inner : typeof Inner
7070

7171
example.y;
@@ -77,9 +77,9 @@ example.y;
7777
Outer.app.statische = function (k) {
7878
>Outer.app.statische = function (k) { return k ** k;} : (k: number) => number
7979
>Outer.app.statische : (k: number) => number
80-
>Outer.app : typeof __object
81-
>Outer : typeof __object
82-
>app : typeof __object
80+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
81+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
82+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
8383
>statische : (k: number) => number
8484
>function (k) { return k ** k;} : (k: number) => number
8585
>k : number
@@ -93,9 +93,9 @@ Outer.app.statische = function (k) {
9393
Outer.app.Application = (function () {
9494
>Outer.app.Application = (function () { /** * Application main class. * Will be instantiated & initialized by HTML page */ var Application = function () { var me = this; me.view = new Outer.app.SomeView(); }; return Application;})() : () => void
9595
>Outer.app.Application : () => void
96-
>Outer.app : typeof __object
97-
>Outer : typeof __object
98-
>app : typeof __object
96+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
97+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
98+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
9999
>Application : () => void
100100
>(function () { /** * Application main class. * Will be instantiated & initialized by HTML page */ var Application = function () { var me = this; me.view = new Outer.app.SomeView(); }; return Application;})() : () => void
101101
>(function () { /** * Application main class. * Will be instantiated & initialized by HTML page */ var Application = function () { var me = this; me.view = new Outer.app.SomeView(); }; return Application;}) : () => () => void
@@ -120,9 +120,9 @@ Outer.app.Application = (function () {
120120
>view : any
121121
>new Outer.app.SomeView() : any
122122
>Outer.app.SomeView : () => void
123-
>Outer.app : typeof __object
124-
>Outer : typeof __object
125-
>app : typeof __object
123+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
124+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
125+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
126126
>SomeView : () => void
127127

128128
};
@@ -135,18 +135,18 @@ var app = new Outer.app.Application();
135135
>app : any
136136
>new Outer.app.Application() : any
137137
>Outer.app.Application : () => void
138-
>Outer.app : typeof __object
139-
>Outer : typeof __object
140-
>app : typeof __object
138+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
139+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
140+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
141141
>Application : () => void
142142

143143
var inner = new Outer.app.Inner();
144144
>inner : Inner
145145
>new Outer.app.Inner() : Inner
146146
>Outer.app.Inner : typeof Inner
147-
>Outer.app : typeof __object
148-
>Outer : typeof __object
149-
>app : typeof __object
147+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
148+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
149+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
150150
>Inner : typeof Inner
151151

152152
inner.y;
@@ -166,9 +166,9 @@ x.y;
166166
Outer.app.statische(101); // Infinity, duh
167167
>Outer.app.statische(101) : number
168168
>Outer.app.statische : (k: number) => number
169-
>Outer.app : typeof __object
170-
>Outer : typeof __object
171-
>app : typeof __object
169+
>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
170+
>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; }
171+
>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }
172172
>statische : (k: number) => number
173173
>101 : 101
174174

tests/baselines/reference/typeFromPropertyAssignment14.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
=== tests/cases/conformance/salsa/def.js ===
22
var Outer = {};
3-
>Outer : typeof Outer
4-
>{} : typeof Outer
3+
>Outer : { [x: string]: any; Inner(): void; }
4+
>{} : { [x: string]: any; Inner(): void; }
55

66
=== tests/cases/conformance/salsa/work.js ===
77
Outer.Inner = function () {}
88
>Outer.Inner = function () {} : () => void
99
>Outer.Inner : () => void
10-
>Outer : typeof Outer
10+
>Outer : { [x: string]: any; Inner(): void; }
1111
>Inner : () => void
1212
>function () {} : () => void
1313

1414
Outer.Inner.prototype = {
1515
>Outer.Inner.prototype = { x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }
1616
>Outer.Inner.prototype : any
1717
>Outer.Inner : () => void
18-
>Outer : typeof Outer
18+
>Outer : { [x: string]: any; Inner(): void; }
1919
>Inner : () => void
2020
>prototype : any
2121
>{ x: 1, m() { }} : { [x: string]: any; x: number; m(): void; }
@@ -48,7 +48,7 @@ var inno = new Outer.Inner()
4848
>inno : { [x: string]: any; x: number; m(): void; }
4949
>new Outer.Inner() : { [x: string]: any; x: number; m(): void; }
5050
>Outer.Inner : () => void
51-
>Outer : typeof Outer
51+
>Outer : { [x: string]: any; Inner(): void; }
5252
>Inner : () => void
5353

5454
inno.x

tests/baselines/reference/typeFromPropertyAssignment4.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
=== tests/cases/conformance/salsa/def.js ===
22
var Outer = {};
3-
>Outer : typeof Outer
4-
>{} : typeof Outer
3+
>Outer : { [x: string]: any; Inner: typeof Inner; }
4+
>{} : { [x: string]: any; Inner: typeof Inner; }
55

66
=== tests/cases/conformance/salsa/a.js ===
77
Outer.Inner = class {
88
>Outer.Inner = class { constructor() { /** @type {number} */ this.y = 12 }} : typeof Inner
99
>Outer.Inner : typeof Inner
10-
>Outer : typeof Outer
10+
>Outer : { [x: string]: any; Inner: typeof Inner; }
1111
>Inner : typeof Inner
1212
>class { constructor() { /** @type {number} */ this.y = 12 }} : typeof Inner
1313

@@ -35,7 +35,7 @@ var inner = new Outer.Inner()
3535
>inner : Inner
3636
>new Outer.Inner() : Inner
3737
>Outer.Inner : typeof Inner
38-
>Outer : typeof Outer
38+
>Outer : { [x: string]: any; Inner: typeof Inner; }
3939
>Inner : typeof Inner
4040

4141
inner.y
@@ -57,7 +57,7 @@ var z = new Outer.Inner()
5757
>z : Inner
5858
>new Outer.Inner() : Inner
5959
>Outer.Inner : typeof Inner
60-
>Outer : typeof Outer
60+
>Outer : { [x: string]: any; Inner: typeof Inner; }
6161
>Inner : typeof Inner
6262

6363
z.y
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
// @noEmit: true
3+
// @allowJs: true
4+
// @checkJs: true
5+
6+
// @Filename: b.d.ts
7+
//// declare class C { }
8+
// @Filename: a.js
9+
//// C.prototype = { m: "q"; }
10+
// @Filename: test.js
11+
//// var c = new C()
12+
//// /*1*/
13+
//// var c = new C()
14+
15+
// #24015
16+
// This failed with 13 and up on my machine, so 20 is 2**7 more than needed.
17+
for (let i = 0; i < 20; i++) {
18+
goTo.marker('1');
19+
edit.insertLine('c');
20+
21+
verify.getSemanticDiagnostics([])
22+
}

0 commit comments

Comments
 (0)