@@ -6,10 +6,11 @@ import { transformAST as removeExtraneousImport } from './remove-extraneous-impo
6
6
7
7
import type { ObjectExpression } from 'jscodeshift'
8
8
import { getCntFunc } from '../src/report'
9
+ import { pushManualList } from '../src/report'
9
10
10
11
// new Router() -> createRouter()
11
12
export const transformAST : ASTTransformation = context => {
12
- const { root, j } = context
13
+ const { root, j, filename } = context
13
14
const routerImportDecls = root . find ( j . ImportDeclaration , {
14
15
source : {
15
16
value : 'vue-router'
@@ -51,6 +52,50 @@ export const transformAST: ASTTransformation = context => {
51
52
source : 'vue-router'
52
53
} )
53
54
}
55
+
56
+ // filter the node to the manual list
57
+ let ifEnd = false
58
+ newVueRouter . forEach ( ( { node } ) => {
59
+ if (
60
+ node . arguments . length > 0 &&
61
+ ! j . ObjectExpression . check ( node . arguments [ 0 ] )
62
+ ) {
63
+ const path = filename
64
+ const name = 'vue-router new VueRouter'
65
+ const suggest = `Currently, only object expressions passed to \`new VueRouter\` can be transformed.`
66
+ const website =
67
+ 'https://next.router.vuejs.org/guide/migration/index.html#new-router-becomes-createrouter'
68
+ pushManualList ( path , node , name , suggest , website )
69
+ ifEnd = true
70
+ return
71
+ }
72
+ if ( node . arguments . length > 0 ) {
73
+ // @ts -ignore
74
+ const routerConfig : ObjectExpression = node . arguments [ 0 ]
75
+ routerConfig . properties . forEach ( p => {
76
+ if (
77
+ ( j . ObjectProperty . check ( p ) || j . Property . check ( p ) ) &&
78
+ ( p . key as any ) . name === 'mode'
79
+ ) {
80
+ const mode = ( p . value as any ) . value
81
+ if ( mode !== 'hash' && mode !== 'history' && mode !== 'abstract' ) {
82
+ const path = filename
83
+ const name = 'vue-router mode'
84
+ const suggest = `mode must be one of 'hash', 'history', or 'abstract'`
85
+ const website =
86
+ 'https://next.router.vuejs.org/guide/migration/index.html#new-history-option-to-replace-mode'
87
+ pushManualList ( path , p , name , suggest , website )
88
+ ifEnd = true
89
+ return
90
+ }
91
+ }
92
+ } )
93
+ }
94
+ } )
95
+ if ( ifEnd ) {
96
+ return
97
+ }
98
+
54
99
newVueRouter . replaceWith ( ( { node } ) => {
55
100
// mode: 'history' -> history: createWebHistory(), etc
56
101
let historyMode = 'createWebHashHistory'
@@ -67,7 +112,6 @@ export const transformAST: ASTTransformation = context => {
67
112
if ( ! j . ObjectProperty . check ( p ) && ! j . Property . check ( p ) ) {
68
113
return true
69
114
}
70
-
71
115
if ( ( p . key as any ) . name === 'mode' ) {
72
116
const mode = ( p . value as any ) . value
73
117
if ( mode === 'hash' ) {
@@ -109,7 +153,6 @@ export const transformAST: ASTTransformation = context => {
109
153
)
110
154
)
111
155
)
112
-
113
156
return j . callExpression ( j . identifier ( localCreateRouter ) , node . arguments )
114
157
} )
115
158
@@ -130,12 +173,10 @@ export const transformAST: ASTTransformation = context => {
130
173
specifier : { type : 'named' , imported : 'START_LOCATION' } ,
131
174
source : 'vue-router'
132
175
} )
133
-
134
176
startLocationMember . replaceWith ( ( { node } ) => {
135
177
return node . property
136
178
} )
137
179
}
138
-
139
180
removeExtraneousImport ( context , {
140
181
localBinding : localVueRouter
141
182
} )
0 commit comments