From 904f8df9c14903e888cc2a50ba26b558996b2518 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 10 May 2018 20:58:59 -0700 Subject: [PATCH] Fix repeated merging of js initializers --- src/compiler/checker.ts | 3 +- .../typeFromPropertyAssignment10.types | 80 +++++++++---------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fc82ebfa02c..0f1ee7e62d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -918,7 +918,8 @@ namespace ts { let targetInitializer = getJSInitializerSymbol(target); if (sourceInitializer !== source || targetInitializer !== target) { if (!(targetInitializer.flags & SymbolFlags.Transient)) { - targetInitializer = cloneSymbol(targetInitializer); + const mergedInitializer = getMergedSymbol(targetInitializer); + targetInitializer = mergedInitializer === targetInitializer ? cloneSymbol(targetInitializer) : mergedInitializer; } mergeSymbol(targetInitializer, sourceInitializer); } diff --git a/tests/baselines/reference/typeFromPropertyAssignment10.types b/tests/baselines/reference/typeFromPropertyAssignment10.types index f4d11816537..a880498f047 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment10.types +++ b/tests/baselines/reference/typeFromPropertyAssignment10.types @@ -1,28 +1,28 @@ === tests/cases/conformance/salsa/module.js === var Outer = Outer || {}; ->Outer : typeof __object ->Outer || {} : typeof __object ->Outer : typeof __object ->{} : typeof __object +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>Outer || {} : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>{} : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } Outer.app = Outer.app || {}; ->Outer.app = Outer.app || {} : typeof __object ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object ->Outer.app || {} : typeof __object ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object ->{} : typeof __object +>Outer.app = Outer.app || {} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer.app || {} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>{} : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } === tests/cases/conformance/salsa/someview.js === Outer.app.SomeView = (function () { >Outer.app.SomeView = (function () { var SomeView = function() { var me = this; } return SomeView;})() : () => void >Outer.app.SomeView : () => void ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >SomeView : () => void >(function () { var SomeView = function() { var me = this; } return SomeView;})() : () => void >(function () { var SomeView = function() { var me = this; } return SomeView;}) : () => () => void @@ -43,9 +43,9 @@ Outer.app.SomeView = (function () { Outer.app.Inner = class { >Outer.app.Inner = class { constructor() { /** @type {number} */ this.y = 12; }} : typeof Inner >Outer.app.Inner : typeof Inner ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >Inner : typeof Inner >class { constructor() { /** @type {number} */ this.y = 12; }} : typeof Inner @@ -63,9 +63,9 @@ var example = new Outer.app.Inner(); >example : Inner >new Outer.app.Inner() : Inner >Outer.app.Inner : typeof Inner ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >Inner : typeof Inner example.y; @@ -77,9 +77,9 @@ example.y; Outer.app.statische = function (k) { >Outer.app.statische = function (k) { return k ** k;} : (k: number) => number >Outer.app.statische : (k: number) => number ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >statische : (k: number) => number >function (k) { return k ** k;} : (k: number) => number >k : number @@ -93,9 +93,9 @@ Outer.app.statische = function (k) { Outer.app.Application = (function () { >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 >Outer.app.Application : () => void ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >Application : () => void >(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 >(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 () { >view : any >new Outer.app.SomeView() : any >Outer.app.SomeView : () => void ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >SomeView : () => void }; @@ -135,18 +135,18 @@ var app = new Outer.app.Application(); >app : any >new Outer.app.Application() : any >Outer.app.Application : () => void ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >Application : () => void var inner = new Outer.app.Inner(); >inner : Inner >new Outer.app.Inner() : Inner >Outer.app.Inner : typeof Inner ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >Inner : typeof Inner inner.y; @@ -166,9 +166,9 @@ x.y; Outer.app.statische(101); // Infinity, duh >Outer.app.statische(101) : number >Outer.app.statische : (k: number) => number ->Outer.app : typeof __object ->Outer : typeof __object ->app : typeof __object +>Outer.app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } +>Outer : { [x: string]: any; app: { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; }; } +>app : { [x: string]: any; SomeView: () => void; Inner: typeof Inner; statische(k: number): number; Application: () => void; } >statische : (k: number) => number >101 : 101