mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
got pattern matching working
This commit is contained in:
parent
a379530d41
commit
98f15d001f
2 changed files with 7 additions and 5 deletions
|
@ -764,7 +764,7 @@
|
|||
// object literals to a value. Peeks at their properties to assign inner names.
|
||||
// See: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
|
||||
compile_pattern_match: function compile_pattern_match(o) {
|
||||
var __a, __b, access_class, assigns, i, obj, val, val_var;
|
||||
var __a, __b, access_class, assigns, i, idx, obj, val, val_var;
|
||||
val_var = o.scope.free_variable();
|
||||
assigns = [this.idt() + val_var + ' = ' + this.value.compile(o) + ';'];
|
||||
o.top = true;
|
||||
|
@ -772,13 +772,14 @@
|
|||
__a = this.variable.base.objects;
|
||||
for (i = 0; i < __a.length; i++) {
|
||||
obj = __a[i];
|
||||
idx = i;
|
||||
if (this.variable.is_object()) {
|
||||
__b = [obj.value, obj.variable.base];
|
||||
obj = __b[0];
|
||||
i = __b[1];
|
||||
idx = __b[1];
|
||||
}
|
||||
access_class = this.variable.is_array() ? IndexNode : AccessorNode;
|
||||
obj instanceof SplatNode ? (val = new LiteralNode(obj.compile_value(o, val_var, this.variable.base.objects.indexOf(obj)))) : (val = new ValueNode(new LiteralNode(val_var), [new access_class(new LiteralNode(i))]));
|
||||
obj instanceof SplatNode ? (val = new LiteralNode(obj.compile_value(o, val_var, this.variable.base.objects.indexOf(obj)))) : (val = new ValueNode(new LiteralNode(val_var), [new access_class(idx)]));
|
||||
assigns.push(new AssignNode(obj, val).compile(o));
|
||||
}
|
||||
return assigns.join("\n");
|
||||
|
|
|
@ -594,12 +594,13 @@ AssignNode: exports.AssignNode: inherit Node, {
|
|||
o.top: true
|
||||
o.as_statement: true
|
||||
for obj, i in @variable.base.objects
|
||||
[obj, i]: [obj.value, obj.variable.base] if @variable.is_object()
|
||||
idx: i
|
||||
[obj, idx]: [obj.value, obj.variable.base] if @variable.is_object()
|
||||
access_class: if @variable.is_array() then IndexNode else AccessorNode
|
||||
if obj instanceof SplatNode
|
||||
val: new LiteralNode(obj.compile_value(o, val_var, @variable.base.objects.indexOf(obj)))
|
||||
else
|
||||
val: new ValueNode(new LiteralNode(val_var), [new access_class(new LiteralNode(i))])
|
||||
val: new ValueNode(new LiteralNode(val_var), [new access_class(idx)])
|
||||
assigns.push(new AssignNode(obj, val).compile(o))
|
||||
assigns.join("\n")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue