@@ -115,7 +115,7 @@ Blockly.Blocks['logic_multi_and'] = {
115115
116116 // Disconnect any children that don't belong.
117117 for ( let k = 0 ; k < this . itemCount_ ; k ++ ) {
118- const connection = this . getInput ( ' AND' + k ) . connection . targetConnection ;
118+ const connection = this . getInput ( ` AND${ k } ` ) . connection . targetConnection ;
119119 if ( connection && ! connections . includes ( connection ) ) {
120120 connection . disconnect ( ) ;
121121 }
@@ -142,11 +142,16 @@ Blockly.Blocks['logic_multi_and'] = {
142142 let i = 0 ;
143143
144144 while ( itemBlock ) {
145- const input = this . getInput ( 'AND' + i ) ;
146- itemBlock . valueConnection_ = input && input . connection . targetConnection ;
145+ let input ;
146+ try {
147+ input = this . getInput ( 'AND' + i ) ;
148+ } catch ( e ) {
149+ // If the input does not exist, it means that the block has been removed.
150+ input = null ;
151+ }
152+ itemBlock . valueConnection_ = input ?. connection . targetConnection ;
147153 i ++ ;
148- itemBlock = itemBlock . nextConnection &&
149- itemBlock . nextConnection . targetBlock ( ) ;
154+ itemBlock = itemBlock . nextConnection ?. targetBlock ( ) ;
150155 }
151156 } ,
152157 /**
@@ -157,16 +162,28 @@ Blockly.Blocks['logic_multi_and'] = {
157162 updateShape_ : function ( ) {
158163 // Add new inputs.
159164 for ( let i = 0 ; i < this . itemCount_ ; i ++ ) {
160- if ( ! this . getInput ( 'AND' + i ) ) {
165+ let input ;
166+ try {
167+ input = this . getInput ( 'AND' + i ) ;
168+ } catch ( e ) {
169+ // If the input does not exist, it means that the block has been removed.
170+ input = null ;
171+ }
172+ if ( ! input ) {
161173 const input = this . appendValueInput ( 'AND' + i ) . setAlign ( Blockly . ALIGN_RIGHT ) ;
162174 if ( i > 0 ) {
163175 input . appendField ( Blockly . Translate ( 'logic_multi_and_and' ) ) ;
164176 }
165177 }
166178 }
167179 // Remove deleted inputs.
168- for ( let i = this . itemCount_ ; this . getInput ( 'AND' + i ) ; i ++ ) {
169- this . removeInput ( 'AND' + i ) ;
180+ try {
181+ for ( let i = this . itemCount_ ; this . getInput ( 'AND' + i ) ; i ++ ) {
182+ this . removeInput ( 'AND' + i ) ;
183+ }
184+ } catch ( e ) {
185+ // If the input does not exist, it means that the block has been removed.
186+ // Do nothing.
170187 }
171188 } ,
172189} ;
@@ -321,11 +338,16 @@ Blockly.Blocks['logic_multi_or'] = {
321338 let i = 0 ;
322339
323340 while ( itemBlock ) {
324- const input = this . getInput ( 'OR' + i ) ;
325- itemBlock . valueConnection_ = input && input . connection . targetConnection ;
341+ let input ;
342+ try {
343+ input = this . getInput ( 'OR' + i ) ;
344+ } catch ( e ) {
345+ // If the input does not exist, it means that the block has been removed.
346+ input = null ;
347+ }
348+ itemBlock . valueConnection_ = input ?. connection . targetConnection ;
326349 i ++ ;
327- itemBlock = itemBlock . nextConnection &&
328- itemBlock . nextConnection . targetBlock ( ) ;
350+ itemBlock = itemBlock . nextConnection ?. targetBlock ( ) ;
329351 }
330352 } ,
331353 /**
@@ -336,16 +358,27 @@ Blockly.Blocks['logic_multi_or'] = {
336358 updateShape_ : function ( ) {
337359 // Add new inputs.
338360 for ( let i = 0 ; i < this . itemCount_ ; i ++ ) {
339- if ( ! this . getInput ( 'OR' + i ) ) {
361+ let input ;
362+ try {
363+ input = this . getInput ( 'OR' + i ) ;
364+ } catch ( e ) {
365+ input = null ;
366+ }
367+ if ( ! input ) {
340368 const input = this . appendValueInput ( 'OR' + i ) . setAlign ( Blockly . ALIGN_RIGHT ) ;
341369 if ( i > 0 ) {
342370 input . appendField ( Blockly . Translate ( 'logic_multi_or_or' ) ) ;
343371 }
344372 }
345373 }
346374 // Remove deleted inputs.
347- for ( let i = this . itemCount_ ; this . getInput ( 'OR' + i ) ; i ++ ) {
348- this . removeInput ( 'OR' + i ) ;
375+ try {
376+ for ( let i = this . itemCount_ ; this . getInput ( 'OR' + i ) ; i ++ ) {
377+ this . removeInput ( 'OR' + i ) ;
378+ }
379+ } catch ( e ) {
380+ // If the input does not exist, it means that the block has been removed.
381+ // Do nothing.
349382 }
350383 } ,
351384} ;
0 commit comments