Skip to content

Commit 543e0af

Browse files
author
Andy
authored
Make exportSymbol public (#17457)
* Make exportSymbol public * Add a `getExportSymbolOfSymbol` method * Use own implementation instead of delegating to `getExportSymbolOfValueSymbolIfExported`
1 parent ea7c7d3 commit 543e0af

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ namespace ts {
138138
node = getParseTreeNode(node, isExportSpecifier);
139139
return node ? getExportSpecifierLocalTargetSymbol(node) : undefined;
140140
},
141+
getExportSymbolOfSymbol(symbol) {
142+
return getMergedSymbol(symbol.exportSymbol || symbol);
143+
},
141144
getTypeAtLocation: node => {
142145
node = getParseTreeNode(node);
143146
return node ? getTypeOfNode(node) : unknownType;

src/compiler/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,15 @@ namespace ts {
25682568
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
25692569
getShorthandAssignmentValueSymbol(location: Node): Symbol | undefined;
25702570
getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol | undefined;
2571+
/**
2572+
* If a symbol is a local symbol with an associated exported symbol, returns the exported symbol.
2573+
* Otherwise returns its input.
2574+
* For example, at `export type T = number;`:
2575+
* - `getSymbolAtLocation` at the location `T` will return the exported symbol for `T`.
2576+
* - But the result of `getSymbolsInScope` will contain the *local* symbol for `T`, not the exported symbol.
2577+
* - Calling `getExportSymbolOfSymbol` on that local symbol will return the exported symbol.
2578+
*/
2579+
getExportSymbolOfSymbol(symbol: Symbol): Symbol;
25712580
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined;
25722581
getTypeAtLocation(node: Node): Type;
25732582
getTypeFromTypeNode(node: TypeNode): Type;

0 commit comments

Comments
 (0)