Skip to content

Adding default variables #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions dist/less-1.1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ less.Parser = function Parser(env) {
}
},
rule: function () {
var name, value, c = input.charAt(i), important, match;
var name, value, c = input.charAt(i), important, isDefault, match;
save();

if (c === '.' || c === '#' || c === '&') { return }
Expand All @@ -1048,9 +1048,10 @@ less.Parser = function Parser(env) {
value = $(this.value);
}
important = $(this.important);
isDefault = $(this.isDefault);

if (value && $(this.end)) {
return new(tree.Rule)(name, value, important, memo);
return new(tree.Rule)(name, value, important, memo, isDefault);
} else {
furthest = i;
restore();
Expand Down Expand Up @@ -1146,6 +1147,11 @@ less.Parser = function Parser(env) {
return $(/^! *important/);
}
},
isDefault: function () {
if (input.charAt(i) === '!') {
return $(/^! *default/);
}
},
sub: function () {
var e;

Expand Down Expand Up @@ -2020,14 +2026,15 @@ tree.Quoted.prototype = {
})(require('less/tree'));
(function (tree) {

tree.Rule = function (name, value, important, index) {
tree.Rule = function (name, value, important, index, isDefault) {
this.name = name;
this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
this.important = important ? ' ' + important.trim() : '';
this.index = index;

if (name.charAt(0) === '@') {
this.variable = true;
this.isDefault = isDefault;
} else { this.variable = false }
};
tree.Rule.prototype.toCSS = function (env) {
Expand All @@ -2040,7 +2047,7 @@ tree.Rule.prototype.toCSS = function (env) {
};

tree.Rule.prototype.eval = function (context) {
return new(tree.Rule)(this.name, this.value.eval(context), this.important, this.index);
return new(tree.Rule)(this.name, this.value.eval(context), this.important,this.index,this.isDefault);
};

tree.Shorthand = function (a, b) {
Expand Down Expand Up @@ -2101,7 +2108,6 @@ tree.Ruleset.prototype = {
// Evaluate everything else
for (var i = 0, rule; i < ruleset.rules.length; i++) {
rule = ruleset.rules[i];

if (! (rule instanceof tree.mixin.Definition)) {
ruleset.rules[i] = rule.eval ? rule.eval(env) : rule;
}
Expand All @@ -2120,7 +2126,8 @@ tree.Ruleset.prototype = {
else {
return this._variables = this.rules.reduce(function (hash, r) {
if (r instanceof tree.Rule && r.variable === true) {
hash[r.name] = r;
if (!(r.isDefault && hash[r.name]))
hash[r.name] = r;
}
return hash;
}, {});
Expand Down