mirror of
https://github.com/google/blockly.git
synced 2026-01-06 00:20:37 +01:00
Remove unneeded generated parens around function calls in indexOf blocks.
This commit is contained in:
@@ -1037,7 +1037,7 @@ Blockly.BlockSvg.prototype.disposeUiEffect = function() {
|
|||||||
this.workspace.getParentSvg().appendChild(clone);
|
this.workspace.getParentSvg().appendChild(clone);
|
||||||
clone.bBox_ = clone.getBBox();
|
clone.bBox_ = clone.getBBox();
|
||||||
// Start the animation.
|
// Start the animation.
|
||||||
Blockly.BlockSvg.disposeUiStep_(clone, this.RTL, new Date(),
|
Blockly.BlockSvg.disposeUiStep_(clone, this.RTL, new Date,
|
||||||
this.workspace.scale);
|
this.workspace.scale);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1052,7 +1052,7 @@ Blockly.BlockSvg.prototype.disposeUiEffect = function() {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) {
|
Blockly.BlockSvg.disposeUiStep_ = function(clone, rtl, start, workspaceScale) {
|
||||||
var ms = (new Date()) - start;
|
var ms = new Date - start;
|
||||||
var percent = ms / 150;
|
var percent = ms / 150;
|
||||||
if (percent > 1) {
|
if (percent > 1) {
|
||||||
goog.dom.removeNode(clone);
|
goog.dom.removeNode(clone);
|
||||||
@@ -1094,7 +1094,7 @@ Blockly.BlockSvg.prototype.connectionUiEffect = function() {
|
|||||||
'stroke': '#888', 'stroke-width': 10},
|
'stroke': '#888', 'stroke-width': 10},
|
||||||
this.workspace.getParentSvg());
|
this.workspace.getParentSvg());
|
||||||
// Start the animation.
|
// 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
|
* @private
|
||||||
*/
|
*/
|
||||||
Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) {
|
Blockly.BlockSvg.connectionUiStep_ = function(ripple, start, workspaceScale) {
|
||||||
var ms = (new Date()) - start;
|
var ms = new Date - start;
|
||||||
var percent = ms / 150;
|
var percent = ms / 150;
|
||||||
if (percent > 1) {
|
if (percent > 1) {
|
||||||
goog.dom.removeNode(ripple);
|
goog.dom.removeNode(ripple);
|
||||||
@@ -1136,7 +1136,7 @@ Blockly.BlockSvg.prototype.disconnectUiEffect = function() {
|
|||||||
magnitude *= -1;
|
magnitude *= -1;
|
||||||
}
|
}
|
||||||
// Start the animation.
|
// 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 DURATION = 200; // Milliseconds.
|
||||||
var WIGGLES = 3; // Half oscillations.
|
var WIGGLES = 3; // Half oscillations.
|
||||||
|
|
||||||
var ms = (new Date()) - start;
|
var ms = new Date - start;
|
||||||
var percent = ms / DURATION;
|
var percent = ms / DURATION;
|
||||||
|
|
||||||
if (percent > 1) {
|
if (percent > 1) {
|
||||||
|
|||||||
@@ -950,7 +950,7 @@ Blockly.WorkspaceSvg.prototype.playAudio = function(name, opt_volume) {
|
|||||||
var sound = this.SOUNDS_[name];
|
var sound = this.SOUNDS_[name];
|
||||||
if (sound) {
|
if (sound) {
|
||||||
// Don't play one sound on top of another.
|
// Don't play one sound on top of another.
|
||||||
var now = new Date();
|
var now = new Date;
|
||||||
if (now - this.lastSound_ < Blockly.SOUND_LIMIT) {
|
if (now - this.lastSound_ < Blockly.SOUND_LIMIT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,8 +90,12 @@ Blockly.Dart['lists_getIndex'] = function(block) {
|
|||||||
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
||||||
var at = Blockly.Dart.valueToCode(block, 'AT',
|
var at = Blockly.Dart.valueToCode(block, 'AT',
|
||||||
Blockly.Dart.ORDER_UNARY_PREFIX) || '1';
|
Blockly.Dart.ORDER_UNARY_PREFIX) || '1';
|
||||||
var list = Blockly.Dart.valueToCode(block, 'VALUE',
|
// Special case to avoid wrapping function calls in unneeded parenthesis.
|
||||||
Blockly.Dart.ORDER_UNARY_POSTFIX) || '[]';
|
// 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 (where == 'FIRST') {
|
||||||
if (mode == 'GET') {
|
if (mode == 'GET') {
|
||||||
|
|||||||
@@ -98,8 +98,12 @@ Blockly.JavaScript['lists_getIndex'] = function(block) {
|
|||||||
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
||||||
var at = Blockly.JavaScript.valueToCode(block, 'AT',
|
var at = Blockly.JavaScript.valueToCode(block, 'AT',
|
||||||
Blockly.JavaScript.ORDER_UNARY_NEGATION) || '1';
|
Blockly.JavaScript.ORDER_UNARY_NEGATION) || '1';
|
||||||
var list = Blockly.JavaScript.valueToCode(block, 'VALUE',
|
// Special case to avoid wrapping function calls in unneeded parenthesis.
|
||||||
Blockly.JavaScript.ORDER_MEMBER) || '[]';
|
// 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 (where == 'FIRST') {
|
||||||
if (mode == 'GET') {
|
if (mode == 'GET') {
|
||||||
|
|||||||
@@ -159,8 +159,17 @@ Blockly.Lua['lists_getIndex'] = function(block) {
|
|||||||
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
||||||
var at = Blockly.Lua.valueToCode(block, 'AT',
|
var at = Blockly.Lua.valueToCode(block, 'AT',
|
||||||
Blockly.Lua.ORDER_ADDITIVE) || '1';
|
Blockly.Lua.ORDER_ADDITIVE) || '1';
|
||||||
var list = Blockly.Lua.valueToCode(block, 'VALUE',
|
if (mode == 'GET') {
|
||||||
Blockly.Lua.ORDER_HIGH) || '({})';
|
// 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 getIndex_ = Blockly.Lua.lists.getIndex_;
|
||||||
var gensym_ = Blockly.Lua.lists.gensym_;
|
var gensym_ = Blockly.Lua.lists.gensym_;
|
||||||
|
|
||||||
@@ -329,7 +338,7 @@ Blockly.Lua['lists_sort'] = function(block) {
|
|||||||
|
|
||||||
var functionName = Blockly.Lua.provideFunction_(
|
var functionName = Blockly.Lua.provideFunction_(
|
||||||
'list_sort',
|
'list_sort',
|
||||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +
|
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(list, typev, direction)',
|
'(list, typev, direction)',
|
||||||
' local t = {}',
|
' local t = {}',
|
||||||
' for n,v in pairs(list) do table.insert(t, v) end', // Shallow-copy.
|
' 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',
|
' return t',
|
||||||
'end']);
|
'end']);
|
||||||
|
|
||||||
var code = functionName +
|
var code = functionName +
|
||||||
'(' + listCode + ',"' + type + '", ' + direction + ')';
|
'(' + listCode + ',"' + type + '", ' + direction + ')';
|
||||||
return [code, Blockly.Lua.ORDER_HIGH];
|
return [code, Blockly.Lua.ORDER_HIGH];
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Lua['lists_split'] = function(block) {
|
Blockly.Lua['lists_split'] = function(block) {
|
||||||
|
|||||||
@@ -132,8 +132,17 @@ Blockly.PHP['lists_getIndex'] = function(block) {
|
|||||||
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
||||||
var at = Blockly.PHP.valueToCode(block, 'AT',
|
var at = Blockly.PHP.valueToCode(block, 'AT',
|
||||||
Blockly.PHP.ORDER_UNARY_NEGATION) || '1';
|
Blockly.PHP.ORDER_UNARY_NEGATION) || '1';
|
||||||
var list = Blockly.PHP.valueToCode(block, 'VALUE',
|
if (mode == 'GET') {
|
||||||
Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
|
// 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 (where == 'FIRST') {
|
||||||
if (mode == 'GET') {
|
if (mode == 'GET') {
|
||||||
|
|||||||
@@ -105,8 +105,12 @@ Blockly.Python['lists_getIndex'] = function(block) {
|
|||||||
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
var where = block.getFieldValue('WHERE') || 'FROM_START';
|
||||||
var at = Blockly.Python.valueToCode(block, 'AT',
|
var at = Blockly.Python.valueToCode(block, 'AT',
|
||||||
Blockly.Python.ORDER_UNARY_SIGN) || '1';
|
Blockly.Python.ORDER_UNARY_SIGN) || '1';
|
||||||
var list = Blockly.Python.valueToCode(block, 'VALUE',
|
// Special case to avoid wrapping function calls in unneeded parenthesis.
|
||||||
Blockly.Python.ORDER_MEMBER) || '[]';
|
// 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 (where == 'FIRST') {
|
||||||
if (mode == 'GET') {
|
if (mode == 'GET') {
|
||||||
@@ -314,12 +318,12 @@ Blockly.Python['lists_getSublist'] = function(block) {
|
|||||||
|
|
||||||
Blockly.Python['lists_sort'] = function(block) {
|
Blockly.Python['lists_sort'] = function(block) {
|
||||||
// Block for sorting a list.
|
// Block for sorting a list.
|
||||||
var listCode = (Blockly.Python.valueToCode(block, 'LIST',
|
var listCode = (Blockly.Python.valueToCode(block, 'LIST',
|
||||||
Blockly.Python.ORDER_MEMBER) || '[]');
|
Blockly.Python.ORDER_MEMBER) || '[]');
|
||||||
var type = block.getFieldValue('TYPE');
|
var type = block.getFieldValue('TYPE');
|
||||||
var reverse = block.getFieldValue('DIRECTION') === '1' ? 'False' : 'True';
|
var reverse = block.getFieldValue('DIRECTION') === '1' ? 'False' : 'True';
|
||||||
var sortFunctionName = Blockly.Python.provideFunction_('lists_sort',
|
var sortFunctionName = Blockly.Python.provideFunction_('lists_sort',
|
||||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ +
|
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ +
|
||||||
'(listv, type, reversev):',
|
'(listv, type, reversev):',
|
||||||
' def tryfloat(s):',
|
' def tryfloat(s):',
|
||||||
' try:',
|
' try:',
|
||||||
@@ -329,14 +333,14 @@ Blockly.Python['lists_sort'] = function(block) {
|
|||||||
' keyFuncts = {',
|
' keyFuncts = {',
|
||||||
' "NUMERIC": tryfloat,',
|
' "NUMERIC": tryfloat,',
|
||||||
' "TEXT": str,',
|
' "TEXT": str,',
|
||||||
' "IGNORE_CASE": lambda s: str(s).lower()',
|
' "IGNORE_CASE": lambda s: str(s).lower()',
|
||||||
' }',
|
' }',
|
||||||
' keyv = keyFuncts[type]',
|
' keyv = keyFuncts[type]',
|
||||||
' tmp_list = list(listv)', // Clone the list.
|
' tmp_list = list(listv)', // Clone the list.
|
||||||
' return sorted(tmp_list, key=keyv, reverse=reversev)'
|
' return sorted(tmp_list, key=keyv, reverse=reversev)'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var code = sortFunctionName +
|
var code = sortFunctionName +
|
||||||
'(' + listCode + ', "' + type + '", ' + reverse + ')';
|
'(' + listCode + ', "' + type + '", ' + reverse + ')';
|
||||||
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
|
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user