Skip to content

Commit

Permalink
Merge pull request jashkenas#4071 from lydell/lone-expansion
Browse files Browse the repository at this point in the history
Fix jashkenas#4070: Improve error message for lone expansion
  • Loading branch information
jashkenas committed Aug 27, 2015
2 parents dc3e177 + f588ecb commit 66716cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^
'''

0 comments on commit 66716cd

Please sign in to comment.