Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,15 @@ export namespace Core {
} = searchOptions;
const escapedText = escapeLeadingUnderscores(text);
const parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
return { symbol, comingFrom, text, escapedText, parents, allSearchSymbols, includes: sym => contains(allSearchSymbols, sym) };
return {
symbol,
comingFrom,
text,
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.

};
}

private readonly symbolIdToReferences: Entry[][] = [];
Expand Down
11 changes: 11 additions & 0 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getNameOfAccessExpression,
getSourceFileOfNode,
getSymbolId,
getSymbolTarget,
hasSyntacticModifier,
Identifier,
ImportCall,
Expand Down Expand Up @@ -635,6 +636,16 @@ export function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: Typ
else if (isJSDocTypedefTag(parent) || isJSDocCallbackTag(parent)) {
return exportInfo(symbol, ExportKind.Named);
}
else {
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.

This comment was marked as spam.

const exportInfo = { exportingModuleSymbol: sourceFile.symbol, exportKind: ExportKind.Named };
return { kind: ImportExport.Export, symbol, exportInfo };
}
}
}
}

function getExportAssignmentExport(ex: ExportAssignment): ExportedSymbol | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// === findAllReferences ===
// === /mod.ts ===
// class Cls {
// /*FIND ALL REFS*/<|[|{| isWriteAccess: true, isDefinition: true |}foo|]() {}|>
// };
//
// export default new Cls();

// === /index.ts ===
// import def from "./mod"
// def.[|foo|]();

// === Definitions ===
// === /mod.ts ===
// class Cls {
// /*FIND ALL REFS*/<|[|foo|]() {}|>
// };
//
// export default new Cls();

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "method",
"name": "(method) Cls.foo(): void",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "method",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Cls",
"kind": "className"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "foo",
"kind": "methodName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
}
]



// === findAllReferences ===
// === /mod.ts ===
// class Cls {
// <|[|{| isWriteAccess: true |}foo|]() {}|>
// };
//
// export default new Cls();

// === /index.ts ===
// import def from "./mod"
// def.[|foo|]/*FIND ALL REFS*/();

// === Definitions ===
// === /mod.ts ===
// class Cls {
// <|[|foo|]() {}|>
// };
//
// export default new Cls();

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "method",
"name": "(method) Cls.foo(): void",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "method",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Cls",
"kind": "className"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "foo",
"kind": "methodName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// === findAllReferences ===
// === /mod.d.ts ===
// export default React;
//
// declare namespace React {
// <|function /*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}lazy|](): void;|>
// }

// === /index.ts ===
// import def from "./mod"
// def.[|lazy|]();

// === Definitions ===
// === /mod.d.ts ===
// export default React;
//
// declare namespace React {
// <|function /*FIND ALL REFS*/[|lazy|](): void;|>
// }

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "function",
"name": "function React.lazy(): void",
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "React",
"kind": "moduleName"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "lazy",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
}
]



// === findAllReferences ===
// === /mod.d.ts ===
// export default React;
//
// declare namespace React {
// <|function [|{| isWriteAccess: true |}lazy|](): void;|>
// }

// === /index.ts ===
// import def from "./mod"
// def.[|lazy|]/*FIND ALL REFS*/();

// === Definitions ===
// === /mod.d.ts ===
// export default React;
//
// declare namespace React {
// <|function [|lazy|](): void;|>
// }

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "function",
"name": "function React.lazy(): void",
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "React",
"kind": "moduleName"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "lazy",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
]
}
]
Loading
Loading