@@ -425,18 +425,11 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
425425 handleError ( context , error )
426426 return undefined
427427 }
428-
429- // Create a new frame (block scoping)
430- const frame = createBlockFrame ( context , "ifBlockFrame" )
431- pushFrame ( context , frame )
432-
433428 if ( test ) {
434429 const result = yield * evaluate ( node . consequent , context )
435- popFrame ( context )
436430 return result
437431 } else if ( node . alternate ) {
438432 const result = yield * evaluate ( node . alternate , context )
439- popFrame ( context )
440433 return result
441434 } else {
442435 return undefined
@@ -468,13 +461,7 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
468461 ! ( value instanceof BreakValue ) &&
469462 ! ( value instanceof TailCallReturnValue )
470463 ) {
471- // Create a new frame (block scoping)
472- const frame = createBlockFrame ( context , "whileBlockFrame" )
473- pushFrame ( context , frame )
474-
475464 value = yield * evaluate ( node . body , context )
476-
477- popFrame ( context )
478465 }
479466 if ( value instanceof BreakValue ) {
480467 return undefined
@@ -496,6 +483,11 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
496483 } ,
497484 BlockStatement : function * ( node : es . BlockStatement , context : Context ) {
498485 let result : Value
486+
487+ // Create a new frame (block scoping)
488+ const frame = createBlockFrame ( context , "blockFrame" )
489+ pushFrame ( context , frame )
490+
499491 for ( const statement of node . body ) {
500492 result = yield * evaluate ( statement , context )
501493 if (
@@ -506,6 +498,7 @@ export const evaluators: { [nodeType: string]: Evaluator<es.Node> } = {
506498 break
507499 }
508500 }
501+ popFrame ( context )
509502 return result
510503 } ,
511504 Program : function * ( node : es . BlockStatement , context : Context ) {
0 commit comments