From 9448a477d25abbada545bbd19e7096c142a00679 Mon Sep 17 00:00:00 2001 From: Timothy Jones Date: Sun, 24 Oct 2010 00:01:26 +1300 Subject: [PATCH] Spacing multiple operators. --- lib/nodes.js | 2 +- src/nodes.coffee | 2 +- test/test_operations.coffee | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 93f1a690..3ffff929 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1291,7 +1291,7 @@ }; Op.prototype.compileUnary = function(o) { var _ref2, parts, space; - space = (_ref2 = this.operator, __indexOf.call(this.PREFIX_OPERATORS, _ref2) >= 0) ? ' ' : ''; + space = (_ref2 = this.operator, __indexOf.call(this.PREFIX_OPERATORS, _ref2) >= 0) || this.first instanceof Op ? ' ' : ''; parts = [this.operator, space, this.first.compile(o, LVL_OP)]; return (this.flip ? parts.reverse() : parts).join(''); }; diff --git a/src/nodes.coffee b/src/nodes.coffee index a14ce373..39baa0bb 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1108,7 +1108,7 @@ exports.Op = class Op extends Base # Compile a unary **Op**. compileUnary: (o) -> - space = if @operator in @PREFIX_OPERATORS then ' ' else '' + space = if @operator in @PREFIX_OPERATORS or @first instanceof Op then ' ' else '' parts = [@operator, space, @first.compile(o, LVL_OP)] (if @flip then parts.reverse() else parts).join '' diff --git a/test/test_operations.coffee b/test/test_operations.coffee index 2b202f11..92a9881c 100644 --- a/test/test_operations.coffee +++ b/test/test_operations.coffee @@ -165,3 +165,7 @@ ok a is 579 a = "1#{2}3" + "456" ok a is '123456' + + +# Multiple operators should space themselves. +ok + +1 is - -1