diff --git a/core/generator.js b/core/generator.js index b375b7a06..b9b488d5c 100644 --- a/core/generator.js +++ b/core/generator.js @@ -77,6 +77,15 @@ Blockly.Generator.prototype.COMMENT_WRAP = 60; */ Blockly.Generator.prototype.ORDER_OVERRIDES = []; +/** + * Whether the init method has been called. + * Generators that set this flag to false after creation and true in init + * will cause blockToCode to emit a warning if the generator has not been + * initialized. If this flag is untouched, it will have no effect. + * @type {?boolean} + */ +Blockly.Generator.prototype.isInitialized = null; + /** * Generate code for all blocks in the workspace to the specified language. * @param {Blockly.Workspace} workspace Workspace to generate code from. @@ -167,6 +176,10 @@ Blockly.Generator.prototype.allNestedComments = function(block) { * operator order value. Returns '' if block is null. */ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { + if (this.isInitialized === false) { + console.warn( + 'Generator init was not called before blockToCode was called.'); + } if (!block) { return ''; } diff --git a/generators/dart.js b/generators/dart.js index 1b276ddf8..a801a0655 100644 --- a/generators/dart.js +++ b/generators/dart.js @@ -71,6 +71,12 @@ Blockly.Dart.ORDER_CASCADE = 15; // .. Blockly.Dart.ORDER_ASSIGNMENT = 16; // = *= /= ~/= %= += -= <<= >>= &= ^= |= Blockly.Dart.ORDER_NONE = 99; // (...) +/** + * Whether the init method has been called. + * @type {?boolean} + */ +Blockly.Dart.isInitialized = false; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. @@ -111,6 +117,7 @@ Blockly.Dart.init = function(workspace) { Blockly.Dart.definitions_['variables'] = 'var ' + defvars.join(', ') + ';'; } + this.isInitialized = true; }; /** diff --git a/generators/javascript.js b/generators/javascript.js index 630fd4786..368a35a6d 100644 --- a/generators/javascript.js +++ b/generators/javascript.js @@ -113,6 +113,12 @@ Blockly.JavaScript.ORDER_OVERRIDES = [ [Blockly.JavaScript.ORDER_LOGICAL_OR, Blockly.JavaScript.ORDER_LOGICAL_OR] ]; +/** + * Whether the init method has been called. + * @type {?boolean} + */ +Blockly.JavaScript.isInitialized = false; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. @@ -153,6 +159,7 @@ Blockly.JavaScript.init = function(workspace) { Blockly.JavaScript.definitions_['variables'] = 'var ' + defvars.join(', ') + ';'; } + this.isInitialized = true; }; /** diff --git a/generators/lua.js b/generators/lua.js index fa16b8182..75a6b7b8b 100644 --- a/generators/lua.js +++ b/generators/lua.js @@ -79,6 +79,12 @@ Blockly.Lua.ORDER_NONE = 99; * option used for lists and text. */ +/** + * Whether the init method has been called. + * @type {?boolean} + */ +Blockly.Lua.isInitialized = false; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. @@ -97,6 +103,7 @@ Blockly.Lua.init = function(workspace) { Blockly.Lua.variableDB_.reset(); } Blockly.Lua.variableDB_.setVariableMap(workspace.getVariableMap()); + this.isInitialized = true; }; /** diff --git a/generators/php.js b/generators/php.js index 0b96b5b21..326cc8ecd 100644 --- a/generators/php.js +++ b/generators/php.js @@ -117,6 +117,12 @@ Blockly.PHP.ORDER_OVERRIDES = [ [Blockly.PHP.ORDER_LOGICAL_OR, Blockly.PHP.ORDER_LOGICAL_OR] ]; +/** + * Whether the init method has been called. + * @type {?boolean} + */ +Blockly.PHP.isInitialized = false; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. @@ -154,6 +160,7 @@ Blockly.PHP.init = function(workspace) { // Declare all of the variables. Blockly.PHP.definitions_['variables'] = defvars.join('\n'); + this.isInitialized = true; }; /** diff --git a/generators/python.js b/generators/python.js index e6191e52e..9844b9501 100644 --- a/generators/python.js +++ b/generators/python.js @@ -125,6 +125,12 @@ Blockly.Python.ORDER_OVERRIDES = [ [Blockly.Python.ORDER_LOGICAL_OR, Blockly.Python.ORDER_LOGICAL_OR] ]; +/** + * Whether the init method has been called. + * @type {?boolean} + */ +Blockly.Python.isInitialized = false; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. @@ -166,6 +172,7 @@ Blockly.Python.init = function(workspace) { } Blockly.Python.definitions_['variables'] = defvars.join('\n'); + this.isInitialized = true; }; /**