@expressjs/codemod
Version:
Codemods for updating express servers.
19 lines (18 loc) • 775 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.recursiveParent = void 0;
const defaultParentExpressionType = ['ArrowFunctionExpression', 'FunctionExpression'];
const recursiveParent = (parent, paramIndex = 0, parentExpressionType = defaultParentExpressionType) => {
if (parentExpressionType.some((type) => parent.value?.type === type)) {
const foundNode = parent.value;
if (foundNode.params[paramIndex]?.type === 'Identifier') {
return foundNode.params[paramIndex].name;
}
return null;
}
if (parent?.parentPath) {
return (0, exports.recursiveParent)(parent.parentPath, paramIndex, parentExpressionType);
}
return null;
};
exports.recursiveParent = recursiveParent;