}
var tokenize = function(body, selector) {
- var tokens = body.split(';');
var keyValues = [];
- if (tokens.length === 0 || (tokens.length == 1 && tokens[0].indexOf(IE_BACKSLASH_HACK) == -1 && tokens[0][tokens[0].length - 1] != ':'))
- return;
-
- for (var i = 0, l = tokens.length; i < l; i++) {
- var token = tokens[i];
- if (token === '')
- continue;
+ for (var i = 0, l = body.length; i < l; i++) {
+ var token = body[i];
var firstColon = token.indexOf(':');
var property = token.substring(0, firstColon);
var rebuild = function(tokens) {
var flat = [];
-
for (var i = 0, l = tokens.length; i < l; i++) {
flat.push(tokens[i][0] + ':' + tokens[i][1]);
}
- return flat.join(';');
+ return flat;
};
var compact = function (input) {
};
return {
- process: function(body, allowAdjacent, skipCompacting, selector) {
- var result = body;
-
- var tokens = tokenize(body, selector);
- if (tokens) {
- var optimized = optimize(tokens, allowAdjacent);
- result = rebuild(optimized);
- }
-
- if (!skipCompacting && processableInfo.implementedFor.test(result)) {
- result = compact(result);
- }
-
- return result;
+ process: function(selector, body, allowAdjacent, skipCompacting) {
+ var tokenized = tokenize(body, selector);
+ var optimized = optimize(tokenized, allowAdjacent);
+ var rebuilt = rebuild(optimized);
+
+ return !skipCompacting && processableInfo.implementedFor.test(rebuilt) ?
+ compact(rebuilt) :
+ rebuilt;
}
};
};
// Breaks up a string of CSS property declarations into tokens so that they can be handled more easily
Token.tokenize = function (input) {
// Split the input by semicolons and parse the parts
- var tokens = input.split(';').map(Token.tokenizeOne);
+ var tokens = input.map(Token.tokenizeOne);
return tokens;
};
tokens = [tokens];
}
- var result = '';
+ var result = [];
// This step takes care of putting together the components of shorthands
// NOTE: this is necessary to do for every shorthand, otherwise we couldn't remove their default values
continue;
}
- if (t.prop)
- result += t.prop + ':';
-
- if (t.value)
- result += t.value;
-
- if (t.isImportant)
- result += important;
-
- result += ';';
+ result.push(t.prop + ':' + t.value + (t.isImportant ? important : ''));
}
- return result.substr(0, result.length - 1);
+ return result;
};
// Gets the final (detokenized) length of the given tokens
// TODO: broken due to joining/splitting
if (lastToken.selector && token.selector.join(',') == lastToken.selector.join(',')) {
var joinAt = [lastToken.body.length];
- // TODO: broken due to joining/splitting
- lastToken.body = this.propertyOptimizer.process(lastToken.body.concat(token.body).join(';'), joinAt, false, token.selector.join(',')).split(';');
+ lastToken.body = this.propertyOptimizer.process(token.selector, lastToken.body.concat(token.body), joinAt, false);
forRemoval.push(i);
// TODO: broken due to joining/splitting
} else if (lastToken.body && token.body.join(';') == lastToken.body.join(';') && !this.isSpecial(token.selector.join(',')) && !this.isSpecial(lastToken.selector.join(','), this.options)) {
[complexSelector.join(',')];
for (var j = 0, m = selectors.length; j < m; j++) {
- // TODO: broken due to joining/splitting
var selector = selectors[j];
if (!candidates[selector])
var where = data[j].where;
var token = tokens[where];
var body = token.body;
- // TODO: broken due to joining/splitting
- bodies.push(body.join(';'));
+
+ bodies = bodies.concat(body);
splitBodies.push(body);
processedTokens.push(where);
}
- for (j = 0, m = bodies.length; j < m; j++) {
- if (bodies[j].length > 0)
+ for (j = 0, m = splitBodies.length; j < m; j++) {
+ if (splitBodies[j].length > 0)
joinsAt.push((joinsAt[j - 1] || 0) + splitBodies[j].length);
}
- // TODO: broken due to joining/splitting
- var optimizedBody = this.propertyOptimizer.process(bodies.join(';'), joinsAt, true, selector);
- var optimizedProperties = optimizedBody.split(';');
+ var optimizedBody = this.propertyOptimizer.process(selector, bodies, joinsAt, true);
+ var optimizedProperties = optimizedBody;
var processedCount = processedTokens.length;
var propertyIdx = optimizedProperties.length - 1;
var token = tokens[i];
if (token.selector) {
- // TODO: broken due to joining/splitting
- token.body = propertyOptimizer.process(token.body.join(';'), false, false, token.selector.join(',')).split(';');
+ token.body = propertyOptimizer.process(token.selector, token.body, false, false);
} else if (token.block) {
optimizeProperties(token.body, propertyOptimizer);
}