Got the DRY object pattern matching style working properly, from Harmony. {name, age}: person now works correctly.

This commit is contained in:
Jeremy Ashkenas
2010-04-25 22:21:53 -04:00
parent 328a14014c
commit a894db35fd
6 changed files with 223 additions and 183 deletions

View File

@@ -690,8 +690,15 @@ exports.AssignNode: class AssignNode extends BaseNode
o.as_statement: true
splat: false
for obj, i in @variable.base.objects
# A regular array pattern-match.
idx: i
[obj, idx]: [obj.value, obj.variable.base] if @variable.is_object()
if @variable.is_object()
if obj instanceof AssignNode
# A regular object pattern-match.
[obj, idx]: [obj.value, obj.variable.base]
else
# A shorthand `{a, b, c}: val` pattern-match.
idx: obj
if not (obj instanceof ValueNode or obj instanceof SplatNode)
throw new Error 'pattern matching must use only identifiers on the left-hand side.'
is_string: idx.value and idx.value.match IS_STRING