Skip to content

Commit 68875dc

Browse files
committed
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.
1 parent 6b21c37 commit 68875dc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ namespace ts {
871871
function mergeSymbol(target: Symbol, source: Symbol) {
872872
if (!(target.flags & getExcludedSymbolFlags(source.flags)) ||
873873
(source.flags | target.flags) & SymbolFlags.JSContainer) {
874+
const targetValueDeclaration = target.valueDeclaration;
875+
Debug.assert(!!(target.flags & SymbolFlags.Transient));
874876
// Javascript static-property-assignment declarations always merge, even though they are also values
875877
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
876878
// reset flag when merging instantiated module into value module that has only const enums
@@ -894,7 +896,8 @@ namespace ts {
894896
}
895897
if ((source.flags | target.flags) & SymbolFlags.JSContainer) {
896898
const sourceInitializer = getJSInitializerSymbol(source);
897-
let targetInitializer = getJSInitializerSymbol(target);
899+
const init = getDeclaredJavascriptInitializer(targetValueDeclaration) || getAssignedJavascriptInitializer(targetValueDeclaration);
900+
let targetInitializer = init && init.symbol ? init.symbol : target;
898901
if (sourceInitializer !== source || targetInitializer !== target) {
899902
if (!(targetInitializer.flags & SymbolFlags.Transient)) {
900903
const mergedInitializer = getMergedSymbol(targetInitializer);

0 commit comments

Comments
 (0)