Merge pull request #4071 from lydell/lone-expansion
Fix #4070: Improve error message for lone expansion
This commit is contained in:
commit
66716cd730
|
@ -1725,8 +1725,12 @@
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
obj = objects[0];
|
||||||
|
if (olen === 1 && obj instanceof Expansion) {
|
||||||
|
obj.error('Destructuring assignment has no target');
|
||||||
|
}
|
||||||
isObject = this.variable.isObject();
|
isObject = this.variable.isObject();
|
||||||
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
if (top && olen === 1 && !(obj instanceof Splat)) {
|
||||||
if (obj instanceof Assign) {
|
if (obj instanceof Assign) {
|
||||||
ref3 = obj, (ref4 = ref3.variable, idx = ref4.base), obj = ref3.value;
|
ref3 = obj, (ref4 = ref3.variable, idx = ref4.base), obj = ref3.value;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1234,8 +1234,11 @@ exports.Assign = class Assign extends Base
|
||||||
unless olen = objects.length
|
unless olen = objects.length
|
||||||
code = value.compileToFragments o
|
code = value.compileToFragments o
|
||||||
return if o.level >= LEVEL_OP then @wrapInBraces code else code
|
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()
|
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`
|
# Unroll simplest cases: `{v} = x` -> `v = x.v`
|
||||||
if obj instanceof Assign
|
if obj instanceof Assign
|
||||||
{variable: {base: idx}, value: obj} = obj
|
{variable: {base: idx}, value: obj} = obj
|
||||||
|
|
|
@ -776,3 +776,19 @@ test "invalid object keys", ->
|
||||||
@a: 1
|
@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
|
||||||
|
^^^
|
||||||
|
'''
|
||||||
|
|
Loading…
Reference in New Issue