fixing a nasty little bug with not dup'ing a string in Scope.rb, causing later functions to start their free_variables where previous functions left off, because they shared their ancestor's @temp_variable string

This commit is contained in:
Jeremy Ashkenas
2010-01-04 00:16:38 -05:00
parent e9b72ee955
commit 3f30712ca1
2 changed files with 172 additions and 168 deletions

View File

@@ -12,12 +12,12 @@ module CoffeeScript
def initialize(parent, expressions)
@parent, @expressions = parent, expressions
@variables = {}
@temp_variable = @parent ? @parent.temp_variable : '__a'
@temp_variable = @parent ? @parent.temp_variable.dup : '__a'
end
# Look up a variable in lexical scope, or declare it if not found.
def find(name, remote=false)
found = check(name, remote)
found = check(name)
return found if found || remote
@variables[name.to_sym] = :var
found
@@ -30,9 +30,9 @@ module CoffeeScript
end
# Just check to see if a variable has already been declared.
def check(name, remote=false)
def check(name)
return true if @variables[name.to_sym]
@parent && @parent.find(name, true)
!!(@parent && @parent.check(name))
end
# You can reset a found variable on the immediate scope.