Skip to content

Commit

Permalink
fix(demos): Update to use new script import names for generators
Browse files Browse the repository at this point in the history
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 google#7150,
implementing the .forBlock dictionary.
  • Loading branch information
cpcallen committed Jun 27, 2023
1 parent 5579098 commit 1bcf210
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions demos/code/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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('');

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1bcf210

Please sign in to comment.