[Pkg-javascript-commits] [less.js] 50/88: Fix some bugs with detached rulesets and media queries
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 baba33ea6a1a4b9a42fa07870c14581a78e05559
Author: Luke Page <luke.a.page at gmail.com>
Date: Mon Feb 17 19:15:47 2014 +0000
Fix some bugs with detached rulesets and media queries
---
build/build.yml | 1 +
lib/less/index.js | 1 +
lib/less/parser.js | 14 +++++++++++---
lib/less/tree/detached-ruleset.js | 21 +++++++++++++++++++++
lib/less/tree/rule.js | 2 +-
lib/less/tree/ruleset-call.js | 3 ++-
lib/less/tree/ruleset.js | 3 +++
test/css/detached-rulesets.css | 25 ++++++++++++++++---------
test/less/detached-rulesets.less | 10 ++++++----
9 files changed, 62 insertions(+), 18 deletions(-)
diff --git a/build/build.yml b/build/build.yml
index 68fa260..b5a2234 100644
--- a/build/build.yml
+++ b/build/build.yml
@@ -127,6 +127,7 @@ tree:
- <%= build.lib %>/tree/color.js
- <%= build.lib %>/tree/comment.js
- <%= build.lib %>/tree/condition.js
+ - <%= build.lib %>/tree/detached-ruleset.js
- <%= build.lib %>/tree/dimension.js
- <%= build.lib %>/tree/directive.js
- <%= build.lib %>/tree/element.js
diff --git a/lib/less/index.js b/lib/less/index.js
index b85a84f..a18b817 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -94,6 +94,7 @@ var less = {
require('./tree/color');
require('./tree/directive');
+require('./tree/detached-ruleset');
require('./tree/operation');
require('./tree/dimension');
require('./tree/keyword');
diff --git a/lib/less/parser.js b/lib/less/parser.js
index 7e0c4a2..032381d 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -1145,7 +1145,7 @@ less.Parser = function Parser(env) {
while (true) {
if (isCall) {
- arg = parsers.blockRuleset() || parsers.expression();
+ arg = parsers.detachedRuleset() || parsers.expression();
} else {
parsers.comments();
if (input.charAt(i) === '.' && $re(/^\.{3}/)) {
@@ -1192,7 +1192,7 @@ less.Parser = function Parser(env) {
// we do not support setting a ruleset as a default variable - it doesn't make sense
// However if we do want to add it, there is nothing blocking it, just don't error
// and remove isCall dependency below
- value = (isCall && parsers.blockRuleset()) || parsers.expression();
+ value = (isCall && parsers.detachedRuleset()) || parsers.expression();
if (!value) {
if (isCall) {
@@ -1491,11 +1491,19 @@ less.Parser = function Parser(env) {
blockRuleset: function() {
var block = this.block();
+
if (block) {
block = new tree.Ruleset(null, block);
}
return block;
},
+
+ detachedRuleset: function() {
+ var blockRuleset = this.blockRuleset();
+ if (blockRuleset) {
+ return new tree.DetachedRuleset(blockRuleset);
+ }
+ },
//
// div, .class, body > p {...}
@@ -1551,7 +1559,7 @@ less.Parser = function Parser(env) {
isVariable = typeof name === "string";
if (isVariable) {
- value = this.blockRuleset();
+ value = this.detachedRuleset();
}
if (!value) {
diff --git a/lib/less/tree/detached-ruleset.js b/lib/less/tree/detached-ruleset.js
new file mode 100644
index 0000000..87e76f2
--- /dev/null
+++ b/lib/less/tree/detached-ruleset.js
@@ -0,0 +1,21 @@
+(function (tree) {
+
+tree.DetachedRuleset = function (ruleset, frames) {
+ this.ruleset = ruleset;
+ this.frames = frames;
+};
+tree.DetachedRuleset.prototype = {
+ type: "DetachedRuleset",
+ accept: function (visitor) {
+ 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)));
+ }
+};
+})(require('../tree'));
diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js
index 5567b07..4e1ccde 100644
--- a/lib/less/tree/rule.js
+++ b/lib/less/tree/rule.js
@@ -45,7 +45,7 @@ tree.Rule.prototype = {
try {
evaldValue = this.value.eval(env);
- if (!this.variable && evaldValue.type === "Ruleset") {
+ if (!this.variable && evaldValue.type === "DetachedRuleset") {
throw { message: "Rulesets cannot be evaluated on a property.",
index: this.index, filename: this.currentFileInfo.filename };
}
diff --git a/lib/less/tree/ruleset-call.js b/lib/less/tree/ruleset-call.js
index ec9e98d..a543c55 100644
--- a/lib/less/tree/ruleset-call.js
+++ b/lib/less/tree/ruleset-call.js
@@ -8,7 +8,8 @@ tree.RulesetCall.prototype = {
accept: function (visitor) {
},
eval: function (env) {
- return new(tree.Variable)(this.variable).eval(env);
+ var detachedRuleset = new(tree.Variable)(this.variable).eval(env);
+ return detachedRuleset.callEval(env);
}
};
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index 15cc80d..3ec0706 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -358,6 +358,9 @@ tree.Ruleset.prototype = {
toCSS: tree.toCSS,
markReferenced: function () {
+ if (!this.selectors) {
+ return;
+ }
for (var s = 0; s < this.selectors.length; s++) {
this.selectors[s].markReferenced();
}
diff --git a/test/css/detached-rulesets.css b/test/css/detached-rulesets.css
index b9642d4..300c08d 100644
--- a/test/css/detached-rulesets.css
+++ b/test/css/detached-rulesets.css
@@ -1,6 +1,7 @@
.wrap-selector {
color: black;
one: 1px;
+ four: magic-frame;
visible-one: visible;
visible-two: visible;
}
@@ -45,20 +46,26 @@ html.lt-ie9 header {
.without-mixins {
b: 1;
}
- at media (orientation: portrait) {
- /* .wrap-media-mixin({
- @media tv {
- .triple-wrapped-mq {
- triple: true;
- }
- }
- });*/
-}
@media (orientation: portrait) and tv {
.my-selector {
background-color: black;
}
}
+ at media (orientation: portrait) and widescreen and print and tv {
+ .triple-wrapped-mq {
+ triple: true;
+ }
+}
+ at media (orientation: portrait) and widescreen and tv {
+ .triple-wrapped-mq {
+ triple: true;
+ }
+}
+ at media (orientation: portrait) and tv {
+ .triple-wrapped-mq {
+ triple: true;
+ }
+}
.a {
test: test;
}
diff --git a/test/less/detached-rulesets.less b/test/less/detached-rulesets.less
index 5af2a74..7e12411 100644
--- a/test/less/detached-rulesets.less
+++ b/test/less/detached-rulesets.less
@@ -7,6 +7,7 @@
.wrap-mixin(@ruleset) {
@a: hidden and if you see this in the output its a bug;
@b: visible;
+ @d: magic-frame; // same behaviour as mixin calls - falls back to this frame
.wrap-selector {
@c: visible;
@ruleset();
@@ -20,6 +21,7 @@
one: @a;
@b: hidden and if you see this in the output its a bug;
@c: hidden and if you see this in the output its a bug;
+ four: @d;
});
.wrap-mixin(@ruleset: {
@@ -72,14 +74,13 @@ header {
};
@media (orientation:portrait) {
@my-ruleset();
- // doesn't work yet
-/* .wrap-media-mixin({
+ .wrap-media-mixin({
@media tv {
.triple-wrapped-mq {
triple: true;
}
}
- });*/
+ });
}
.wrap-media-mixin(@ruleset) {
@media widescreen {
@@ -99,4 +100,5 @@ header {
@my-mixins();
.a {
.mixin();
-}
\ No newline at end of file
+}
+// Same fallback frame behaviour as mixin calls
\ 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