Enchancing pattern matching with @vars ... issue #721

This commit is contained in:
Jeremy Ashkenas
2010-10-04 22:10:10 -04:00
parent 8eb283df2c
commit d1bca6364a
7 changed files with 220 additions and 175 deletions

View File

@@ -300,11 +300,14 @@
return ReturnNode;
})();
exports.ValueNode = (function() {
ValueNode = function(_arg, _arg2) {
ValueNode = function(_arg, _arg2, tag) {
this.properties = _arg2;
this.base = _arg;
ValueNode.__super__.constructor.call(this);
this.properties || (this.properties = []);
if (tag) {
this.tags[tag] = true;
}
return this;
};
__extends(ValueNode, BaseNode);
@@ -798,7 +801,9 @@
join = '';
}
indent = prop instanceof CommentNode ? '' : this.idt(1);
if (!(prop instanceof AssignNode || prop instanceof CommentNode)) {
if (prop instanceof ValueNode && prop.tags['this']) {
prop = new AssignNode(prop.properties[0].name, prop, 'object');
} else if (!(prop instanceof AssignNode) && !(prop instanceof CommentNode)) {
prop = new AssignNode(prop, prop, 'object');
}
return indent + prop.compile(o) + join;
@@ -1018,7 +1023,11 @@
if (obj instanceof AssignNode) {
_ref2 = [obj.value, obj.variable.base], obj = _ref2[0], idx = _ref2[1];
} else {
idx = obj;
if (obj.tags['this']) {
idx = obj.properties[0].name;
} else {
idx = obj;
}
}
}
if (!(obj instanceof ValueNode || obj instanceof SplatNode)) {