mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #1641 from geraldalewis/1591_splats_in_destructuring
1591 Splatted Expressions in Destructuring Assignment Must Be Assignable
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user