Fix variables with important to be consistent - Fixes #2286

This commit is contained in:
Luke Page
2014-11-15 11:07:10 +00:00
parent 0037a8d2d7
commit 27dea8ed2b
5 changed files with 22 additions and 2 deletions

View File

@@ -49,13 +49,15 @@ var evalCopyProperties = [
'importMultiple', // whether we are currently importing multiple copies
'urlArgs', // whether to add args into url tokens
'javascriptEnabled',// option - whether JavaScript is enabled. if undefined, defaults to true
'pluginManager' // Used as the plugin manager for the session
'pluginManager', // Used as the plugin manager for the session
'importantScope' // used to bubble up !important statements
];
contexts.Eval = function(options, frames) {
copyFromOriginal(options, this, evalCopyProperties);
this.frames = frames || [];
this.importantScope = this.importantScope || [];
};
contexts.Eval.prototype.inParenthesis = function () {

View File

@@ -52,16 +52,22 @@ Rule.prototype.eval = function (context) {
context.strictMath = true;
}
try {
context.importantScope.push({});
evaldValue = this.value.eval(context);
if (!this.variable && evaldValue.type === "DetachedRuleset") {
throw { message: "Rulesets cannot be evaluated on a property.",
index: this.index, filename: this.currentFileInfo.filename };
}
var important = this.important,
importantResult = context.importantScope.pop();
if (!important && importantResult.important) {
important = importantResult.important;
}
return new Rule(name,
evaldValue,
this.important,
important,
this.merge,
this.index, this.currentFileInfo, this.inline,
variable);

View File

@@ -26,6 +26,10 @@ Variable.prototype.eval = function (context) {
variable = this.find(context.frames, function (frame) {
var v = frame.variable(name);
if (v) {
if (v.important) {
var importantScope = context.importantScope[context.importantScope.length-1];
importantScope.important = v.important;
}
return v.value.eval(context);
}
});

View File

@@ -17,6 +17,9 @@
minus-one: -1;
font-family: 'Trebuchet', 'Trebuchet', 'Trebuchet';
color: #888888 !important;
same-color: #888888 !important;
same-again: #888888 !important;
multi-important: #888888 #888888, 'Trebuchet' !important;
multi: something 'A', B, C, 'Trebuchet';
}
.variable-names {

View File

@@ -36,12 +36,17 @@
zero: @var;
}
@important-var: @c !important;
@important-var-two: @a !important;
.values {
minus-one: @var;
@a: 'Trebuchet';
@multi: 'A', B, C;
font-family: @a, @a, @a;
color: @c !important;
same-color: @important-var;
same-again: @important-var !important;
multi-important: @important-var @important-var, @important-var-two;
multi: something @multi, @a;
}