mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixing Issue #506. existential chains should force parentheses in the presense of a compiled ternary operator.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user