added test for lexical scope sharing through generated closure wrappers, something uncommonly used, but that was a regression

This commit is contained in:
Jeremy Ashkenas
2010-01-24 13:39:27 -05:00
parent 817e8deb27
commit af53a04932
3 changed files with 13 additions and 4 deletions

View File

@@ -55,10 +55,11 @@ module CoffeeScript
closure ? compile_closure(@options) : compile_node(@options)
end
# Statements converted into expressions share scope with their parent
# closure, to preserve JavaScript-style lexical scope.
def compile_closure(o={})
indent = o[:indent]
@indent = (o[:indent] = idt(1))
ClosureNode.wrap(self).compile(o)
@indent = o[:indent]
ClosureNode.wrap(self).compile(o.merge(:shared_scope => o[:scope]))
end
# Quick short method for the current indentation level, plus tabbing in.

View File

@@ -51,4 +51,5 @@ arr: ["--", "----"]
print(arr.pop()?.length is 4)
print(arr.pop()?.length is 2)
print(arr.pop()?.length is undefined)
print(arr[0]?.length is undefined)
print(arr.pop()?.length?.non?.existent()?.property is undefined)

View File

@@ -1,3 +1,10 @@
num: 1 + 2 + (a: 3)
print(num is 6)
print(num is 6)
result: if true
false
other: "result"
print(result is "result" and other is "result")