@@ -6,6 +6,19 @@ CONSTRUCTOR_NAME = "new"
66import insert from table
77import build, ntype, NOOP from require " moonscript.types"
88
9+ super_scope = ( value, key) ->
10+ local prev_method
11+
12+ {
13+ " scoped" ,
14+ Run =>
15+ prev_method = @get " current_method"
16+ @set " current_method" , key
17+ value
18+ Run =>
19+ @set " current_method" , prev_method
20+ }
21+
922( node, ret, parent_assign) =>
1023 _, name, parent_val, body = unpack node
1124 parent_val = nil if parent_val == " "
@@ -32,7 +45,8 @@ import build, ntype, NOOP from require "moonscript.types"
3245 constructor = tuple[ 2 ]
3346 continue
3447 else
35- tuple
48+ { key, val} = tuple
49+ { key, super_scope val, key}
3650
3751 parent_cls_name = NameProxy " parent"
3852 base_name = NameProxy " base"
@@ -77,7 +91,7 @@ import build, ntype, NOOP from require "moonscript.types"
7791 { " string" , ' "' , flattened_name}
7892
7993 cls = build. table {
80- { " __init" , constructor}
94+ { " __init" , super_scope constructor, { " key_literal " , " __init " } }
8195 { " __base" , base_name}
8296 { " __name" , real_name} -- "quote the string"
8397 parent_val and { " __parent" , parent_cls_name} or nil
@@ -173,7 +187,7 @@ import build, ntype, NOOP from require "moonscript.types"
173187 switch head[ 1 ]
174188 -- calling super, inject calling name and self into chain
175189 when " call"
176- calling_name = block\ get" current_block "
190+ calling_name = block\ get " current_method "
177191 assert calling_name, " missing calling name"
178192 chain_tail[ 1 ] = { " call" , { " self" , unpack head[ 2 ]}}
179193
0 commit comments