File tree Expand file tree Collapse file tree 3 files changed +24
-9
lines changed
Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import {
55 StringLiteral ,
66 NumericLiteral ,
77 ArrayExpression ,
8+ Property ,
9+ ObjectMethod ,
10+ SpreadProperty ,
11+ SpreadElement ,
812} from 'jscodeshift'
913import j from 'jscodeshift'
1014import * as postcss from 'postcss'
@@ -228,20 +232,31 @@ export function convertSelectors(root: ObjectExpression): void {
228232 }
229233 }
230234 const addMissingClassProperties = ( node : ObjectExpression ) : void => {
231- if ( node === root ) insertMissingClassPropertyBefore = 0
232-
233- for ( const prop of node . properties ) {
234- if ( prop . type !== 'ObjectProperty' ) continue
235+ function process (
236+ prop :
237+ | ObjectProperty
238+ | Property
239+ | ObjectMethod
240+ | SpreadProperty
241+ | SpreadElement
242+ ) : void {
243+ if ( prop . type !== 'ObjectProperty' ) return
235244 const { value } = prop
236245 const key = getRawKey ( prop . key )
237- if ( ! key || value . type !== 'ObjectExpression' ) continue
246+ if ( ! key || value . type !== 'ObjectExpression' ) return
238247 const [ localSelector ] = splitGlobals ( key )
239248 if ( localSelector ) {
240249 addMissingClassPropertiesSelector . processSync ( localSelector )
241250 }
242-
243251 addMissingClassProperties ( value )
244- insertMissingClassPropertyBefore ++
252+ }
253+ if ( node === root ) {
254+ for ( let i = 0 ; i < node . properties . length ; i ++ ) {
255+ insertMissingClassPropertyBefore = i
256+ process ( node . properties [ i ] )
257+ }
258+ } else {
259+ for ( const prop of node . properties ) process ( prop )
245260 }
246261 }
247262 const convertClassReferences = ( node : ObjectExpression ) : void => {
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ const styles = {
6161 color: 'red',
6262 },
6363 },
64+ baz: {},
6465 foo: {
6566 color: 'green',
6667 '& $barQux, & $glorm:after': {
@@ -101,6 +102,5 @@ const styles = {
101102 },
102103 },
103104 },
104- baz: {},
105105}
106106`
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ const styles = {
2929
3030export const expected = `
3131const styles = {
32+ baz: {},
3233 foo: {
3334 color: 'green',
3435 '& $barQux, & $glorm:after': {
@@ -38,7 +39,6 @@ const styles = {
3839 color: 'blue',
3940 }
4041 },
41- baz: {},
4242 glorm: {
4343 color: 'green',
4444 },
You can’t perform that action at this time.
0 commit comments