Skip to content

Commit e06aa02

Browse files
release: v10.0.2 #7295 and #7297 (#7298)
* fix(generators): Changes to exports and access controls for TypeScript compatibility (#7295) * fix(generators): Add missing declarations for Order enums * chore(generators): Remove spurious whitespace * fix(generators): Make provideFunction_ etc. public Remove the protected declaration on provideFunction_ and FUNCTION_NAME_PLACEHOLDER_ so they can be used from generator functions written in TypeScript. Not strictly part of #7283, but closely related and required to fixing the related issue RaspberryPiFoundation/blockly-samples#1785. * chore(generators): format (cherry picked from commit d503fbb) * fix: Correct errors in `HSV_SATURATION`, `HSV_VALUE` accessors (#7297) * fix: Correct errors in HSV_SATURATION, HSV_VALUE accessors Fix the comment / message errors noted in #7249 (comment) * chore: Add renamings for HSV_SATURATION, HSV_VALUE (cherry picked from commit 1bc4f67) * release: Update version number to 10.0.2 --------- Co-authored-by: Christopher Allen <cpcallen+git@google.com>
1 parent 2042334 commit e06aa02

11 files changed

Lines changed: 186 additions & 33 deletions

File tree

core/generator.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class CodeGenerator {
4949
* legitimately appear in a function definition (or comment), and it must
5050
* not confuse the regular expression parser.
5151
*/
52-
protected FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}';
52+
FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}';
5353
FUNCTION_NAME_PLACEHOLDER_REGEXP_: RegExp;
5454

