mirror of
https://github.com/google/blockly.git
synced 2026-01-11 19:07:08 +01:00
Add warning to blockToCode (#4492)
* Add warning to blockToCode * Address PR comments
This commit is contained in:
@@ -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 '';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user