Skip to content

Commit acaaaac

Browse files
author
Adolph-WSY
authored
fix: bus usage changes new Vue() to createapp (#65)
1 parent d9e3ff6 commit acaaaac

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

transformations/__tests__/new-vue-to-create-app.spec.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ defineInlineTest(
99
'transform `new Vue()` to createApp()'
1010
)
1111

12-
defineInlineTest(
13-
transform,
14-
{},
15-
`new Vue()`,
16-
`Vue.createApp()`,
17-
'transform `new Vue()` to createApp() with no arguments'
18-
)
12+
// Vue.prototype.$baseEventBus = new Vue() will be transform to Vue.prototype.$baseEventBus = new createApp()
13+
// defineInlineTest(
14+
// transform,
15+
// {},
16+
// `new Vue()`,
17+
// `Vue.createApp()`,
18+
// 'transform `new Vue()` to createApp() with no arguments'
19+
// )
1920

2021
defineInlineTest(
2122
transform,
@@ -83,3 +84,11 @@ defineInlineTest(
8384
'transform `new MyComponent` with `el` prop'
8485
)
8586

87+
defineInlineTest(
88+
transform,
89+
{},
90+
`Vue.prototype.$baseEventBus = new Vue()`,
91+
`Vue.prototype.$baseEventBus = new Vue()`,
92+
'mitt and tiny-emitter are recommended in vue-next'
93+
)
94+

transformations/new-vue-to-create-app.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ export const transformAST: ASTTransformation<Params | void> = (
2222
const { j, root } = context
2323
const { includeMaybeComponents = true } = params
2424

25-
const newVue = root.find(j.NewExpression, {
26-
callee: {
27-
type: 'Identifier',
28-
name: 'Vue'
29-
}
30-
})
25+
const newVue = root
26+
.find(j.NewExpression, {
27+
callee: {
28+
type: 'Identifier',
29+
name: 'Vue'
30+
}
31+
})
32+
.filter(({ node }) => {
33+
return node.arguments.length > 0
34+
})
3135

3236
// new Vue() -> Vue.createApp()
3337
newVue.replaceWith(({ node }) => {

transformations/router/router-update-addRoute.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { ASTTransformation } from '../../src/wrapAstTransformation'
33

44
// addRoute() addRoutes()-> forEach addRoute
55
export const transformAST: ASTTransformation = context => {
6-
76
const { root, j } = context
87
const addRouteExpression = root.find(j.CallExpression, {
98
callee: {

0 commit comments

Comments
 (0)