From: Jakub Pawlowicz Date: Mon, 24 Aug 2015 04:36:56 +0000 (+0100) Subject: Adds breaking splits on a closing token. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f2d2a8e4ae9ccee16b300c97d40467fbd8d753a4;p=clean-css.git Adds breaking splits on a closing token. So we can break body on a closing brace which is a separator at the same time. --- diff --git a/lib/utils/split.js b/lib/utils/split.js index 4a978a38..d4ffa603 100644 --- a/lib/utils/split.js +++ b/lib/utils/split.js @@ -24,7 +24,9 @@ function split(value, separator, includeSeparator, openLevel, closeLevel) { level++; } else if (value[cursor] == closeLevel) { level--; - } else if ((withRegex ? separator.test(value[cursor]) : value[cursor] == separator) && level === 0) { + } + + if ((withRegex ? separator.test(value[cursor]) : value[cursor] == separator) && level === 0) { tokens.push(value.substring(lastStart, cursor + (includeSeparator ? 1 : 0))); lastStart = cursor + 1; } diff --git a/test/utils/split-test.js b/test/utils/split-test.js index f045022c..fb1df8f1 100644 --- a/test/utils/split-test.js +++ b/test/utils/split-test.js @@ -103,6 +103,12 @@ vows.describe(split) split: function (input) { assert.deepEqual(split(input, ';', false, '{', '}'), ['--my-toolbar:{color:red;width:100%}']); } + }, + 'with custom wrappers - on close brace': { + topic: 'a{ color:red; --var { color:red; display: none } } p{ color:red }', + split: function (input) { + assert.deepEqual(split(input, '}', true, '{', '}'), [ 'a{ color:red; --var { color:red; display: none } }', ' p{ color:red }', '' ]); + } } }) .export(module);