File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { defineInlineTest } from 'jscodeshift/src/testUtils'
2
+
3
+ const transform = require ( '../element-plus/locale-lang-file-lower-case' )
4
+
5
+ defineInlineTest (
6
+ transform ,
7
+ { } ,
8
+ `
9
+ import locale1 from 'element-plus/lib/locale/lang/zh-CN'
10
+ import locale2 from 'element-plus/lib/locale/lang/tr-TR'
11
+ import locale3 from 'element-plus/lib/locale/lang/en'
12
+ ` ,
13
+ `
14
+ import locale1 from "element-plus/lib/locale/lang/zh-cn"
15
+ import locale2 from "element-plus/lib/locale/lang/tr-tr"
16
+ import locale3 from 'element-plus/lib/locale/lang/en'
17
+ ` ,
18
+ 'element-ui locale lang file lower case'
19
+ )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import wrap from '../src/wrapAstTransformation'
2
2
import type { ASTTransformation } from '../src/wrapAstTransformation'
3
3
import { transformAST as elementPlusImport } from './element-plus/element-plus-import'
4
4
import { transformAST as elementPlusComponentName } from './element-plus/element-plus-component-name'
5
+ import { transformAST as langLowerCase } from './element-plus/locale-lang-file-lower-case'
5
6
import { getCntFunc } from '../src/report'
6
7
7
8
export const transformAST : ASTTransformation = context => {
@@ -11,6 +12,7 @@ export const transformAST: ASTTransformation = context => {
11
12
)
12
13
elementPlusImport ( context )
13
14
elementPlusComponentName ( context )
15
+ langLowerCase ( context )
14
16
const afterCount = Object . keys ( subRules ) . reduce (
15
17
( sum , key ) => sum + subRules [ key ] ,
16
18
0
Original file line number Diff line number Diff line change
1
+ import wrap from '../../src/wrapAstTransformation'
2
+ import type { ASTTransformation } from '../../src/wrapAstTransformation'
3
+
4
+ export const transformAST : ASTTransformation = ( { root, j } ) => {
5
+ const importValuePrefix = 'element-plus/lib/locale/lang/'
6
+ // find element-ui lang import
7
+ const langImport = root . find ( j . ImportDeclaration , node => {
8
+ return (
9
+ node . source . type === 'StringLiteral' &&
10
+ node . source . value ?. startsWith ( importValuePrefix )
11
+ )
12
+ } )
13
+
14
+ if ( langImport . length ) {
15
+ langImport . replaceWith ( ( { node } ) => {
16
+ const value = node . source . value as string
17
+ const lang = value . replace ( importValuePrefix , '' )
18
+ // if lang contains upper-case,converts to lower-case
19
+ if ( / [ A - Z ] + / . test ( lang ) ) {
20
+ node . source . value = importValuePrefix + lang . toLowerCase ( )
21
+ }
22
+ return node
23
+ } )
24
+ }
25
+ }
26
+
27
+ export default wrap ( transformAST )
28
+ export const parser = 'babylon'
You can’t perform that action at this time.
0 commit comments