export function getBestComment(nodePath: NodePath): string|undefined { const maybeComment = getAttachedComment(nodePath.node); if (maybeComment !== undefined) { return maybeComment; } const parent = nodePath.parentPath; if (parent === undefined) { return undefined; } if (!isStatementWithUniqueStatementChild(parent.node) && babel.isStatement(nodePath.node)) { // Don't walk up above the nearest statement. return undefined; } if (babel.isVariableDeclaration(parent.node) && parent.node.declarations.length !== 1) { // The parent node is multiple declarations. We can't be sure its // comment applies to us. return undefined; } if (parent.isClassBody() || nodePath.isObjectMember()) { // don't go above an object or class member. return undefined; } return getBestComment(parent); }
export function getCanonicalStatement(nodePath: NodePath): babel.Statement| undefined { const node = nodePath.node; const parent = nodePath.parentPath; if ((parent && !isStatementWithUniqueStatementChild(parent.node)) && babel.isStatement(node)) { return node; } if (parent != null) { return getCanonicalStatement(parent); } return undefined; }