1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Issue #1703, - --x

This commit is contained in:
Jeremy Ashkenas 2011-09-17 22:21:47 -04:00
parent 19f77cfff5
commit 4419f7ca0f
3 changed files with 12 additions and 5 deletions

View file

@ -1579,12 +1579,13 @@
}).addElse(this.second).compile(o); }).addElse(this.second).compile(o);
}; };
Op.prototype.compileUnary = function(o) { Op.prototype.compileUnary = function(o) {
var op, parts; var op, parts, plusMinus;
parts = [op = this.operator]; parts = [op = this.operator];
if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) { plusMinus = op === '+' || op === '-';
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
parts.push(' '); parts.push(' ');
} }
if (op === 'new' && this.first.isStatement(o)) { if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {
this.first = new Parens(this.first); this.first = new Parens(this.first);
} }
parts.push(this.first.compile(o, LEVEL_OP)); parts.push(this.first.compile(o, LEVEL_OP));

View file

@ -1366,9 +1366,11 @@ exports.Op = class Op extends Base
# Compile a unary **Op**. # Compile a unary **Op**.
compileUnary: (o) -> compileUnary: (o) ->
parts = [op = @operator] parts = [op = @operator]
plusMinus = op in ['+', '-']
parts.push ' ' if op in ['new', 'typeof', 'delete'] or parts.push ' ' if op in ['new', 'typeof', 'delete'] or
op in ['+', '-'] and @first instanceof Op and @first.operator is op plusMinus and @first instanceof Op and @first.operator is op
@first = new Parens @first if op is 'new' and @first.isStatement o 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.push @first.compile o, LEVEL_OP
parts.reverse() if @flip parts.reverse() if @flip
parts.join '' parts.join ''

View file

@ -247,3 +247,7 @@ test "#1234: Applying a splat to :: applies the splat to the wrong object", ->
test "#1102: String literal prevents line continuation", -> test "#1102: String literal prevents line continuation", ->
eq "': '", '' + eq "': '", '' +
"': '" "': '"
test "#1703, ---x is invalid JS", ->
x = 2
eq (- --x), -1