diff --git a/lib/grammar.js b/lib/grammar.js index 3ee16e6d..8bbdbf49 100644 --- a/lib/grammar.js +++ b/lib/grammar.js @@ -323,7 +323,7 @@ ], SimpleArgs: [ o("Expression"), o("SimpleArgs , Expression", function() { - return ($1 instanceof Array) ? $1.concat([$3]) : [$1].concat([$3]); + return $1 instanceof Array ? $1.concat([$3]) : [$1].concat([$3]); }) ], Try: [ diff --git a/lib/helpers.js b/lib/helpers.js index 76cff280..af94f522 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -80,7 +80,7 @@ _b = array; for (_a = 0, _c = _b.length; _a < _c; _a++) { item = _b[_a]; - (item instanceof Array) ? (memo = memo.concat(item)) : memo.push(item); + item instanceof Array ? (memo = memo.concat(item)) : memo.push(item); } return memo; }); diff --git a/lib/nodes.js b/lib/nodes.js index d7f1500c..c006cf2d 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -464,7 +464,7 @@ _c = this.args; for (_b = 0, _d = _c.length; _b < _d; _b++) { arg = _c[_b]; - (arg instanceof SplatNode) ? (compilation = this.compileSplat(o)) : null; + arg instanceof SplatNode ? (compilation = this.compileSplat(o)) : null; } if (!(compilation)) { args = (function() { @@ -687,7 +687,7 @@ if (i === this.properties.length - 1) { join = ''; } - indent = (prop instanceof CommentNode) ? '' : this.idt(1); + indent = prop instanceof CommentNode ? '' : this.idt(1); if (!(prop instanceof AssignNode || prop instanceof CommentNode)) { prop = new AssignNode(prop, prop, 'object'); } @@ -1140,6 +1140,7 @@ this.second = second; this.operator = this.CONVERSIONS[operator] || operator; this.flip = !!flip; + this.first instanceof ValueNode && this.first.base instanceof ObjectNode ? (this.first = new ParentheticalNode(this.first)) : null; return this; }; __extends(OpNode, BaseNode); @@ -1373,7 +1374,7 @@ if (code.substr(l - 1, 1) === ';') { code = code.substr(o, l - 1); } - return (this.expression instanceof AssignNode) ? code : ("(" + code + ")"); + return this.expression instanceof AssignNode ? code : ("(" + code + ")"); }; return ParentheticalNode; })(); @@ -1519,8 +1520,6 @@ this.tags = tags || {}; if (this.tags.invert) { this.condition = new OpNode('!', new ParentheticalNode(this.condition)); - } else if (this.condition instanceof OpNode && this.condition.operator === 'instanceof') { - this.condition = new ParentheticalNode(this.condition); } this.elseBody = null; this.isChain = false; @@ -1606,7 +1605,7 @@ } }; IfNode.prototype.ensureExpressions = function(node) { - return (node instanceof Expressions) ? node : new Expressions([node]); + return node instanceof Expressions ? node : new Expressions([node]); }; IfNode.prototype.compileStatement = function(o) { var body, child, comDent, condO, elsePart, ifDent, ifPart; diff --git a/src/nodes.coffee b/src/nodes.coffee index 1abf49e4..05821495 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1039,6 +1039,8 @@ exports.OpNode = class OpNode extends BaseNode @second = second @operator = @CONVERSIONS[operator] or operator @flip = !!flip + if @first instanceof ValueNode and @first.base instanceof ObjectNode + @first = new ParentheticalNode @first isUnary: -> not @second @@ -1335,10 +1337,7 @@ exports.IfNode = class IfNode extends BaseNode @condition = condition @body = body @tags = tags or {} - if @tags.invert - @condition = new OpNode('!', new ParentheticalNode(@condition)) - else if @condition instanceof OpNode and @condition.operator is 'instanceof' - @condition = new ParentheticalNode(@condition) + @condition = new OpNode('!', new ParentheticalNode(@condition)) if @tags.invert @elseBody = null @isChain = false diff --git a/test/test_if.coffee b/test/test_if.coffee index bd5422c7..82929c9e 100644 --- a/test/test_if.coffee +++ b/test/test_if.coffee @@ -74,3 +74,6 @@ if {} instanceof Object ok yes else ok no + +result = {} + {} +ok result is '[object Object][object Object]' \ No newline at end of file