Skip to content

Commit 42138ac

Browse files
authored
Variable blocks name with spaces
Correct an issue where variable blocks where the variable name contains one or more space characters was not getting preprocessed to replace the space characters with underscore characters. This would cause the project to fail a compile.
1 parent 625c588 commit 42138ac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/webapp/cdn/blockly/generators/propc/variables.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ Blockly.Blocks.variables_set = {
112112

113113
Blockly.propc.variables_get = function () {
114114
// Variable getter.
115-
var code = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR').replace(/^[^a-zA-Z_]+|[^a-zA-Z_0-9]+/g, '_'),
115+
var code = Blockly.propc.variableDB_.getName(
116+
this.getFieldValue('VAR'),
116117
Blockly.Variables.NAME_TYPE);
117118
return [code, Blockly.propc.ORDER_ATOMIC];
118119
};
@@ -123,7 +124,8 @@ Blockly.propc.variables_declare = function () {
123124
//TODO: settype to variable
124125
var argument0 = Blockly.propc.valueToCode(this, 'VALUE',
125126
Blockly.propc.ORDER_ASSIGNMENT) || '0';
126-
var varName = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR').replace(/^[^a-zA-Z_]+|[^a-zA-Z_0-9]+/g, '_'),
127+
var varName = Blockly.propc.variableDB_.getName(
128+
this.getFieldValue('VAR'),
127129
Blockly.Variables.NAME_TYPE);
128130
Blockly.propc.setups_['setup_var' + varName] = varName + ' = ' + argument0 + ';\n';
129131
Blockly.propc.vartype_[varName] = dropdown_type;
@@ -134,7 +136,8 @@ Blockly.propc.variables_set = function () {
134136
// Variable setter.
135137
var argument0 = Blockly.propc.valueToCode(this, 'VALUE',
136138
Blockly.propc.ORDER_ASSIGNMENT) || '0';
137-
var varName = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR').replace(/^[^a-zA-Z_]+|[^a-zA-Z_0-9]+/g, '_'),
139+
var varName = Blockly.propc.variableDB_.getName(
140+
this.getFieldValue('VAR'),
138141
Blockly.Variables.NAME_TYPE);
139142
if (Blockly.propc.vartype_[varName] === undefined) {
140143
if (argument0.indexOf("int") > -1) {
@@ -370,4 +373,4 @@ Blockly.propc.array_clear = function () {
370373
} else {
371374
return 'memset(' + varName + ', 0, sizeof ' + varName + ');\n';
372375
}
373-
};
376+
};

0 commit comments

Comments
 (0)