@@ -432,86 +432,92 @@ function peerUtilityToSass(
432432 * @returns string
433433 */
434434function getSassTree ( nodeTree : IHtmlNode [ ] ) : string {
435- return nodeTree
436- . map ( ( node : IHtmlNode ) => {
437- let treeString = '' ,
438- subTreeString = ''
435+ let sassTree = ''
439436
440- if ( Array . isArray ( node . children ) && node . children . length ) {
441- subTreeString = getSassTree ( node . children )
442- }
437+ nodeTree . forEach ( ( node : IHtmlNode ) => {
438+ let treeString = '' ,
439+ subTreeString = ''
443440
444- if ( node . filterAttributes ) {
445- // print tailwind class names
446- if ( node . filterAttributes . class ) {
447- treeString += node . filterAttributes . class
448- ? `@apply ${ node . filterAttributes . class } ;`
449- : ''
450- }
441+ const hasSubElement = node . children ?. filter (
442+ ( child ) => child . type === 'element'
443+ ) . length
451444
452- // inline style printing
453- if ( node . filterAttributes . style ) {
454- node . filterAttributes . style = Utils . addMissingSuffix (
455- node . filterAttributes . style ,
456- ';'
457- )
445+ if ( hasSubElement ) {
446+ subTreeString = getSassTree ( node . children )
447+ }
458448
459- treeString += node . filterAttributes . style
460- ? `\n\n${ node . filterAttributes . style } `
461- : ''
462- }
449+ if ( node . filterAttributes ) {
450+ // print tailwind class names
451+ if ( node . filterAttributes . class ) {
452+ treeString += node . filterAttributes . class
453+ ? `@apply ${ node . filterAttributes . class } ;`
454+ : ''
463455 }
464456
465- if ( treeString . length || subTreeString . length ) {
466- const classComment = _defaultOptions . printSassComments
467- ? `/* ${ node . comment ? node . comment : node . tagName } ${
468- node . order ? ' -> ' + node . order : ''
469- } */`
457+ // inline style printing
458+ if ( node . filterAttributes . style ) {
459+ node . filterAttributes . style = Utils . addMissingSuffix (
460+ node . filterAttributes . style ,
461+ ';'
462+ )
463+
464+ treeString += node . filterAttributes . style
465+ ? `\n\n${ node . filterAttributes . style } `
470466 : ''
467+ }
468+ }
471469
472- const className = getClassName ( node , node . order )
470+ if ( treeString . length || subTreeString . length ) {
471+ const classComment = _defaultOptions . printSassComments
472+ ? `/* ${ node . comment ? node . comment : node . tagName } ${
473+ node . order ? ' -> ' + node . order : ''
474+ } */`
475+ : ''
473476
474- let groupUtilityTree = ''
477+ const className = getClassName ( node , node . order )
475478
476- // convert group utilities
477- if ( node . filterAttributes ?. class ?. match ( / ( g r o u p ) (? ! - ) / gm) ) {
478- groupUtilityTree = groupUtilityToSass ( node . children )
479+ let groupUtilityTree = ''
479480
480- if ( groupUtilityTree !== '' ) {
481- treeString += groupUtilityTree
481+ // convert group utilities
482+ if ( node . filterAttributes ?. class ?. match ( / ( g r o u p ) (? ! - ) / gm) ) {
483+ groupUtilityTree = groupUtilityToSass ( node . children )
482484
483- // clear parent group class name
484- treeString = treeString . replace ( / ( g r o u p ) (? ! - ) / gm , ' ' )
485+ if ( groupUtilityTree !== '' ) {
486+ treeString += groupUtilityTree
485487
486- // clear group modifier classes from @apply
487- subTreeString = subTreeString . replace (
488- / g r o u p - ( [ a - z 0 - 9 ] + ) : ( [ a - z 0 - 9 -:\/ ] + ) / gm,
489- ''
490- )
491- }
488+ // clear parent group class name
489+ treeString = treeString . replace ( / ( g r o u p ) (? ! - ) / gm, ' ' )
490+
491+ // clear group modifier classes from @apply
492+ subTreeString = subTreeString . replace (
493+ / g r o u p - ( [ a - z 0 - 9 ] + ) : ( [ a - z 0 - 9 -:\/ ] + ) / gm,
494+ ''
495+ )
492496 }
497+ }
493498
494- let peerUtilityTree = ''
499+ let peerUtilityTree = ''
495500
496- // convert peer utilities
497- if ( node . filterAttributes ?. class ?. match ( / ( p e e r ) (? ! - ) / gm) ) {
498- peerUtilityTree = peerUtilityToSass ( nodeTree , className )
501+ // convert peer utilities
502+ if ( node . filterAttributes ?. class ?. match ( / ( p e e r ) (? ! - ) / gm) ) {
503+ peerUtilityTree = peerUtilityToSass ( nodeTree , className )
499504
500- if ( peerUtilityTree !== '' ) {
501- // clear parent group class name
502- treeString = treeString . replace ( / ( p e e r ) (? ! - ) / gm, ' ' )
503- }
505+ if ( peerUtilityTree !== '' ) {
506+ // clear parent group class name
507+ treeString = treeString . replace ( / ( p e e r ) (? ! - ) / gm, ' ' )
504508 }
509+ }
505510
506- return `${ classComment } ${ peerUtilityTree }
511+ sassTree += `${ classComment } ${ peerUtilityTree }
507512 ${ className } {
508513 ${ treeString } ${ subTreeString }
509514 }`
510- }
515+ }
511516
512- return null
513- } )
514- . join ( '' )
517+ return null
518+ } )
519+
520+ return sassTree
515521}
516522
517523/**
0 commit comments