Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ namespace ts.FindAllReferences {
}
}
else {
const exportNode = getExportNode(parent);
const exportNode = getExportNode(parent, node);
if (exportNode && hasModifier(exportNode, ModifierFlags.Export)) {
if (isImportEqualsDeclaration(exportNode) && exportNode.moduleReference === node) {
// We're at `Y` in `export import X = Y`. This is not the exported symbol, the left-hand-side is. So treat this as an import statement.
Expand Down Expand Up @@ -558,10 +558,11 @@ namespace ts.FindAllReferences {

// If a reference is a class expression, the exported node would be its parent.
// If a reference is a variable declaration, the exported node would be the variable statement.
function getExportNode(parent: Node): Node | undefined {
function getExportNode(parent: Node, node: Node): Node | undefined {
if (parent.kind === SyntaxKind.VariableDeclaration) {
const p = parent as ts.VariableDeclaration;
return p.parent.kind === ts.SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined;
return p.name !== node ? undefined :
p.parent.kind === ts.SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined;
}
else {
return parent;
Expand Down
17 changes: 17 additions & 0 deletions tests/cases/fourslash/findAllRefsExportConstEqualToClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />

// @Filename: /a.ts
////class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {}
////export const [|{| "isWriteAccess": true, "isDefinition": true |}D|] = [|C|];

// @Filename: /b.ts
////import { [|{| "isWriteAccess": true, "isDefinition": true |}D|] } from "./a";

const [C0, D0, C1, D1] = test.ranges();

verify.singleReferenceGroup("class C", [C0, C1]);

const d0Group = { definition: "const D: typeof C", ranges: [D0] };
const d1Group = { definition: "import D", ranges: [D1] };
verify.referenceGroups(D0, [d0Group, d1Group]);
verify.referenceGroups(D1, [d1Group, d0Group]);