1
0
Fork 0
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:
Jeremy Ashkenas 2010-01-13 22:25:58 -05:00
parent 2d206e7b60
commit ed8a54995d
2 changed files with 27 additions and 4 deletions

View file

@ -482,9 +482,12 @@ module CoffeeScript
@variable.base.objects.each_with_index do |obj, i|
obj, i = obj.value, obj.variable.base if @variable.object?
access_class = @variable.array? ? IndexNode : AccessorNode
assigns << AssignNode.new(
obj, ValueNode.new(Value.new(val_var), [access_class.new(Value.new(i.to_s))])
).compile(o)
if obj.is_a?(SplatNode)
val = LiteralNode.wrap(obj.compile_value(o, val_var, @variable.base.objects.index(obj)))
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
write(assigns.join("\n"))
end
@ -609,6 +612,10 @@ module CoffeeScript
@name.compile(o)
end
def compile_value(o, name, index)
"Array.prototype.slice.call(#{name}, #{index})"
end
end
# An object literal.

View file

@ -43,4 +43,20 @@ person: {
{name: a, family: {brother: {addresses: [one, {city: b}]}}}: person
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")