5555
/**
@@ -471,10 +471,7 @@ export class CodeGenerator {
471471
* @returns The actual name of the new function. This may differ from
472472
* desiredName if the former has already been taken by the user.
473473
*/
474-
protected provideFunction_(
475-
desiredName: string,
476-
code: string[] | string
477-
): string {
474+
provideFunction_(desiredName: string, code: string[] | string): string {
478475
if (!this.definitions_[desiredName]) {
479476
const functionName = this.nameDB_!.getDistinctName(
480477
desiredName,

core/main.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Object.defineProperties(Blockly, {
3232
* Must be in the range of 0 (inclusive) to 1 (exclusive).
3333
* @name Blockly.HSV_SATURATION
3434
* @type {number}
35-
* @deprecated Use Blockly.colour.getHsvSaturation() / .setHsvSaturation(
36-
* instead. (July 2023)
35+
* @deprecated Use Blockly.utils.colour.getHsvSaturation() /
36+
* .setHsvSaturation() instead. (July 2023)
3737
* @suppress {checkTypes}
3838
*/
3939
HSV_SATURATION: {
@@ -42,7 +42,7 @@ Object.defineProperties(Blockly, {
4242
'Blockly.HSV_SATURATION',
4343
'version 10',
4444
'version 11',
45-
'Blockly.colour.getHsvSaturation()'
45+
'Blockly.utils.colour.getHsvSaturation()'
4646
);
4747
return colour.getHsvSaturation();
4848
},
@@ -51,7 +51,7 @@ Object.defineProperties(Blockly, {
5151
'Blockly.HSV_SATURATION',
5252
'version 10',
5353
'version 11',
54-
'Blockly.colour.setHsvSaturation()'
54+
'Blockly.utils.colour.setHsvSaturation()'
5555
);
5656
colour.setHsvSaturation(newValue);
5757
},
@@ -61,7 +61,7 @@ Object.defineProperties(Blockly, {
6161
* Must be in the range of 0 (inclusive) to 1 (exclusive).
6262
* @name Blockly.HSV_VALUE
6363
* @type {number}
64-
* @deprecated Use Blockly.colour.getHsvValue() / .setHsvValue instead.
64+
* @deprecated Use Blockly.utils.colour.getHsvValue() / .setHsvValue instead.
6565
* (July 2023)
6666
* @suppress {checkTypes}
6767
*/
@@ -71,7 +71,7 @@ Object.defineProperties(Blockly, {
7171
'Blockly.HSV_VALUE',
7272
'version 10',
7373
'version 11',
74-
'Blockly.colour.getHsvValue()'
74+
'Blockly.utils.colour.getHsvValue()'
7575
);
7676
return colour.getHsvValue();
7777
},
@@ -80,7 +80,7 @@ Object.defineProperties(Blockly, {
8080
'Blockly.HSV_VALUE',
8181
'version 10',
8282
'version 11',
83-
'Blockly.colour.setHsvValue()'
83+
'Blockly.utils.colour.setHsvValue()'
8484
);
8585
colour.setHsvValue(newValue);
8686
},

generators/python/python_generator.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ export class PythonGenerator extends CodeGenerator {
7272
// (foo.bar)() -> foo.bar()
7373
// (foo[0])() -> foo[0]()
7474
[Order.MEMBER, Order.FUNCTION_CALL],
75-
75+
7676
// not (not foo) -> not not foo
7777
[Order.LOGICAL_NOT, Order.LOGICAL_NOT],
7878
// a and (b and c) -> a and b and c
7979
[Order.LOGICAL_AND, Order.LOGICAL_AND],
8080
// a or (b or c) -> a or b or c
8181
[Order.LOGICAL_OR, Order.LOGICAL_OR]
8282
];
83-
83+
8484
constructor(name) {
8585
super(name ?? 'Python');
8686
this.isInitialized = false;
@@ -143,30 +143,30 @@ export class PythonGenerator extends CodeGenerator {
143143
'vars,xrange,zip'
144144
);
145145
}
146-
146+
147147
/**
148148
* Initialise the database of variable names.
149149
* @param {!Workspace} workspace Workspace to generate code from.
150150
* @this {CodeGenerator}
151151
*/
152152
init(workspace) {
153153
super.init(workspace);
154-
154+
155155
/**
156156
* Empty loops or conditionals are not allowed in Python.
157157
*/
158158
this.PASS = this.INDENT + 'pass\n';
159-
159+
160160
if (!this.nameDB_) {
161161
this.nameDB_ = new Names(this.RESERVED_WORDS_);
162162
} else {
163163
this.nameDB_.reset();
164164
}
165-
165+
166166
this.nameDB_.setVariableMap(workspace.getVariableMap());
167167
this.nameDB_.populateVariables(workspace);
168168
this.nameDB_.populateProcedures(workspace);
169-
169+
170170
const defvars = [];
171171
// Add developer variables (not created or named by the user).
172172
const devVarList = Variables.allDeveloperVariables(workspace);
@@ -175,19 +175,19 @@ export class PythonGenerator extends CodeGenerator {
175175
this.nameDB_.getName(devVarList[i], Names.DEVELOPER_VARIABLE_TYPE) +
176176
' = None');
177177
}
178-
178+
179179
// Add user variables, but only ones that are being used.
180180
const variables = Variables.allUsedVarModels(workspace);
181181
for (let i = 0; i < variables.length; i++) {
182182
defvars.push(
183183
this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE) +
184184
' = None');
185185
}
186-
186+
187187
this.definitions_['variables'] = defvars.join('\n');
188188
this.isInitialized = true;
189189
}
190-
190+
191191
/**
192192
* Prepend the generated code with import statements and variable definitions.
193193
* @param {string} code Generated code.
@@ -208,12 +208,12 @@ export class PythonGenerator extends CodeGenerator {
208208
// Call Blockly.CodeGenerator's finish.
209209
code = super.finish(code);
210210
this.isInitialized = false;
211-
211+
212212
this.nameDB_.reset();
213213
const allDefs = imports.join('\n') + '\n\n' + definitions.join('\n\n');
214214
return allDefs.replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n\n\n') + code;
215215
}
216-
216+
217217
/**
218218
* Naked values are top-level blocks with outputs that aren't plugged into
219219
* anything.
@@ -223,7 +223,7 @@ export class PythonGenerator extends CodeGenerator {
223223
scrubNakedValue(line) {
224224
return line + '\n';
225225
}
226-
226+
227227
/**
228228
* Encode a string as a properly escaped Python string, complete with quotes.
229229
* @param {string} string Text to encode.
@@ -232,7 +232,7 @@ export class PythonGenerator extends CodeGenerator {
232232
*/
233233
quote_(string) {
234234
string = string.replace(/\\/g, '\\\\').replace(/\n/g, '\\\n');
235-
235+
236236
// Follow the CPython behaviour of repr() for a non-byte string.
237237
let quote = '\'';
238238
if (string.indexOf('\'') !== -1) {
@@ -244,7 +244,7 @@ export class PythonGenerator extends CodeGenerator {
244244
}
245245
return quote + string + quote;
246246
}
247-
247+
248248
/**
249249
* Encode a string as a properly escaped multiline Python string, complete
250250
* with quotes.
@@ -258,7 +258,7 @@ export class PythonGenerator extends CodeGenerator {
258258
// + '\n' +
259259
return lines.join(' + \'\\n\' + \n');
260260
}
261-
261+
262262
/**
263263
* Common tasks for generating Python from blocks.
264264
* Handles comments for the specified block and any connected value blocks.
@@ -297,7 +297,7 @@ export class PythonGenerator extends CodeGenerator {
297297
const nextCode = opt_thisOnly ? '' : this.blockToCode(nextBlock);
298298
return commentCode + code + nextCode;
299299
}
300-
300+
301301
/**
302302
* Gets a property and adjusts the value, taking into account indexing.
303303
* If a static int, casts to an integer, otherwise returns a code string.
@@ -315,7 +315,7 @@ export class PythonGenerator extends CodeGenerator {
315315
const defaultAtIndex = block.workspace.options.oneBasedIndex ? '1' : '0';
316316
const atOrder = delta ? this.ORDER_ADDITIVE : this.ORDER_NONE;
317317
let at = this.valueToCode(block, atId, atOrder) || defaultAtIndex;
318-
318+
319319
if (stringUtils.isNumber(at)) {
320320
// If the index is a naked number, adjust it right now.
321321
at = parseInt(at, 10) + delta;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockly",
3-
"version": "10.0.1",
3+
"version": "10.0.2",
44
"description": "Blockly is a library for building visual programming editors.",
55
"keywords": [
66
"blockly"

scripts/migration/renamings.json5

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,5 +1577,23 @@
15771577
},
15781578
],
15791579

1580+
'10.0.1': [
1581+
{
1582+
oldName: 'Blockly',
1583+
exports: {
1584+
HSV_SATURATION: {
1585+
newModule: 'Blockly.utils.colour',
1586+
getMethod: 'getHsvSaturation',
1587+
setMethod: 'setHsvSaturation',
1588+
},
1589+
HSV_VALUE: {
1590+
newModule: 'Blockly.utils.colour',
1591+
getMethod: 'getHsvValue',
1592+
setMethod: 'setHsvValue',
1593+
},
1594+
},
1595+
},
1596+
],
1597+
15801598
'develop': [],
15811599
}

typings/dart.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,25 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
export enum Order {
8+
ATOMIC = 0, // 0 "" ...
9+
UNARY_POSTFIX = 1, // expr++ expr-- () [] . ?.
10+
UNARY_PREFIX = 2, // -expr !expr ~expr ++expr --expr
11+
MULTIPLICATIVE = 3, // * / % ~/
12+
ADDITIVE = 4, // + -
13+
SHIFT = 5, // << >>
14+
BITWISE_AND = 6, // &
15+
BITWISE_XOR = 7, // ^
16+
BITWISE_OR = 8, // |
17+
RELATIONAL = 9, // >= > <= < as is is!
18+
EQUALITY = 10, // == !=
19+
LOGICAL_AND = 11, // &&
20+
LOGICAL_OR = 12, // ||
21+
IF_NULL = 13, // ??
22+
CONDITIONAL = 14, // expr ? expr : expr
23+
CASCADE = 15, // ..
24+
ASSIGNMENT = 16, // = *= /= ~/= %= += -= <<= >>= &= ^= |=
25+
NONE = 99, // (...)
26+
}
27+
728
export declare const dartGenerator: any;

typings/javascript.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,42 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
export enum Order {
8+
ATOMIC = 0, // 0 "" ...
9+
NEW = 1.1, // new
10+
MEMBER = 1.2, // . []
11+
FUNCTION_CALL = 2, // ()
12+
INCREMENT = 3, // ++
13+
DECREMENT = 3, // --
14+
BITWISE_NOT = 4.1, // ~
15+
UNARY_PLUS = 4.2, // +
16+
UNARY_NEGATION = 4.3, // -
17+
LOGICAL_NOT = 4.4, // !
18+
TYPEOF = 4.5, // typeof
19+
VOID = 4.6, // void
20+
DELETE = 4.7, // delete
21+
AWAIT = 4.8, // await
22+
EXPONENTIATION = 5.0, // **
23+
MULTIPLICATION = 5.1, // *
24+
DIVISION = 5.2, // /
25+
MODULUS = 5.3, // %
26+
SUBTRACTION = 6.1, // -
27+
ADDITION = 6.2, // +
28+
BITWISE_SHIFT = 7, // << >> >>>
29+
RELATIONAL = 8, // < <= > >=
30+
IN = 8, // in
31+
INSTANCEOF = 8, // instanceof
32+
EQUALITY = 9, // == != === !==
33+
BITWISE_AND = 10, // &
34+
BITWISE_XOR = 11, // ^
35+
BITWISE_OR = 12, // |
36+
LOGICAL_AND = 13, // &&
37+
LOGICAL_OR = 14, // ||
38+
CONDITIONAL = 15, // ?:
39+
ASSIGNMENT = 16, // = += -= **= *= /= %= <<= >>= ...
40+
YIELD = 17, // yield
41+
COMMA = 18, // ,
42+
NONE = 99, // (...)
43+
}
44+
745
export declare const javascriptGenerator: any;

typings/lua.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,19 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
export enum Order {
8+
ATOMIC = 0, // literals
9+
// The next level was not explicit in documentation and inferred by Ellen.
10+
HIGH = 1, // Function calls, tables[]
11+
EXPONENTIATION = 2, // ^
12+
UNARY = 3, // not # - ~
13+
MULTIPLICATIVE = 4, // * / %
14+
ADDITIVE = 5, // + -
15+
CONCATENATION = 6, // ..
16+
RELATIONAL = 7, // < > <= >= ~= ==
17+
AND = 8, // and
18+
OR = 9, // or
19+
NONE = 99,
20+
}
21+
722
export declare const luaGenerator: any;

0 commit comments

Comments
 (0)