From 4c3f00cf7792bb5840a0c14bad92c19b1aeaf627 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 8 Jan 2010 10:54:44 -0500 Subject: [PATCH] fixing calling super from constructors --- lib/coffee_script/nodes.rb | 4 +++- test/fixtures/execution/test_calling_super.coffee | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 3fc6d6e9..ce7275ca 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -243,7 +243,9 @@ module CoffeeScript def compile_super(args, o) methname = o[:last_assign] arg_part = args.empty? ? '' : ", #{args}" - "#{o[:proto_assign]}.__superClass__.#{methname}.call(this#{arg_part})" + meth = o[:proto_assign] ? "#{o[:proto_assign]}.__superClass__.#{methname}" : + "#{methname}.__superClass__.constructor" + "#{meth}.call(this#{arg_part})" end def compile_splat(o) diff --git a/test/fixtures/execution/test_calling_super.coffee b/test/fixtures/execution/test_calling_super.coffee index 0dee5757..65de1b0c 100644 --- a/test/fixtures/execution/test_calling_super.coffee +++ b/test/fixtures/execution/test_calling_super.coffee @@ -22,3 +22,17 @@ result: (new ThirdChild()).func('four') print(result is 'zero/one/two/three/four') + +TopClass: arg => + this.prop: 'top-' + arg + +SuperClass: arg => + super('super-' + arg) + +SubClass: => + super('sub') + +SuperClass extends TopClass +SubClass extends SuperClass + +print((new SubClass()).prop is 'top-super-sub') \ No newline at end of file