[Pkg-javascript-commits] [less.js] 72/88: Do not evaluate css with guards if the guards fail. Fixes #1873
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:22:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v1.7.0
in repository less.js.
commit 5ab0e086657d926a1bec4c5fb6af6740de178b7d
Author: Luke Page <luke.a.page at gmail.com>
Date: Fri Feb 21 12:37:40 2014 +0000
Do not evaluate css with guards if the guards fail. Fixes #1873
---
lib/less/tree/ruleset.js | 20 ++++++++++++++------
test/less/css-guards.less | 3 +++
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index d657976..1902300 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -20,7 +20,8 @@ tree.Ruleset.prototype = {
},
eval: function (env) {
var thisSelectors = this.selectors, selectors,
- selCnt, i, defaultFunc = tree.defaultFunc;
+ selCnt, selector, i, defaultFunc = tree.defaultFunc, hasOnePassingSelector = false;
+
if (thisSelectors && (selCnt = thisSelectors.length)) {
selectors = [];
defaultFunc.error({
@@ -28,9 +29,15 @@ tree.Ruleset.prototype = {
message: "it is currently only allowed in parametric mixin guards,"
});
for (i = 0; i < selCnt; i++) {
- selectors.push(thisSelectors[i].eval(env));
+ selector = thisSelectors[i].eval(env);
+ selectors.push(selector);
+ if (selector.evaldCondition) {
+ hasOnePassingSelector = true;
+ }
}
defaultFunc.reset();
+ } else {
+ hasOnePassingSelector = true;
}
var rules = this.rules ? this.rules.slice(0) : null,
@@ -45,6 +52,10 @@ tree.Ruleset.prototype = {
if(this.debugInfo) {
ruleset.debugInfo = this.debugInfo;
}
+
+ if (!hasOnePassingSelector) {
+ rules.length = 0;
+ }
// push the current ruleset to the frames stack
var envFrames = env.frames;
@@ -122,10 +133,7 @@ tree.Ruleset.prototype = {
// check if it can be folded in (e.g. & where)
if (rule.selectors[0].isJustParentSelector()) {
rsRules.splice(i--, 1);
- // cannot call if there is no selector, so we can just continue
- if (!rule.selectors[0].evaldCondition) {
- continue;
- }
+
for(var j = 0; j < rule.rules.length; j++) {
subRule = rule.rules[j];
if (!(subRule instanceof tree.Rule) || !subRule.variable) {
diff --git a/test/less/css-guards.less b/test/less/css-guards.less
index 6dd1cd6..85ec8d2 100644
--- a/test/less/css-guards.less
+++ b/test/less/css-guards.less
@@ -97,3 +97,6 @@
.scope-check();
@k:4px;
}
+.errors-if-called when (@c = never) {
+ .mixin-doesnt-exist();
+}
\ No newline at end of file
--
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