mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Add method to suppress prefix/suffix from blocks.
This allows generators to have more control over the placement of suffix. Needed for ‘if’ blocks and function calls which require their suffix code to be somewhere other than the end. Also, add loop’s prefix to ‘break’ blocks, since the loop’s suffix will be the next statement hit. Also, reuse procedures_callreturn generator for procedures_callnoreturn.
This commit is contained in:
@@ -165,25 +165,30 @@ Blockly.JavaScript['controls_forEach'] = function(block) {
|
||||
|
||||
Blockly.JavaScript['controls_flow_statements'] = function(block) {
|
||||
// Flow statements: continue, break.
|
||||
var flowType = block.getFieldValue('FLOW');
|
||||
var xfix = '';
|
||||
if (Blockly.JavaScript.STATEMENT_PREFIX) {
|
||||
// Automatic prefix insertion is switched off for this block. Add manually.
|
||||
xfix += Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,
|
||||
block);
|
||||
}
|
||||
if (Blockly.JavaScript.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.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,
|
||||
block);
|
||||
}
|
||||
if (Blockly.JavaScript.STATEMENT_PREFIX && flowType == 'CONTINUE') {
|
||||
if (Blockly.JavaScript.STATEMENT_PREFIX) {
|
||||
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.
|
||||
// of the loop will not get executed if 'continue' is triggered.
|
||||
// In the case of 'break', a prefix is needed due to the loop's suffix.
|
||||
xfix += Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,
|
||||
loop);
|
||||
}
|
||||
}
|
||||
switch (flowType) {
|
||||
switch (block.getFieldValue('FLOW')) {
|
||||
case 'BREAK':
|
||||
return xfix + 'break;\n';
|
||||
case 'CONTINUE':
|
||||
|
||||
Reference in New Issue
Block a user