1
1
function transformComponentsProp ( attributeNode ) {
2
- attributeNode . name . name = 'slots' ;
3
-
4
- const valueExpression = attributeNode . value . expression ;
5
- if ( valueExpression ?. type !== 'ObjectExpression' ) {
2
+ attributeNode . name . name = 'slots' ;
3
+
4
+ const valueExpression = attributeNode . value . expression ;
5
+ if ( valueExpression ?. type !== 'ObjectExpression' ) {
6
+ return ;
7
+ }
8
+
9
+ valueExpression . properties . forEach ( ( property ) => {
10
+ property . key . name = property . key . name [ 0 ] . toLowerCase ( ) + property . key . name . slice ( 1 ) ;
11
+
12
+ if ( property . shorthand ) {
13
+ property . shorthand = false ;
14
+ }
15
+ } ) ;
16
+ }
17
+
18
+ function transformComponentsPropsProp ( attributeNode ) {
19
+ attributeNode . name . name = 'slotProps' ;
20
+ }
21
+
22
+ /**
23
+ * @param {import('jscodeshift').FileInfo } file
24
+ * @param {import('jscodeshift').API } api
25
+ */
26
+ export default function transformer ( file , api , options ) {
27
+ const j = api . jscodeshift ;
28
+ const root = j ( file . source ) ;
29
+ const printOptions = options . printOptions ;
30
+
31
+ const transformed = root . findJSXElements ( ) . forEach ( ( path ) => {
32
+ if ( path . node . type !== 'JSXElement' ) {
6
33
return ;
7
34
}
8
-
9
- valueExpression . properties . forEach ( ( property ) => {
10
- property . key . name = property . key . name [ 0 ] . toLowerCase ( ) + property . key . name . slice ( 1 ) ;
11
-
12
- if ( property . shorthand ) {
13
- property . shorthand = false ;
14
- }
15
- } ) ;
16
- }
17
-
18
- function transformComponentsPropsProp ( attributeNode ) {
19
- attributeNode . name . name = 'slotProps' ;
20
- }
21
-
22
- /**
23
- * @param {import('jscodeshift').FileInfo } file
24
- * @param {import('jscodeshift').API } api
25
- */
26
- export default function transformer ( file , api , options ) {
27
- const j = api . jscodeshift ;
28
- const root = j ( file . source ) ;
29
- const printOptions = options . printOptions ;
30
-
31
- const transformed = root . findJSXElements ( ) . forEach ( ( path ) => {
32
- if ( path . node . type !== "JSXElement" ) {
35
+
36
+ path . node . openingElement . attributes . forEach ( ( node ) => {
37
+ if ( node . type !== 'JSXAttribute' ) {
33
38
return ;
34
39
}
35
-
36
- path . node . openingElement . attributes . forEach ( ( node ) => {
37
- if ( node . type !== 'JSXAttribute' ) {
38
- return ;
39
- }
40
-
41
- switch ( node . name . name ) {
42
- case 'components' :
43
- transformComponentsProp ( node ) ;
44
- break ;
45
-
46
- case 'componentsProps' :
47
- transformComponentsPropsProp ( node ) ;
48
- break ;
49
-
50
- default :
51
- }
52
- } ) ;
40
+
41
+ switch ( node . name . name ) {
42
+ case 'components' :
43
+ transformComponentsProp ( node ) ;
44
+ break ;
45
+
46
+ case 'componentsProps' :
47
+ transformComponentsPropsProp ( node ) ;
48
+ break ;
49
+
50
+ default :
51
+ }
53
52
} ) ;
54
-
55
- return transformed . toSource ( printOptions ) ;
56
- }
57
-
53
+ } ) ;
54
+
55
+ return transformed . toSource ( printOptions ) ;
56
+ }
0 commit comments