[Pkg-javascript-commits] [less.js] 06/26: Fix variables with important to be consistent - Fixes #2286
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:25:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.1.0
in repository less.js.
commit 27dea8ed2b54eec89e6173caeb7950831df8c28f
Author: Luke Page <luke.a.page at gmail.com>
Date: Sat Nov 15 11:07:10 2014 +0000
Fix variables with important to be consistent - Fixes #2286
---
lib/less/contexts.js | 4 +++-
lib/less/tree/rule.js | 8 +++++++-
lib/less/tree/variable.js | 4 ++++
test/css/variables.css | 3 +++
test/less/variables.less | 5 +++++
5 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/lib/less/contexts.js b/lib/less/contexts.js
index e3de368..39ab0a4 100644
--- a/lib/less/contexts.js
+++ b/lib/less/contexts.js
@@ -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 () {
diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js
index 402ebc5..119cbaf 100644
--- a/lib/less/tree/rule.js
+++ b/lib/less/tree/rule.js
@@ -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);
diff --git a/lib/less/tree/variable.js b/lib/less/tree/variable.js
index b19dd21..d6b7919 100644
--- a/lib/less/tree/variable.js
+++ b/lib/less/tree/variable.js
@@ -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);
}
});
diff --git a/test/css/variables.css b/test/css/variables.css
index 1f27920..9c704a4 100644
--- a/test/css/variables.css
+++ b/test/css/variables.css
@@ -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 {
diff --git a/test/less/variables.less b/test/less/variables.less
index d45293f..f0b92ea 100644
--- a/test/less/variables.less
+++ b/test/less/variables.less
@@ -36,12 +36,17 @@
zero: @var;
}
+ at important-var: @c !important;
+ at 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;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list