Remove unneeded generated parens around function calls in indexOf blocks.

This commit is contained in:
Neil Fraser
2016-06-13 18:49:18 -07:00
parent 6851baea12
commit fd6f743f0e
7 changed files with 55 additions and 25 deletions

View File

@@ -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') {