From ac28edd77cd98d0b89f3796f148fd6ca4b43519e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 15 Aug 2024 17:06:24 -0400 Subject: [PATCH 1/2] Do not overwrite original pointer when indirectly points to location --- src/compiler/checker.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1673c6c032716..1a3890dfb6a9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6063,10 +6063,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!location) { return range; } - if (!context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(getOriginalNode(location))) { - 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 + // Don't overwrite the original node if `range` has an `original` node that points either directly or indirectly to `location` + let original = range.original; + while (original && original !== location) { + original = original.original; } - return setTextRangeWorker(setOriginalNode(range, location), location); + if (!original) { + setOriginalNode(range, location); + } + // only set positions if range comes from the same file since copying text across files isn't supported by the emitter + if (context.enclosingFile && context.enclosingFile === getSourceFileOfNode(getOriginalNode(location))) { + return setTextRangeWorker(range, location); + } + return range; } /** From 8d270579667d32e1b47c801db7e49b2300429d7f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 15 Aug 2024 17:48:16 -0400 Subject: [PATCH 2/2] Fix formatting --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1a3890dfb6a9b..ad9728ea62ccf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6063,7 +6063,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!location) { return range; } - // Don't overwrite the original node if `range` has an `original` node that points either directly or indirectly to `location` + // Don't overwrite the original node if `range` has an `original` node that points either directly or indirectly to `location` let original = range.original; while (original && original !== location) { original = original.original;