diff --git a/index.js b/index.js index b3d5c1d..af19928 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ const CLOSE_BRACKET = ']' const OPEN_BRACE = '{' const CLOSE_BRACE = '}' const EMPTY_BLOCK = '{}' +const COMMA = ',' const TYPE_ATRULE = 'Atrule' const TYPE_RULE = 'Rule' const TYPE_BLOCK = 'Block' @@ -150,7 +151,7 @@ export function format(css, { minify = false } = {}) { } if (item.next !== null) { - buffer += `,` + NEWLINE + buffer += COMMA + NEWLINE } let end = item.next !== null ? start_offset(item.next.data) : end_offset(node) @@ -203,13 +204,13 @@ export function format(css, { minify = false } = {}) { break } case TYPE_SELECTORLIST: { - child.children.forEach((grandchild, item) => { - if (grandchild.type === TYPE_SELECTOR) { - buffer += print_simple_selector(grandchild) + child.children.forEach((selector_list_item, item) => { + if (selector_list_item.type === TYPE_SELECTOR) { + buffer += print_simple_selector(selector_list_item) } - if (item.next) { - buffer += ',' + SPACE + if (item.next && item.next.data.type === TYPE_SELECTOR) { + buffer += COMMA + OPTIONAL_SPACE } }) break diff --git a/test/minify.test.js b/test/minify.test.js index 026bd7b..99957e3 100644 --- a/test/minify.test.js +++ b/test/minify.test.js @@ -83,4 +83,10 @@ test('removes whitespace before !important', () => { assert.equal(actual, expected) }) +test.only('minifies complex selectors', () => { + let actual = minify(`:is(a, b) { color: green }`) + let expected = `:is(a,b){color:green}` + assert.equal(actual, expected) +}) + test.run()