Skip to content

Commit

Permalink
fixes #2055: destructuring assignment with new
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Jan 19, 2012
1 parent 97cd2db commit 7c56da2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/coffee-script/nodes.js

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

7 changes: 5 additions & 2 deletions src/nodes.coffee
Expand Up @@ -759,13 +759,14 @@ exports.Slice = class Slice extends Base
compileNode: (o) ->
{to, from} = @range
fromStr = from and from.compile(o, LEVEL_PAREN) or '0'
compiled = to and to.compile o, LEVEL_ACCESS
compiled = to and to.compile o, LEVEL_PAREN
if to and not (not @range.exclusive and +compiled is -1)
toStr = ', ' + if @range.exclusive
compiled
else if SIMPLENUM.test compiled
(+compiled + 1).toString()
"#{+compiled + 1}"
else
compiled = to.compile o, LEVEL_ACCESS
"#{compiled} + 1 || 9e9"
".slice(#{ fromStr }#{ toStr or '' })"

Expand Down Expand Up @@ -1506,6 +1507,8 @@ exports.Op = class Op extends Base

# Compile a unary **Op**.
compileUnary: (o) ->
if o.level >= LEVEL_ACCESS
return (new Parens this).compile o
parts = [op = @operator]
plusMinus = op in ['+', '-']
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
Expand Down
4 changes: 4 additions & 0 deletions test/assignment.coffee
Expand Up @@ -267,6 +267,10 @@ test "#1005: invalid identifiers allowed on LHS of destructuring assignment", ->
CoffeeScript.compile "[@#{v}] = x"
CoffeeScript.compile "[@#{v}...] = x"

test "#2055: destructuring assignment with `new`", ->
{length} = new Array
eq 0, length


# Existential Assignment

Expand Down

0 comments on commit 7c56da2

Please sign in to comment.