Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (symbol.flags & ts.SymbolFlags.ExportValue) {
symbol = this._typeChecker.getExportSymbolOfSymbol(symbol);
}
if (symbol.flags & ts.SymbolFlags.Alias) {
symbol = this._typeChecker.getAliasedSymbol(symbol);
}
if (isExternalModuleSymbol(symbol)) {
if (!includeModuleSymbols) {
return undefined;
}
const sourceFile: ts.SourceFile | undefined =
symbol.declarations
&& symbol.declarations[0]
&& symbol.declarations[0].getSourceFile();
return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));
}
// Do not generate a declaration reference for a type parameter.
if (symbol.flags & ts.SymbolFlags.TypeParameter) {
return undefined;
}
const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);
let parentRef: DeclarationReference | undefined;
if (parent) {
parentRef = this._symbolToDeclarationReference(parent, ts.SymbolFlags.Namespace, /*includeModuleSymbols*/ true);
} else {
// this may be a local symbol in a module...
const sourceFile: ts.SourceFile | undefined =
symbol.declarations
&& symbol.declarations[0]
if (symbol.flags & ts.SymbolFlags.TypeParameter) {
return undefined;
}
const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);
let parentRef: DeclarationReference | undefined;
if (parent) {
parentRef = this._symbolToDeclarationReference(parent, ts.SymbolFlags.Namespace, /*includeModuleSymbols*/ true);
} else {
// this may be a local symbol in a module...
const sourceFile: ts.SourceFile | undefined =
symbol.declarations
&& symbol.declarations[0]
&& symbol.declarations[0].getSourceFile();
if (ts.isExternalModule(sourceFile)) {
parentRef = new DeclarationReference(this._sourceFileToModuleSource(sourceFile));
} else {
parentRef = new DeclarationReference(GlobalSource.instance);
}
}
if (parentRef === undefined) {
return undefined;
}
let localName: string = symbol.name;
if (symbol.escapedName === ts.InternalSymbolName.Constructor) {
localName = 'constructor';
} else {
const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(symbol.escapedName);
if (wellKnownName) {
// TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.
}
const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);
let parentRef: DeclarationReference | undefined;
if (parent) {
parentRef = this._symbolToDeclarationReference(parent, ts.SymbolFlags.Namespace, /*includeModuleSymbols*/ true);
} else {
// this may be a local symbol in a module...
const sourceFile: ts.SourceFile | undefined =
symbol.declarations
&& symbol.declarations[0]
&& symbol.declarations[0].getSourceFile();
if (ts.isExternalModule(sourceFile)) {
parentRef = new DeclarationReference(this._sourceFileToModuleSource(sourceFile));
} else {
parentRef = new DeclarationReference(GlobalSource.instance);
}
}
if (parentRef === undefined) {
return undefined;
}
let localName: string = symbol.name;
if (symbol.escapedName === ts.InternalSymbolName.Constructor) {
localName = 'constructor';
} else {
const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(symbol.escapedName);
if (wellKnownName) {
// TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.
// This converts a string like '__@iterator' into the property name '[Symbol.iterator]'.
localName = wellKnownName;
const declName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(decl);
if (declName && ts.isComputedPropertyName(declName)) {
const lateName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declName);
if (lateName !== undefined) {
localName = lateName;
break;
}
}
}
}
}
let navigation: Navigation | 'global' = getNavigationToSymbol(symbol);
if (navigation === 'global') {
if (parentRef.source !== GlobalSource.instance) {
parentRef = new DeclarationReference(GlobalSource.instance);
}
navigation = Navigation.Exports;
}
return parentRef
.addNavigationStep(navigation, localName)
.withMeaning(getMeaningOfSymbol(symbol, meaning));
}