From 1ba622dd8dc8a44f072a9e5a89bf19986313d2cd Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 17 Feb 2012 11:57:31 +0100 Subject: [PATCH] fixed a bug when using @media with mixins --- lib/less/tree/media.js | 27 ++++++++++++++------------- test/css/media.css | 26 ++++++++++++++++++++++++++ test/less/media.less | 20 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/lib/less/tree/media.js b/lib/less/tree/media.js index 4b5d44db..2b7b26e5 100644 --- a/lib/less/tree/media.js +++ b/lib/less/tree/media.js @@ -22,22 +22,23 @@ tree.Media.prototype = { env.mediaBlocks = []; env.mediaPath = []; } - - env.mediaBlocks.push(this); + + var blockIndex = env.mediaBlocks.length; env.mediaPath.push(this); + env.mediaBlocks.push(this); - this.features = this.features.eval(env); - env.frames.unshift(this); - this.ruleset = this.ruleset.eval(env); + var media = new(tree.Media)([], []); + media.features = this.features.eval(env); + + env.frames.unshift(this.ruleset); + media.ruleset = this.ruleset.eval(env); env.frames.shift(); - + + env.mediaBlocks[blockIndex] = media; env.mediaPath.pop(); - if (env.mediaPath.length === 0) { - return this.evalTop(env); - } else { - return this.evalNested(env); - } + return env.mediaPath.length === 0 ? media.evalTop(env) : + media.evalNested(env) }, variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) }, find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) }, @@ -93,9 +94,9 @@ tree.Media.prototype = { return new(tree.Ruleset)([], []); }, permute: function (arr) { - if (arr.length == 0) { + if (arr.length === 0) { return []; - } else if (arr.length == 1) { + } else if (arr.length === 1) { return arr[0]; } else { var result = []; diff --git a/test/css/media.css b/test/css/media.css index a591017e..bbfad74d 100644 --- a/test/css/media.css +++ b/test/css/media.css @@ -48,3 +48,29 @@ width: 100%; } } +.a { + background: black; +} +@media handheld { + .a { + background: white; + } +} +@media handheld and (max-width: 100px) { + .a { + background: red; + } +} +.b { + background: black; +} +@media handheld { + .b { + background: white; + } +} +@media handheld and (max-width: 200px) { + .b { + background: red; + } +} diff --git a/test/less/media.less b/test/less/media.less index 6a3749b7..1196a524 100644 --- a/test/less/media.less +++ b/test/less/media.less @@ -52,4 +52,24 @@ body { width: 100%; } } +} + +.mediaMixin(@fallback: 200px) { + background: black; + + @media handheld { + background: white; + + @media (max-width: @fallback) { + background: red; + } + } +} + +.a { + .mediaMixin(100px); +} + +.b { + .mediaMixin(); } \ No newline at end of file