* Gets a human-readable name for a symbol. * Should *not* be used for the right-hand side of a `.` -- use `symbolName(symbol)` for that instead. * * Unlike `symbolName(symbol)`, this will include quotes if the name is from a string literal. * It will also use a re
(symbol, context)
| 55429 | * It will also use a representation of a number as written instead of a decimal form, e.g. `0o11` instead of `9`. |
| 55430 | */ |
| 55431 | function getNameOfSymbolAsWritten(symbol, context) { |
| 55432 | if (context && symbol.escapedName === "default" /* InternalSymbolName.Default */ && !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */) && |
| 55433 | // If it's not the first part of an entity name, it must print as `default` |
| 55434 | (!(context.flags & 16777216 /* NodeBuilderFlags.InInitialEntityName */) || |
| 55435 | // if the symbol is synthesized, it will only be referenced externally it must print as `default` |
| 55436 | !symbol.declarations || |
| 55437 | // if not in the same binding context (source file, module declaration), it must print as `default` |
| 55438 | (context.enclosingDeclaration && ts.findAncestor(symbol.declarations[0], isDefaultBindingContext) !== ts.findAncestor(context.enclosingDeclaration, isDefaultBindingContext)))) { |
| 55439 | return "default"; |
| 55440 | } |
| 55441 | if (symbol.declarations && symbol.declarations.length) { |
| 55442 | var declaration = ts.firstDefined(symbol.declarations, function (d) { return ts.getNameOfDeclaration(d) ? d : undefined; }); // Try using a declaration with a name, first |
| 55443 | var name_4 = declaration && ts.getNameOfDeclaration(declaration); |
| 55444 | if (declaration && name_4) { |
| 55445 | if (ts.isCallExpression(declaration) && ts.isBindableObjectDefinePropertyCall(declaration)) { |
| 55446 | return ts.symbolName(symbol); |
| 55447 | } |
| 55448 | if (ts.isComputedPropertyName(name_4) && !(ts.getCheckFlags(symbol) & 4096 /* CheckFlags.Late */)) { |
| 55449 | var nameType = getSymbolLinks(symbol).nameType; |
| 55450 | if (nameType && nameType.flags & 384 /* TypeFlags.StringOrNumberLiteral */) { |
| 55451 | // Computed property name isn't late bound, but has a well-known name type - use name type to generate a symbol name |
| 55452 | var result = getNameOfSymbolFromNameType(symbol, context); |
| 55453 | if (result !== undefined) { |
| 55454 | return result; |
| 55455 | } |
| 55456 | } |
| 55457 | } |
| 55458 | return ts.declarationNameToString(name_4); |
| 55459 | } |
| 55460 | if (!declaration) { |
| 55461 | declaration = symbol.declarations[0]; // Declaration may be nameless, but we'll try anyway |
| 55462 | } |
| 55463 | if (declaration.parent && declaration.parent.kind === 254 /* SyntaxKind.VariableDeclaration */) { |
| 55464 | return ts.declarationNameToString(declaration.parent.name); |
| 55465 | } |
| 55466 | switch (declaration.kind) { |
| 55467 | case 226 /* SyntaxKind.ClassExpression */: |
| 55468 | case 213 /* SyntaxKind.FunctionExpression */: |
| 55469 | case 214 /* SyntaxKind.ArrowFunction */: |
| 55470 | if (context && !context.encounteredError && !(context.flags & 131072 /* NodeBuilderFlags.AllowAnonymousIdentifier */)) { |
| 55471 | context.encounteredError = true; |
| 55472 | } |
| 55473 | return declaration.kind === 226 /* SyntaxKind.ClassExpression */ ? "(Anonymous class)" : "(Anonymous function)"; |
| 55474 | } |
| 55475 | } |
| 55476 | var name = getNameOfSymbolFromNameType(symbol, context); |
| 55477 | return name !== undefined ? name : ts.symbolName(symbol); |
| 55478 | } |
| 55479 | function isDeclarationVisible(node) { |
| 55480 | if (node) { |
| 55481 | var links = getNodeLinks(node); |
no test coverage detected