import silent to work with media queries and directives

This commit is contained in:
Luke Page
2013-03-21 16:38:56 +00:00
parent b912a971d3
commit aa802bd84c
7 changed files with 53 additions and 18 deletions

View File

@@ -1379,7 +1379,7 @@ less.Parser = function Parser(env) {
features = $(this.mediaFeatures);
if (rules = $(this.block)) {
media = new(tree.Media)(rules, features);
media = new(tree.Media)(rules, features, i, env.currentFileInfo);
if(env.dumpLineNumbers)
media.debugInfo = debugInfo;
return media;
@@ -1455,11 +1455,11 @@ less.Parser = function Parser(env) {
if (hasBlock)
{
if (rules = $(this.block)) {
return new(tree.Directive)(name, rules);
return new(tree.Directive)(name, rules, i, env.currentFileInfo);
}
} else {
if ((value = hasExpression ? $(this.expression) : $(this.entity)) && $(';')) {
var directive = new(tree.Directive)(name, value);
var directive = new(tree.Directive)(name, value, i, env.currentFileInfo);
if (env.dumpLineNumbers) {
directive.debugInfo = getDebugInfo(i, input, env);
}

View File

@@ -1,6 +1,6 @@
(function (tree) {
tree.Directive = function (name, value) {
tree.Directive = function (name, value, index, currentFileInfo) {
this.name = name;
if (Array.isArray(value)) {
@@ -9,6 +9,7 @@ tree.Directive = function (name, value) {
} else {
this.value = value;
}
this.currentFileInfo = currentFileInfo;
};
tree.Directive.prototype = {
type: "Directive",
@@ -17,6 +18,11 @@ tree.Directive.prototype = {
this.value = visitor.visit(this.value);
},
toCSS: function (env) {
if (this.currentFileInfo.silent) {
return "";
}
if (this.ruleset) {
this.ruleset.root = true;
return this.name + (env.compress ? '{' : ' {\n ') +
@@ -30,7 +36,7 @@ tree.Directive.prototype = {
var evaldDirective = this;
if (this.ruleset) {
env.frames.unshift(this);
evaldDirective = new(tree.Directive)(this.name);
evaldDirective = new(tree.Directive)(this.name, null, this.index, this.currentFileInfo);
evaldDirective.ruleset = this.ruleset.eval(env);
env.frames.shift();
}

View File

@@ -1,6 +1,9 @@
(function (tree) {
tree.Media = function (value, features) {
tree.Media = function (value, features, index, currentFileInfo) {
this.index = index;
this.currentFileInfo = currentFileInfo;
var selectors = this.emptySelectors();
this.features = new(tree.Value)(features);
@@ -16,9 +19,14 @@ tree.Media.prototype = {
toCSS: function (env) {
var features = this.features.toCSS(env);
return '@media ' + features + (env.compress ? '{' : ' {\n ') +
this.ruleset.toCSS(env).trim().replace(/\n/g, '\n ') +
(env.compress ? '}': '\n}\n');
var content = this.ruleset.toCSS(env).trim().replace(/\n/g, '\n ');
if (content.match(/\S/)) {
return '@media ' + features + (env.compress ? '{' : ' {\n ') + content +
(env.compress ? '}': '\n}\n');
} else {
return "";
}
},
eval: function (env) {
if (!env.mediaBlocks) {
@@ -26,7 +34,7 @@ tree.Media.prototype = {
env.mediaPath = [];
}
var media = new(tree.Media)([], []);
var media = new(tree.Media)([], [], this.index, this.currentFileInfo);
if(this.debugInfo) {
this.ruleset.debugInfo = this.debugInfo;
media.debugInfo = this.debugInfo;
@@ -62,7 +70,7 @@ tree.Media.prototype = {
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
emptySelectors: function() {
var el = new(tree.Element)('', '&', 0);
return [new(tree.Selector)([el])];
return [new(tree.Selector)([el], null, this.index, this.currentFileInfo)];
},
evalTop: function (env) {