Blockly commandeer code generation for following statements

247 Views Asked by At

How can I make a block that compiles to wrap all blocks that follow it?

Here is an example of the block I want to make:

enter image description here

I want to write generators that create the output:

console.log('1');
console.log('2');
(function () {
  console.log('3');
  console.log('4');
}());

I have thought of two possible solutions:

My idea 1

The pseudo-C-block generator should do what a normal C-block generator does.

  1. Get the transpilation of all following blocks.
  2. Prevent Blockly from automatically transpiling the following blocks itself.

I have already looked at doing 1 using block.nextConnection.targetBlock() and Blockly.JavaScript.blockToCode. It's inconvenient to loop like that, and I also haven't figured out how to solve the second point.

The second point is because I don't want output like

console.log('1');
console.log('2');
(function () {
  console.log('3');
  console.log('4');
}());
console.log('3');
console.log('4');

My idea 2

Create a custom style for the pseudo-C-block. It really does have a input_statement argument, but the input_statement is invisible to the user and instead any blocks attached to the bottom of the psuedo-C-block are actually being attached into that input_statement

Unfortunately I have no idea how to accomplish this.


Please could someone point me in the right directions?

0

There are 0 best solutions below