Fixing Issue #506. existential chains should force parentheses in the presense of a compiled ternary operator.

This commit is contained in:
Jeremy Ashkenas
2010-07-15 21:38:35 -04:00
parent 72c4efbc39
commit b810d10e80
3 changed files with 9 additions and 2 deletions

View File

@@ -1598,6 +1598,7 @@
};
IfNode.prototype.compileTernary = function(o) {
var elsePart, ifPart;
o.operation = true;
ifPart = this.condition.compile(o) + ' ? ' + this.bodyNode().compile(o);
elsePart = this.elseBody ? this.elseBodyNode().compile(o) : 'null';
return "" + ifPart + " : " + elsePart;

View File

@@ -1402,8 +1402,9 @@ exports.IfNode: class IfNode extends BaseNode
# Compile the IfNode as a ternary operator.
compileTernary: (o) ->
ifPart: @condition.compile(o) + ' ? ' + @bodyNode().compile(o)
elsePart: if @elseBody then @elseBodyNode().compile(o) else 'null'
o.operation: true
ifPart: @condition.compile(o) + ' ? ' + @bodyNode().compile(o)
elsePart: if @elseBody then @elseBodyNode().compile(o) else 'null'
"$ifPart : $elsePart"
# Faux-Nodes

View File

@@ -93,3 +93,8 @@ ok result is undefined
# Assign to the result of an exsitential operation with a minus.
x: null ? - 1
ok x is - 1
# Things that compile to ternaries should force parentheses, like operators do.
duration: if options?.animated then 150 else 0
ok duration is 0