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

Function createClassElementsFromSymbol

test/fixtures/snapshot/typescript.js:151137–151302  ·  view source on GitHub ↗
(symbol)

Source from the content-addressed store, hash-verified

151135 }
151136 }
151137 function createClassElementsFromSymbol(symbol) {
151138 var memberElements = [];
151139 // all static members are stored in the "exports" array of symbol
151140 if (symbol.exports) {
151141 symbol.exports.forEach(function (member) {
151142 if (member.name === "prototype" && member.declarations) {
151143 var firstDeclaration = member.declarations[0];
151144 // only one "x.prototype = { ... }" will pass
151145 if (member.declarations.length === 1 &&
151146 ts.isPropertyAccessExpression(firstDeclaration) &&
151147 ts.isBinaryExpression(firstDeclaration.parent) &&
151148 firstDeclaration.parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ &&
151149 ts.isObjectLiteralExpression(firstDeclaration.parent.right)) {
151150 var prototypes = firstDeclaration.parent.right;
151151 createClassElement(prototypes.symbol, /** modifiers */ undefined, memberElements);
151152 }
151153 }
151154 else {
151155 createClassElement(member, [ts.factory.createToken(124 /* SyntaxKind.StaticKeyword */)], memberElements);
151156 }
151157 });
151158 }
151159 // all instance members are stored in the "member" array of symbol (done last so instance members pulled from prototype assignments have priority)
151160 if (symbol.members) {
151161 symbol.members.forEach(function (member, key) {
151162 var _a, _b, _c, _d;
151163 if (key === "constructor" && member.valueDeclaration) {
151164 var prototypeAssignment = (_d = (_c = (_b = (_a = symbol.exports) === null || _a === void 0 ? void 0 : _a.get("prototype")) === null || _b === void 0 ? void 0 : _b.declarations) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.parent;
151165 if (prototypeAssignment && ts.isBinaryExpression(prototypeAssignment) && ts.isObjectLiteralExpression(prototypeAssignment.right) && ts.some(prototypeAssignment.right.properties, isConstructorAssignment)) {
151166 // fn.prototype = { constructor: fn }
151167 // Already deleted in `createClassElement` in first pass
151168 }
151169 else {
151170 // fn.prototype.constructor = fn
151171 changes.delete(sourceFile, member.valueDeclaration.parent);
151172 }
151173 return;
151174 }
151175 createClassElement(member, /*modifiers*/ undefined, memberElements);
151176 });
151177 }
151178 return memberElements;
151179 function shouldConvertDeclaration(_target, source) {
151180 // Right now the only thing we can convert are function expressions, get/set accessors and methods
151181 // other values like normal value fields ({a: 1}) shouldn't get transformed.
151182 // We can update this once ES public class properties are available.
151183 if (ts.isAccessExpression(_target)) {
151184 if (ts.isPropertyAccessExpression(_target) && isConstructorAssignment(_target))
151185 return true;
151186 return ts.isFunctionLike(source);
151187 }
151188 else {
151189 return ts.every(_target.properties, function (property) {
151190 // a() {}
151191 if (ts.isMethodDeclaration(property) || ts.isGetOrSetAccessorDeclaration(property))
151192 return true;
151193 // a: function() {}
151194 if (ts.isPropertyAssignment(property) && ts.isFunctionExpression(property.initializer) && !!property.name)

Calls 5

createClassElementFunction · 0.85
someMethod · 0.80
forEachMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected