@@ -433,22 +433,26 @@ export class ScriptLetContext {
433433
434434 public nestEachBlock (
435435 expression : ESTree . Expression ,
436- context : ESTree . Pattern ,
436+ context : ESTree . Pattern | null ,
437437 indexRange : { start : number ; end : number } | null ,
438438 eachBlock : SvelteEachBlock ,
439439 callback : (
440440 expr : ESTree . Expression ,
441- ctx : ESTree . Pattern ,
441+ ctx : ESTree . Pattern | null ,
442442 index : ESTree . Identifier | null ,
443443 ) => void ,
444444 ) : void {
445445 const exprRange = getNodeRange ( expression ) ;
446- const ctxRange = getNodeRange ( context ) ;
446+ const ctxRange = context && getNodeRange ( context ) ;
447447 let source = "Array.from(" ;
448448 const exprOffset = source . length ;
449449 source += `${ this . ctx . code . slice ( ...exprRange ) } ).forEach((` ;
450450 const ctxOffset = source . length ;
451- source += this . ctx . code . slice ( ...ctxRange ) ;
451+ if ( ctxRange ) {
452+ source += this . ctx . code . slice ( ...ctxRange ) ;
453+ } else {
454+ source += "__$ctx__" ;
455+ }
452456 let idxOffset : number | null = null ;
453457 if ( indexRange ) {
454458 source += "," ;
@@ -473,7 +477,7 @@ export class ScriptLetContext {
473477 const scope = result . getScope ( fn . body ) ;
474478
475479 // Process for nodes
476- callback ( expr , ctx , idx ) ;
480+ callback ( expr , context ? ctx : null , idx ) ;
477481
478482 // Process for scope
479483 result . registerNodeToScope ( eachBlock , scope ) ;
@@ -484,6 +488,10 @@ export class ScriptLetContext {
484488 }
485489 }
486490 }
491+ if ( ! context ) {
492+ // remove `__$ctx__` variable
493+ removeIdentifierVariable ( ctx , scope ) ;
494+ }
487495 // remove Array reference
488496 const arrayId = ( callArrayFrom . callee as ESTree . MemberExpression )
489497 . object ;
@@ -512,18 +520,24 @@ export class ScriptLetContext {
512520 tokens . pop ( ) ; // )
513521 tokens . pop ( ) ; // ;
514522
515- const map = [
523+ const map : {
524+ offset : number ;
525+ range : [ number , number ] ;
526+ newNode : ESTree . Expression | ESTree . Pattern ;
527+ } [ ] = [
516528 {
517529 offset : exprOffset ,
518530 range : exprRange ,
519531 newNode : expr ,
520532 } ,
521- {
533+ ] ;
534+ if ( ctxRange ) {
535+ map . push ( {
522536 offset : ctxOffset ,
523537 range : ctxRange ,
524538 newNode : ctx ,
525- } ,
526- ] ;
539+ } ) ;
540+ }
527541 if ( indexRange ) {
528542 map . push ( {
529543 offset : idxOffset ! ,
0 commit comments