File tree 2 files changed +23
-22
lines changed
2 files changed +23
-22
lines changed Original file line number Diff line number Diff line change @@ -13,32 +13,11 @@ module.exports = function(fileInfo, api) {
13
13
require ( './remove-contextual-h' ) ( context )
14
14
15
15
// remove extraneous imports
16
+ const removeExtraneousImport = require ( '../utils/remove-extraneous-import' )
16
17
removeExtraneousImport ( context , 'Vue' )
17
18
removeExtraneousImport ( context , 'Vuex' )
18
19
removeExtraneousImport ( context , 'VueRouter' )
19
20
20
21
return root . toSource ( { lineTerminator : '\n' } )
21
22
}
22
23
23
- /**
24
- * @param {Object } context
25
- * @param {import('jscodeshift').JSCodeshift } context.j
26
- * @param {ReturnType<import('jscodeshift').Core> } context.root
27
- */
28
- function removeExtraneousImport ( { root, j } , name ) {
29
- const localUsages = root . find ( j . Identifier , { name } )
30
- if ( localUsages . length === 1 ) {
31
- const importDecl = localUsages . closest ( j . ImportDeclaration )
32
-
33
- if ( ! importDecl . length ) {
34
- return
35
- }
36
-
37
- if ( importDecl . get ( 0 ) . node . specifiers . length === 1 ) {
38
- importDecl . remove ( )
39
- } else {
40
- localUsages . closest ( j . ImportSpecifier ) . remove ( )
41
- localUsages . closest ( j . ImportDefaultSpecifier ) . remove ( )
42
- }
43
- }
44
- }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {Object } context
3
+ * @param {import('jscodeshift').JSCodeshift } context.j
4
+ * @param {ReturnType<import('jscodeshift').Core> } context.root
5
+ */
6
+ function removeExtraneousImport ( { root, j } , name ) {
7
+ const localUsages = root . find ( j . Identifier , { name } )
8
+ if ( localUsages . length === 1 ) {
9
+ const importDecl = localUsages . closest ( j . ImportDeclaration )
10
+
11
+ if ( ! importDecl . length ) {
12
+ return
13
+ }
14
+
15
+ if ( importDecl . get ( 0 ) . node . specifiers . length === 1 ) {
16
+ importDecl . remove ( )
17
+ } else {
18
+ localUsages . closest ( j . ImportSpecifier ) . remove ( )
19
+ localUsages . closest ( j . ImportDefaultSpecifier ) . remove ( )
20
+ }
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments