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.
This commit is contained in:
Nathan Shively-Sanders
2018-05-14 14:58:35 -07:00
parent 6b21c37937
commit 68875dc5c8

View File

@@ -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);