Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix minifier bug #366 #376

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/minify/index.js
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
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)
})
})
})