mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Prefix and suffix edge cases for flow statements.
Call suffix code on break/continue before executing the break/continue. Call prefix code for enclosing loop before executing continue.
This commit is contained in:
@@ -154,11 +154,27 @@ Blockly.PHP['controls_forEach'] = function(block) {
|
||||
|
||||
Blockly.PHP['controls_flow_statements'] = function(block) {
|
||||
// Flow statements: continue, break.
|
||||
switch (block.getFieldValue('FLOW')) {
|
||||
var flowType = block.getFieldValue('FLOW');
|
||||
var xfix = '';
|
||||
if (Blockly.PHP.STATEMENT_SUFFIX) {
|
||||
// Inject any statement suffix here since the regular one at the end
|
||||
// will not get executed if the break/continue is triggered.
|
||||
xfix += Blockly.PHP.injectId(Blockly.PHP.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.PHP.STATEMENT_PREFIX && flowType == 'CONTINUE') {
|
||||
var loop = Blockly.Constants.Loops
|
||||
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
|
||||
if (loop) {
|
||||
// Inject loop's statement prefix here since the regular one at the end
|
||||
// of the loop will not get executed if the continue is triggered.
|
||||
xfix += Blockly.PHP.injectId(Blockly.PHP.STATEMENT_PREFIX, loop);
|
||||
}
|
||||
}
|
||||
switch (flowType) {
|
||||
case 'BREAK':
|
||||
return 'break;\n';
|
||||
return xfix + 'break;\n';
|
||||
case 'CONTINUE':
|
||||
return 'continue;\n';
|
||||
return xfix + 'continue;\n';
|
||||
}
|
||||
throw Error('Unknown flow statement.');
|
||||
};
|
||||
|
||||
@@ -127,7 +127,6 @@ Blockly.PHP['procedures_ifreturn'] = function(block) {
|
||||
if (Blockly.PHP.STATEMENT_SUFFIX) {
|
||||
// Inject any statement suffix here since the regular one at the end
|
||||
// will not get executed if the return is triggered.
|
||||
var id = block.id.replace(/\$/g, '$$$$'); // Issue 251.
|
||||
code += Blockly.PHP.prefixLines(
|
||||
Blockly.PHP.injectId(Blockly.PHP.STATEMENT_SUFFIX, block),
|
||||
Blockly.PHP.INDENT);
|
||||
|
||||
Reference in New Issue
Block a user