[Pkg-javascript-commits] [less.js] 51/88: make mixin definitions have similar coding style to detached rulesets for grabbing frames

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:25 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 88b44dfc43d9dd9e11a8993be8635ed85d359715
Author: Luke Page <luke.a.page at gmail.com>
Date:   Mon Feb 17 19:50:43 2014 +0000

    make mixin definitions have similar coding style to detached rulesets for grabbing frames
---
 lib/less/tree/detached-ruleset.js |  3 +--
 lib/less/tree/mixin.js            | 13 ++++++++-----
 lib/less/tree/ruleset.js          |  6 +++---
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/less/tree/detached-ruleset.js b/lib/less/tree/detached-ruleset.js
index 87e76f2..0a5512a 100644
--- a/lib/less/tree/detached-ruleset.js
+++ b/lib/less/tree/detached-ruleset.js
@@ -10,12 +10,11 @@ tree.DetachedRuleset.prototype = {
         this.ruleset = visitor.visit(this.ruleset);
     },
     eval: function (env) {
-        // TODO - handle mixin definition like this
         var frames = this.frames || env.frames.slice(0);
         return new tree.DetachedRuleset(this.ruleset, frames);
     },
     callEval: function (env) {
-        return this.ruleset.eval(new(tree.evalEnv)(env, this.frames.concat(env.frames)));
+        return this.ruleset.eval(this.frames ? new(tree.evalEnv)(env, this.frames.concat(env.frames)) : env);
     }
 };
 })(require('../tree'));
diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js
index 1d903e8..506561b 100644
--- a/lib/less/tree/mixin.js
+++ b/lib/less/tree/mixin.js
@@ -103,7 +103,7 @@ tree.mixin.Call.prototype = {
                                 mixin.originalRuleset = mixins[m].originalRuleset || mixins[m];
                             }
                             Array.prototype.push.apply(
-                                  rules, mixin.eval(env, args, this.important).rules);
+                                  rules, mixin.evalCall(env, args, this.important).rules);
                         } catch (e) {
                             throw { message: e.message, index: this.index, filename: this.currentFileInfo.filename, stack: e.stack };
                         }
@@ -150,7 +150,7 @@ tree.mixin.Call.prototype = {
     }
 };
 
-tree.mixin.Definition = function (name, params, rules, condition, variadic) {
+tree.mixin.Definition = function (name, params, rules, condition, variadic, frames) {
     this.name = name;
     this.selectors = [new(tree.Selector)([new(tree.Element)(null, name, this.index, this.currentFileInfo)])];
     this.params = params;
@@ -164,7 +164,7 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) {
         else                                 { return count; }
     }, 0);
     this.parent = tree.Ruleset.prototype;
-    this.frames = [];
+    this.frames = frames;
 };
 tree.mixin.Definition.prototype = {
     type: "MixinDefinition",
@@ -258,9 +258,12 @@ tree.mixin.Definition.prototype = {
 
         return frame;
     },
-    eval: function (env, args, important) {
+    eval: function (env) {
+        return new tree.mixin.Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || env.frames.slice(0));
+    },
+    evalCall: function (env, args, important) {
         var _arguments = [],
-            mixinFrames = this.frames.concat(env.frames),
+            mixinFrames = this.frames ? this.frames.concat(env.frames) : env.frames,
             frame = this.evalParams(env, new(tree.evalEnv)(env, mixinFrames), args, _arguments),
             rules, ruleset;
 
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index 3ec0706..7571b0e 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -66,8 +66,8 @@ tree.Ruleset.prototype = {
         // so they can be evaluated like closures when the time comes.
         var rsRules = ruleset.rules, rsRuleCnt = rsRules ? rsRules.length : 0;
         for (i = 0; i < rsRuleCnt; i++) {
-            if (rsRules[i] instanceof tree.mixin.Definition) {
-                rsRules[i].frames = envFrames.slice(0);
+            if (rsRules[i] instanceof tree.mixin.Definition || rsRules[i] instanceof tree.DetachedRuleset) {
+                rsRules[i] = rsRules[i].eval(env);
             }
         }
 
@@ -109,7 +109,7 @@ tree.Ruleset.prototype = {
         // Evaluate everything else
         for (i = 0; i < rsRules.length; i++) {
             rule = rsRules[i];
-            if (! (rule instanceof tree.mixin.Definition)) {
+            if (! (rule instanceof tree.mixin.Definition || rule instanceof tree.DetachedRuleset)) {
                 rsRules[i] = rule = rule.eval ? rule.eval(env) : rule;
                 // for rulesets, check if it is a css guard and can be removed
                 if (rule instanceof tree.Ruleset && rule.selectors && rule.selectors.length === 1) {

-- 
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