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

Commit5aa04ca

Browse files
committed
refactor: extract remove-extraneous-import
1 parentcf3b9c4 commit5aa04ca

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

‎generator/codemods/global-api/index.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,11 @@ module.exports = function(fileInfo, api) {
1313
require('./remove-contextual-h')(context)
1414

1515
// remove extraneous imports
16+
constremoveExtraneousImport=require('../utils/remove-extraneous-import')
1617
removeExtraneousImport(context,'Vue')
1718
removeExtraneousImport(context,'Vuex')
1819
removeExtraneousImport(context,'VueRouter')
1920

2021
returnroot.toSource({lineTerminator:'\n'})
2122
}
2223

23-
/**
24-
*@param {Object} context
25-
*@param {import('jscodeshift').JSCodeshift} context.j
26-
*@param {ReturnType<import('jscodeshift').Core>} context.root
27-
*/
28-
functionremoveExtraneousImport({ root, j},name){
29-
constlocalUsages=root.find(j.Identifier,{ name})
30-
if(localUsages.length===1){
31-
constimportDecl=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-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
*@param {Object} context
3+
*@param {import('jscodeshift').JSCodeshift} context.j
4+
*@param {ReturnType<import('jscodeshift').Core>} context.root
5+
*/
6+
functionremoveExtraneousImport({ root, j},name){
7+
constlocalUsages=root.find(j.Identifier,{ name})
8+
if(localUsages.length===1){
9+
constimportDecl=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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp