Adds breaking splits on a closing token.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 24 Aug 2015 04:36:56 +0000 (05:36 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 24 Aug 2015 05:50:38 +0000 (06:50 +0100)
So we can break body on a closing brace which is a separator at the
same time.

lib/utils/split.js
test/utils/split-test.js

index 4a978a3..d4ffa60 100644 (file)
@@ -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;
     }
index f045022..fb1df8f 100644 (file)
@@ -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);