Skip to content

Commit

Permalink
release: v10.0.2 google#7295 and google#7297 (google#7298)
Browse files Browse the repository at this point in the history
* fix(generators): Changes to exports and access controls for TypeScript compatibility (google#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 google#7283, but closely related and required to
  fixing the related issue google/blockly-samples#1785.

* chore(generators): format

(cherry picked from commit d503fbb)

* fix: Correct errors in `HSV_SATURATION`, `HSV_VALUE` accessors (google#7297)

* fix: Correct errors in HSV_SATURATION, HSV_VALUE accessors

  Fix the comment / message errors noted in
  google#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 <[email protected]>
  • Loading branch information
ericblackmonGoogle and cpcallen authored Jul 17, 2023
1 parent 2042334 commit e06aa02
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 33 deletions.
7 changes: 2 additions & 5 deletions core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CodeGenerator {
* legitimately appear in a function definition (or comment), and it must
* not confuse the regular expression parser.
*/
protected FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}';
FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}';
FUNCTION_NAME_PLACEHOLDER_REGEXP_: RegExp;

/**
Expand Down Expand Up @@ -471,10 +471,7 @@ export class CodeGenerator {
* @returns The actual name of the new function. This may differ from
* desiredName if the former has already been taken by the user.
*/
protected provideFunction_(
desiredName: string,
code: string[] | string
): string {
provideFunction_(desiredName: string, code: string[] | string): string {
if (!this.definitions_[desiredName]) {
const functionName = this.nameDB_!.getDistinctName(
desiredName,
Expand Down
14 changes: 7 additions & 7 deletions core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Object.defineProperties(Blockly, {
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_SATURATION
* @type {number}
* @deprecated Use Blockly.colour.getHsvSaturation() / .setHsvSaturation(
* instead. (July 2023)
* @deprecated Use Blockly.utils.colour.getHsvSaturation() /
* .setHsvSaturation() instead. (July 2023)
* @suppress {checkTypes}
*/
HSV_SATURATION: {
Expand All @@ -42,7 +42,7 @@ Object.defineProperties(Blockly, {
'Blockly.HSV_SATURATION',
'version 10',
'version 11',
'Blockly.colour.getHsvSaturation()'
'Blockly.utils.colour.getHsvSaturation()'
);
return colour.getHsvSaturation();
},
Expand All @@ -51,7 +51,7 @@ Object.defineProperties(Blockly, {
'Blockly.HSV_SATURATION',
'version 10',
'version 11',
'Blockly.colour.setHsvSaturation()'
'Blockly.utils.colour.setHsvSaturation()'
);
colour.setHsvSaturation(newValue);
},
Expand All @@ -61,7 +61,7 @@ Object.defineProperties(Blockly, {
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_VALUE
* @type {number}
* @deprecated Use Blockly.colour.getHsvValue() / .setHsvValue instead.
* @deprecated Use Blockly.utils.colour.getHsvValue() / .setHsvValue instead.
* (July 2023)
* @suppress {checkTypes}
*/
Expand All @@ -71,7 +71,7 @@ Object.defineProperties(Blockly, {
'Blockly.HSV_VALUE',
'version 10',
'version 11',
'Blockly.colour.getHsvValue()'
'Blockly.utils.colour.getHsvValue()'
);
return colour.getHsvValue();
},
Expand All @@ -80,7 +80,7 @@ Object.defineProperties(Blockly, {
'Blockly.HSV_VALUE',
'version 10',
'version 11',
'Blockly.colour.setHsvValue()'
'Blockly.utils.colour.setHsvValue()'
);
colour.setHsvValue(newValue);
},
Expand Down
36 changes: 18 additions & 18 deletions generators/python/python_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ export class PythonGenerator extends CodeGenerator {
// (foo.bar)() -> foo.bar()
// (foo[0])() -> foo[0]()
[Order.MEMBER, Order.FUNCTION_CALL],

// not (not foo) -> not not foo
[Order.LOGICAL_NOT, Order.LOGICAL_NOT],
// a and (b and c) -> a and b and c
[Order.LOGICAL_AND, Order.LOGICAL_AND],
// a or (b or c) -> a or b or c
[Order.LOGICAL_OR, Order.LOGICAL_OR]
];

constructor(name) {
super(name ?? 'Python');
this.isInitialized = false;
Expand Down Expand Up @@ -143,30 +143,30 @@ export class PythonGenerator extends CodeGenerator {
'vars,xrange,zip'
);
}

/**
* Initialise the database of variable names.
* @param {!Workspace} workspace Workspace to generate code from.
* @this {CodeGenerator}
*/
init(workspace) {
super.init(workspace);

/**
* Empty loops or conditionals are not allowed in Python.
*/
this.PASS = this.INDENT + 'pass\n';

if (!this.nameDB_) {
this.nameDB_ = new Names(this.RESERVED_WORDS_);
} else {
this.nameDB_.reset();
}

this.nameDB_.setVariableMap(workspace.getVariableMap());
this.nameDB_.populateVariables(workspace);
this.nameDB_.populateProcedures(workspace);

const defvars = [];
// Add developer variables (not created or named by the user).
const devVarList = Variables.allDeveloperVariables(workspace);
Expand All @@ -175,19 +175,19 @@ export class PythonGenerator extends CodeGenerator {
this.nameDB_.getName(devVarList[i], Names.DEVELOPER_VARIABLE_TYPE) +
' = None');
}

// Add user variables, but only ones that are being used.
const variables = Variables.allUsedVarModels(workspace);
for (let i = 0; i < variables.length; i++) {
defvars.push(
this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE) +
' = None');
}

this.definitions_['variables'] = defvars.join('\n');
this.isInitialized = true;
}

/**
* Prepend the generated code with import statements and variable definitions.
* @param {string} code Generated code.
Expand All @@ -208,12 +208,12 @@ export class PythonGenerator extends CodeGenerator {
// Call Blockly.CodeGenerator's finish.
code = super.finish(code);
this.isInitialized = false;

this.nameDB_.reset();
const allDefs = imports.join('\n') + '\n\n' + definitions.join('\n\n');
return allDefs.replace(/\n\n+/g, '\n\n').replace(/\n*$/, '\n\n\n') + code;
}

/**
* Naked values are top-level blocks with outputs that aren't plugged into
* anything.
Expand All @@ -223,7 +223,7 @@ export class PythonGenerator extends CodeGenerator {
scrubNakedValue(line) {
return line + '\n';
}

/**
* Encode a string as a properly escaped Python string, complete with quotes.
* @param {string} string Text to encode.
Expand All @@ -232,7 +232,7 @@ export class PythonGenerator extends CodeGenerator {
*/
quote_(string) {
string = string.replace(/\\/g, '\\\\').replace(/\n/g, '\\\n');

// Follow the CPython behaviour of repr() for a non-byte string.
let quote = '\'';
if (string.indexOf('\'') !== -1) {
Expand All @@ -244,7 +244,7 @@ export class PythonGenerator extends CodeGenerator {
}
return quote + string + quote;
}

/**
* Encode a string as a properly escaped multiline Python string, complete
* with quotes.
Expand All @@ -258,7 +258,7 @@ export class PythonGenerator extends CodeGenerator {
// + '\n' +
return lines.join(' + \'\\n\' + \n');
}

/**
* Common tasks for generating Python from blocks.
* Handles comments for the specified block and any connected value blocks.
Expand Down Expand Up @@ -297,7 +297,7 @@ export class PythonGenerator extends CodeGenerator {
const nextCode = opt_thisOnly ? '' : this.blockToCode(nextBlock);
return commentCode + code + nextCode;
}

/**
* Gets a property and adjusts the value, taking into account indexing.
* If a static int, casts to an integer, otherwise returns a code string.
Expand All @@ -315,7 +315,7 @@ export class PythonGenerator extends CodeGenerator {
const defaultAtIndex = block.workspace.options.oneBasedIndex ? '1' : '0';
const atOrder = delta ? this.ORDER_ADDITIVE : this.ORDER_NONE;
let at = this.valueToCode(block, atId, atOrder) || defaultAtIndex;

if (stringUtils.isNumber(at)) {
// If the index is a naked number, adjust it right now.
at = parseInt(at, 10) + delta;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockly",
"version": "10.0.1",
"version": "10.0.2",
"description": "Blockly is a library for building visual programming editors.",
"keywords": [
"blockly"
Expand Down
18 changes: 18 additions & 0 deletions scripts/migration/renamings.json5
Original file line number Diff line number Diff line change
Expand Up @@ -1577,5 +1577,23 @@
},
],

'10.0.1': [
{
oldName: 'Blockly',
exports: {
HSV_SATURATION: {
newModule: 'Blockly.utils.colour',
getMethod: 'getHsvSaturation',
setMethod: 'setHsvSaturation',
},
HSV_VALUE: {
newModule: 'Blockly.utils.colour',
getMethod: 'getHsvValue',
setMethod: 'setHsvValue',
},
},
},
],

'develop': [],
}
21 changes: 21 additions & 0 deletions typings/dart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,25 @@
* SPDX-License-Identifier: Apache-2.0
*/

export enum Order {
ATOMIC = 0, // 0 "" ...
UNARY_POSTFIX = 1, // expr++ expr-- () [] . ?.
UNARY_PREFIX = 2, // -expr !expr ~expr ++expr --expr
MULTIPLICATIVE = 3, // * / % ~/
ADDITIVE = 4, // + -
SHIFT = 5, // << >>
BITWISE_AND = 6, // &
BITWISE_XOR = 7, // ^
BITWISE_OR = 8, // |
RELATIONAL = 9, // >= > <= < as is is!
EQUALITY = 10, // == !=
LOGICAL_AND = 11, // &&
LOGICAL_OR = 12, // ||
IF_NULL = 13, // ??
CONDITIONAL = 14, // expr ? expr : expr
CASCADE = 15, // ..
ASSIGNMENT = 16, // = *= /= ~/= %= += -= <<= >>= &= ^= |=
NONE = 99, // (...)
}

export declare const dartGenerator: any;
38 changes: 38 additions & 0 deletions typings/javascript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,42 @@
* SPDX-License-Identifier: Apache-2.0
*/

export enum Order {
ATOMIC = 0, // 0 "" ...
NEW = 1.1, // new
MEMBER = 1.2, // . []
FUNCTION_CALL = 2, // ()
INCREMENT = 3, // ++
DECREMENT = 3, // --
BITWISE_NOT = 4.1, // ~
UNARY_PLUS = 4.2, // +
UNARY_NEGATION = 4.3, // -
LOGICAL_NOT = 4.4, // !
TYPEOF = 4.5, // typeof
VOID = 4.6, // void
DELETE = 4.7, // delete
AWAIT = 4.8, // await
EXPONENTIATION = 5.0, // **
MULTIPLICATION = 5.1, // *
DIVISION = 5.2, // /
MODULUS = 5.3, // %
SUBTRACTION = 6.1, // -
ADDITION = 6.2, // +
BITWISE_SHIFT = 7, // << >> >>>
RELATIONAL = 8, // < <= > >=
IN = 8, // in
INSTANCEOF = 8, // instanceof
EQUALITY = 9, // == != === !==
BITWISE_AND = 10, // &
BITWISE_XOR = 11, // ^
BITWISE_OR = 12, // |
LOGICAL_AND = 13, // &&
LOGICAL_OR = 14, // ||
CONDITIONAL = 15, // ?:
ASSIGNMENT = 16, // = += -= **= *= /= %= <<= >>= ...
YIELD = 17, // yield
COMMA = 18, // ,
NONE = 99, // (...)
}

export declare const javascriptGenerator: any;
15 changes: 15 additions & 0 deletions typings/lua.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

export enum Order {
ATOMIC = 0, // literals
// The next level was not explicit in documentation and inferred by Ellen.
HIGH = 1, // Function calls, tables[]
EXPONENTIATION = 2, // ^
UNARY = 3, // not # - ~
MULTIPLICATIVE = 4, // * / %
ADDITIVE = 5, // + -
CONCATENATION = 6, // ..
RELATIONAL = 7, // < > <= >= ~= ==
AND = 8, // and
OR = 9, // or
NONE = 99,
}

export declare const luaGenerator: any;
Loading

0 comments on commit e06aa02

Please sign in to comment.