@@ -302,6 +302,10 @@ class RubyToBlocksConverter {
302302 return value && value . type === 'hash' ;
303303 }
304304
305+ _isConst ( value ) {
306+ return value && value . type === 'const' ;
307+ }
308+
305309 _isBlock ( block ) {
306310 try {
307311 return block . hasOwnProperty ( 'opcode' ) ;
@@ -378,6 +382,9 @@ class RubyToBlocksConverter {
378382 }
379383
380384 _createFieldBlock ( opcode , fieldName , value ) {
385+ if ( this . _isBlock ( value ) ) {
386+ return value ;
387+ }
381388 return this . _createBlock ( opcode , 'value' , {
382389 fields : {
383390 [ fieldName ] : {
@@ -461,6 +468,14 @@ class RubyToBlocksConverter {
461468 this . _addInput ( block , name , this . _createTextBlock ( inputValue ) , shadowBlock ) ;
462469 }
463470
471+ _addFieldInput ( block , name , opcode , fieldName , inputValue , shadowValue ) {
472+ let shadowBlock ;
473+ if ( ! this . _isString ( inputValue ) ) {
474+ shadowBlock = this . _createFieldBlock ( opcode , fieldName , shadowValue ) ;
475+ }
476+ this . _addInput ( block , name , this . _createFieldBlock ( opcode , fieldName , inputValue ) , shadowBlock ) ;
477+ }
478+
464479 _addSubstack ( block , substackBlock , num = 1 ) {
465480 let name = 'SUBSTACK' ;
466481 if ( num > 1 ) {
@@ -893,7 +908,11 @@ class RubyToBlocksConverter {
893908 _onConst ( node ) {
894909 this . _checkNumChildren ( node , 2 ) ;
895910
896- return this . _createRubyExpressionBlock ( this . _getSource ( node ) ) ;
911+ const value = {
912+ scope : this . _process ( node . children [ 0 ] ) ,
913+ name : node . children [ 1 ] . toString ( )
914+ } ;
915+ return new Primitive ( 'const' , value , node ) ;
897916 }
898917
899918 _onArgs ( node ) {
0 commit comments