fixing single evaluation of functions used in chained comparisons wrapped in parentheses.

This commit is contained in:
Jeremy Ashkenas
2010-03-31 22:48:47 -04:00
parent f86fca2739
commit 3605168e85
3 changed files with 22 additions and 2 deletions

View File

@@ -98,6 +98,10 @@ exports.BaseNode: class BaseNode
return true if node.contains and node.contains block
false
# Is this node of a certain type, or does it contain the type?
contains_type: (type) ->
this instanceof type or @contains (n) -> n instanceof type
# Convenience for the most common use of contains. Does the node contain
# a pure statement?
contains_pure_statement: ->
@@ -928,7 +932,7 @@ exports.OpNode: class OpNode extends BaseNode
# true
compile_chain: (o) ->
shared: @first.unwrap().second
[@first.second, shared]: shared.compile_reference(o) if shared instanceof CallNode
[@first.second, shared]: shared.compile_reference(o) if shared.contains_type CallNode
[first, second, shared]: [@first.compile(o), @second.compile(o), shared.compile(o)]
"($first) && ($shared $@operator $second)"