@@ -42,23 +42,16 @@ export class Frame {
4242 private constructor ( ) { }
4343
4444 public getMethod ( name : string ) : Method | Error {
45- let frame : Frame | null = this
46- while ( frame ) {
47- const method = frame . _methods . get ( name )
48- if ( method ) return method
49- frame = frame . _parentFrame
50- }
45+ const method = this . _methods . get ( name )
46+ if ( method ) return method
47+ if ( this . _parentFrame ) return this . _parentFrame . getMethod ( name )
5148 return new CannotFindSymbolError ( )
5249 }
5350
5451 public getReturn ( ) : Type | Error {
55- let frame : Frame | null = this
56- while ( frame ) {
57- const type = frame . _returnType
58- if ( type ) return type
59- frame = frame . _parentFrame
60- }
61- return new Error ( 'Cannot find return type.' )
52+ if ( this . _returnType ) return this . _returnType
53+ if ( this . _parentFrame ) return this . _parentFrame . getReturn ( )
54+ return new Error ( 'cannot find return type' )
6255 }
6356
6457 public getType ( name : string ) : Type | Error {
@@ -69,22 +62,16 @@ export class Frame {
6962 return new Array ( prefixType )
7063 }
7164
72- let frame : Frame | null = this
73- while ( frame ) {
74- const type = frame . _types . get ( name )
75- if ( type ) return type
76- frame = frame . _parentFrame
77- }
65+ const type = this . _types . get ( name )
66+ if ( type ) return type
67+ if ( this . _parentFrame ) return this . _parentFrame . getType ( name )
7868 return new CannotFindSymbolError ( )
7969 }
8070
8171 public getVariable ( name : string ) : Type | Error {
82- let frame : Frame | null = this
83- while ( frame ) {
84- const type = frame . _variables . get ( name )
85- if ( type ) return type
86- frame = frame . _parentFrame
87- }
72+ const variable = this . _variables . get ( name )
73+ if ( variable ) return variable
74+ if ( this . _parentFrame ) return this . _parentFrame . getVariable ( name )
8875 return new CannotFindSymbolError ( )
8976 }
9077
0 commit comments