mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Fix variables with important to be consistent - Fixes #2286
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user