mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +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:
@@ -197,11 +197,27 @@ Blockly.Python['controls_forEach'] = function(block) {
|
||||
|
||||
Blockly.Python['controls_flow_statements'] = function(block) {
|
||||
// Flow statements: continue, break.
|
||||
switch (block.getFieldValue('FLOW')) {
|
||||
var flowType = block.getFieldValue('FLOW');
|
||||
var xfix = '';
|
||||
if (Blockly.Python.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.Python.injectId(Blockly.Python.STATEMENT_SUFFIX, block);
|
||||
}
|
||||
if (Blockly.Python.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.Python.injectId(Blockly.Python.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.');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user