@@ -11,7 +11,7 @@ import {
1111 getDefaultImportSpecifierName ,
1212 getImportSpecifierName ,
1313 getImportDeclaration ,
14- getJSXAttributesByName ,
14+ getJSXAttributes ,
1515} from '@codeshift/utils' ;
1616
1717function updateAvatarProps ( j : core . JSCodeshift , source : ReturnType < typeof j > ) {
@@ -24,15 +24,15 @@ function updateAvatarProps(j: core.JSCodeshift, source: ReturnType<typeof j>) {
2424 if ( ! defaultSpecifier ) return ;
2525
2626 source . findJSXElements ( defaultSpecifier ) . forEach ( element => {
27- getJSXAttributesByName ( j , element , 'isHover' ) . remove ( ) ;
28- getJSXAttributesByName ( j , element , 'isActive' ) . remove ( ) ;
29- getJSXAttributesByName ( j , element , 'isFocus' ) . remove ( ) ;
30- getJSXAttributesByName ( j , element , 'isSelected' ) . remove ( ) ;
31- getJSXAttributesByName ( j , element , 'theme' ) . remove ( ) ;
27+ getJSXAttributes ( j , element , 'isHover' ) . remove ( ) ;
28+ getJSXAttributes ( j , element , 'isActive' ) . remove ( ) ;
29+ getJSXAttributes ( j , element , 'isFocus' ) . remove ( ) ;
30+ getJSXAttributes ( j , element , 'isSelected' ) . remove ( ) ;
31+ getJSXAttributes ( j , element , 'theme' ) . remove ( ) ;
3232
33- const nameAttributes = getJSXAttributesByName ( j , element , 'name' ) ;
33+ const nameAttributes = getJSXAttributes ( j , element , 'name' ) ;
3434 const name = nameAttributes . length && nameAttributes . get ( ) ;
35- const enableTooltipAttributes = getJSXAttributesByName (
35+ const enableTooltipAttributes = getJSXAttributes (
3636 j ,
3737 element ,
3838 'enableTooltip' ,
@@ -121,61 +121,59 @@ function updateAvatarItemProps(
121121 if ( ! importSpecifier ) return ;
122122
123123 source . findJSXElements ( importSpecifier ) . forEach ( element => {
124- getJSXAttributesByName ( j , element , 'isHover' ) . remove ( ) ;
125- getJSXAttributesByName ( j , element , 'isActive' ) . remove ( ) ;
126- getJSXAttributesByName ( j , element , 'isFocus' ) . remove ( ) ;
127- getJSXAttributesByName ( j , element , 'isSelected' ) . remove ( ) ;
128- getJSXAttributesByName ( j , element , 'theme' ) . remove ( ) ;
129- getJSXAttributesByName ( j , element , 'enableTextTruncate' ) . forEach (
130- attribute => {
131- // Change the prop name to isTruncationDisabled
132- j ( attribute )
133- . find ( j . JSXIdentifier )
134- . replaceWith ( j . jsxIdentifier ( 'isTruncationDisabled' ) ) ;
135-
136- // Remove if enableTextTruncate was true or given no value (ie true)
137- j ( attribute )
138- . filter ( attr => attr . node . value == null )
139- . remove ( ) ;
140-
141- j ( attribute )
142- . filter ( attr => {
143- return ! ! j ( attr )
124+ getJSXAttributes ( j , element , 'isHover' ) . remove ( ) ;
125+ getJSXAttributes ( j , element , 'isActive' ) . remove ( ) ;
126+ getJSXAttributes ( j , element , 'isFocus' ) . remove ( ) ;
127+ getJSXAttributes ( j , element , 'isSelected' ) . remove ( ) ;
128+ getJSXAttributes ( j , element , 'theme' ) . remove ( ) ;
129+ getJSXAttributes ( j , element , 'enableTextTruncate' ) . forEach ( attribute => {
130+ // Change the prop name to isTruncationDisabled
131+ j ( attribute )
132+ . find ( j . JSXIdentifier )
133+ . replaceWith ( j . jsxIdentifier ( 'isTruncationDisabled' ) ) ;
134+
135+ // Remove if enableTextTruncate was true or given no value (ie true)
136+ j ( attribute )
137+ . filter ( attr => attr . node . value == null )
138+ . remove ( ) ;
139+
140+ j ( attribute )
141+ . filter ( attr => {
142+ return ! ! j ( attr )
143+ . find ( j . JSXExpressionContainer )
144+ . find ( j . BooleanLiteral )
145+ . filter ( literal => literal . node . value ) . length ;
146+ } )
147+ . remove ( ) ;
148+
149+ // if `enableTextTruncate` value is negative we can change it to 'true'
150+ j ( attribute )
151+ . filter (
152+ attr =>
153+ ! ! j ( attr )
144154 . find ( j . JSXExpressionContainer )
145- . find ( j . BooleanLiteral )
146- . filter ( literal => literal . node . value ) . length ;
147- } )
148- . remove ( ) ;
149-
150- // if `enableTextTruncate` value is negative we can change it to 'true'
151- j ( attribute )
152- . filter (
153- attr =>
154- ! ! j ( attr )
155- . find ( j . JSXExpressionContainer )
156- . filter (
157- expression =>
158- j ( expression )
159- . find ( j . BooleanLiteral )
160- . filter ( literal => ! literal . node . value ) . length > 0 ,
161- ) . length ,
162- )
163- . replaceWith ( j . jsxAttribute ( j . jsxIdentifier ( 'isTruncationDisabled' ) ) ) ;
164-
165- // if `enableTextTruncate` was an expression, negate it
166- j ( attribute )
167- . find ( j . JSXExpressionContainer )
168- . filter ( container => j ( container ) . find ( j . BooleanLiteral ) . length === 0 )
169- . forEach ( container => {
170- j ( container ) . replaceWith (
171- j . jsxExpressionContainer (
172- //@ts -ignore
173- j . unaryExpression ( '!' , container . node . expression ) ,
174- ) ,
175- ) ;
176- } ) ;
177- } ,
178- ) ;
155+ . filter (
156+ expression =>
157+ j ( expression )
158+ . find ( j . BooleanLiteral )
159+ . filter ( literal => ! literal . node . value ) . length > 0 ,
160+ ) . length ,
161+ )
162+ . replaceWith ( j . jsxAttribute ( j . jsxIdentifier ( 'isTruncationDisabled' ) ) ) ;
163+
164+ // if `enableTextTruncate` was an expression, negate it
165+ j ( attribute )
166+ . find ( j . JSXExpressionContainer )
167+ . filter ( container => j ( container ) . find ( j . BooleanLiteral ) . length === 0 )
168+ . forEach ( container => {
169+ j ( container ) . replaceWith (
170+ j . jsxExpressionContainer (
171+ //@ts -ignore
172+ j . unaryExpression ( '!' , container . node . expression ) ,
173+ ) ,
174+ ) ;
175+ } ) ;
176+ } ) ;
179177 } ) ;
180178}
181179
0 commit comments