Add prefix/suffix to orphaned value blocks.

Also respect suppressPrefixSuffix on loops when generating prefix/suffix with continue/break blocks.
This commit is contained in:
Neil Fraser
2019-05-15 17:03:21 -07:00
committed by Neil Fraser
parent 32631577a4
commit 05253d0766
6 changed files with 13 additions and 7 deletions

View File

@@ -116,6 +116,12 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) {
// This block is a naked value. Ask the language's code generator if
// it wants to append a semicolon, or something.
line = this.scrubNakedValue(line);
if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) {
line = this.injectId(this.STATEMENT_PREFIX, block) + line;
}
if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) {
line = line + this.injectId(this.STATEMENT_SUFFIX, block);
}
}
code.push(line);
}
@@ -322,11 +328,11 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) {
branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block),
this.INDENT) + branch;
}
if (this.STATEMENT_SUFFIX) {
if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) {
branch = this.prefixLines(this.injectId(this.STATEMENT_SUFFIX, block),
this.INDENT) + branch;
}
if (this.STATEMENT_PREFIX) {
if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) {
branch = branch + this.prefixLines(this.injectId(this.STATEMENT_PREFIX,
block), this.INDENT);
}

View File

@@ -166,7 +166,7 @@ Blockly.Dart['controls_flow_statements'] = function(block) {
if (Blockly.Dart.STATEMENT_PREFIX) {
var loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
if (loop) {
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// 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.

View File

@@ -180,7 +180,7 @@ Blockly.JavaScript['controls_flow_statements'] = function(block) {
if (Blockly.JavaScript.STATEMENT_PREFIX) {
var loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
if (loop) {
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// 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.

View File

@@ -170,7 +170,7 @@ Blockly.Lua['controls_flow_statements'] = function(block) {
if (Blockly.Lua.STATEMENT_PREFIX) {
var loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
if (loop) {
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// 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.

View File

@@ -167,7 +167,7 @@ Blockly.PHP['controls_flow_statements'] = function(block) {
if (Blockly.PHP.STATEMENT_PREFIX) {
var loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
if (loop) {
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// 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.

View File

@@ -210,7 +210,7 @@ Blockly.Python['controls_flow_statements'] = function(block) {
if (Blockly.Python.STATEMENT_PREFIX) {
var loop = Blockly.Constants.Loops
.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(block);
if (loop) {
if (loop && !loop.suppressPrefixSuffix) {
// Inject loop's statement prefix here since the regular one at the end
// 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.