Last active
May 23, 2019 07:27
-
-
Save Timebutt/9ddf4b28b8ec986ab8cab7e79713ddf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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