File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,18 @@ export const compressSymbols = code =>
6464
6565 // Only manipulate symbols outside of strings
6666 if (
67- countOccurences ( str , "'" ) % 2 === 0 &&
68- countOccurences ( str , '"' ) % 2 = == 0
67+ countOccurences ( str , "'" ) % 2 !== 0 ||
68+ countOccurences ( str , '"' ) % 2 ! == 0
6969 ) {
70- return str + fragment . trim ( )
70+ return str + fragment
71+ }
72+
73+ // Preserve whitespace preceding colon, to avoid joining selectors.
74+ if ( / ^ \s + : / . test ( fragment ) ) {
75+ return str + ' ' + fragment . trim ( )
7176 }
7277
73- return str + fragment
78+ return str + fragment . trim ( )
7479 } , '' )
7580
7681// Detects lines that are exclusively line comments
Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ describe('minify utils', () => {
113113
114114 describe ( 'compressSymbols' , ( ) => {
115115 it ( 'removes spaces around symbols' , ( ) => {
116+ // The whitespace preceding the colon is removed here as part of the
117+ // trailing whitespace on the semi-colon. Contrast to the "preserves"
118+ // test below.
116119 const input = '; : { } , ; '
117120 const expected = ';:{},;'
118121
@@ -125,5 +128,12 @@ describe('minify utils', () => {
125128
126129 expect ( compressSymbols ( input ) ) . toBe ( expected )
127130 } )
131+
132+ it ( 'preserves whitespace preceding colons' , ( ) => {
133+ const input = '& :last-child { color: blue; }'
134+ const expected = '& :last-child{color:blue;}'
135+
136+ expect ( compressSymbols ( input ) ) . toBe ( expected )
137+ } )
128138 } )
129139} )
You can’t perform that action at this time.
0 commit comments