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

Function getTypeReferenceSerializationKind

test/fixtures/snapshot/typescript.js:87064–87137  ·  view source on GitHub ↗
(typeNameIn, location)

Source from the content-addressed store, hash-verified

87062 return !!(type.flags & 524288 /* TypeFlags.Object */) && getSignaturesOfType(type, 0 /* SignatureKind.Call */).length > 0;
87063 }
87064 function getTypeReferenceSerializationKind(typeNameIn, location) {
87065 var _a, _b;
87066 // ensure both `typeName` and `location` are parse tree nodes.
87067 var typeName = ts.getParseTreeNode(typeNameIn, ts.isEntityName);
87068 if (!typeName)
87069 return ts.TypeReferenceSerializationKind.Unknown;
87070 if (location) {
87071 location = ts.getParseTreeNode(location);
87072 if (!location)
87073 return ts.TypeReferenceSerializationKind.Unknown;
87074 }
87075 // Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
87076 var isTypeOnly = false;
87077 if (ts.isQualifiedName(typeName)) {
87078 var rootValueSymbol = resolveEntityName(ts.getFirstIdentifier(typeName), 111551 /* SymbolFlags.Value */, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
87079 isTypeOnly = !!((_a = rootValueSymbol === null || rootValueSymbol === void 0 ? void 0 : rootValueSymbol.declarations) === null || _a === void 0 ? void 0 : _a.every(ts.isTypeOnlyImportOrExportDeclaration));
87080 }
87081 var valueSymbol = resolveEntityName(typeName, 111551 /* SymbolFlags.Value */, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
87082 var resolvedSymbol = valueSymbol && valueSymbol.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(valueSymbol) : valueSymbol;
87083 isTypeOnly || (isTypeOnly = !!((_b = valueSymbol === null || valueSymbol === void 0 ? void 0 : valueSymbol.declarations) === null || _b === void 0 ? void 0 : _b.every(ts.isTypeOnlyImportOrExportDeclaration)));
87084 // Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
87085 var typeSymbol = resolveEntityName(typeName, 788968 /* SymbolFlags.Type */, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
87086 if (resolvedSymbol && resolvedSymbol === typeSymbol) {
87087 var globalPromiseSymbol = getGlobalPromiseConstructorSymbol(/*reportErrors*/ false);
87088 if (globalPromiseSymbol && resolvedSymbol === globalPromiseSymbol) {
87089 return ts.TypeReferenceSerializationKind.Promise;
87090 }
87091 var constructorType = getTypeOfSymbol(resolvedSymbol);
87092 if (constructorType && isConstructorType(constructorType)) {
87093 return isTypeOnly ? ts.TypeReferenceSerializationKind.TypeWithCallSignature : ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
87094 }
87095 }
87096 // We might not be able to resolve type symbol so use unknown type in that case (eg error case)
87097 if (!typeSymbol) {
87098 return isTypeOnly ? ts.TypeReferenceSerializationKind.ObjectType : ts.TypeReferenceSerializationKind.Unknown;
87099 }
87100 var type = getDeclaredTypeOfSymbol(typeSymbol);
87101 if (isErrorType(type)) {
87102 return isTypeOnly ? ts.TypeReferenceSerializationKind.ObjectType : ts.TypeReferenceSerializationKind.Unknown;
87103 }
87104 else if (type.flags & 3 /* TypeFlags.AnyOrUnknown */) {
87105 return ts.TypeReferenceSerializationKind.ObjectType;
87106 }
87107 else if (isTypeAssignableToKind(type, 16384 /* TypeFlags.Void */ | 98304 /* TypeFlags.Nullable */ | 131072 /* TypeFlags.Never */)) {
87108 return ts.TypeReferenceSerializationKind.VoidNullableOrNeverType;
87109 }
87110 else if (isTypeAssignableToKind(type, 528 /* TypeFlags.BooleanLike */)) {
87111 return ts.TypeReferenceSerializationKind.BooleanType;
87112 }
87113 else if (isTypeAssignableToKind(type, 296 /* TypeFlags.NumberLike */)) {
87114 return ts.TypeReferenceSerializationKind.NumberLikeType;
87115 }
87116 else if (isTypeAssignableToKind(type, 2112 /* TypeFlags.BigIntLike */)) {
87117 return ts.TypeReferenceSerializationKind.BigIntLikeType;
87118 }
87119 else if (isTypeAssignableToKind(type, 402653316 /* TypeFlags.StringLike */)) {
87120 return ts.TypeReferenceSerializationKind.StringLikeType;
87121 }

Callers

nothing calls this directly

Calls 12

resolveEntityNameFunction · 0.85
resolveAliasFunction · 0.85
getTypeOfSymbolFunction · 0.85
isConstructorTypeFunction · 0.85
getDeclaredTypeOfSymbolFunction · 0.85
isErrorTypeFunction · 0.85
isTypeAssignableToKindFunction · 0.85
isTupleTypeFunction · 0.85
isFunctionTypeFunction · 0.85
isArrayTypeFunction · 0.85
everyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…