Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/minify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ export const compressSymbols = code =>

// Only manipulate symbols outside of strings
if (
countOccurences(str, "'") % 2 === 0 &&
countOccurences(str, '"') % 2 === 0
countOccurences(str, "'") % 2 !== 0 ||
countOccurences(str, '"') % 2 !== 0
) {
return str + fragment.trim()
return str + fragment
}

// Preserve whitespace preceding colon, to avoid joining selectors.
if (/^\s+:/.test(fragment)) {
return str + ' ' + fragment.trim()
}

return str + fragment
return str + fragment.trim()
}, '')

// Detects lines that are exclusively line comments
Expand Down
10 changes: 10 additions & 0 deletions test/minify/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ describe('minify utils', () => {

describe('compressSymbols', () => {
it('removes spaces around symbols', () => {
// The whitespace preceding the colon is removed here as part of the
// trailing whitespace on the semi-colon. Contrast to the "preserves"
// test below.
const input = '; : { } , ; '
const expected = ';:{},;'

Expand All @@ -125,5 +128,12 @@ describe('minify utils', () => {

expect(compressSymbols(input)).toBe(expected)
})

it('preserves whitespace preceding colons', () => {
const input = '& :last-child { color: blue; }'
const expected = '& :last-child{color:blue;}'

expect(compressSymbols(input)).toBe(expected)
})
})
})