+++ /dev/null
-// Divides `data` into chunks of `chunkSize` for faster processing
-function Chunker(data, breakString, chunkSize) {
- this.chunks = [];
-
- for (var cursor = 0, dataSize = data.length; cursor < dataSize;) {
- var nextCursor = cursor + chunkSize > dataSize ?
- dataSize - 1 :
- cursor + chunkSize;
-
- if (data[nextCursor] != breakString)
- nextCursor = data.indexOf(breakString, nextCursor);
- if (nextCursor == -1)
- nextCursor = data.length - 1;
-
- this.chunks.push(data.substring(cursor, nextCursor + breakString.length));
- cursor = nextCursor + breakString.length;
- }
-}
-
-Chunker.prototype.isEmpty = function () {
- return this.chunks.length === 0;
-};
-
-Chunker.prototype.next = function () {
- return this.chunks.shift();
-};
-
-module.exports = Chunker;
-var Chunker = require('./chunker');
var extractProperties = require('./extract-properties');
var extractSelectors = require('./extract-selectors');
var track = require('../source-maps/track');
var flatBlock = /(@(font\-face|page|\-ms\-viewport|\-o\-viewport|viewport|counter\-style)|\\@.+?)/;
function tokenize(data, outerContext) {
- var chunker = new Chunker(normalize(data), '}', 128);
- if (chunker.isEmpty())
+ var chunks = split(normalize(data), '}', true, '{', '}');
+ if (chunks.length === 0)
return [];
var context = {
- chunk: chunker.next(),
- chunker: chunker,
+ chunk: chunks.shift(),
+ chunks: chunks,
column: 0,
cursor: 0,
line: 1,
var closest;
if (chunk.length == context.cursor) {
- if (context.chunker.isEmpty())
+ if (context.chunks.length === 0)
return null;
- context.chunk = chunk = context.chunker.next();
+ context.chunk = chunk = context.chunks.shift();
context.cursor = 0;
}
},
'should raise one warning': function (error, minified) {
assert.lengthOf(minified.warnings, 1);
- assert.equal(minified.warnings[0], 'Unexpected \'}\' in \'a{display:block}}\'. Ignoring.');
+ assert.equal(minified.warnings[0], 'Unexpected \'}\' in \'}\'. Ignoring.');
}
},
'warnings on missing closing brace': {
+++ /dev/null
-var vows = require('vows');
-var assert = require('assert');
-var Chunker = require('../../lib/tokenizer/chunker');
-
-vows.describe(Chunker)
- .addBatch({
- 'empty string': {
- 'topic': function () {
- return new Chunker('', '', 128);
- },
- 'is empty': function (chunker) {
- assert.isTrue(chunker.isEmpty());
- },
- 'has no next': function (chunker) {
- assert.isUndefined(chunker.next());
- }
- },
- 'css': {
- 'topic': function () {
- return new Chunker('a{color:red}p{}', '}', 3);
- },
- 'is not empty': function (chunker) {
- assert.isFalse(chunker.isEmpty());
- },
- 'breaks at first brace': function (chunker) {
- assert.equal(chunker.next(), 'a{color:red}');
- },
- 'breaks at second brace': function (chunker) {
- assert.equal(chunker.next(), 'p{}');
- }
- },
- 'comments': {
- 'topic': function () {
- return new Chunker('/* one */ /* two */', '*/', 3);
- },
- 'is not empty': function (chunker) {
- assert.isFalse(chunker.isEmpty());
- },
- 'breaks at first brace': function (chunker) {
- assert.equal(chunker.next(), '/* one */');
- },
- 'breaks at second brace': function (chunker) {
- assert.equal(chunker.next(), ' /* two */');
- }
- }
- })
- .export(module);