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 {
3333 super ( name , "iterable" ) ;
3434 }
3535}
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 44 ErrNotSupport ,
55 ErrDuplicateDeclard ,
66 ErrUnexpectedToken ,
7- ErrInvalidIterable
7+ ErrInvalidIterable ,
8+ ErrNoSuper
89} from "./error" ;
910import { Scope , ScopeVar , Kind } from "./scope" ;
1011import {
@@ -832,7 +833,24 @@ const evaluate_map = {
832833 }
833834 } ) ;
834835
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+ ) ;
836854 }
837855
838856 return __this ;
You can’t perform that action at this time.
0 commit comments