Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
harsilspatel committed Jul 2, 2021
2 parents d7434e6 + ea8274f commit e181d0c
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ export default function transformer(file, { jscodeshift: j }) {
wfFns
.find(j.CallExpression)
.filter(hasCallback)
.replaceWith(awaitFn({ tryCatch: true }));
.forEach(awaitFn({ tryCatch: true }));
wfFns.find(j.FunctionExpression).filter(filterImmediateFns).replaceWith(removeWrapperFn);
wfFns.find(j.ArrowFunctionExpression).filter(filterImmediateFns).replaceWith(removeWrapperFn);
j(wf)
// convert async.waterfall's 2nd argument to await
.replaceWith(awaitFn({ tryCatch: false }))
.forEach(awaitFn({ tryCatch: false }))
.replaceWith((p) => {
console.log("pppppppppppp", p.parent.node);
// remove async.waterfall wrapper
return null;
const wfBody = p.node.block.body;
const wfBody = p.node.arguments;
const asyncWaterfallFns = wfBody.shift();

// if it's an assignment then we get nodes from `asyncWaterfallFns.expression.right` if not it will be variable declaration
const fns = (asyncWaterfallFns.expression ? asyncWaterfallFns.expression.right : asyncWaterfallFns.declarations[0].init).argument.arguments[0].elements;
return createBlockStatement(fns.concat(wfBody));
const fns = asyncWaterfallFns.elements || (asyncWaterfallFns.expression ? asyncWaterfallFns.expression.right : asyncWaterfallFns.declarations[0].init).argument.arguments[0].elements;
const x = createBlockStatement(fns.concat(wfBody));
return x
});

// remove the async.waterfall() contents from block statement
Expand Down Expand Up @@ -144,14 +143,9 @@ function getFns(j) {
// when tryContents is false, ideally we should be returning tryContents.body but
// there is no way to do it so attaching it to parent fn's body
if (tryCatch && hasCatchClause) {
return tryStatement;
// CHECKPOINT ===============================================================================================================================================
// look into declaring variables outside try-catch blocks
const x = createBlockStatement([tryStatement]);
const x = createBlockStatement([j.variableDeclaration("let", [j.variableDeclarator(variableDeclaratorId)]), tryStatement]);
removeWrappingParenthesis(p, x.body);
console.log("after shit");
} else {
console.log("tryContents.body", tryContents);
removeWrappingParenthesis(p, tryContents.body);
}
};
Expand Down Expand Up @@ -216,6 +210,10 @@ function getFns(j) {
};
}

function c () {
console.log
}

/*
TODO handle async.waterfall() scenarios like:
function completed(err, project, attendant) {
Expand Down

0 comments on commit e181d0c

Please sign in to comment.