Closed Alexejhero closed 4 years ago
Update:
I added this to the generator, and it now causes an infinite loop.
if (generator.type != block.type) return Blockly.JavaScript[block.type](block);
I don't understand what's happening anymore.
Fixed. There was a bug in my code.
I have the following block:![image](https://user-images.githubusercontent.com/32238504/76140953-578dd680-6068-11ea-807b-ea50719c956e.png)
with the following definition:
How the generator property is handled
```js if (json.generator || json.returnGen) { generators.push({ type: json.block.type, generator: json.generator, returnGen: json.returnGen, }); } ``` Client-side (not used for anything except debugging): ```ejs <% generators.forEach(g => { %> Blockly.JavaScript['<%= g.type %>'] = function(block) { var _return; if (block.returns) eval(decode("<%= g.returnGen %>")); else eval(decode("<%= g.generator %>")); return _return; } <% }); %> ``` Server-side (used for compiling): ```js for (var generator of dlocklyInstance.generators) { Blockly.JavaScript[generator.type] = function (block) { var _return; if (block.returns) eval(generator.returnGen.replace(/\\\\/g, "\\")); else eval(generator.generator.replace(/\\\\/g, "\\")); return _return; } } ``` Basically, in the end, the block's generator is set correctly. The `returns` property of the block is used for a generic mutation, and this error only occurs with event/root blocks. (unmutated)I use two environments. I use the browser version of Blockly (obviously), and I also use the Node version of Blockly in order to compile XML server-side and avoid code injection.
When running the
workspaceToCode
function in the browser, the returned code is correct:However, when running the
workspaceToCode
function server-side, an error is thrownI replaced the server-side generator with this, in order to add some console logs:
And I got the following result:
generator.type
=send_message
block.type
=on_message
_return
=await .send();
// Code generated via thesend_message
generatorWhat?? The block uses a different generator?
I have been trying to wrap my head around this for a while. I do not think this is an issue with my code, since no matter how badly I mess up the code,
generator.type
should never be different fromblock.type
. Right?I decided to post this issue here first before posting it on the main blockly repository, in case there was any relation specifically to the node version.