@@ -769,7 +769,21 @@ export class PugPrinter {
769769 // Add leading and trailing parentheses
770770 this . currentLineLength += 2 ;
771771 }
772- logger . debug ( this . currentLineLength ) ;
772+ if ( this . options . pugClassLocation === 'after-attributes' ) {
773+ let tempClassIndex : number = tempIndex ;
774+ let tempClassToken : EndAttributesToken | ClassToken = this . tokens [ ++ tempClassIndex ] as
775+ | EndAttributesToken
776+ | ClassToken ;
777+ while ( tempClassToken . type === 'class' ) {
778+ const val : string = tempClassToken . val . toString ( ) ;
779+ // Add leading . for classes
780+ this . currentLineLength += 1 + val . length ;
781+ logger . debug ( { tokenVal : val , length : val . length } , this . currentLineLength ) ;
782+
783+ tempClassToken = this . tokens [ ++ tempClassIndex ] as EndAttributesToken | ClassToken ;
784+ }
785+ }
786+ logger . debug ( 'final line length' , { currentLineLength : this . currentLineLength } ) ;
773787 if (
774788 ! this . currentlyInPugInterpolation &&
775789 ! this . wrapAttributes &&
@@ -1020,6 +1034,8 @@ export class PugPrinter {
10201034 this . classLiteralAfterAttributes . length
10211035 ) ;
10221036 this . result += `.${ classes . join ( '.' ) } ` ;
1037+ }
1038+ if ( this . options . pugClassLocation === 'after-attributes' ) {
10231039 this . possibleClassPosition = this . result . length ;
10241040 }
10251041 if ( this . nextToken ?. type === 'text' || this . nextToken ?. type === 'path' ) {
@@ -1069,9 +1085,7 @@ export class PugPrinter {
10691085 }
10701086 } else {
10711087 const val : string = `.${ token . val } ` ;
1072- if ( this . options . pugClassLocation === 'before-attributes' ) {
1073- this . currentLineLength += val . length ;
1074- }
1088+ this . currentLineLength += val . length ;
10751089 logger . debug (
10761090 'before class' ,
10771091 { result : this . result , val, length : val . length , previousToken : this . previousToken } ,
@@ -1107,19 +1121,6 @@ export class PugPrinter {
11071121 default : {
11081122 if ( this . options . pugClassLocation === 'after-attributes' ) {
11091123 this . classLiteralAfterAttributes . push ( val . slice ( 1 ) ) ;
1110- logger . debug ( 'class default' , {
1111- classLiteralAfterAttributes : this . classLiteralAfterAttributes
1112- } ) ;
1113- let result : string = this . result . slice ( 0 , this . possibleClassPosition ) ;
1114- if ( [ 'text' , 'newline' , 'indent' , 'eos' , 'code' , undefined ] . includes ( this . nextToken ?. type ) ) {
1115- const classes : string [ ] = this . classLiteralAfterAttributes . splice (
1116- 0 ,
1117- this . classLiteralAfterAttributes . length
1118- ) ;
1119- result += '.' + classes . join ( '.' ) ;
1120- }
1121- this . result = [ result , this . result . slice ( this . possibleClassPosition ) ] . join ( '' ) ;
1122- this . possibleClassPosition = this . result . length ;
11231124 } else {
11241125 const prefix : string = this . result . slice ( 0 , this . possibleClassPosition ) ;
11251126 this . result = [ prefix , val , this . result . slice ( this . possibleClassPosition ) ] . join ( '' ) ;
@@ -1128,6 +1129,19 @@ export class PugPrinter {
11281129 break ;
11291130 }
11301131 }
1132+ if ( this . options . pugClassLocation === 'after-attributes' && this . classLiteralAfterAttributes . length > 0 ) {
1133+ let result : string = this . result . slice ( 0 , this . possibleClassPosition ) ;
1134+ if ( [ 'text' , 'newline' , 'indent' , 'outdent' , 'eos' , 'code' , undefined ] . includes ( this . nextToken ?. type ) ) {
1135+ const classes : string [ ] = this . classLiteralAfterAttributes . splice (
1136+ 0 ,
1137+ this . classLiteralAfterAttributes . length
1138+ ) ;
1139+ result += '.' + classes . join ( '.' ) ;
1140+ }
1141+ this . result = [ result , this . result . slice ( this . possibleClassPosition ) ] . join ( '' ) ;
1142+ this . possibleClassPosition = this . result . length ;
1143+ this . replaceTagWithLiteralIfPossible ( / d i v \. / , '.' ) ;
1144+ }
11311145 logger . debug ( 'after class' , { result : this . result , val, length : val . length } , this . currentLineLength ) ;
11321146 if ( this . nextToken ?. type === 'text' ) {
11331147 this . currentLineLength += 1 ;
0 commit comments