diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index f89cd96b..64463d29 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -100,7 +100,9 @@ module CoffeeScript if node.statement? node.compile(o.merge(:return => true)) else - "#{o[:indent]}return #{node.compile(o)};" + constructor = o[:top] && o[:last_assign] && o[:last_assign][0..0][/[A-Z]/] + prefix = constructor ? "if (#{o[:last_assign]} !== this.constructor) " : '' + "#{o[:indent]}#{prefix}return #{node.compile(o)};" end else ending = node.statement? ? '' : ';' diff --git a/test/fixtures/execution/test_calling_super.coffee b/test/fixtures/execution/test_calling_super.coffee index 8a9d4bc1..0dee5757 100644 --- a/test/fixtures/execution/test_calling_super.coffee +++ b/test/fixtures/execution/test_calling_super.coffee @@ -6,13 +6,14 @@ FirstChild: => FirstChild extends Base FirstChild.prototype.func: string => super('one/') + string - + SecondChild: => SecondChild extends FirstChild SecondChild.prototype.func: string => super('two/') + string - + ThirdChild: => + this.array: [1, 2, 3] ThirdChild extends SecondChild ThirdChild.prototype.func: string => super('three/') + string