@@ -180,7 +180,7 @@ const visitors: EvaluateMap = {
180180 } ,
181181 LabeledStatement ( path ) {
182182 const label = path . node . label as types . Identifier ;
183- evaluate (
183+ return evaluate (
184184 path . createChild ( path . node . body , path . scope , { labelName : label . name } )
185185 ) ;
186186 } ,
@@ -416,15 +416,6 @@ const visitors: EvaluateMap = {
416416 evaluate ( path . createChild ( node . init , forScope ) ) ;
417417 }
418418
419- const labelVarName : string = "@label-" + labelName ;
420- const labelBreakVarName : string = "@break-" + labelName ;
421-
422- // set the label for loop
423- if ( labelName ) {
424- // var label
425- forScope . const ( labelVarName , labelName ) ;
426- }
427-
428419 function update ( ) : void {
429420 if ( node . update ) {
430421 evaluate ( path . createChild ( node . update , forScope ) ) ;
@@ -441,44 +432,36 @@ const visitors: EvaluateMap = {
441432 const loopScope = forScope . fork ( "for_child" ) ;
442433 loopScope . isolated = false ;
443434
444- if ( ! test ( ) || forScope . hasOwnBinding ( labelBreakVarName ) ) {
435+ if ( ! test ( ) ) {
445436 break ;
446437 }
447438
448- const result = evaluate (
439+ const signal = evaluate (
449440 path . createChild ( node . body , loopScope , { labelName : undefined } )
450441 ) ;
451442
452- if ( Signal . isBreak ( result ) ) {
453- if ( result . value ) {
454- // Break specified loop
455- // first, find the scope
456- const labelScope = loopScope . locate ( "@label-" + result . value ) ;
457-
458- // if scope exist, set break mark
459- if ( labelScope && labelScope . origin ) {
460- labelScope . origin . var ( "@break-" + result . value , true ) ;
461- return new Signal ( "break" , result . value ) ;
462- }
443+ if ( Signal . isBreak ( signal ) ) {
444+ if ( ! signal . value ) {
445+ break ;
463446 }
464-
465- break ;
466- } else if ( Signal . isContinue ( result ) ) {
467- if ( result . value ) {
468- if ( result . value === labelName ) {
447+ if ( signal . value === labelName ) {
448+ break ;
449+ }
450+ return new Signal ( "break" , signal . value ) ;
451+ } else if ( Signal . isContinue ( signal ) ) {
452+ if ( signal . value ) {
453+ if ( signal . value === labelName ) {
469454 update ( ) ;
470455 continue ;
471456 }
472- return new Signal ( "continue" , result . value ) ;
457+ return new Signal ( "continue" , signal . value ) ;
473458 }
474459 continue ;
475- } else if ( Signal . isReturn ( result ) ) {
476- return result ;
460+ } else if ( Signal . isReturn ( signal ) ) {
461+ return signal ;
477462 }
478463
479- if ( ! forScope . hasOwnBinding ( labelBreakVarName ) ) {
480- update ( ) ;
481- }
464+ update ( ) ;
482465 }
483466 } ,
484467 // @es 2015 for of
0 commit comments