Skip to content

Do not overwrite original pointer when indirectly points to location #59647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down