-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
35 lines (29 loc) · 925 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { getParser } = require('codemod-cli').jscodeshift;
const { getOptions } = require('codemod-cli');
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
root
.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: { type: "FunctionExpression" },
property: { name: "computed" }
}
})
//.forEach(p => console.log(p))
.replaceWith(path => {
let computedImport = j.importDeclaration(
[j.importSpecifier(j.identifier("computed"))],
j.literal("@ember/object")
);
let body = root.get().value.program.body;
body.unshift(computedImport);
return j.callExpression(
j.identifier("computed"),
path.value.arguments.concat(path.value.callee.object)
);
});
return root.toSource({quote: 'single'});
}