var Chunker = require('../utils/chunker');
module.exports = function Tokenizer(data, minifyContext) {
- var chunker = new Chunker(data, 128);
+ var chunker = new Chunker(data, '}', 128);
var chunk = chunker.next();
var flatBlock = /(^@(font\-face|page|\-ms\-viewport|\-o\-viewport|viewport)|\\@.+?)/;
-module.exports = function Chunker(data, chunkSize) {
+module.exports = function Chunker(data, breakString, chunkSize) {
// Divides `data` into chunks of `chunkSize` for faster processing
var chunks = [];
for (var cursor = 0, dataSize = data.length; cursor < dataSize;) {
dataSize - 1 :
cursor + chunkSize;
- if (data[nextCursor] != '}')
- nextCursor = data.indexOf('}', nextCursor);
+ if (data[nextCursor] != breakString)
+ nextCursor = data.indexOf(breakString, nextCursor);
if (nextCursor == -1)
nextCursor = data.length - 1;
- chunks.push(data.substring(cursor, nextCursor + 1));
- cursor = nextCursor + 1;
+ chunks.push(data.substring(cursor, nextCursor + breakString.length));
+ cursor = nextCursor + breakString.length;
}
return {
vows.describe(Chunker)
.addBatch({
'empty string': {
- topic: new Chunker('', 128),
+ topic: new Chunker('', '', 128),
'is empty': function (chunker) {
assert.isTrue(chunker.isEmpty());
},
}
},
'css': {
- topic: new Chunker('a{color:red}p{}', 3),
+ topic: new Chunker('a{color:red}p{}', '}', 3),
'is not empty': function (chunker) {
assert.isFalse(chunker.isEmpty());
},
'breaks at second brace': function (chunker) {
assert.equal('p{}', chunker.next());
}
+ },
+ 'comments': {
+ topic: new Chunker('/* one */ /* two */', '*/', 3),
+ 'is not empty': function (chunker) {
+ assert.isFalse(chunker.isEmpty());
+ },
+ 'breaks at first brace': function (chunker) {
+ assert.equal('/* one */', chunker.next());
+ },
+ 'breaks at second brace': function (chunker) {
+ assert.equal(' /* two */', chunker.next());
+ }
}
})
.export(module);