Merge pull request #4071 from lydell/lone-expansion

Fix #4070: Improve error message for lone expansion
This commit is contained in:
Jeremy Ashkenas 2015-08-27 13:09:54 -04:00
commit 66716cd730
3 changed files with 25 additions and 2 deletions

View File

@ -1725,8 +1725,12 @@
return code;
}
}
obj = objects[0];
if (olen === 1 && obj instanceof Expansion) {
obj.error('Destructuring assignment has no target');
}
isObject = this.variable.isObject();
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
if (top && olen === 1 && !(obj instanceof Splat)) {
if (obj instanceof Assign) {
ref3 = obj, (ref4 = ref3.variable, idx = ref4.base), obj = ref3.value;
} else {

View File

@ -1234,8 +1234,11 @@ exports.Assign = class Assign extends Base
unless olen = objects.length
code = value.compileToFragments o
return if o.level >= LEVEL_OP then @wrapInBraces code else code
[obj] = objects
if olen is 1 and obj instanceof Expansion
obj.error 'Destructuring assignment has no target'
isObject = @variable.isObject()
if top and olen is 1 and (obj = objects[0]) not instanceof Splat
if top and olen is 1 and obj not instanceof Splat
# Unroll simplest cases: `{v} = x` -> `v = x.v`
if obj instanceof Assign
{variable: {base: idx}, value: obj} = obj

View File

@ -776,3 +776,19 @@ test "invalid object keys", ->
@a: 1
^^
'''
test "#4070: lone expansion", ->
assertErrorFormat '''
[...] = a
''', '''
[stdin]:1:2: error: Destructuring assignment has no target
[...] = a
^^^
'''
assertErrorFormat '''
[ ..., ] = a
''', '''
[stdin]:1:3: error: Destructuring assignment has no target
[ ..., ] = a
^^^
'''