mirror of
https://github.com/less/less.js.git
synced 2026-02-07 05:25:04 -05:00
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
(function (tree) {
|
|
|
|
tree.Rule = function (name, value, important, index, inline) {
|
|
this.name = name;
|
|
this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
|
|
this.important = important ? ' ' + important.trim() : '';
|
|
this.index = index;
|
|
this.inline = inline || false;
|
|
|
|
if (name.charAt(0) === '@') {
|
|
this.variable = true;
|
|
} else { this.variable = false }
|
|
};
|
|
tree.Rule.prototype.toCSS = function (env) {
|
|
if (this.variable) { return "" }
|
|
else {
|
|
return this.name + (env.compress ? ':' : ': ') +
|
|
this.value.toCSS(env) +
|
|
this.important + (this.inline ? "" : ";");
|
|
}
|
|
};
|
|
|
|
tree.Rule.prototype.eval = function (env) {
|
|
var strictMathsBypass = false;
|
|
if (this.name === "font" && env.strictMaths === false) {
|
|
strictMathsBypass = true;
|
|
env.strictMaths = true;
|
|
}
|
|
try {
|
|
return new(tree.Rule)(this.name,
|
|
this.value.eval(env),
|
|
this.important,
|
|
this.index, this.inline);
|
|
}
|
|
finally {
|
|
if (strictMathsBypass) {
|
|
env.strictMaths = false;
|
|
}
|
|
}
|
|
};
|
|
|
|
tree.Rule.prototype.makeImportant = function () {
|
|
return new(tree.Rule)(this.name,
|
|
this.value,
|
|
"!important",
|
|
this.index, this.inline);
|
|
};
|
|
|
|
})(require('../tree'));
|