@@ -34,7 +34,6 @@ const stringify = (object, type) => {
3434 if ( type === 'array' && ! Array . isArray ( object ) ) return '[]' ;
3535 if ( type === 'object' && Array . isArray ( object ) ) return '{}' ;
3636 }
37- console . log ( object , type ) ;
3837 return ( ( typeof object === 'string' ) ? object : JSON . stringify ( object ?? (
3938 type === 'object' ? ( new Object ( ) ) : ( new Array ( ) )
4039 ) ) ) ;
@@ -536,11 +535,11 @@ class JSGenerator {
536535 case 'json.valueOfKey' :
537536 return new TypedInput ( `(${ this . descendInput ( node . object ) . asObject ( ) } [${ this . descendInput ( node . key ) . asString ( ) } ] ?? "")` , TYPE_STRING ) ;
538537 case 'json.setKey' :
539- return new TypedInput ( `(object = {... ${ this . descendInput ( node . object ) . asObject ( ) } } , object[${ this . descendInput ( node . key ) . asString ( ) } ] = ${ this . descendInput ( node . value ) . asUnknown ( ) } , object)` , TYPE_OBJECT ) ;
538+ return new TypedInput ( `(object = Object.assign({}, ${ this . descendInput ( node . object ) . asObject ( ) } ) , object[${ this . descendInput ( node . key ) . asString ( ) } ] = ${ this . descendInput ( node . value ) . asUnknown ( ) } , object)` , TYPE_OBJECT ) ;
540539 case 'json.deleteKey' :
541- return new TypedInput ( `(object = {... ${ this . descendInput ( node . object ) . asObject ( ) } } , delete object[${ this . descendInput ( node . key ) . asString ( ) } ], object)` , TYPE_OBJECT ) ;
540+ return new TypedInput ( `(object = Object.assign({}, ${ this . descendInput ( node . object ) . asObject ( ) } ) , delete object[${ this . descendInput ( node . key ) . asString ( ) } ], object)` , TYPE_OBJECT ) ;
542541 case 'json.mergeObject' :
543- return new TypedInput ( `{... ${ this . descendInput ( node . object1 ) . asObject ( ) } , ... ${ this . descendInput ( node . object2 ) . asObject ( ) } } ` , TYPE_OBJECT ) ;
542+ return new TypedInput ( `mergeObjects( ${ this . descendInput ( node . object1 ) . asObject ( ) } , ${ this . descendInput ( node . object2 ) . asObject ( ) } ) ` , TYPE_OBJECT ) ;
544543 case 'json.hasKey' :
545544 return new TypedInput ( `${ this . descendInput ( node . object ) . asObject ( ) } .hasOwnProperty(${ this . descendInput ( node . key ) . asString ( ) } )` , TYPE_BOOLEAN ) ;
546545 case 'json.newArray' :
@@ -552,15 +551,15 @@ class JSGenerator {
552551 case 'json.indexOfValue' :
553552 return new TypedInput ( `(${ this . descendInput ( node . array ) . asArray ( ) } .indexOf(${ this . descendInput ( node . value ) . asUnknown ( ) } ) !== -1 ? ${ this . descendInput ( node . array ) . asArray ( ) } .indexOf(${ this . descendInput ( node . value ) . asUnknown ( ) } ) : "")` , TYPE_NUMBER ) ;
554553 case 'json.addItem' :
555- return new TypedInput ( `(array = [... ${ this . descendInput ( node . array ) . asArray ( ) } ] , array.push(${ this . descendInput ( node . item ) . asUnknown ( ) } ), array)` , TYPE_ARRAY ) ;
554+ return new TypedInput ( `(array = ${ this . descendInput ( node . array ) . asArray ( ) } .slice(0) , array.push(${ this . descendInput ( node . item ) . asUnknown ( ) } ), array)` , TYPE_ARRAY ) ;
556555 case 'json.replaceIndex' :
557556 return new TypedInput ( `(${ this . descendInput ( node . index ) . asNumber ( ) } >= 0 && ${ this . descendInput ( node . index ) . asNumber ( ) } < ${ this . descendInput ( node . array ) . asArray ( ) } .length ? (array = [...${ this . descendInput ( node . array ) . asArray ( ) } ], array[${ this . descendInput ( node . index ) . asNumber ( ) } ] = ${ this . descendInput ( node . item ) . asUnknown ( ) } , array) : new Array())` , TYPE_ARRAY ) ;
558557 case 'json.deleteIndex' :
559558 return new TypedInput ( `(${ this . descendInput ( node . index ) . asNumber ( ) } >= 0 && ${ this . descendInput ( node . index ) . asNumber ( ) } < ${ this . descendInput ( node . array ) . asArray ( ) } .length ? (array = [...${ this . descendInput ( node . array ) . asArray ( ) } ], array.splice(${ this . descendInput ( node . index ) . asNumber ( ) } , 1), array) : new Array())` , TYPE_ARRAY ) ;
560559 case 'json.deleteAllOccurrences' :
561560 return new TypedInput ( `${ this . descendInput ( node . array ) . asArray ( ) } .filter((item) => item !== ${ this . descendInput ( node . item ) . asString ( ) } )` , TYPE_ARRAY ) ;
562561 case 'json.mergeArray' :
563- return new TypedInput ( `[... ${ this . descendInput ( node . array1 ) . asArray ( ) } , ... ${ this . descendInput ( node . array2 ) . asArray ( ) } ] ` , TYPE_ARRAY ) ;
562+ return new TypedInput ( `${ this . descendInput ( node . array1 ) . asArray ( ) } .concat( ${ this . descendInput ( node . array2 ) . asArray ( ) } ) ` , TYPE_ARRAY ) ;
564563 case 'json.hasItem' :
565564 return new TypedInput ( `${ this . descendInput ( node . array ) . asArray ( ) } .includes(${ this . descendInput ( node . item ) . asUnknown ( ) } )` , TYPE_BOOLEAN ) ;
566565
0 commit comments