jashkenas--coffeescript/test/test_expressions.coffee

28 lines
576 B
CoffeeScript
Raw Normal View History

# Ensure that we don't wrap Nodes that are "pureStatement" in a closure.
2010-07-25 05:23:37 +00:00
items = [1, 2, 3, "bacon", 4, 5]
2010-02-11 07:41:24 +00:00
for item in items
break if item is "bacon"
2010-07-25 05:23:37 +00:00
findit = (items) ->
for item in items
return item if item is "bacon"
ok findit(items) is "bacon"
# When when a closure wrapper is generated for expression conversion, make sure
# that references to "this" within the wrapper are safely converted as well.
2010-07-25 05:23:37 +00:00
obj = {
2010-02-11 07:41:24 +00:00
num: 5
func: ->
2010-07-25 05:23:37 +00:00
this.result = if false
2010-02-11 07:41:24 +00:00
10
else
"a"
"b"
this.num
}
ok obj.num is obj.func()
ok obj.num is obj.result