Skip to content

Commit 8ec231b

Browse files
committed
Replaced incorrect logic of detecting symbol's visibility type
After discussion in microsoft/TypeScript#38344
1 parent 1330e50 commit 8ec231b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/transformer.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ import {
88
isPrivateClassMember,
99
splitTransientSymbol,
1010
getNodeJSDocComment,
11+
isNodeNamedDeclaration,
1112
} from './typescript-helpers';
1213

13-
// https://github.com/microsoft/TypeScript/issues/38344
14-
interface TSSymbolInternal extends ts.Symbol {
15-
parent?: TSSymbolInternal;
16-
}
17-
1814
export interface RenameOptions {
1915
/**
2016
* An array of entry source files which will used to detect exported and internal fields.
@@ -267,7 +263,7 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
267263
return symbol;
268264
}
269265

270-
function getNodeSymbol(node: ts.Expression | ts.Identifier | ts.StringLiteral | ts.NamedDeclaration): ts.Symbol | null {
266+
function getNodeSymbol(node: ts.Expression | ts.NamedDeclaration | ts.DeclarationName): ts.Symbol | null {
271267
const symbol = typeChecker.getSymbolAtLocation(node);
272268
if (symbol === undefined) {
273269
return null;
@@ -379,6 +375,7 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
379375
return getSymbolVisibilityType(symbol);
380376
}
381377

378+
// tslint:disable-next-line:cyclomatic-complexity
382379
function getSymbolVisibilityType(nodeSymbol: ts.Symbol): VisibilityType {
383380
nodeSymbol = getActualSymbol(nodeSymbol);
384381

@@ -414,14 +411,23 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
414411
}
415412
}
416413

417-
// if declaration is "exported" somehow
418-
let symbol: TSSymbolInternal | undefined = nodeSymbol as TSSymbolInternal;
419-
while (symbol !== undefined) {
420-
if (exportsSymbolTree.isSymbolAccessibleFromExports(symbol)) {
421-
return putToCache(nodeSymbol, VisibilityType.External);
414+
if (exportsSymbolTree.isSymbolAccessibleFromExports(nodeSymbol)) {
415+
return putToCache(nodeSymbol, VisibilityType.External)
416+
}
417+
418+
for (const declaration of symbolDeclarations) {
419+
if (!isNodeNamedDeclaration(declaration.parent) || declaration.parent.name === undefined) {
420+
continue;
421+
}
422+
423+
const parentSymbol = getNodeSymbol(declaration.parent.name);
424+
if (parentSymbol === null) {
425+
continue;
422426
}
423427

424-
symbol = symbol.parent;
428+
if (getSymbolVisibilityType(parentSymbol) === VisibilityType.External) {
429+
return putToCache(nodeSymbol, VisibilityType.External);
430+
}
425431
}
426432

427433
return putToCache(nodeSymbol, VisibilityType.Internal);

0 commit comments

Comments
 (0)