MCPcopy Index your code
hub / github.com/nodejs/node / symbolToTypeNode

Function symbolToTypeNode

test/fixtures/snapshot/typescript.js:53596–53734  ·  view source on GitHub ↗
(symbol, context, meaning, overrideTypeArguments)

Source from the content-addressed store, hash-verified

53594 return symbol.parent ? ts.factory.createQualifiedName(symbolToEntityNameNode(symbol.parent), identifier) : identifier;
53595 }
53596 function symbolToTypeNode(symbol, context, meaning, overrideTypeArguments) {
53597 var _a, _b, _c, _d;
53598 var chain = lookupSymbolChain(symbol, context, meaning, !(context.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */)); // If we're using aliases outside the current scope, dont bother with the module
53599 var isTypeOf = meaning === 111551 /* SymbolFlags.Value */;
53600 if (ts.some(chain[0].declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
53601 // module is root, must use `ImportTypeNode`
53602 var nonRootParts = chain.length > 1 ? createAccessFromSymbolChain(chain, chain.length - 1, 1) : undefined;
53603 var typeParameterNodes = overrideTypeArguments || lookupTypeParameterNodes(chain, 0, context);
53604 var contextFile = ts.getSourceFileOfNode(ts.getOriginalNode(context.enclosingDeclaration));
53605 var targetFile = ts.getSourceFileOfModule(chain[0]);
53606 var specifier = void 0;
53607 var assertion = void 0;
53608 if (ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext) {
53609 // An `import` type directed at an esm format file is only going to resolve in esm mode - set the esm mode assertion
53610 if ((targetFile === null || targetFile === void 0 ? void 0 : targetFile.impliedNodeFormat) === ts.ModuleKind.ESNext && targetFile.impliedNodeFormat !== (contextFile === null || contextFile === void 0 ? void 0 : contextFile.impliedNodeFormat)) {
53611 specifier = getSpecifierForModuleSymbol(chain[0], context, ts.ModuleKind.ESNext);
53612 assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([
53613 ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral("import"))
53614 ])));
53615 (_b = (_a = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _b === void 0 ? void 0 : _b.call(_a);
53616 }
53617 }
53618 if (!specifier) {
53619 specifier = getSpecifierForModuleSymbol(chain[0], context);
53620 }
53621 if (!(context.flags & 67108864 /* NodeBuilderFlags.AllowNodeModulesRelativePaths */) && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Classic && specifier.indexOf("/node_modules/") >= 0) {
53622 var oldSpecifier = specifier;
53623 if (ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(compilerOptions) === ts.ModuleResolutionKind.NodeNext) {
53624 // We might be able to write a portable import type using a mode override; try specifier generation again, but with a different mode set
53625 var swappedMode = (contextFile === null || contextFile === void 0 ? void 0 : contextFile.impliedNodeFormat) === ts.ModuleKind.ESNext ? ts.ModuleKind.CommonJS : ts.ModuleKind.ESNext;
53626 specifier = getSpecifierForModuleSymbol(chain[0], context, swappedMode);
53627 if (specifier.indexOf("/node_modules/") >= 0) {
53628 // Still unreachable :(
53629 specifier = oldSpecifier;
53630 }
53631 else {
53632 assertion = ts.factory.createImportTypeAssertionContainer(ts.factory.createAssertClause(ts.factory.createNodeArray([
53633 ts.factory.createAssertEntry(ts.factory.createStringLiteral("resolution-mode"), ts.factory.createStringLiteral(swappedMode === ts.ModuleKind.ESNext ? "import" : "require"))
53634 ])));
53635 (_d = (_c = context.tracker).reportImportTypeNodeResolutionModeOverride) === null || _d === void 0 ? void 0 : _d.call(_c);
53636 }
53637 }
53638 if (!assertion) {
53639 // If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error
53640 // since declaration files with these kinds of references are liable to fail when published :(
53641 context.encounteredError = true;
53642 if (context.tracker.reportLikelyUnsafeImportRequiredError) {
53643 context.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier);
53644 }
53645 }
53646 }
53647 var lit = ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(specifier));
53648 if (context.tracker.trackExternalModuleSymbolOfImportTypeNode)
53649 context.tracker.trackExternalModuleSymbolOfImportTypeNode(chain[0]);
53650 context.approximateLength += specifier.length + 10; // specifier + import("")
53651 if (!nonRootParts || ts.isEntityName(nonRootParts)) {
53652 if (nonRootParts) {
53653 var lastId = ts.isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right;

Callers 3

typeToTypeNodeHelperFunction · 0.85
createAnonymousTypeNodeFunction · 0.85
typeReferenceToTypeNodeFunction · 0.85

Calls 8

lookupSymbolChainFunction · 0.85
lookupTypeParameterNodesFunction · 0.85
someMethod · 0.80
callMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…