This repository was archived by the owner on Sep 10, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +233
-190
lines changed Expand file tree Collapse file tree 3 files changed +233
-190
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,7 @@ export class ErrInvalidIterable extends ErrIsNot {
33
33
super ( name , "iterable" ) ;
34
34
}
35
35
}
36
+
37
+ export const ErrNoSuper = new ReferenceError (
38
+ `Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor`
39
+ ) ;
Original file line number Diff line number Diff line change 4
4
ErrNotSupport ,
5
5
ErrDuplicateDeclard ,
6
6
ErrUnexpectedToken ,
7
- ErrInvalidIterable
7
+ ErrInvalidIterable ,
8
+ ErrNoSuper
8
9
} from "./error" ;
9
10
import { Scope , ScopeVar , Kind } from "./scope" ;
10
11
import {
@@ -832,7 +833,24 @@ const evaluate_map = {
832
833
}
833
834
} ) ;
834
835
835
- evaluate ( constructor , newScope , { SuperClass} ) ;
836
+ if ( node . superClass ) {
837
+ // make sure super exist in first line
838
+ const superCallExpression : types . ExpressionStatement = < types . ExpressionStatement > ( < any > constructor ) . body . body . shift ( ) ;
839
+
840
+ if (
841
+ ! types . isExpressionStatement ( superCallExpression ) ||
842
+ ! types . isCallExpression ( superCallExpression . expression ) ||
843
+ ! types . isSuper ( superCallExpression . expression . callee )
844
+ ) {
845
+ throw ErrNoSuper ;
846
+ } else {
847
+ // TODO: run super
848
+ }
849
+ }
850
+
851
+ constructor . body . body . forEach ( n =>
852
+ evaluate ( n , newScope , { SuperClass} )
853
+ ) ;
836
854
}
837
855
838
856
return __this ;
You can’t perform that action at this time.
0 commit comments