MCPcopy Create free account
hub / github.com/nodejs/node / tryMergeEs5Class

Function tryMergeEs5Class

test/fixtures/snapshot/typescript.js:141175–141251  ·  view source on GitHub ↗
(a, b, bIndex, parent)

Source from the content-addressed store, hash-verified

141173 _a[4 /* AssignmentDeclarationKind.ThisProperty */] = false,
141174 _a);
141175 function tryMergeEs5Class(a, b, bIndex, parent) {
141176 function isPossibleConstructor(node) {
141177 return ts.isFunctionExpression(node) || ts.isFunctionDeclaration(node) || ts.isVariableDeclaration(node);
141178 }
141179 var bAssignmentDeclarationKind = ts.isBinaryExpression(b.node) || ts.isCallExpression(b.node) ?
141180 ts.getAssignmentDeclarationKind(b.node) :
141181 0 /* AssignmentDeclarationKind.None */;
141182 var aAssignmentDeclarationKind = ts.isBinaryExpression(a.node) || ts.isCallExpression(a.node) ?
141183 ts.getAssignmentDeclarationKind(a.node) :
141184 0 /* AssignmentDeclarationKind.None */;
141185 // We treat this as an es5 class and merge the nodes in in one of several cases
141186 if ((isEs5ClassMember[bAssignmentDeclarationKind] && isEs5ClassMember[aAssignmentDeclarationKind]) // merge two class elements
141187 || (isPossibleConstructor(a.node) && isEs5ClassMember[bAssignmentDeclarationKind]) // ctor function & member
141188 || (isPossibleConstructor(b.node) && isEs5ClassMember[aAssignmentDeclarationKind]) // member & ctor function
141189 || (ts.isClassDeclaration(a.node) && isSynthesized(a.node) && isEs5ClassMember[bAssignmentDeclarationKind]) // class (generated) & member
141190 || (ts.isClassDeclaration(b.node) && isEs5ClassMember[aAssignmentDeclarationKind]) // member & class (generated)
141191 || (ts.isClassDeclaration(a.node) && isSynthesized(a.node) && isPossibleConstructor(b.node)) // class (generated) & ctor
141192 || (ts.isClassDeclaration(b.node) && isPossibleConstructor(a.node) && isSynthesized(a.node)) // ctor & class (generated)
141193 ) {
141194 var lastANode = a.additionalNodes && ts.lastOrUndefined(a.additionalNodes) || a.node;
141195 if ((!ts.isClassDeclaration(a.node) && !ts.isClassDeclaration(b.node)) // If neither outline node is a class
141196 || isPossibleConstructor(a.node) || isPossibleConstructor(b.node) // If either function is a constructor function
141197 ) {
141198 var ctorFunction = isPossibleConstructor(a.node) ? a.node :
141199 isPossibleConstructor(b.node) ? b.node :
141200 undefined;
141201 if (ctorFunction !== undefined) {
141202 var ctorNode = ts.setTextRange(ts.factory.createConstructorDeclaration(/* decorators */ undefined, /* modifiers */ undefined, [], /* body */ undefined), ctorFunction);
141203 var ctor = emptyNavigationBarNode(ctorNode);
141204 ctor.indent = a.indent + 1;
141205 ctor.children = a.node === ctorFunction ? a.children : b.children;
141206 a.children = a.node === ctorFunction ? ts.concatenate([ctor], b.children || [b]) : ts.concatenate(a.children || [__assign({}, a)], [ctor]);
141207 }
141208 else {
141209 if (a.children || b.children) {
141210 a.children = ts.concatenate(a.children || [__assign({}, a)], b.children || [b]);
141211 if (a.children) {
141212 mergeChildren(a.children, a);
141213 sortChildren(a.children);
141214 }
141215 }
141216 }
141217 lastANode = a.node = ts.setTextRange(ts.factory.createClassDeclaration(
141218 /* decorators */ undefined,
141219 /* modifiers */ undefined, a.name || ts.factory.createIdentifier("__class__"),
141220 /* typeParameters */ undefined,
141221 /* heritageClauses */ undefined, []), a.node);
141222 }
141223 else {
141224 a.children = ts.concatenate(a.children, b.children);
141225 if (a.children) {
141226 mergeChildren(a.children, a);
141227 }
141228 }
141229 var bNode = b.node;
141230 // We merge if the outline node previous to b (bIndex - 1) is already part of the current class
141231 // We do this so that statements between class members that do not generate outline nodes do not split up the class outline:
141232 // Ex This should produce one outline node C:

Callers 1

tryMergeFunction · 0.85

Calls 6

isPossibleConstructorFunction · 0.85
isSynthesizedFunction · 0.85
emptyNavigationBarNodeFunction · 0.85
mergeChildrenFunction · 0.85
sortChildrenFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected