Skip to content

Commit

Permalink
Issue jashkenas#1703, - --x
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Sep 18, 2011
1 parent 19f77cf commit 4419f7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/coffee-script/nodes.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/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1366,9 +1366,11 @@ exports.Op = class Op extends Base
# Compile a unary **Op**.
compileUnary: (o) ->
parts = [op = @operator]
plusMinus = op in ['+', '-']
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
op in ['+', '-'] and @first instanceof Op and @first.operator is op
@first = new Parens @first if op is 'new' and @first.isStatement o
plusMinus and @first instanceof Op and @first.operator is op
if (plusMinus && @first instanceof Op) or (op is 'new' and @first.isStatement o)
@first = new Parens @first
parts.push @first.compile o, LEVEL_OP
parts.reverse() if @flip
parts.join ''
Expand Down
4 changes: 4 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,7 @@ test "#1234: Applying a splat to :: applies the splat to the wrong object", ->
test "#1102: String literal prevents line continuation", ->
eq "': '", '' +
"': '"

test "#1703, ---x is invalid JS", ->
x = 2
eq (- --x), -1

0 comments on commit 4419f7c

Please sign in to comment.