Skip to content

Commit

Permalink
Fix #4130: Unassignable param destructuring crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Oct 22, 2015
1 parent 968f94f commit 1dd5795
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/coffee-script/nodes.js

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

2 changes: 1 addition & 1 deletion src/nodes.coffee
Expand Up @@ -1526,7 +1526,7 @@ exports.Param = class Param extends Base
return iterator name.value, name if name instanceof Literal
# * at-params `@foo`
return atParam name if name instanceof Value
for obj in name.objects
for obj in name.objects ? []
# * destructured parameter with default value
if obj instanceof Assign and not obj.context?
obj = obj.variable
Expand Down
40 changes: 40 additions & 0 deletions test/error_messages.coffee
Expand Up @@ -825,6 +825,46 @@ test "#3926: implicit object in parameter list", ->
^
'''

test "#4130: unassignable in destructured param", ->
assertErrorFormat '''
fun = ({
@param : null
}) ->
console.log "Oh hello!"
''', '''
[stdin]:2:12: error: "null" cannot be assigned
@param : null
^^^^
'''
assertErrorFormat '''
({a: null}) ->
''', '''
[stdin]:1:6: error: "null" cannot be assigned
({a: null}) ->
^^^^
'''
assertErrorFormat '''
({a: 1}) ->
''', '''
[stdin]:1:6: error: "1" cannot be assigned
({a: 1}) ->
^
'''
assertErrorFormat '''
({1}) ->
''', '''
[stdin]:1:3: error: "1" cannot be assigned
({1}) ->
^
'''
assertErrorFormat '''
({a: true = 1}) ->
''', '''
[stdin]:1:6: error: reserved word 'true' can't be assigned
({a: true = 1}) ->
^^^^
'''

test "`yield` outside of a function", ->
assertErrorFormat '''
yield 1
Expand Down

0 comments on commit 1dd5795

Please sign in to comment.