mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
improve import support with media features
This commit is contained in:
@@ -6,6 +6,7 @@ tree.Directive = function (name, value, features) {
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
this.ruleset = new(tree.Ruleset)([], value);
|
||||
this.ruleset.allowImports = true;
|
||||
} else {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,12 @@ tree.Import.prototype = {
|
||||
}
|
||||
},
|
||||
eval: function (env) {
|
||||
var ruleset;
|
||||
var ruleset, features = this.features && this.features.eval(env);
|
||||
|
||||
if (this.css) {
|
||||
this.features = this.features && this.features.eval(env);
|
||||
return this;
|
||||
} else {
|
||||
ruleset = new(tree.Ruleset)(null, this.root.rules.slice(0));
|
||||
ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
|
||||
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.Import) {
|
||||
@@ -73,7 +72,7 @@ tree.Import.prototype = {
|
||||
[i, 1].concat(ruleset.rules[i].eval(env)));
|
||||
}
|
||||
}
|
||||
return ruleset.rules;
|
||||
return this.features ? new(tree.Directive)('@media', ruleset.rules, this.features.value) : ruleset.rules;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,12 +11,13 @@ tree.Ruleset.prototype = {
|
||||
var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0));
|
||||
|
||||
ruleset.root = this.root;
|
||||
ruleset.allowImports = this.allowImports;
|
||||
|
||||
// push the current ruleset to the frames stack
|
||||
env.frames.unshift(ruleset);
|
||||
|
||||
// Evaluate imports
|
||||
if (ruleset.root) {
|
||||
if (ruleset.root || ruleset.allowImports) {
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.Import) {
|
||||
Array.prototype.splice
|
||||
|
||||
5
test/css/import.css
vendored
5
test/css/import.css
vendored
@@ -16,3 +16,8 @@
|
||||
width: 10px;
|
||||
height: 30%;
|
||||
}
|
||||
@media screen and (max-width: 600px) {
|
||||
body {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
1
test/less/import.less
vendored
1
test/less/import.less
vendored
@@ -8,3 +8,4 @@
|
||||
width: 10px;
|
||||
height: @a + 10%;
|
||||
}
|
||||
@import "import/import-test-e" screen and (max-width: 600px);
|
||||
|
||||
2
test/less/import/import-test-e.less
Normal file
2
test/less/import/import-test-e.less
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
body { width: 100% }
|
||||
Reference in New Issue
Block a user