@@ -7,13 +7,21 @@ module.exports = function createAppMount(context) {
7
7
const { j, root } = context
8
8
9
9
// new Vue(...).$mount()
10
- const mountCalls = root . find ( j . CallExpression , n => {
11
- return (
12
- n . callee . type === 'MemberExpression' &&
13
- n . callee . property . name === '$mount' &&
14
- n . callee . object . type === 'NewExpression' &&
15
- n . callee . object . callee . name === 'Vue'
16
- )
10
+ const mountCalls = root . find ( j . ExpressionStatement , {
11
+ expression : {
12
+ type : 'CallExpression' ,
13
+ callee : {
14
+ type : 'MemberExpression' ,
15
+ object : {
16
+ type : 'NewExpression' ,
17
+ callee : {
18
+ type : 'Identifier' ,
19
+ name : 'Vue'
20
+ }
21
+ } ,
22
+ property : { type : 'Identifier' , name : '$mount' }
23
+ }
24
+ }
17
25
} )
18
26
19
27
if ( ! mountCalls . length ) {
@@ -23,16 +31,26 @@ module.exports = function createAppMount(context) {
23
31
const addImport = require ( '../utils/add-import' )
24
32
addImport ( context , { imported : 'createApp' } , 'vue' )
25
33
26
- mountCalls . replaceWith ( ( { node } ) => {
27
- let rootProps = node . callee . object . arguments [ 0 ]
28
- const el = node . arguments [ 0 ]
34
+ const rootProps = mountCalls . at ( 0 ) . get ( ) . node . expression . callee . object
35
+ . arguments
36
+ mountCalls . insertBefore (
37
+ j . variableDeclaration ( 'const' , [
38
+ j . variableDeclarator (
39
+ j . identifier ( 'app' ) ,
40
+ j . callExpression ( j . identifier ( 'createApp' ) , rootProps )
41
+ )
42
+ ] )
43
+ )
29
44
30
- return j . callExpression (
31
- j . memberExpression (
32
- j . callExpression ( j . identifier ( 'createApp' ) , [ rootProps ] ) ,
33
- j . identifier ( 'mount' )
34
- ) ,
35
- [ el ]
45
+ const args = mountCalls . at ( 0 ) . get ( ) . node . expression . arguments
46
+ mountCalls . insertBefore (
47
+ j . expressionStatement (
48
+ j . callExpression (
49
+ j . memberExpression ( j . identifier ( 'app' ) , j . identifier ( 'mount' ) , false ) ,
50
+ args
51
+ )
36
52
)
37
- } )
53
+ )
54
+
55
+ mountCalls . remove ( )
38
56
}
0 commit comments