UNPKG

754 BJavaScriptView Raw
1module.exports = (file, api) => {
2 const j = api.jscodeshift
3 const root = j(file.source)
4
5 const appRoots = root.find(j.CallExpression, (node) => {
6 if (j.Identifier.check(node.callee) && node.callee.name === 'createApp') {
7 return true
8 }
9
10 if (
11 j.MemberExpression.check(node.callee) &&
12 j.Identifier.check(node.callee.object) &&
13 node.callee.object.name === 'Vue' &&
14 j.Identifier.check(node.callee.property) &&
15 node.callee.property.name === 'createApp'
16 ) {
17 return true
18 }
19 })
20
21 appRoots.replaceWith(({ node: createAppCall }) => {
22 return j.callExpression(
23 j.memberExpression(createAppCall, j.identifier('use')),
24 [j.identifier('router')]
25 )
26 })
27
28 return root.toSource()
29}