!this.isSpecial(token.metadata.selector) && !this.isSpecial(lastToken.metadata.selector)) {
changeSelectorOf(
lastToken,
- CleanUp.selectors(lastToken.value.concat(token.value))
+ CleanUp.selectors(lastToken.value.concat(token.value), false)
);
forRemoval.push(i);
} else {
}
var CleanUp = {
- selectors: function (selectors) {
+ selectors: function (selectors, removeUnsupported) {
var plain = [];
var tokenized = [];
for (var i = 0, l = selectors.length; i < l; i++) {
var selector = selectors[i];
- var value = selector.value;
- var reduced = value
- .replace(/\s/g, ' ')
- .replace(/\s{2,}/g, ' ')
+ var reduced = selector.value
+ .replace(/\s+/g, ' ')
.replace(/ ?, ?/g, ',')
.replace(/\s*([>\+\~])\s*/g, '$1')
.trim();
- if (value.indexOf('*') > -1) {
+ if (removeUnsupported && (reduced.indexOf('*+html ') != -1 || reduced.indexOf('*:first-child+html ') != -1))
+ continue;
+
+ if (reduced.indexOf('*') > -1) {
reduced = reduced
.replace(/\*([:#\.\[])/g, '$1')
.replace(/^(\:first\-child)?\+html/, '*$1+html');
}
- if (value.indexOf('[') > -1)
+ if (reduced.indexOf('[') > -1)
reduced = reduced.replace(/\[([^\]]+)\]/g, removeWhitespace);
if (plain.indexOf(reduced) == -1) {
options.updateMetadata = this.options.advanced;
}
-function removeUnsupported(selectors, options) {
- if (options.compatibility.selectors.ie7Hack)
- return selectors;
-
- var supported = [];
- var values = [];
- for (var i = 0, l = selectors.tokenized.length; i < l; i++) {
- var selector = selectors.tokenized[i];
-
- if (selector.value.indexOf('*+html ') === -1 && selector.value.indexOf('*:first-child+html ') === -1) {
- supported.push(selector);
- values.push(selector.value);
- }
- }
-
- return {
- tokenized: supported,
- list: values
- };
-}
-
var valueMinifiers = {
'background': function (value) {
return value == 'none' || value == 'transparent' ? '0 0' : value;
break;
if (token.kind == 'selector') {
- var newSelectors = removeUnsupported(CleanUp.selectors(token.value), options);
+ var newSelectors = CleanUp.selectors(token.value, !options.compatibility.selectors.ie7Hack);
token.value = newSelectors.tokenized;
if (token.value.length === 0) {