Skip to content

Commit 3a93301

Browse files
authored
feat: START_LOCATION change to import (#62)
1 parent 0f85300 commit 3a93301

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

transformations/__testfixtures__/vue-router-v4/create-router.input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ new VueRouter({
2424
fallback: false
2525
});
2626

27+
router.beforeEach((to,from, next) => {
28+
if(from === VueRouter.START_LOCATION){
29+
next('/motomo');
30+
}
31+
});
32+
2733
export default router;

transformations/__testfixtures__/vue-router-v4/create-router.output.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRouter, createWebHashHistory } from 'vue-router';
1+
import { createRouter, createWebHashHistory, START_LOCATION } from 'vue-router';
22
import Home from '../views/Home.vue';
33

44
const routes = [
@@ -24,4 +24,10 @@ createRouter({
2424
routes
2525
});
2626

27+
router.beforeEach((to,from, next) => {
28+
if(from === START_LOCATION){
29+
next('/motomo');
30+
}
31+
});
32+
2733
export default router;

transformations/vue-router-v4.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ export const transformAST: ASTTransformation = context => {
9191

9292
return j.callExpression(j.identifier('createRouter'), node.arguments)
9393
})
94+
95+
// VueRouter.START_LOCATION => import {START_LOCATION} from 'vue-router'
96+
const startLocationMember = root.find(j.MemberExpression, {
97+
object: {
98+
type: 'Identifier',
99+
name: localVueRouter
100+
},
101+
property: {
102+
type: 'Identifier',
103+
name: 'START_LOCATION'
104+
}
105+
})
106+
107+
if (startLocationMember.length) {
108+
addImport(context, {
109+
specifier: { type: 'named', imported: 'START_LOCATION' },
110+
source: 'vue-router'
111+
})
112+
113+
startLocationMember.replaceWith(({ node }) => {
114+
return node.property
115+
})
116+
}
117+
94118
removeExtraneousImport(context, {
95119
localBinding: localVueRouter
96120
})

0 commit comments

Comments
 (0)