Adds option to generate code for a single block

This commit is contained in:
Abby Schmiedt
2018-11-21 09:00:29 -08:00
parent 9423970755
commit 26a4774b35
6 changed files with 19 additions and 13 deletions

View File

@@ -158,11 +158,12 @@ Blockly.Generator.prototype.allNestedComments = function(block) {
/**
* Generate code for the specified block (and attached blocks).
* @param {Blockly.Block} block The block to generate code for.
* @param {boolean} opt_thisOnly True to generate code for only this block.
* @return {string|!Array} For statement blocks, the generated code.
* For value blocks, an array containing the generated code and an
* operator order value. Returns '' if block is null.
*/
Blockly.Generator.prototype.blockToCode = function(block) {
Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) {
if (!block) {
return '';
}
@@ -186,13 +187,13 @@ Blockly.Generator.prototype.blockToCode = function(block) {
if (!block.outputConnection) {
throw TypeError('Expecting string from statement block: ' + block.type);
}
return [this.scrub_(block, code[0]), code[1]];
return [this.scrub_(block, code[0], opt_thisOnly), code[1]];
} else if (typeof code == 'string') {
var id = block.id.replace(/\$/g, '$$$$'); // Issue 251.
if (this.STATEMENT_PREFIX) {
code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') + code;
}
return this.scrub_(block, code);
return this.scrub_(block, code, opt_thisOnly);
} else if (code === null) {
// Block has handled code generation itself.
return '';