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

Function serializeTypeReferenceNode

test/fixtures/snapshot/typescript.js:92949–92989  ·  view source on GitHub ↗

* Serializes a TypeReferenceNode to an appropriate JS constructor value for use with * decorator type metadata. * * @param node The type reference node.

(node)

Source from the content-addressed store, hash-verified

92947 * @param node The type reference node.
92948 */
92949 function serializeTypeReferenceNode(node) {
92950 var kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope);
92951 switch (kind) {
92952 case ts.TypeReferenceSerializationKind.Unknown:
92953 // From conditional type type reference that cannot be resolved is Similar to any or unknown
92954 if (ts.findAncestor(node, function (n) { return n.parent && ts.isConditionalTypeNode(n.parent) && (n.parent.trueType === n || n.parent.falseType === n); })) {
92955 return factory.createIdentifier("Object");
92956 }
92957 var serialized = serializeEntityNameAsExpressionFallback(node.typeName);
92958 var temp = factory.createTempVariable(hoistVariableDeclaration);
92959 return factory.createConditionalExpression(factory.createTypeCheck(factory.createAssignment(temp, serialized), "function"),
92960 /*questionToken*/ undefined, temp,
92961 /*colonToken*/ undefined, factory.createIdentifier("Object"));
92962 case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
92963 return serializeEntityNameAsExpression(node.typeName);
92964 case ts.TypeReferenceSerializationKind.VoidNullableOrNeverType:
92965 return factory.createVoidZero();
92966 case ts.TypeReferenceSerializationKind.BigIntLikeType:
92967 return getGlobalBigIntNameWithFallback();
92968 case ts.TypeReferenceSerializationKind.BooleanType:
92969 return factory.createIdentifier("Boolean");
92970 case ts.TypeReferenceSerializationKind.NumberLikeType:
92971 return factory.createIdentifier("Number");
92972 case ts.TypeReferenceSerializationKind.StringLikeType:
92973 return factory.createIdentifier("String");
92974 case ts.TypeReferenceSerializationKind.ArrayLikeType:
92975 return factory.createIdentifier("Array");
92976 case ts.TypeReferenceSerializationKind.ESSymbolType:
92977 return languageVersion < 2 /* ScriptTarget.ES2015 */
92978 ? getGlobalSymbolNameWithFallback()
92979 : factory.createIdentifier("Symbol");
92980 case ts.TypeReferenceSerializationKind.TypeWithCallSignature:
92981 return factory.createIdentifier("Function");
92982 case ts.TypeReferenceSerializationKind.Promise:
92983 return factory.createIdentifier("Promise");
92984 case ts.TypeReferenceSerializationKind.ObjectType:
92985 return factory.createIdentifier("Object");
92986 default:
92987 return ts.Debug.assertNever(kind);
92988 }
92989 }
92990 function createCheckedValue(left, right) {
92991 return factory.createLogicalAnd(factory.createStrictInequality(factory.createTypeOfExpression(left), factory.createStringLiteral("undefined")), right);
92992 }

Callers 1

serializeTypeNodeFunction · 0.85

Tested by

no test coverage detected