mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
a whole chunk of compile_pattern_match was redundant, axed it -- along with the array/vs/object split
This commit is contained in:
parent
5e1e949bf6
commit
d54fa2f2a1
1 changed files with 9 additions and 11 deletions
|
@ -466,21 +466,19 @@ module CoffeeScript
|
||||||
@variable.array? || @variable.object?
|
@variable.array? || @variable.object?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Implementation of recursive pattern matching, when assigning array or
|
||||||
|
# object literals to a value. Peeks at their properties to assign inner names.
|
||||||
|
# See: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
|
||||||
def compile_pattern_match(o)
|
def compile_pattern_match(o)
|
||||||
val_var = o[:scope].free_variable
|
val_var = o[:scope].free_variable
|
||||||
assigns = ["#{idt}#{val_var} = #{@value.compile(o)};"]
|
assigns = ["#{idt}#{val_var} = #{@value.compile(o)};"]
|
||||||
@variable.base.objects.each_with_index do |obj, i|
|
@variable.base.objects.each_with_index do |obj, i|
|
||||||
if @variable.array?
|
obj, i = obj.value, obj.variable.base if @variable.object?
|
||||||
assigns << AssignNode.new(obj, ValueNode.new(Value.new(val_var), [IndexNode.new(Value.new(i.to_s))])).compile(o.merge(:top => true, :as_statement => true))
|
access_class = @variable.array? ? IndexNode : AccessorNode
|
||||||
elsif @variable.object?
|
assigns << AssignNode.new(
|
||||||
obj, i = obj.value, obj.variable.base
|
obj,
|
||||||
assigns << AssignNode.new(obj, ValueNode.new(Value.new(val_var), [AccessorNode.new(Value.new(i.to_s))])).compile(o.merge(:top => true, :as_statement => true))
|
ValueNode.new(Value.new(val_var), [access_class.new(Value.new(i.to_s))])
|
||||||
else
|
).compile(o.merge(:top => true, :as_statement => true))
|
||||||
left = obj.compile(o)
|
|
||||||
o[:scope].find(left) if obj.base.is_a?(Value)
|
|
||||||
access = @variable.object? ? ".#{i}" : "[#{i}]"
|
|
||||||
assigns << "#{idt}#{left} = #{val_var}#{access};"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
write(assigns.join("\n"))
|
write(assigns.join("\n"))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue