Thanks Neil, while Agrawal tries your suggestion, here are more details on it: We have a custom block which changes shape from producing output to statement block depending on a value selection from a dropdown. Here is the sample code that I wrote to produce this error:
Blockly.Blocks['UpgradeTestBlock'] = {
init: function () {
const getsetOptions = [['Get', 'Get'], ['Set', 'Set'], ['Remove', 'Remove']];
var modeMenu = new Blockly.FieldDropdown(getsetOptions, function (value) {
var isStatement = value == 'Set' || value == 'Remove';
this.getSourceBlock().updateStatement_(isStatement);
});
this.appendValueInput('KeyName')
.appendField('In Lookup', 'Lookup')
.appendField(modeMenu, 'GetOrSet')
this.setOutput(true);
},
updateStatement_: function (newStatement) {
var oldStatement = !this.outputConnection;
if (newStatement != oldStatement) {
this.unplug(true, true);
if (newStatement) {
this.setOutput(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
} else {
this.setPreviousStatement(false);
this.setNextStatement(false);
this.setOutput(true);
}
}
}
};
Here is the snapshot of the sample block:
If the same block which changes shape is used in a function or a contained stack statement, it gives the error Agrawal mentioned:
TypeError: Next block does not have previous statement.
at module$contents$Blockly$Xml_domToBlockHeadless (blockly_compressed.js:246:81)
at module$contents$Blockly$Xml_applyNextTagNodes (blockly_compressed.js:244:423)
at module$contents$Blockly$Xml_domToBlockHeadless (blockly_compressed.js:246:457)
at module$contents$Blockly$Xml_applyInputTagNodes (blockly_compressed.js:243:494)
at module$contents$Blockly$Xml_domToBlockHeadless (blockly_compressed.js:246:395)
at $.module$exports$Blockly$Xml.domToBlock (blockly_compressed.js:236:280)
at $.module$exports$Blockly$Xml.domToWorkspace (blockly_compressed.js:231:124)
at BlocklyComponent.getBlocklyWorkspace (blockly.component.ts:723:13)
at BlocklyComponent.ngAfterViewInit (blockly.component.ts:680:18)
at callHook (core.mjs:2577:22)
Thanks,
Lax