mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
with splats allowed in destructuring assignment
This commit is contained in:
parent
2d206e7b60
commit
ed8a54995d
2 changed files with 27 additions and 4 deletions
|
@ -482,9 +482,12 @@ module CoffeeScript
|
||||||
@variable.base.objects.each_with_index do |obj, i|
|
@variable.base.objects.each_with_index do |obj, i|
|
||||||
obj, i = obj.value, obj.variable.base if @variable.object?
|
obj, i = obj.value, obj.variable.base if @variable.object?
|
||||||
access_class = @variable.array? ? IndexNode : AccessorNode
|
access_class = @variable.array? ? IndexNode : AccessorNode
|
||||||
assigns << AssignNode.new(
|
if obj.is_a?(SplatNode)
|
||||||
obj, ValueNode.new(Value.new(val_var), [access_class.new(Value.new(i.to_s))])
|
val = LiteralNode.wrap(obj.compile_value(o, val_var, @variable.base.objects.index(obj)))
|
||||||
).compile(o)
|
else
|
||||||
|
val = ValueNode.new(Value.new(val_var), [access_class.new(Value.new(i.to_s))])
|
||||||
|
end
|
||||||
|
assigns << AssignNode.new(obj, val).compile(o)
|
||||||
end
|
end
|
||||||
write(assigns.join("\n"))
|
write(assigns.join("\n"))
|
||||||
end
|
end
|
||||||
|
@ -609,6 +612,10 @@ module CoffeeScript
|
||||||
@name.compile(o)
|
@name.compile(o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def compile_value(o, name, index)
|
||||||
|
"Array.prototype.slice.call(#{name}, #{index})"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# An object literal.
|
# An object literal.
|
||||||
|
|
|
@ -44,3 +44,19 @@ person: {
|
||||||
|
|
||||||
print(a is "Bob")
|
print(a is "Bob")
|
||||||
print(b is "Moquasset NY, 10021")
|
print(b is "Moquasset NY, 10021")
|
||||||
|
|
||||||
|
|
||||||
|
test: {
|
||||||
|
person: {
|
||||||
|
address: [
|
||||||
|
"------"
|
||||||
|
"Street 101"
|
||||||
|
"Apt 101"
|
||||||
|
"City 101"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{person: {address: [ignore, addr...]}}: test
|
||||||
|
|
||||||
|
print(addr.join(', ') is "Street 101, Apt 101, City 101")
|
Loading…
Add table
Reference in a new issue