From 68875dc5c87399b36bf27f3fe038f19d58dbcc0c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 14 May 2018 14:58:35 -0700 Subject: [PATCH] JS initializers use original valueDecl, not mutated target's valueDeclaration is set to the source's if it is not present. This makes it incorrect to use getJSInitializerSymbol because it relies on the symbol's valueDeclaration. This fix just saves the original valueDeclaration before mutating and uses that. --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0b0668dc5a0..fb326b7f388 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -871,6 +871,8 @@ namespace ts { function mergeSymbol(target: Symbol, source: Symbol) { if (!(target.flags & getExcludedSymbolFlags(source.flags)) || (source.flags | target.flags) & SymbolFlags.JSContainer) { + const targetValueDeclaration = target.valueDeclaration; + Debug.assert(!!(target.flags & SymbolFlags.Transient)); // Javascript static-property-assignment declarations always merge, even though they are also values if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) { // reset flag when merging instantiated module into value module that has only const enums @@ -894,7 +896,8 @@ namespace ts { } if ((source.flags | target.flags) & SymbolFlags.JSContainer) { const sourceInitializer = getJSInitializerSymbol(source); - let targetInitializer = getJSInitializerSymbol(target); + const init = getDeclaredJavascriptInitializer(targetValueDeclaration) || getAssignedJavascriptInitializer(targetValueDeclaration); + let targetInitializer = init && init.symbol ? init.symbol : target; if (sourceInitializer !== source || targetInitializer !== target) { if (!(targetInitializer.flags & SymbolFlags.Transient)) { const mergedInitializer = getMergedSymbol(targetInitializer);