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

Function makeSerializePropertySymbol

test/fixtures/snapshot/typescript.js:55110–55184  ·  view source on GitHub ↗
(createProperty, methodKind, useAccessors)

Source from the content-addressed store, hash-verified

55108 ts.every(getPropertiesOfType(typeToSerialize), function (p) { return ts.isIdentifierText(ts.symbolName(p), languageVersion); });
55109 }
55110 function makeSerializePropertySymbol(createProperty, methodKind, useAccessors) {
55111 return function serializePropertySymbol(p, isStatic, baseType) {
55112 var _a, _b, _c, _d, _e;
55113 var modifierFlags = ts.getDeclarationModifierFlagsFromSymbol(p);
55114 var isPrivate = !!(modifierFlags & 8 /* ModifierFlags.Private */);
55115 if (isStatic && (p.flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */))) {
55116 // Only value-only-meaning symbols can be correctly encoded as class statics, type/namespace/alias meaning symbols
55117 // need to be merged namespace members
55118 return [];
55119 }
55120 if (p.flags & 4194304 /* SymbolFlags.Prototype */ ||
55121 (baseType && getPropertyOfType(baseType, p.escapedName)
55122 && isReadonlySymbol(getPropertyOfType(baseType, p.escapedName)) === isReadonlySymbol(p)
55123 && (p.flags & 16777216 /* SymbolFlags.Optional */) === (getPropertyOfType(baseType, p.escapedName).flags & 16777216 /* SymbolFlags.Optional */)
55124 && isTypeIdenticalTo(getTypeOfSymbol(p), getTypeOfPropertyOfType(baseType, p.escapedName)))) {
55125 return [];
55126 }
55127 var flag = (modifierFlags & ~256 /* ModifierFlags.Async */) | (isStatic ? 32 /* ModifierFlags.Static */ : 0);
55128 var name = getPropertyNameNodeForSymbol(p, context);
55129 var firstPropertyLikeDecl = (_a = p.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.or(ts.isPropertyDeclaration, ts.isAccessor, ts.isVariableDeclaration, ts.isPropertySignature, ts.isBinaryExpression, ts.isPropertyAccessExpression));
55130 if (p.flags & 98304 /* SymbolFlags.Accessor */ && useAccessors) {
55131 var result = [];
55132 if (p.flags & 65536 /* SymbolFlags.SetAccessor */) {
55133 result.push(ts.setTextRange(ts.factory.createSetAccessorDeclaration(
55134 /*decorators*/ undefined, ts.factory.createModifiersFromModifierFlags(flag), name, [ts.factory.createParameterDeclaration(
55135 /*decorators*/ undefined,
55136 /*modifiers*/ undefined,
55137 /*dotDotDotToken*/ undefined, "arg",
55138 /*questionToken*/ undefined, isPrivate ? undefined : serializeTypeForDeclaration(context, getTypeOfSymbol(p), p, enclosingDeclaration, includePrivateSymbol, bundled))],
55139 /*body*/ undefined), ((_b = p.declarations) === null || _b === void 0 ? void 0 : _b.find(ts.isSetAccessor)) || firstPropertyLikeDecl));
55140 }
55141 if (p.flags & 32768 /* SymbolFlags.GetAccessor */) {
55142 var isPrivate_1 = modifierFlags & 8 /* ModifierFlags.Private */;
55143 result.push(ts.setTextRange(ts.factory.createGetAccessorDeclaration(
55144 /*decorators*/ undefined, ts.factory.createModifiersFromModifierFlags(flag), name, [], isPrivate_1 ? undefined : serializeTypeForDeclaration(context, getTypeOfSymbol(p), p, enclosingDeclaration, includePrivateSymbol, bundled),
55145 /*body*/ undefined), ((_c = p.declarations) === null || _c === void 0 ? void 0 : _c.find(ts.isGetAccessor)) || firstPropertyLikeDecl));
55146 }
55147 return result;
55148 }
55149 // This is an else/if as accessors and properties can't merge in TS, but might in JS
55150 // If this happens, we assume the accessor takes priority, as it imposes more constraints
55151 else if (p.flags & (4 /* SymbolFlags.Property */ | 3 /* SymbolFlags.Variable */ | 98304 /* SymbolFlags.Accessor */)) {
55152 return ts.setTextRange(createProperty(
55153 /*decorators*/ undefined, ts.factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 64 /* ModifierFlags.Readonly */ : 0) | flag), name, p.flags & 16777216 /* SymbolFlags.Optional */ ? ts.factory.createToken(57 /* SyntaxKind.QuestionToken */) : undefined, isPrivate ? undefined : serializeTypeForDeclaration(context, getTypeOfSymbol(p), p, enclosingDeclaration, includePrivateSymbol, bundled),
55154 // TODO: https://github.com/microsoft/TypeScript/pull/32372#discussion_r328386357
55155 // interface members can't have initializers, however class members _can_
55156 /*initializer*/ undefined), ((_d = p.declarations) === null || _d === void 0 ? void 0 : _d.find(ts.or(ts.isPropertyDeclaration, ts.isVariableDeclaration))) || firstPropertyLikeDecl);
55157 }
55158 if (p.flags & (8192 /* SymbolFlags.Method */ | 16 /* SymbolFlags.Function */)) {
55159 var type = getTypeOfSymbol(p);
55160 var signatures = getSignaturesOfType(type, 0 /* SignatureKind.Call */);
55161 if (flag & 8 /* ModifierFlags.Private */) {
55162 return ts.setTextRange(createProperty(
55163 /*decorators*/ undefined, ts.factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 64 /* ModifierFlags.Readonly */ : 0) | flag), name, p.flags & 16777216 /* SymbolFlags.Optional */ ? ts.factory.createToken(57 /* SyntaxKind.QuestionToken */) : undefined,
55164 /*type*/ undefined,
55165 /*initializer*/ undefined), ((_e = p.declarations) === null || _e === void 0 ? void 0 : _e.find(ts.isFunctionLikeDeclaration)) || signatures[0] && signatures[0].declaration || p.declarations && p.declarations[0]);
55166 }
55167 var results_1 = [];

Callers 1

Calls 14

getPropertyOfTypeFunction · 0.85
isReadonlySymbolFunction · 0.85
isTypeIdenticalToFunction · 0.85
getTypeOfSymbolFunction · 0.85
getTypeOfPropertyOfTypeFunction · 0.85
createPropertyFunction · 0.85
getSignaturesOfTypeFunction · 0.85
concatMethod · 0.80
findMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…