@@ -13,7 +13,7 @@ const {
1313
1414export const report = ( ) => `Use shorthand properties` ;
1515
16- export const fix = ( { path, from, to, toRename} ) => {
16+ export const fix = ( { path, from, to, keyPath , toRename} ) => {
1717 if ( isImportSpecifier ( path ) ) {
1818 path . node . imported = path . node . local ;
1919 return ;
@@ -24,8 +24,6 @@ export const fix = ({path, from, to, toRename}) => {
2424
2525 path . node . shorthand = true ;
2626
27- const keyPath = path . get ( 'key' ) ;
28-
2927 if ( keyPath . isStringLiteral ( ) ) {
3028 replaceWith ( keyPath , identifier ( keyPath . node . value ) ) ;
3129 path . node . computed = false ;
@@ -46,16 +44,17 @@ export const traverse = ({push, options}) => ({
4644 if ( shorthand )
4745 continue ;
4846
49- const valuePath = propPath . get ( 'value' ) ;
5047 const keyPath = propPath . get ( 'key' ) ;
48+ const keyIsString = keyPath . isStringLiteral ( ) ;
5149
52- if ( computed && ! keyPath . isStringLiteral ( ) )
50+ if ( computed && ! keyIsString )
5351 continue ;
5452
55- if ( ! computed && keyPath . isStringLiteral ( ) )
53+ if ( ! computed && keyIsString )
5654 continue ;
5755
5856 const { rename, ignore = [ ] } = options ;
57+ const valuePath = propPath . get ( 'value' ) ;
5958
6059 const from = getName ( valuePath ) ;
6160 const to = getName ( keyPath ) ;
@@ -75,6 +74,7 @@ export const traverse = ({push, options}) => ({
7574 path : propPath ,
7675 from,
7776 to,
77+ keyPath,
7878 } ) ;
7979
8080 continue ;
@@ -98,6 +98,7 @@ export const traverse = ({push, options}) => ({
9898 path : propPath ,
9999 from,
100100 to,
101+ keyPath,
101102 toRename : true ,
102103 } ) ;
103104 }
0 commit comments