@@ -36,6 +36,14 @@ export default function (Generator) {
36
36
return `list(${ Generator . quote_ ( list ) } )` ;
37
37
} ;
38
38
39
+ const getListIndex = function ( block ) {
40
+ const index = Generator . valueToCode ( block , 'INDEX' , Generator . ORDER_NONE ) || 1 ;
41
+ if ( index === '0' ) {
42
+ return 1 ;
43
+ }
44
+ return index ;
45
+ } ;
46
+
39
47
Generator . data_listcontents = function ( block ) {
40
48
const list = getListName ( block ) ;
41
49
return [ list , Generator . ORDER_COLLECTION ] ;
@@ -48,7 +56,7 @@ export default function (Generator) {
48
56
} ;
49
57
50
58
Generator . data_deleteoflist = function ( block ) {
51
- const index = Generator . valueToCode ( block , 'INDEX' , Generator . ORDER_NONE ) - 1 || 0 ;
59
+ const index = getListIndex ( block ) ;
52
60
const list = getListName ( block ) ;
53
61
return `${ list } .delete_at(${ Generator . nosToCode ( index ) } )\n` ;
54
62
} ;
@@ -59,21 +67,21 @@ export default function (Generator) {
59
67
} ;
60
68
61
69
Generator . data_insertatlist = function ( block ) {
62
- const index = Generator . valueToCode ( block , 'INDEX' , Generator . ORDER_NONE ) - 1 || 0 ;
70
+ const index = getListIndex ( block ) ;
63
71
const item = Generator . valueToCode ( block , 'ITEM' , Generator . ORDER_NONE ) || '0' ;
64
72
const list = getListName ( block ) ;
65
73
return `${ list } .insert(${ index } , ${ Generator . nosToCode ( item ) } )\n` ;
66
74
} ;
67
75
68
76
Generator . data_replaceitemoflist = function ( block ) {
69
- const index = Generator . valueToCode ( block , 'INDEX' , Generator . ORDER_INDEX ) - 1 || 0 ;
77
+ const index = getListIndex ( block ) ;
70
78
const item = Generator . valueToCode ( block , 'ITEM' , Generator . ORDER_NONE ) || '0' ;
71
79
const list = getListName ( block ) ;
72
80
return `${ list } [${ index } ] = ${ Generator . nosToCode ( item ) } \n` ;
73
81
} ;
74
82
75
83
Generator . data_itemoflist = function ( block ) {
76
- const index = Generator . valueToCode ( block , 'INDEX' , Generator . ORDER_INDEX ) - 1 || 0 ;
84
+ const index = getListIndex ( block ) ;
77
85
const list = getListName ( block ) ;
78
86
return [ `${ list } [${ index } ]` , Generator . ORDER_FUNCTION_CAL ] ;
79
87
} ;
0 commit comments