removing the constructor safety check -- it wasn't safe enough (Issue 36)

This commit is contained in:
Jeremy Ashkenas
2010-02-09 07:59:48 -05:00
parent 522df2a355
commit c6a6788694
4 changed files with 22 additions and 14 deletions

View File

@@ -171,11 +171,8 @@ module CoffeeScript
return "#{stmt ? '' : idt}#{node.compile(o.merge(:top => true))}#{stmt ? '' : ';'}" unless returns
# If it's a statement, the node knows how to return itself.
return node.compile(o.merge(:return => true)) if node.statement?
# If it's not part of a constructor, we can just return the value of the expression.
return "#{idt}return #{node.compile(o)};" unless o[:scope].function && o[:scope].function.constructor?
# It's the last line of a constructor, add a safety check.
temp = o[:scope].free_variable
"#{idt}#{temp} = #{node.compile(o)};\n#{idt}return #{o[:scope].function.name} === this.constructor ? this : #{temp};"
# Otherwise, we can just return the value of the expression.
return "#{idt}return #{node.compile(o)};"
end
end