Merge pull request #1641 from geraldalewis/1591_splats_in_destructuring

1591 Splatted Expressions in Destructuring Assignment Must Be Assignable
This commit is contained in:
Jeremy Ashkenas
2011-08-30 08:23:26 -07:00
3 changed files with 10 additions and 0 deletions

View File

@@ -1153,6 +1153,9 @@
}
}
if (!splat && obj instanceof Splat) {
if (!obj.name.unwrapAll().isAssignable()) {
throw SyntaxError("\"" + (obj.name.compile(o)) + "\" cannot be assigned.");
}
name = obj.name.unwrap().value;
val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
if (rest = olen - i - 1) {

View File

@@ -1005,6 +1005,8 @@ exports.Assign = class Assign extends Base
else
idx = if obj.this then obj.properties[0].name else obj
if not splat and obj instanceof Splat
unless obj.name.unwrapAll().isAssignable()
throw SyntaxError "\"#{ obj.name.compile(o) }\" cannot be assigned."
name = obj.name.unwrap().value
val = "#{olen} <= #{vvar}.length ? #{ utility 'slice' }.call(#{vvar}, #{i}"
if rest = olen - i - 1

View File

@@ -301,3 +301,8 @@ test "#1348, #1216: existential assignment compilation", ->
if a then a ?= 2 else a = 3
eq a, nonce
test "#1591, #1101: splatted expressions in destructuring assignment must be assignable", ->
nonce = {}
for nonref in ['', '""', '0', 'f()', '(->)'].concat CoffeeScript.RESERVED
eq nonce, (try CoffeeScript.compile "[#{nonref}...] = v" catch e then nonce)