diff --git a/core/block_svg.js b/core/block_svg.js index 094373973..8fc64f3a8 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1037,7 +1037,7 @@ Blockly.BlockSvg.prototype.disposeUiEffect = function() { this.workspace.getParentSvg().appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - Blockly.BlockSvg.disposeUiStep_(clone, this.RTL, new Date(), + Blockly.BlockSvg.disposeUiStep_(clone, this.RTL, new Date, this.workspace.scale); }; @@ -1052,7 +1052,7 @@ Blockly.BlockSvg.prototype.disposeUiEffect = function() { * @private */ Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) { - var ms = (new Date()) - start; + var ms = new Date - start; var percent = ms / 150; if (percent > 1) { goog.dom.removeNode(clone); @@ -1094,7 +1094,7 @@ Blockly.BlockSvg.prototype.connectionUiEffect = function() { 'stroke': '#888', 'stroke-width': 10}, this.workspace.getParentSvg()); // Start the animation. - Blockly.BlockSvg.connectionUiStep_(ripple, new Date(), this.workspace.scale); + Blockly.BlockSvg.connectionUiStep_(ripple, new Date, this.workspace.scale); }; /** @@ -1105,7 +1105,7 @@ Blockly.BlockSvg.prototype.connectionUiEffect = function() { * @private */ Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) { - var ms = (new Date()) - start; + var ms = new Date - start; var percent = ms / 150; if (percent > 1) { goog.dom.removeNode(ripple); @@ -1136,7 +1136,7 @@ Blockly.BlockSvg.prototype.disconnectUiEffect = function() { magnitude *= -1; } // Start the animation. - Blockly.BlockSvg.disconnectUiStep_(this.svgGroup_, magnitude, new Date()); + Blockly.BlockSvg.disconnectUiStep_(this.svgGroup_, magnitude, new Date); }; /** @@ -1150,7 +1150,7 @@ Blockly.BlockSvg.disconnectUiStep_ = function(group, magnitude, start) { var DURATION = 200; // Milliseconds. var WIGGLES = 3; // Half oscillations. - var ms = (new Date()) - start; + var ms = new Date - start; var percent = ms / DURATION; if (percent > 1) { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 7b68c5b03..de636a7a2 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -950,7 +950,7 @@ Blockly.WorkspaceSvg.prototype.playAudio = function(name, opt_volume) { var sound = this.SOUNDS_[name]; if (sound) { // Don't play one sound on top of another. - var now = new Date(); + var now = new Date; if (now - this.lastSound_ < Blockly.SOUND_LIMIT) { return; } diff --git a/generators/dart/lists.js b/generators/dart/lists.js index 24fcd2243..c357ddd0a 100644 --- a/generators/dart/lists.js +++ b/generators/dart/lists.js @@ -90,8 +90,12 @@ Blockly.Dart['lists_getIndex'] = function(block) { var where = block.getFieldValue('WHERE') || 'FROM_START'; var at = Blockly.Dart.valueToCode(block, 'AT', Blockly.Dart.ORDER_UNARY_PREFIX) || '1'; - var list = Blockly.Dart.valueToCode(block, 'VALUE', - Blockly.Dart.ORDER_UNARY_POSTFIX) || '[]'; + // Special case to avoid wrapping function calls in unneeded parenthesis. + // func()[0] is prefered over (func())[0] + var valueBlock = this.getInputTargetBlock('VALUE'); + var order = (valueBlock && valueBlock.type == 'procedures_callreturn') ? + Blockly.Dart.ORDER_NONE : Blockly.Dart.ORDER_UNARY_POSTFIX; + var list = Blockly.Dart.valueToCode(block, 'VALUE', order) || '[]'; if (where == 'FIRST') { if (mode == 'GET') { diff --git a/generators/javascript/lists.js b/generators/javascript/lists.js index 4bb6aac20..b05b6d380 100644 --- a/generators/javascript/lists.js +++ b/generators/javascript/lists.js @@ -98,8 +98,12 @@ Blockly.JavaScript['lists_getIndex'] = function(block) { var where = block.getFieldValue('WHERE') || 'FROM_START'; var at = Blockly.JavaScript.valueToCode(block, 'AT', Blockly.JavaScript.ORDER_UNARY_NEGATION) || '1'; - var list = Blockly.JavaScript.valueToCode(block, 'VALUE', - Blockly.JavaScript.ORDER_MEMBER) || '[]'; + // Special case to avoid wrapping function calls in unneeded parenthesis. + // func()[0] is prefered over (func())[0] + var valueBlock = this.getInputTargetBlock('VALUE'); + var order = (valueBlock && valueBlock.type == 'procedures_callreturn') ? + Blockly.JavaScript.ORDER_NONE : Blockly.JavaScript.ORDER_MEMBER; + var list = Blockly.JavaScript.valueToCode(block, 'VALUE', order) || '[]'; if (where == 'FIRST') { if (mode == 'GET') { diff --git a/generators/lua/lists.js b/generators/lua/lists.js index 0d4cfa4b1..a2afebd05 100644 --- a/generators/lua/lists.js +++ b/generators/lua/lists.js @@ -159,8 +159,17 @@ Blockly.Lua['lists_getIndex'] = function(block) { 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', - Blockly.Lua.ORDER_HIGH) || '({})'; + if (mode == 'GET') { + // Special case to avoid wrapping function calls in unneeded parenthesis. + // func()[0] is prefered over (func())[0] + var valueBlock = this.getInputTargetBlock('VALUE'); + var order = (valueBlock && valueBlock.type == 'procedures_callreturn') ? + Blockly.Lua.ORDER_NONE : Blockly.Lua.ORDER_HIGH; + } else { + // List will be an argument in a function call. + var order = Blockly.Lua.ORDER_NONE; + } + var list = Blockly.Lua.valueToCode(block, 'VALUE', order) || '({})'; var getIndex_ = Blockly.Lua.lists.getIndex_; var gensym_ = Blockly.Lua.lists.gensym_; @@ -329,7 +338,7 @@ Blockly.Lua['lists_sort'] = function(block) { var functionName = Blockly.Lua.provideFunction_( 'list_sort', - ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + + ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(list, typev, direction)', ' local t = {}', ' for n,v in pairs(list) do table.insert(t, v) end', // Shallow-copy. @@ -351,9 +360,9 @@ Blockly.Lua['lists_sort'] = function(block) { ' return t', 'end']); - var code = functionName + + var code = functionName + '(' + listCode + ',"' + type + '", ' + direction + ')'; - return [code, Blockly.Lua.ORDER_HIGH]; + return [code, Blockly.Lua.ORDER_HIGH]; }; Blockly.Lua['lists_split'] = function(block) { diff --git a/generators/php/lists.js b/generators/php/lists.js index d7111b19e..2176f5f1b 100644 --- a/generators/php/lists.js +++ b/generators/php/lists.js @@ -132,8 +132,17 @@ Blockly.PHP['lists_getIndex'] = function(block) { var where = block.getFieldValue('WHERE') || 'FROM_START'; var at = Blockly.PHP.valueToCode(block, 'AT', Blockly.PHP.ORDER_UNARY_NEGATION) || '1'; - var list = Blockly.PHP.valueToCode(block, 'VALUE', - Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()'; + if (mode == 'GET') { + // Special case to avoid wrapping function calls in unneeded parenthesis. + // func()[0] is prefered over (func())[0] + var valueBlock = this.getInputTargetBlock('VALUE'); + var order = (valueBlock && valueBlock.type == 'procedures_callreturn') ? + Blockly.PHP.ORDER_NONE : Blockly.PHP.ORDER_FUNCTION_CALL; + } else { + // List will be an argument in a function call. + var order = Blockly.PHP.ORDER_COMMA; + } + var list = Blockly.PHP.valueToCode(block, 'VALUE', order) || 'array()'; if (where == 'FIRST') { if (mode == 'GET') { diff --git a/generators/python/lists.js b/generators/python/lists.js index 43352c2c2..afc5d7708 100644 --- a/generators/python/lists.js +++ b/generators/python/lists.js @@ -105,8 +105,12 @@ Blockly.Python['lists_getIndex'] = function(block) { var where = block.getFieldValue('WHERE') || 'FROM_START'; var at = Blockly.Python.valueToCode(block, 'AT', Blockly.Python.ORDER_UNARY_SIGN) || '1'; - var list = Blockly.Python.valueToCode(block, 'VALUE', - Blockly.Python.ORDER_MEMBER) || '[]'; + // Special case to avoid wrapping function calls in unneeded parenthesis. + // func()[0] is prefered over (func())[0] + var valueBlock = this.getInputTargetBlock('VALUE'); + var order = (valueBlock && valueBlock.type == 'procedures_callreturn') ? + Blockly.Python.ORDER_NONE : Blockly.Python.ORDER_MEMBER; + var list = Blockly.Python.valueToCode(block, 'VALUE', order) || '[]'; if (where == 'FIRST') { if (mode == 'GET') { @@ -314,12 +318,12 @@ Blockly.Python['lists_getSublist'] = function(block) { Blockly.Python['lists_sort'] = function(block) { // Block for sorting a list. - var listCode = (Blockly.Python.valueToCode(block, 'LIST', + var listCode = (Blockly.Python.valueToCode(block, 'LIST', Blockly.Python.ORDER_MEMBER) || '[]'); var type = block.getFieldValue('TYPE'); var reverse = block.getFieldValue('DIRECTION') === '1' ? 'False' : 'True'; var sortFunctionName = Blockly.Python.provideFunction_('lists_sort', - ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + + ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(listv, type, reversev):', ' def tryfloat(s):', ' try:', @@ -329,14 +333,14 @@ Blockly.Python['lists_sort'] = function(block) { ' keyFuncts = {', ' "NUMERIC": tryfloat,', ' "TEXT": str,', - ' "IGNORE_CASE": lambda s: str(s).lower()', + ' "IGNORE_CASE": lambda s: str(s).lower()', ' }', ' keyv = keyFuncts[type]', ' tmp_list = list(listv)', // Clone the list. ' return sorted(tmp_list, key=keyv, reverse=reversev)' - ]); + ]); - var code = sortFunctionName + + var code = sortFunctionName + '(' + listCode + ', "' + type + '", ' + reverse + ')'; return [code, Blockly.Python.ORDER_FUNCTION_CALL]; };