mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Basic functionality and basic tests for import silent
This commit is contained in:
@@ -1168,7 +1168,7 @@ less.Parser = function Parser(env) {
|
||||
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') { break }
|
||||
}
|
||||
|
||||
if (elements.length > 0) { return new(tree.Selector)(elements, extendList); }
|
||||
if (elements.length > 0) { return new(tree.Selector)(elements, extendList, i, env.currentFileInfo); }
|
||||
if (extendList.length) { error("Extend must be used to extend a selector, it cannot be used on its own"); }
|
||||
},
|
||||
attribute: function () {
|
||||
|
||||
@@ -241,24 +241,36 @@ tree.Ruleset.prototype = {
|
||||
} else {
|
||||
if (rules.length > 0) {
|
||||
debugInfo = tree.debugInfo(env, this);
|
||||
selector = this.paths.map(function (p) {
|
||||
return p.map(function (s) {
|
||||
return s.toCSS(env);
|
||||
}).join('').trim();
|
||||
}).join(env.compress ? ',' : ',\n');
|
||||
selector = this.paths
|
||||
.filter(function(p) {
|
||||
var i;
|
||||
for(i = 0; i < p.length; i++) {
|
||||
if (!p[i].isSilent()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.map(function (p) {
|
||||
return p.map(function (s) {
|
||||
return s.toCSS(env);
|
||||
}).join('').trim();
|
||||
}).join(env.compress ? ',' : ',\n');
|
||||
|
||||
// Remove duplicates
|
||||
for (var i = rules.length - 1; i >= 0; i--) {
|
||||
if (rules[i].slice(0, 2) === "/*" || _rules.indexOf(rules[i]) === -1) {
|
||||
_rules.unshift(rules[i]);
|
||||
if (selector) {
|
||||
// Remove duplicates
|
||||
for (var i = rules.length - 1; i >= 0; i--) {
|
||||
if (rules[i].slice(0, 2) === "/*" || _rules.indexOf(rules[i]) === -1) {
|
||||
_rules.unshift(rules[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
rules = _rules;
|
||||
rules = _rules;
|
||||
|
||||
css.push(debugInfo + selector +
|
||||
(env.compress ? '{' : ' {\n ') +
|
||||
rules.join(env.compress ? '' : '\n ') +
|
||||
(env.compress ? '}' : '\n}\n'));
|
||||
css.push(debugInfo + selector +
|
||||
(env.compress ? '{' : ' {\n ') +
|
||||
rules.join(env.compress ? '' : '\n ') +
|
||||
(env.compress ? '}' : '\n}\n'));
|
||||
}
|
||||
}
|
||||
}
|
||||
css.push(rulesets);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Selector = function (elements, extendList) {
|
||||
tree.Selector = function (elements, extendList, index, currentFileInfo) {
|
||||
this.elements = elements;
|
||||
this.extendList = extendList || [];
|
||||
this.currentFileInfo = currentFileInfo || {}; // TODO remove
|
||||
};
|
||||
tree.Selector.prototype = {
|
||||
type: "Selector",
|
||||
@@ -36,7 +37,7 @@ tree.Selector.prototype = {
|
||||
return e.eval(env);
|
||||
}), this.extendList.map(function(extend) {
|
||||
return extend.eval(env);
|
||||
}));
|
||||
}), this.index, this.currentFileInfo);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
if (this._css) { return this._css }
|
||||
@@ -56,6 +57,9 @@ tree.Selector.prototype = {
|
||||
}).join('');
|
||||
|
||||
return this._css;
|
||||
},
|
||||
isSilent: function() {
|
||||
return this.currentFileInfo.silent;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
3
test/css/import-silent.css
Normal file
3
test/css/import-silent.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.b {
|
||||
color: red;
|
||||
}
|
||||
6
test/less/import-silent.less
Normal file
6
test/less/import-silent.less
Normal file
@@ -0,0 +1,6 @@
|
||||
@import (silent) url("import-once.less");
|
||||
@import (silent) url("import/import-silent.less");
|
||||
|
||||
.b {
|
||||
.a();
|
||||
}
|
||||
3
test/less/import/import-silent.less
Normal file
3
test/less/import/import-silent.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.a {
|
||||
color: red;
|
||||
}
|
||||
Reference in New Issue
Block a user