Skip to content

Commit

Permalink
Merge pull request #4073 from lydell/issue-3926
Browse files Browse the repository at this point in the history
Fix #3926: Disallow implicit objects as parameter destructuring
  • Loading branch information
jashkenas committed Sep 1, 2015
2 parents 56d75ba + 2c4d437 commit 98dd1bf
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/coffee-script/grammar.js

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

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.

8 changes: 6 additions & 2 deletions lib/coffee-script/parser.js

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

6 changes: 4 additions & 2 deletions src/grammar.coffee
Expand Up @@ -168,9 +168,11 @@ grammar =
# the ordinary **Assign** is that these allow numbers and strings as keys.
AssignObj: [
o 'ObjAssignable', -> new Value $1
o 'ObjAssignable : Expression', -> new Assign LOC(1)(new Value $1), $3, 'object'
o 'ObjAssignable : Expression', -> new Assign LOC(1)(new Value $1), $3, 'object',
operatorToken: LOC(2)(new Literal $2)
o 'ObjAssignable :
INDENT Expression OUTDENT', -> new Assign LOC(1)(new Value $1), $4, 'object'
INDENT Expression OUTDENT', -> new Assign LOC(1)(new Value $1), $4, 'object',
operatorToken: LOC(2)(new Literal $2)
o 'SimpleObjAssignable = Expression', -> new Assign LOC(1)(new Value $1), $3, null,
operatorToken: LOC(2)(new Literal $2)
o 'SimpleObjAssignable =
Expand Down
3 changes: 3 additions & 0 deletions src/nodes.coffee
Expand Up @@ -1482,6 +1482,9 @@ exports.Param = class Param extends Base
constructor: (@name, @value, @splat) ->
if (name = @name.unwrapAll().value) in STRICT_PROSCRIBED
@name.error "parameter name \"#{name}\" is not allowed"
if @name instanceof Obj and @name.generated
token = @name.objects[0].operatorToken
token.error "unexpected #{token.value}"

children: ['name', 'value']

Expand Down
16 changes: 16 additions & 0 deletions test/error_messages.coffee
Expand Up @@ -808,3 +808,19 @@ test "#4070: lone expansion", ->
[ ..., ] = a
^^^
'''

test "#3926: implicit object in parameter list", ->
assertErrorFormat '''
(a: b) ->
''', '''
[stdin]:1:3: error: unexpected :
(a: b) ->
^
'''
assertErrorFormat '''
(one, two, {three, four: five}, key: value) ->
''', '''
[stdin]:1:36: error: unexpected :
(one, two, {three, four: five}, key: value) ->
^
'''
5 changes: 2 additions & 3 deletions test/strict.coffee
Expand Up @@ -93,7 +93,6 @@ test "duplicate formal parameters are prohibited", ->
strict '(_,[_,{__}])->', 'param, [param, {param2}]'
strict '(_,[__,{_}])->', 'param, [param2, {param}]'
strict '(__,[_,{_}])->', 'param, [param2, {param2}]'
strict '(0:a,1:a)->', '0:param,1:param'
strict '({0:a,1:a})->', '{0:param,1:param}'
# the following function expressions should **not** throw errors
strictOk '(_,@_)->'
Expand All @@ -115,8 +114,8 @@ test "duplicate formal parameters are prohibited", ->
strictOk '(@case...,_case)->'
strictOk '(_case,@case)->'
strictOk '(_case,@case...)->'
strictOk '(a:a)->'
strictOk '(a:a,a:b)->'
strictOk '({a:a})->'
strictOk '({a:a,a:b})->'

test "`delete` operand restrictions", ->
strict 'a = 1; delete a'
Expand Down

0 comments on commit 98dd1bf

Please sign in to comment.