From f2d2a8e4ae9ccee16b300c97d40467fbd8d753a4 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Mon, 24 Aug 2015 05:36:56 +0100 Subject: [PATCH] Adds breaking splits on a closing token. So we can break body on a closing brace which is a separator at the same time. --- lib/utils/split.js | 4 +++- test/utils/split-test.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); -- 2.34.1