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

Function createAnonymousTypeNode

test/fixtures/snapshot/typescript.js:52713–52765  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

52711 return result;
52712 }
52713 function createAnonymousTypeNode(type) {
52714 var _a;
52715 var typeId = type.id;
52716 var symbol = type.symbol;
52717 if (symbol) {
52718 var isInstanceType = isClassInstanceSide(type) ? 788968 /* SymbolFlags.Type */ : 111551 /* SymbolFlags.Value */;
52719 if (isJSConstructor(symbol.valueDeclaration)) {
52720 // Instance and static types share the same symbol; only add 'typeof' for the static side.
52721 return symbolToTypeNode(symbol, context, isInstanceType);
52722 }
52723 // Always use 'typeof T' for type of class, enum, and module objects
52724 else if (symbol.flags & 32 /* SymbolFlags.Class */
52725 && !getBaseTypeVariableOfClass(symbol)
52726 && !(symbol.valueDeclaration && symbol.valueDeclaration.kind === 226 /* SyntaxKind.ClassExpression */ && context.flags & 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */) ||
52727 symbol.flags & (384 /* SymbolFlags.Enum */ | 512 /* SymbolFlags.ValueModule */) ||
52728 shouldWriteTypeOfFunctionSymbol()) {
52729 return symbolToTypeNode(symbol, context, isInstanceType);
52730 }
52731 else if ((_a = context.visitedTypes) === null || _a === void 0 ? void 0 : _a.has(typeId)) {
52732 // If type is an anonymous type literal in a type alias declaration, use type alias name
52733 var typeAlias = getTypeAliasForTypeLiteral(type);
52734 if (typeAlias) {
52735 // The specified symbol flags need to be reinterpreted as type flags
52736 return symbolToTypeNode(typeAlias, context, 788968 /* SymbolFlags.Type */);
52737 }
52738 else {
52739 return createElidedInformationPlaceholder(context);
52740 }
52741 }
52742 else {
52743 return visitAndTransformType(type, createTypeNodeFromObjectType);
52744 }
52745 }
52746 else {
52747 // Anonymous types without a symbol are never circular.
52748 return createTypeNodeFromObjectType(type);
52749 }
52750 function shouldWriteTypeOfFunctionSymbol() {
52751 var _a;
52752 var isStaticMethodSymbol = !!(symbol.flags & 8192 /* SymbolFlags.Method */) && // typeof static method
52753 ts.some(symbol.declarations, function (declaration) { return ts.isStatic(declaration); });
52754 var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* SymbolFlags.Function */) &&
52755 (symbol.parent || // is exported function symbol
52756 ts.forEach(symbol.declarations, function (declaration) {
52757 return declaration.parent.kind === 305 /* SyntaxKind.SourceFile */ || declaration.parent.kind === 262 /* SyntaxKind.ModuleBlock */;
52758 }));
52759 if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
52760 // typeof is allowed only for static/non local functions
52761 return (!!(context.flags & 4096 /* NodeBuilderFlags.UseTypeOfFunction */) || ((_a = context.visitedTypes) === null || _a === void 0 ? void 0 : _a.has(typeId))) && // it is type of the symbol uses itself recursively
52762 (!(context.flags & 8 /* NodeBuilderFlags.UseStructuralFallback */) || isValueSymbolAccessible(symbol, context.enclosingDeclaration)); // And the build is going to succeed without visibility error or there is no structural fallback allowed
52763 }
52764 }
52765 }
52766 function visitAndTransformType(type, transform) {
52767 var _a, _b;
52768 var typeId = type.id;

Callers 2

typeToTypeNodeHelperFunction · 0.85
typeReferenceToTypeNodeFunction · 0.85

Calls 10

isClassInstanceSideFunction · 0.85
isJSConstructorFunction · 0.85
symbolToTypeNodeFunction · 0.85
visitAndTransformTypeFunction · 0.85
hasMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…