@@ -180,7 +180,7 @@ const visitors: EvaluateMap = {
180
180
} ,
181
181
LabeledStatement ( path ) {
182
182
const label = path . node . label as types . Identifier ;
183
- evaluate (
183
+ return evaluate (
184
184
path . createChild ( path . node . body , path . scope , { labelName : label . name } )
185
185
) ;
186
186
} ,
@@ -416,15 +416,6 @@ const visitors: EvaluateMap = {
416
416
evaluate ( path . createChild ( node . init , forScope ) ) ;
417
417
}
418
418
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
-
428
419
function update ( ) : void {
429
420
if ( node . update ) {
430
421
evaluate ( path . createChild ( node . update , forScope ) ) ;
@@ -441,44 +432,36 @@ const visitors: EvaluateMap = {
441
432
const loopScope = forScope . fork ( "for_child" ) ;
442
433
loopScope . isolated = false ;
443
434
444
- if ( ! test ( ) || forScope . hasOwnBinding ( labelBreakVarName ) ) {
435
+ if ( ! test ( ) ) {
445
436
break ;
446
437
}
447
438
448
- const result = evaluate (
439
+ const signal = evaluate (
449
440
path . createChild ( node . body , loopScope , { labelName : undefined } )
450
441
) ;
451
442
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 ;
463
446
}
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 ) {
469
454
update ( ) ;
470
455
continue ;
471
456
}
472
- return new Signal ( "continue" , result . value ) ;
457
+ return new Signal ( "continue" , signal . value ) ;
473
458
}
474
459
continue ;
475
- } else if ( Signal . isReturn ( result ) ) {
476
- return result ;
460
+ } else if ( Signal . isReturn ( signal ) ) {
461
+ return signal ;
477
462
}
478
463
479
- if ( ! forScope . hasOwnBinding ( labelBreakVarName ) ) {
480
- update ( ) ;
481
- }
464
+ update ( ) ;
482
465
}
483
466
} ,
484
467
// @es 2015 for of
0 commit comments