Skip to content

Instantly share code, notes, and snippets.

@Timebutt
Last active May 23, 2019 07:27
Show Gist options
  • Save Timebutt/9ddf4b28b8ec986ab8cab7e79713ddf9 to your computer and use it in GitHub Desktop.
Save Timebutt/9ddf4b28b8ec986ab8cab7e79713ddf9 to your computer and use it in GitHub Desktop.
/**
* This codemod refactors calls like combineLatest(stream1$, stream2$, ...) to combineLatest([stream1$, stream2$, ...]) as
* the first call signature was deprecated in rxjs 6.5 (see the reason here: https://github.com/reactivex/rxjs/commit/6661c79).
* I run this with jscodeshift (for Typescript files): jscodeshift -t combineLatest.js PATH --parser ts --extensions=ts
*/
module.exports = function(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const calls = root
.find(j.CallExpression, {
callee: {
name: 'combineLatest'
}
})
.filter(
p =>
p.value.arguments.length > 1 ||
(p.value.arguments[0].type !== 'ArrayExpression' && p.value.arguments[0].type !== 'SpreadElement')
);
calls.forEach(p => {
p.value.arguments = [j.arrayExpression([...p.value.arguments])];
});
console.log(`Transformed ${calls.length} instances of combineLatest()`);
return root.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment