fix(demos): Update to use new script import names for generators (#7213)

This is mostly just chore updating to the new import names
(e.g. BlocklyJavaScript -> javascript.javascriptGenerator),
but the change to Code.checkAllGeneratorFunctionsDefined is
a necessary fix due to the breaking change in PR #7150,
implementing the .forBlock dictionary.
This commit is contained in:
Christopher Allen
2023-06-27 17:50:36 +01:00
committed by GitHub
parent 5579098e35
commit e49c028c84

View File

@@ -356,15 +356,15 @@ Code.renderContent = function() {
Blockly.serialization.workspaces.save(Code.workspace), null, 2);
jsonTextarea.focus();
} else if (content.id === 'content_javascript') {
Code.attemptCodeGeneration(Blockly.JavaScript);
Code.attemptCodeGeneration(javascript.javascriptGenerator);
} else if (content.id === 'content_python') {
Code.attemptCodeGeneration(Blockly.Python);
Code.attemptCodeGeneration(python.pythonGenerator);
} else if (content.id === 'content_php') {
Code.attemptCodeGeneration(Blockly.PHP);
Code.attemptCodeGeneration(php.phpGenerator);
} else if (content.id === 'content_dart') {
Code.attemptCodeGeneration(Blockly.Dart);
Code.attemptCodeGeneration(dart.dartGenerator);
} else if (content.id === 'content_lua') {
Code.attemptCodeGeneration(Blockly.Lua);
Code.attemptCodeGeneration(lua.luaGenerator);
}
if (typeof PR === 'object') {
PR.prettyPrint();
@@ -395,7 +395,7 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
var missingBlockGenerators = [];
for (var i = 0; i < blocks.length; i++) {
var blockType = blocks[i].type;
if (!generator[blockType]) {
if (!generator.forBlock[blockType]) {
if (missingBlockGenerators.indexOf(blockType) === -1) {
missingBlockGenerators.push(blockType);
}
@@ -477,7 +477,7 @@ Code.init = function() {
// Add to reserved word list: Local variables in execution environment (runJS)
// and the infinite loop detection function.
Blockly.JavaScript.addReservedWords('code,timeouts,checkTimeout');
javascript.javascriptGenerator.addReservedWords('code,timeouts,checkTimeout');
Code.loadBlocks('');
@@ -588,15 +588,15 @@ Code.runJS = function(event) {
event.preventDefault();
}
Blockly.JavaScript.INFINITE_LOOP_TRAP = 'checkTimeout();\n';
javascript.javascriptGenerator.INFINITE_LOOP_TRAP = 'checkTimeout();\n';
var timeouts = 0;
var checkTimeout = function() {
if (timeouts++ > 1000000) {
throw MSG['timeout'];
}
};
var code = Blockly.JavaScript.workspaceToCode(Code.workspace);
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
var code = javascript.javascriptGenerator.workspaceToCode(Code.workspace);
javascript.javascriptGenerator.INFINITE_LOOP_TRAP = null;
try {
eval(code);
} catch (e) {