Skip to content

Commit 856e472

Browse files
authored
Do not overwrite original pointer when indirectly points to location (microsoft#59647)
1 parent 5239589 commit 856e472

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6082,10 +6082,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
60826082
if (!location) {
60836083
return range;
60846084
}
6085-
if (!context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(getOriginalNode(location))) {
6086-
return setOriginalNode(range, location); // if `location` is from another file, only set/update original pointer, and not positions, since copying text across files isn't supported by the emitter
6085+
// Don't overwrite the original node if `range` has an `original` node that points either directly or indirectly to `location`
6086+
let original = range.original;
6087+
while (original && original !== location) {
6088+
original = original.original;
60876089
}
6088-
return setTextRangeWorker(setOriginalNode(range, location), location);
6090+
if (!original) {
6091+
setOriginalNode(range, location);
6092+
}
6093+
// only set positions if range comes from the same file since copying text across files isn't supported by the emitter
6094+
if (context.enclosingFile && context.enclosingFile === getSourceFileOfNode(getOriginalNode(location))) {
6095+
return setTextRangeWorker(range, location);
6096+
}
6097+
return range;
60896098
}
60906099

60916100
/**

0 commit comments

Comments
 (0)