-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathremove-vue-use.ts
58 lines (51 loc) · 1.56 KB
/
remove-vue-use.ts
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
57
58
/**
* Remove `Vue.use()` calls
* Per current design, `Vue.use` is replaced by `app.use`.
* But in library implementations like `vue-router` and `vuex`,
* the new `app.use` does not reuse the same argument passed to `Vue.use()`,
* but expects instantiated instances that are used to pass to the root components instead.
* So we now expect the migration to be done in the `root-prop-to-use` transformation,
* and the `Vue.use` statements can be just abandoned.
*/
import wrap from '../src/wrapAstTransformation'
import type { ASTTransformation } from '../src/wrapAstTransformation'
import { transformAST as removeExtraneousImport } from './remove-extraneous-import'
type Params = {
removablePlugins: string[]
}
export const transformAST: ASTTransformation<Params> = (
context,
{ removablePlugins }
) => {
const { j, root } = context
const vueUseCalls = root.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
object: {
name: 'Vue',
},
property: {
name: 'use',
},
},
})
const removedPlugins: string[] = []
const removableUseCalls = vueUseCalls.filter(({ node }) => {
if (j.Identifier.check(node.arguments[0])) {
const plugin = node.arguments[0].name
if (removablePlugins.includes(plugin)) {
removedPlugins.push(plugin)
return true
}
}
return false
})
removableUseCalls.remove()
removedPlugins.forEach((name) =>
removeExtraneousImport(context, {
localBinding: name,
})
)
}
export default wrap(transformAST)
export const parser = 'babylon'