8000 fixed a bug when using @media with mixins · rusongyu/less.js@1ba622d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ba622d

Browse files
committed
fixed a bug when using @media with mixins
1 parent 081c26d commit 1ba622d

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

lib/less/tree/media.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ tree.Media.prototype = {
2222
env.mediaBlocks = [];
2323
env.mediaPath = [];
2424
}
25-
26-
env.mediaBlocks.push(this);
25+
26+
var blockIndex = env.mediaBlocks.length;
2727
env.mediaPath.push(this);
28+
env.mediaBlocks.push(this);
2829

29-
this.features = this.features.eval(env);
30-
env.frames.unshift(this);
31-
this.ruleset = this.ruleset.eval(env);
30+
var media = new(tree.Media)([], []);
31+
media.features = this.features.eval(env);
32+
33+
env.frames.unshift(this.ruleset);
34+
media.ruleset = this.ruleset.eval(env);
3235
env.frames.shift();
33-
36+
37+
env.mediaBlocks[blockIndex] = media;
3438
env.mediaPath.pop();
3539

36-
if (env.mediaPath.length === 0) {
37-
return this.evalTop(env);
38-
} else {
39-
return this.evalNested(env);
40-
}
40+
return env.mediaPath.length === 0 ? media.evalTop(env) :
41+
media.evalNested(env)
4142
},
4243
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
4344
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
@@ -93,9 +94,9 @@ tree.Media.prototype = {
9394
return new(tree.Ruleset)([], []);
9495
},
9596
permute: function (arr) {
96-
if (arr.length == 0) {
97+
if (arr.length === 0) {
9798
return [];
98-
} else if (arr.length == 1) {
99+
} else if (arr.length === 1) {
99100
return arr[0];
100101
} else {
101102
var result = [];

test/css/media.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,29 @@
4848
width: 100%;
4949
}
5050
}
51+
.a {
52+
background: black;
53+
}
54+
@media handheld {
55+
.a {
56+
background: white;
57+
}
58+
}
59+
@media handheld and (max-width: 100px) {
60+
.a {
61+
background: red;
62+
}
63+
}
64+
.b {
65+
background: black;
66+
}
67+
@media handheld {
68+
.b {
69+
background: white;
70+
}
71+
}
72+
@media handheld and (max-width: 200px) {
73+
.b {
74+
background: red;
75+
}
76+
}

test/less/media.less

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,24 @@ body {
5252
width: 100%;
5353
}
5454
}
55+
}
56+
57+
.mediaMixin(@fallback: 200px) {
58+
background: black;
59+
60+
@media handheld {
61+
background: white;
62+
63+
@media (max-width: @fallback) {
64+
background: red;
65+
}
66+
}
67+
}
68+
69+
.a {
70+
.mediaMixin(100px);
71+
}
72+
73+
.b {
74+
.mediaMixin();
5575
}

0 commit comments

Comments
 (0)
0