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:
parent
19f77cfff5
commit
4419f7ca0f
3 changed files with 12 additions and 5 deletions
|
@ -1579,12 +1579,13 @@
|
|||
}).addElse(this.second).compile(o);
|
||||
};
|
||||
Op.prototype.compileUnary = function(o) {
|
||||
var op, parts;
|
||||
var op, parts, plusMinus;
|
||||
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(' ');
|
||||
}
|
||||
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);
|
||||
}
|
||||
parts.push(this.first.compile(o, LEVEL_OP));
|
||||
|
|
|
@ -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 ''
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue