Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
Fixed destructured assign, added new example
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed May 24, 2016
1 parent fb100c1 commit 3d35855
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 13 additions & 0 deletions examples/destructuring.spoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env coffee

date = ->
[24, "May", 2016]

[day, month, year] = date!

person = {
name: "John",
age: 50
}

{name: name, age: age} = person
12 changes: 5 additions & 7 deletions lib/spoon/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ def compile
@@assign_counter += 1

left.children.each_with_index do |child, index|
child_name = compile_next(child)
@content << @parent.tab
scope_name(child)
@content << "#{child_name} #{operator} #{assign_name}[#{index}]"
@content << scope_name(child)
@content << " #{operator} #{assign_name}[#{index}]"
@content << eol(child) unless child.equal? left.children.last
end
elsif left.type == :map
Expand All @@ -246,12 +245,11 @@ def compile
left.children.each do |child|
child_children = child.children.dup
child_children.shift
child_alias_node = child_children.shift
child_alias = compile_next(child_alias_node)
child_name = compile_next(child_children.shift)
child_alias_node = child_children.shift
@content << @parent.tab
scope_name(child_alias_node)
@content << "#{child_alias} #{operator} #{assign_name}.#{child_name}"
@content << scope_name(child_alias_node)
@content << " #{operator} #{assign_name}.#{child_name}"
@content << eol(child) unless child.equal? left.children.last
end
elsif @parent.parent != nil && @parent.parent.node.type == :class
Expand Down

0 comments on commit 3d35855

Please sign in to comment.