Skip to content

Conversation

Andarist
Copy link
Contributor

fixes #62348

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Sep 10, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 10, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/cases/fourslash/findAllRefsEqualExportedObjectMember1.ts
tests/cases/fourslash/findAllRefsEqualExportedObjectMember2.ts
tests/cases/fourslash/findAllRefsEqualExportedClassInstanceMember1.ts

The 3 above can't find the 1st marker at 2nd and 3rd markers. That's the opposite problem to the raised issue and I think it can be treated as such (once this one would get merged I could open a new issue about it). I think it's still worth keeping the tests here though.

const sourceFile = getSourceFileOfNode(node);
if (sourceFile.symbol?.exports?.has(InternalSymbolName.ExportEquals)) {
const moduleSymbol = checker.resolveExternalModuleSymbol(sourceFile.symbol);
if (moduleSymbol && (moduleSymbol === symbol.parent || some(checker.getPropertiesOfType(checker.getTypeOfSymbol(moduleSymbol)), s => getSymbolTarget(s, checker) === symbol))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions how to improve some(getPropertiesOfType(getTypeOfSymbol(...)), ...) bit. I couldn't find an easier way to do this for the presented object literal (and class instance!) cases.

escapedText,
parents,
allSearchSymbols,
includes: sym => contains(allSearchSymbols, sym, (s1, s2) => this.checker.getMergedSymbol(s1) === this.checker.getMergedSymbol(s2)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the added checker.resolveExternalModuleSymbol call triggered a symbol merge. And that broke this test case (tests/cases/fourslash/renameExportCrash.ts):

///<reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: Foo.js
//// let a;
//// module.exports = /**/a;
//// exports["foo"] = a;

verify.baselineRename("", { });
  1. The search state had the original symbol in its allSearchSymbols (the state was created first)
  2. then the symbol was merged by the added code (through resolveExternalModuleSymbol -> getCommonJsExportEquals -> cloneSymbol -> recordMergedSymbol)
  3. then state.checker.getSymbolAtLocation(referenceLocation) called by getReferencesAtLocation found the merged symbol through resolveEntityName -> resolveNameHelper -> result = lookup(location.locals, name, meaning) -> getSymbol -> getMergedSymbol
  4. and at the ned this includes was called with that merged symbol

So it seems this was always prone to issues with lazily-merged symbols and comparing merged symbols of both looks like a reasonable solution to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Usage references can't be found for symbols exported through an exported namespace
2 participants