forked from vuejs/vue-cli-plugin-vue-next
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-app-mount.js
56 lines (50 loc) · 1.33 KB
/
create-app-mount.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @param {Object} context
* @param {import('jscodeshift').JSCodeshift} context.j
* @param {ReturnType<import('jscodeshift').Core>} context.root
*/
module.exports = function createAppMount(context) {
const { j, root } = context
// new Vue(...).$mount()
const mountCalls = root.find(j.ExpressionStatement, {
expression: {
type: 'CallExpression',
callee: {
type: 'MemberExpression',
object: {
type: 'NewExpression',
callee: {
type: 'Identifier',
name: 'Vue'
}
},
property: { type: 'Identifier', name: '$mount' }
}
}
})
if (!mountCalls.length) {
return
}
const addImport = require('../utils/add-import')
addImport(context, { imported: 'createApp' }, 'vue')
const rootProps = mountCalls.at(0).get().node.expression.callee.object
.arguments
mountCalls.insertBefore(
j.variableDeclaration('const', [
j.variableDeclarator(
j.identifier('app'),
j.callExpression(j.identifier('createApp'), rootProps)
)
])
)
const args = mountCalls.at(0).get().node.expression.arguments
mountCalls.insertBefore(
j.expressionStatement(
j.callExpression(
j.memberExpression(j.identifier('app'), j.identifier('mount'), false),
args
)
)
)
mountCalls.remove()
}