mirror of
https://github.com/less/less.js.git
synced 2026-01-22 13:48:03 -05:00
As described in https://github.com/less/less.js/issues/2675 in-value comments are not preserved in referenced rules. This patch adds reference marking to nodes below rules and expressions if markReferenced is available.
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
var Node = require("./node"),
|
|
Paren = require("./paren"),
|
|
Comment = require("./comment");
|
|
|
|
var Expression = function (value) {
|
|
this.value = value;
|
|
if (!value) {
|
|
throw new Error("Expression requires an array parameter");
|
|
}
|
|
};
|
|
Expression.prototype = new Node();
|
|
Expression.prototype.type = "Expression";
|
|
Expression.prototype.accept = function (visitor) {
|
|
this.value = visitor.visitArray(this.value);
|
|
};
|
|
Expression.prototype.eval = function (context) {
|
|
var returnValue,
|
|
inParenthesis = this.parens && !this.parensInOp,
|
|
doubleParen = false;
|
|
if (inParenthesis) {
|
|
context.inParenthesis();
|
|
}
|
|
if (this.value.length > 1) {
|
|
returnValue = new Expression(this.value.map(function (e) {
|
|
return e.eval(context);
|
|
}));
|
|
} else if (this.value.length === 1) {
|
|
if (this.value[0].parens && !this.value[0].parensInOp) {
|
|
doubleParen = true;
|
|
}
|
|
returnValue = this.value[0].eval(context);
|
|
} else {
|
|
returnValue = this;
|
|
}
|
|
if (inParenthesis) {
|
|
context.outOfParenthesis();
|
|
}
|
|
if (this.parens && this.parensInOp && !(context.isMathOn()) && !doubleParen) {
|
|
returnValue = new Paren(returnValue);
|
|
}
|
|
return returnValue;
|
|
};
|
|
Expression.prototype.genCSS = function (context, output) {
|
|
for (var i = 0; i < this.value.length; i++) {
|
|
this.value[i].genCSS(context, output);
|
|
if (i + 1 < this.value.length) {
|
|
output.add(" ");
|
|
}
|
|
}
|
|
};
|
|
Expression.prototype.throwAwayComments = function () {
|
|
this.value = this.value.filter(function(v) {
|
|
return !(v instanceof Comment);
|
|
});
|
|
};
|
|
Expression.prototype.markReferenced = function () {
|
|
this.value.forEach(function (value) {
|
|
if (value.markReferenced) { value.markReferenced(); }
|
|
});
|
|
};
|
|
module.exports = Expression;
|