var BACKSLASH_HACK = '\\';
-var IMPORTANT_TOKEN = '!important';
+var IMPORTANT_WORD = 'important';
+var IMPORTANT_TOKEN = '!'+IMPORTANT_WORD;
+var IMPORTANT_WORD_MATCH = new RegExp(IMPORTANT_WORD+'$', 'i');
+var IMPORTANT_TOKEN_MATCH = new RegExp(IMPORTANT_TOKEN+'$', 'i');
var STAR_HACK = '*';
var UNDERSCORE_HACK = '_';
var BANG_HACK = '!';
type = 'underscore';
} else if (name[0] == STAR_HACK) {
type = 'star';
- } else if (lastValue[0][0] == BANG_HACK && lastValue[0].indexOf('important') == -1) {
+ } else if (lastValue[0][0] == BANG_HACK && !lastValue[0].match(IMPORTANT_WORD_MATCH)) {
type = 'bang';
- } else if (lastValue[0].indexOf(BANG_HACK) > 0 && lastValue[0].indexOf('important') == -1) {
+ } else if (lastValue[0].indexOf(BANG_HACK) > 0 && !lastValue[0].match(IMPORTANT_WORD_MATCH)) {
type = 'bang';
} else if (lastValue[0].indexOf(BACKSLASH_HACK) > 0 && lastValue[0].indexOf(BACKSLASH_HACK) == lastValue[0].length - BACKSLASH_HACK.length - 1) {
type = 'backslash';
}
function isImportant(property) {
- return property.length > 1 ?
- property[property.length - 1][0].indexOf(IMPORTANT_TOKEN) > 0 :
- false;
+ if (property.length > 1) {
+ var p = property[property.length - 1][0];
+ if (typeof(p) === 'string') {
+ return IMPORTANT_TOKEN_MATCH.test(p);
+ }
+ }
+ return false;
}
function stripImportant(property) {
if (property.length > 0)
- property[property.length - 1][0] = property[property.length - 1][0].replace(IMPORTANT_TOKEN, '');
+ property[property.length - 1][0] = property[property.length - 1][0].replace(IMPORTANT_TOKEN_MATCH, '');
}
function stripPrefixHack(property) {
var AT_RULE = 'at-rule';
+var IMPORTANT_WORD = 'important';
+var IMPORTANT_TOKEN = '!'+IMPORTANT_WORD;
+var IMPORTANT_WORD_MATCH = new RegExp('^'+IMPORTANT_WORD+'$', 'i');
+var IMPORTANT_TOKEN_MATCH = new RegExp('^'+IMPORTANT_TOKEN+'$', 'i');
+
function selectorName(value) {
return value[0];
}
}
var pos = body.length - 1;
- if (trimmed == 'important' && body[pos][0] == '!') {
+ if (IMPORTANT_WORD_MATCH.test(trimmed) && body[pos][0] == '!') {
context.track(trimmed);
- body[pos - 1][0] += '!important';
+ body[pos - 1][0] += IMPORTANT_TOKEN;
body.pop();
continue;
}
- if (trimmed == '!important' || (trimmed == 'important' && body[pos][0][body[pos][0].length - 1] == '!')) {
+ if (IMPORTANT_TOKEN_MATCH.test(trimmed) || (IMPORTANT_WORD_MATCH.test(trimmed) && body[pos][0][body[pos][0].length - 1] == '!')) {
context.track(trimmed);
body[pos][0] += trimmed;
continue;
'space between ! and important': [
'body{background-color:#fff ! important}',
'body{background-color:#fff!important}'
+ ],
+ 'Capital letters': [
+ 'a{color: red !ImporTant }',
+ 'a{color:red!important}'
+ ],
+ 'Match word': [
+ 'a{color: red !importante }',
+ ''
]
})
)