Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6719d0c

Browse files
committed
feat: implement vuex transform
1 parent660cace commit6719d0c

File tree

10 files changed

+128
-18
lines changed

10 files changed

+128
-18
lines changed

‎generator/codemods/router/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = function(fileInfo, api) {
33
constj=api.jscodeshift
44
constroot=j(fileInfo.source)
55

6-
// TODO: Vue.use(router) might be in either`router/index.js` or `main.js`
6+
// TODO: new Router() -> createRouter()
7+
// TODO: mode: 'history' -> history: createWebHistory()
78

89
returnroot.toSource({lineTerminator:'\n'})
910
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import{StoreasTheStore}from'vuex';
2+
3+
conststore=newTheStore({
4+
state(){
5+
return{
6+
count:1
7+
}
8+
}
9+
});
10+
11+
exportdefaultstore;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import{createStore}from'vuex'
1+
import{createStore}from'vuex';
22

33
conststore=createStore({
44
state(){
55
return{
66
count:1
77
}
88
}
9-
})
9+
});
1010

11-
exportdefaultstore
11+
exportdefaultstore;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import{Store}from'vuex';
2+
3+
conststore=newStore({
4+
state(){
5+
return{
6+
count:1
7+
}
8+
}
9+
});
10+
11+
exportdefaultstore;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import{createStore}from'vuex';
2+
3+
conststore=createStore({
4+
state(){
5+
return{
6+
count:1
7+
}
8+
}
9+
});
10+
11+
exportdefaultstore;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importVuexfrom'vuex';
2+
3+
conststore=newVuex.Store({
4+
state(){
5+
return{
6+
count:1
7+
}
8+
}
9+
});
10+
11+
exportdefaultstore;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importVuexfrom'vuex';
2+
3+
conststore=Vuex.createStore({
4+
state(){
5+
return{
6+
count:1
7+
}
8+
}
9+
});
10+
11+
exportdefaultstore;

‎generator/codemods/vuex/__testfixtures__/vuex-store.input.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
jest.autoMockOff()
2+
3+
const{ defineTest}=require('jscodeshift/dist/testUtils')
4+
5+
defineTest(__dirname,'index',null,'store')
6+
defineTest(__dirname,'index',null,'vuex-dot-store')
7+
defineTest(__dirname,'index',null,'import-alias')

‎generator/codemods/vuex/index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,68 @@
1+
constaddImport=require('../utils/add-import')
2+
constremoveExtraneousImport=require('../utils/remove-extraneous-import')
3+
14
/**@type {import('jscodeshift').Transform} */
25
module.exports=function(fileInfo,api){
36
constj=api.jscodeshift
47
constroot=j(fileInfo.source)
8+
constcontext={ j, root}
9+
10+
// TODO: new Store() -> createStore()
11+
12+
constvuexImportDecls=root.find(j.ImportDeclaration,{
13+
source:{
14+
value:'vuex'
15+
}
16+
})
17+
18+
constimportedVuex=vuexImportDecls.find(j.ImportDefaultSpecifier)
19+
constimportedStore=vuexImportDecls.find(j.ImportSpecifier,{
20+
imported:{
21+
name:'Store'
22+
}
23+
})
24+
25+
if(importedVuex.length){
26+
constlocalVuex=importedVuex.get(0).node.local.name
27+
constnewVuexDotStore=root.find(j.NewExpression,{
28+
callee:{
29+
type:'MemberExpression',
30+
object:{
31+
type:'Identifier',
32+
name:localVuex
33+
},
34+
property:{
35+
name:'Store'
36+
}
37+
}
38+
})
39+
40+
newVuexDotStore.replaceWith(({ node})=>{
41+
returnj.callExpression(
42+
j.memberExpression(
43+
j.identifier(localVuex),
44+
j.identifier('createStore')
45+
),
46+
node.arguments
47+
)
48+
})
49+
}
50+
51+
if(importedStore.length){
52+
constlocalStore=importedStore.get(0).node.local.name
53+
constnewStore=root.find(j.NewExpression,{
54+
callee:{
55+
type:'Identifier',
56+
name:localStore
57+
}
58+
})
59+
60+
addImport(context,{imported:'createStore'},'vuex')
61+
newStore.replaceWith(({ node})=>{
62+
returnj.callExpression(j.identifier('createStore'),node.arguments)
63+
})
64+
removeExtraneousImport(context,localStore)
65+
}
566

667
returnroot.toSource({lineTerminator:'\n'})
768
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp