tweak mixin pattern matching to be more useful

This commit is contained in:
Alexis Sellier
2011-01-20 20:02:15 -05:00
parent 6b8a5c4f27
commit 0bd18489bc
2 changed files with 5 additions and 10 deletions

View File

@@ -48,14 +48,14 @@ tree.mixin.Definition = function (name, params, rules) {
this.rules = rules;
this._lookups = {};
this.required = params.reduce(function (count, p) {
if (p.name && !p.value) { return count + 1 }
else { return count }
if (!p.name || (p.name && !p.value)) { return count + 1 }
else { return count }
}, 0);
this.parent = tree.Ruleset.prototype;
this.frames = [];
};
tree.mixin.Definition.prototype = {
toCSS: function () { return "" },
toCSS: function () { return "" },
variable: function (name) { return this.parent.variable.call(this, name) },
variables: function () { return this.parent.variables.call(this) },
find: function () { return this.parent.find.apply(this, arguments) },
@@ -81,7 +81,8 @@ tree.mixin.Definition.prototype = {
match: function (args, env) {
var argsLength = (args && args.length) || 0, len;
if (argsLength < this.required) { return false }
if (argsLength < this.required) { return false }
if ((this.required > 0) && (argsLength > this.params.length)) { return false }
len = Math.min(argsLength, this.arity);

View File

@@ -14,14 +14,12 @@
.two {
zero: 0;
one: 1;
one-req: 1;
two: 2;
three: 3;
}
.three {
zero: 0;
one: 1;
one-req: 1;
two: 2;
three-req: 3;
three: 3;
@@ -41,15 +39,11 @@
border-left: 4px;
}
.only-right {
both: 330;
right: 33;
}
.only-left {
both: 330;
left: 33;
}
.left-right {
both: 330;
left: 33;
right: 33;
}