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

Function serializeAsClass

test/fixtures/snapshot/typescript.js:54765–54825  ·  view source on GitHub ↗
(symbol, localName, modifierFlags)

Source from the content-addressed store, hash-verified

54763 return undefined;
54764 }
54765 function serializeAsClass(symbol, localName, modifierFlags) {
54766 var _a, _b;
54767 var originalDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isClassLike);
54768 var oldEnclosing = context.enclosingDeclaration;
54769 context.enclosingDeclaration = originalDecl || oldEnclosing;
54770 var localParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
54771 var typeParamDecls = ts.map(localParams, function (p) { return typeParameterToDeclaration(p, context); });
54772 var classType = getDeclaredTypeOfClassOrInterface(symbol);
54773 var baseTypes = getBaseTypes(classType);
54774 var originalImplements = originalDecl && ts.getEffectiveImplementsTypeNodes(originalDecl);
54775 var implementsExpressions = originalImplements && sanitizeJSDocImplements(originalImplements)
54776 || ts.mapDefined(getImplementsTypes(classType), serializeImplementedType);
54777 var staticType = getTypeOfSymbol(symbol);
54778 var isClass = !!((_b = staticType.symbol) === null || _b === void 0 ? void 0 : _b.valueDeclaration) && ts.isClassLike(staticType.symbol.valueDeclaration);
54779 var staticBaseType = isClass
54780 ? getBaseConstructorTypeOfClass(staticType)
54781 : anyType;
54782 var heritageClauses = __spreadArray(__spreadArray([], !ts.length(baseTypes) ? [] : [ts.factory.createHeritageClause(94 /* SyntaxKind.ExtendsKeyword */, ts.map(baseTypes, function (b) { return serializeBaseType(b, staticBaseType, localName); }))], true), !ts.length(implementsExpressions) ? [] : [ts.factory.createHeritageClause(117 /* SyntaxKind.ImplementsKeyword */, implementsExpressions)], true);
54783 var symbolProps = getNonInterhitedProperties(classType, baseTypes, getPropertiesOfType(classType));
54784 var publicSymbolProps = ts.filter(symbolProps, function (s) {
54785 // `valueDeclaration` could be undefined if inherited from
54786 // a union/intersection base type, but inherited properties
54787 // don't matter here.
54788 var valueDecl = s.valueDeclaration;
54789 return !!valueDecl && !(ts.isNamedDeclaration(valueDecl) && ts.isPrivateIdentifier(valueDecl.name));
54790 });
54791 var hasPrivateIdentifier = ts.some(symbolProps, function (s) {
54792 // `valueDeclaration` could be undefined if inherited from
54793 // a union/intersection base type, but inherited properties
54794 // don't matter here.
54795 var valueDecl = s.valueDeclaration;
54796 return !!valueDecl && ts.isNamedDeclaration(valueDecl) && ts.isPrivateIdentifier(valueDecl.name);
54797 });
54798 // Boil down all private properties into a single one.
54799 var privateProperties = hasPrivateIdentifier ?
54800 [ts.factory.createPropertyDeclaration(
54801 /*decorators*/ undefined,
54802 /*modifiers*/ undefined, ts.factory.createPrivateIdentifier("#private"),
54803 /*questionOrExclamationToken*/ undefined,
54804 /*type*/ undefined,
54805 /*initializer*/ undefined)] :
54806 ts.emptyArray;
54807 var publicProperties = ts.flatMap(publicSymbolProps, function (p) { return serializePropertySymbolForClass(p, /*isStatic*/ false, baseTypes[0]); });
54808 // Consider static members empty if symbol also has function or module meaning - function namespacey emit will handle statics
54809 var staticMembers = ts.flatMap(ts.filter(getPropertiesOfType(staticType), function (p) { return !(p.flags & 4194304 /* SymbolFlags.Prototype */) && p.escapedName !== "prototype" && !isNamespaceMember(p); }), function (p) { return serializePropertySymbolForClass(p, /*isStatic*/ true, staticBaseType); });
54810 // When we encounter an `X.prototype.y` assignment in a JS file, we bind `X` as a class regardless as to whether
54811 // the value is ever initialized with a class or function-like value. For cases where `X` could never be
54812 // created via `new`, we will inject a `private constructor()` declaration to indicate it is not createable.
54813 var isNonConstructableClassLikeInJsFile = !isClass &&
54814 !!symbol.valueDeclaration &&
54815 ts.isInJSFile(symbol.valueDeclaration) &&
54816 !ts.some(getSignaturesOfType(staticType, 1 /* SignatureKind.Construct */));
54817 var constructors = isNonConstructableClassLikeInJsFile ?
54818 [ts.factory.createConstructorDeclaration(/*decorators*/ undefined, ts.factory.createModifiersFromModifierFlags(8 /* ModifierFlags.Private */), [], /*body*/ undefined)] :
54819 serializeSignatures(1 /* SignatureKind.Construct */, staticType, staticBaseType, 171 /* SyntaxKind.Constructor */);
54820 var indexSignatures = serializeIndexSignatures(classType, baseTypes[0]);
54821 context.enclosingDeclaration = oldEnclosing;
54822 addResult(ts.setTextRange(ts.factory.createClassDeclaration(

Callers 1

serializeSymbolWorkerFunction · 0.85

Calls 15

getBaseTypesFunction · 0.85
sanitizeJSDocImplementsFunction · 0.85
getImplementsTypesFunction · 0.85
getTypeOfSymbolFunction · 0.85
serializeBaseTypeFunction · 0.85
getPropertiesOfTypeFunction · 0.85
isNamespaceMemberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…