Skip to content

Commit 4635eb5

Browse files
author
Alan Wang
authored
fix: avoiding repeated imported createRouter (#101)
1 parent a89dd8d commit 4635eb5

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

transformations/vue-router-v4.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,29 @@ export const transformAST: ASTTransformation = context => {
3535
const createRouterIdentifiers = root.find(j.Identifier, {
3636
name: 'createRouter'
3737
})
38-
if (createRouterIdentifiers.length) {
39-
// rename createRouter to newCreateRouter
40-
localCreateRouter = 'newCreateRouter'
41-
addImport(context, {
42-
specifier: {
43-
type: 'named',
44-
imported: 'createRouter',
45-
local: localCreateRouter
46-
},
47-
source: 'vue-router'
48-
})
49-
} else {
50-
addImport(context, {
51-
specifier: { type: 'named', imported: 'createRouter' },
52-
source: 'vue-router'
53-
})
38+
const importedCreateRouter = importedVueRouter.find(j.ImportSpecifier, {
39+
imported: {
40+
name: 'createRouter'
41+
}
42+
})
43+
if (!importedCreateRouter.length) {
44+
if (createRouterIdentifiers.length) {
45+
// rename createRouter to newCreateRouter
46+
localCreateRouter = 'newCreateRouter'
47+
addImport(context, {
48+
specifier: {
49+
type: 'named',
50+
imported: 'createRouter',
51+
local: localCreateRouter
52+
},
53+
source: 'vue-router'
54+
})
55+
} else {
56+
addImport(context, {
57+
specifier: { type: 'named', imported: 'createRouter' },
58+
source: 'vue-router'
59+
})
60+
}
5461
}
5562

5663
// filter the node to the manual list

0 commit comments

Comments
 (0)