From a7892d1aee96459cc297a90ff69f706a01417934 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 18 Mar 2016 14:17:31 -0700 Subject: [PATCH] Raise error if statement block returns tuple. --- core/generator.js | 2 ++ core/workspace_svg.js | 4 ++-- generators/lua/lists.js | 6 +++--- generators/lua/text.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/generator.js b/core/generator.js index 082101b40..506ead3e5 100644 --- a/core/generator.js +++ b/core/generator.js @@ -163,6 +163,8 @@ Blockly.Generator.prototype.blockToCode = function(block) { var code = func.call(block, block); if (goog.isArray(code)) { // Value blocks return tuples of code and operator order. + goog.asserts.assert(block.outputConnection, + 'Expecting string from statement block "%s".', block.type); return [this.scrub_(block, code[0]), code[1]]; } else if (goog.isString(code)) { if (this.STATEMENT_PREFIX) { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 3b70e033b..287402fcd 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -737,12 +737,12 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { // Options to undo/redo previous action. var undoOption = {}; undoOption.text = Blockly.Msg.UNDO; - undoOption.enabled = !!this.undoStack_.length > 0; + undoOption.enabled = this.undoStack_.length > 0; undoOption.callback = this.undo.bind(this, false); menuOptions.push(undoOption); var redoOption = {}; redoOption.text = Blockly.Msg.REDO; - redoOption.enabled = !!this.redoStack_.length > 0; + redoOption.enabled = this.redoStack_.length > 0; redoOption.callback = this.undo.bind(this, true); menuOptions.push(redoOption); diff --git a/generators/lua/lists.js b/generators/lua/lists.js index 619f6d8d7..b7fe54586 100644 --- a/generators/lua/lists.js +++ b/generators/lua/lists.js @@ -87,7 +87,7 @@ Blockly.Lua['lists_indexOf'] = function(block) { var argument1 = Blockly.Lua.valueToCode(block, 'VALUE', Blockly.Lua.ORDER_NONE) || '({})'; var functionName; - if (block.getTitleValue('END') == 'FIRST') { + if (block.getFieldValue('END') == 'FIRST') { functionName = Blockly.Lua.provideFunction_( 'first_index', ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(t, elem)', @@ -155,8 +155,8 @@ Blockly.Lua.lists.gensym_ = function() { Blockly.Lua['lists_getIndex'] = function(block) { // Get element at index. // Note: Until January 2013 this block did not have MODE or WHERE inputs. - var mode = block.getTitleValue('MODE') || 'GET'; - var where = block.getTitleValue('WHERE') || 'FROM_START'; + var mode = block.getFieldValue('MODE') || 'GET'; + var where = block.getFieldValue('WHERE') || 'FROM_START'; var at = Blockly.Lua.valueToCode(block, 'AT', Blockly.Lua.ORDER_ADDITIVE) || '1'; var list = Blockly.Lua.valueToCode(block, 'VALUE', diff --git a/generators/lua/text.js b/generators/lua/text.js index 7e7c73f6a..8a6a02702 100644 --- a/generators/lua/text.js +++ b/generators/lua/text.js @@ -93,7 +93,7 @@ Blockly.Lua['text_indexOf'] = function(block) { Blockly.Lua.ORDER_NONE) || '\'\''; var str = Blockly.Lua.valueToCode(block, 'VALUE', Blockly.Lua.ORDER_NONE) || '\'\''; - if (block.getTitleValue('END') == 'FIRST') { + if (block.getFieldValue('END') == 'FIRST') { var functionName = Blockly.Lua.provideFunction_( 'firstIndexOf', ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +