Permalink
Browse files

Fixes issue where destructured assignment params were incorrectly ide…

…ntified as duplicates.
  • Loading branch information...
geraldalewis committed Apr 24, 2012
1 parent 3b1a566 commit 99394e1011ac1526163d1f73fe3492523a153e8c
Showing with 14 additions and 3 deletions.
  1. +1 −1 lib/coffee-script/nodes.js
  2. +1 −1 src/nodes.coffee
  3. +7 −0 test/functions.coffee
  4. +5 −1 test/strict.coffee

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1278,7 +1278,7 @@ exports.Param = class Param extends Base
for obj in name.objects
# * assignments within destructured parameters `{foo:bar}`
if obj instanceof Assign
- names.push obj.variable.base.value
+ names.push obj.value.base.value

This comment has been minimized.

Show comment Hide comment
@geraldalewis

geraldalewis Apr 24, 2012

Owner

Would love a sanity check here :) Don't know how I mixed it up before.

@geraldalewis

geraldalewis Apr 24, 2012

Owner

Would love a sanity check here :) Don't know how I mixed it up before.

# * splats within destructured parameters `[xs...]`
else if obj instanceof Splat
names.push obj.name.unwrap().value
View
@@ -95,6 +95,13 @@ test "splats", ->
arrayEq [0, 1], (((splat..., _, _1) -> splat) 0, 1, 2, 3)
arrayEq [2], (((_, _1, splat..., _2) -> splat) 0, 1, 2, 3)
+test "destructured splatted parameters", ->
+ arr = [0,1,2]
+ splatArray = ([a...]) -> a
+ splatArrayRest = ([a...],b...) -> arrayEq(a,b); b
+ arrayEq splatArray(arr), arr
+ arrayEq splatArrayRest(arr,0,1,2), arr
+
test "@-parameters: automatically assign an argument's value to a property of the context", ->
nonce = {}
View
@@ -60,7 +60,7 @@ test "duplicate property definitions in object literals are prohibited", ->
strict 'o = {x:1,x:1}'
strict 'x = 1; o = {x, x: 2}'
-test "duplicate formal parameter are prohibited", ->
+test "duplicate formal parameters are prohibited", ->
nonce = {}
# a Param can be an Identifier, ThisProperty( @-param ), Array, or Object
@@ -87,6 +87,8 @@ test "duplicate formal parameter 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 '({},_arg)->'
strictOk '({},{})->'
@@ -99,6 +101,8 @@ test "duplicate formal parameter are prohibited", ->
strictOk '(@case...,_case)->'
strictOk '(_case,@case)->'
strictOk '(_case,@case...)->'
+ strictOk '(a:a)->'
+ strictOk '(a:a,a:b)->'
test "`delete` operand restrictions", ->
strict 'a = 1; delete a'

0 comments on commit 99394e1

Please sign in to comment.