release: Merge branch 'develop' into rc/v11.0.0

This commit is contained in:
Christopher Allen
2024-03-18 19:57:04 +00:00
40 changed files with 69 additions and 71 deletions

View File

@@ -227,7 +227,7 @@ const LISTS_CREATE_WITH = {
// Disconnect any children that don't belong.
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i)!.connection!.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
if (connection && !connections.includes(connection)) {
connection.disconnect();
}
}

View File

@@ -858,7 +858,7 @@ const PROCEDURE_CALL_COMMON = {
if (
mutatorOpen &&
connection &&
paramIds.indexOf(this.quarkIds_[i]) === -1
!paramIds.includes(this.quarkIds_[i])
) {
// This connection should no longer be attached to this block.
connection.disconnect();
@@ -1041,7 +1041,7 @@ const PROCEDURE_CALL_COMMON = {
}
if (
event.type === Events.BLOCK_CREATE &&
(event as BlockCreate).ids!.indexOf(this.id) !== -1
(event as BlockCreate).ids!.includes(this.id)
) {
// Look for the case where a procedure call was created (usually through
// paste) and there is no matching definition. In this case, create
@@ -1286,7 +1286,7 @@ const PROCEDURES_IFRETURN = {
// Is the block nested in a procedure?
let block = this; // eslint-disable-line @typescript-eslint/no-this-alias
do {
if (this.FUNCTION_TYPES.indexOf(block.type) !== -1) {
if (this.FUNCTION_TYPES.includes(block.type)) {
legal = true;
break;
}

View File

@@ -796,7 +796,7 @@ const JOIN_MUTATOR_MIXIN = {
// Disconnect any children that don't belong.
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i)!.connection!.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
if (connection && !connections.includes(connection)) {
connection.disconnect();
}
}

View File

@@ -1529,8 +1529,7 @@ export class Block implements IASTNodeLocation, IDeletable {
checks = connection.targetConnection.getCheck();
}
return (
!!checks &&
(checks.indexOf('Boolean') !== -1 || checks.indexOf('Number') !== -1)
!!checks && (checks.includes('Boolean') || checks.includes('Number'))
);
}

View File

@@ -99,7 +99,7 @@ export function bumpIntoBoundsHandler(
return;
}
if (eventUtils.BUMP_EVENTS.indexOf(e.type ?? '') !== -1) {
if (eventUtils.BUMP_EVENTS.includes(e.type ?? '')) {
const scrollMetricsInWsCoords = metricsManager.getScrollMetrics(true);
// Triggered by move/create event

View File

@@ -172,7 +172,7 @@ export class ComponentManager {
capability = `${capability}`.toLowerCase();
return (
this.componentData.has(id) &&
this.componentData.get(id)!.capabilities.indexOf(capability) !== -1
this.componentData.get(id)!.capabilities.includes(capability)
);
}

View File

@@ -210,7 +210,7 @@ export class ConnectionChecker implements IConnectionChecker {
}
// Find any intersection in the check lists.
for (let i = 0; i < checkArrayOne.length; i++) {
if (checkArrayTwo.indexOf(checkArrayOne[i]) !== -1) {
if (checkArrayTwo.includes(checkArrayOne[i])) {
return true;
}
}
@@ -298,7 +298,7 @@ export class ConnectionChecker implements IConnectionChecker {
}
// Don't let blocks try to connect to themselves or ones they nest.
if (common.draggingConnections.indexOf(b) !== -1) {
if (common.draggingConnections.includes(b)) {
return false;
}
@@ -321,7 +321,7 @@ export class ConnectionChecker implements IConnectionChecker {
}
// Don't let blocks try to connect to themselves or ones they nest.
if (common.draggingConnections.indexOf(b) !== -1) {
if (common.draggingConnections.includes(b)) {
return false;
}

View File

@@ -401,7 +401,7 @@ export function buildTooltipForDropdown(
const blockTypesChecked: string[] = [];
return function (this: Block) {
if (blockTypesChecked.indexOf(this.type) === -1) {
if (!blockTypesChecked.includes(this.type)) {
checkDropdownOptionsInTable(this, dropdownName, lookupTable);
blockTypesChecked.push(this.type);
}

View File

@@ -408,7 +408,13 @@ export class FieldDropdown extends Field<string> {
* @param newValue The input value.
* @returns A valid language-neutral option, or null if invalid.
*/
protected override doClassValidation_(newValue?: string): string | null {
protected override doClassValidation_(
newValue: string,
): string | null | undefined;
protected override doClassValidation_(newValue?: string): string | null;
protected override doClassValidation_(
newValue?: string,
): string | null | undefined {
const options = this.getOptions(true);
const isValueValid = options.some((option) => option[1] === newValue);
@@ -426,7 +432,7 @@ export class FieldDropdown extends Field<string> {
}
return null;
}
return newValue as string;
return newValue;
}
/**

View File

@@ -216,7 +216,7 @@ export class FieldNumber extends FieldInput<number> {
private setPrecisionInternal(precision: number | string | undefined | null) {
this.precision_ = Number(precision) || 0;
let precisionString = String(this.precision_);
if (precisionString.indexOf('e') !== -1) {
if (precisionString.includes('e')) {
// String() is fast. But it turns .0000001 into '1e-7'.
// Use the much slower toLocaleString to access all the digits.
precisionString = this.precision_.toLocaleString('en-US', {

View File

@@ -1201,7 +1201,7 @@ export abstract class Flyout
private filterForCapacity() {
const blocks = this.workspace_.getTopBlocks(false);
for (let i = 0, block; (block = blocks[i]); i++) {
if (this.permanentlyDisabled.indexOf(block) === -1) {
if (!this.permanentlyDisabled.includes(block)) {
const enable = this.targetWorkspace.isCapacityAvailable(
common.getBlockTypeCounts(block),
);

View File

@@ -568,11 +568,7 @@ export class CodeGenerator {
* @param _opt_thisOnly True to generate code for only this statement.
* @returns Code with comments and subsequent blocks added.
*/
protected scrub_(
_block: Block,
code: string,
_opt_thisOnly?: boolean,
): string {
scrub_(_block: Block, code: string, _opt_thisOnly?: boolean): string {
// Optionally override
return code;
}

View File

@@ -218,7 +218,7 @@ export class Names {
// https://github.com/google/blockly/issues/1654
name = encodeURI(name.replace(/ /g, '_')).replace(/[^\w]/g, '_');
// Most languages don't allow names with leading numbers.
if ('0123456789'.indexOf(name[0]) !== -1) {
if ('0123456789'.includes(name[0])) {
name = 'my_' + name;
}
}

View File

@@ -617,7 +617,7 @@ export class ConstantProvider {
getBlockStyle(blockStyleName: string | null): BlockStyle {
return (
this.blockStyles[blockStyleName || ''] ||
(blockStyleName && blockStyleName.indexOf('auto_') === 0
(blockStyleName && blockStyleName.startsWith('auto_')
? this.getBlockStyleForColour(blockStyleName.substring(5)).style
: this.createBlockStyle_('#000000'))
);

View File

@@ -536,13 +536,13 @@ export class ConstantProvider extends BaseConstantProvider {
}
}
// Includes doesn't work in IE.
if (checks && checks.indexOf('Boolean') !== -1) {
if (checks && checks.includes('Boolean')) {
return this.HEXAGONAL!;
}
if (checks && checks.indexOf('Number') !== -1) {
if (checks && checks.includes('Number')) {
return this.ROUNDED!;
}
if (checks && checks.indexOf('String') !== -1) {
if (checks && checks.includes('String')) {
return this.ROUNDED!;
}
return this.ROUNDED!;

View File

@@ -325,7 +325,7 @@ export class ShortcutRegistry {
const modifierKeyCode = (
ShortcutRegistry.modifierKeys as AnyDuringMigration
)[modifier];
if (modifiers.indexOf(modifierKeyCode) > -1) {
if (modifiers.includes(modifierKeyCode)) {
if (serializedKey !== '') {
serializedKey += '+';
}

View File

@@ -616,7 +616,7 @@ export class Trashcan
const cleanedJson = JSON.stringify(
this.cleanBlockJson(deleteEvent.oldJson),
);
if (this.contents.indexOf(cleanedJson) !== -1) {
if (this.contents.includes(cleanedJson)) {
return;
}
this.contents.unshift(cleanedJson);

View File

@@ -204,9 +204,9 @@ function wrapScore(
score -= Math.pow(maxLength - lineLengths[i], 1.5);
// Optimize for structure.
// Add score to line endings after punctuation.
if ('.?!'.indexOf(linePunctuation[i]) !== -1) {
if ('.?!'.includes(linePunctuation[i])) {
score += limit / 3;
} else if (',;)]}'.indexOf(linePunctuation[i]) !== -1) {
} else if (',;)]}'.includes(linePunctuation[i])) {
score += limit / 4;
}
}

View File

@@ -62,7 +62,7 @@ export function getRelativeXY(element: Element): Coordinate {
// Then check for style = transform: translate(...) or translate3d(...)
const style = element.getAttribute('style');
if (style && style.indexOf('translate') > -1) {
if (style && style.includes('translate')) {
const styleComponents = style.match(XY_STYLE_REGEX);
if (styleComponents) {
xy.x += Number(styleComponents[1]);
@@ -90,7 +90,7 @@ export function getInjectionDivXY(element: Element): Coordinate {
x = x + xy.x;
y = y + xy.y;
const classes = element.getAttribute('class') || '';
if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) {
if ((' ' + classes + ' ').includes(' injectionDiv ')) {
break;
}
element = element.parentNode as Element;

View File

@@ -381,7 +381,7 @@ function addAttributes(node: Node, obj: AnyDuringMigration) {
// AnyDuringMigration because: Property 'attributes' does not exist on type
// 'Node'.
const attr = (node as AnyDuringMigration).attributes[j];
if (attr.nodeName.indexOf('css-') > -1) {
if (attr.nodeName.includes('css-')) {
obj['cssconfig'] = obj['cssconfig'] || {};
obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value;
} else {

View File

@@ -37,7 +37,7 @@ let isMobile: boolean;
* @returns True if name is present.
*/
function has(name: string): boolean {
return rawUpper.indexOf(name.toUpperCase()) !== -1;
return rawUpper.includes(name.toUpperCase());
}
// Browsers. Logic from:

View File

@@ -642,7 +642,7 @@ export function getAddedVariables(
const variable = allCurrentVariables[i];
// For any variable that is present in allCurrentVariables but not
// present in originalVariables, add the variable to addedVariables.
if (originalVariables.indexOf(variable) === -1) {
if (!originalVariables.includes(variable)) {
addedVariables.push(variable);
}
}

View File

@@ -690,7 +690,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
let element: Element = this.svgGroup_;
while (element) {
const classes = element.getAttribute('class') || '';
if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) {
if ((' ' + classes + ' ').includes(' injectionDiv ')) {
this.injectionDiv = element;
break;
}
@@ -1301,7 +1301,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
// Using Set here would be great, but at the cost of IE10 support.
if (!state) {
arrayUtils.removeElem(this.highlightedBlocks, block);
} else if (this.highlightedBlocks.indexOf(block) === -1) {
} else if (!this.highlightedBlocks.includes(block)) {
this.highlightedBlocks.push(block);
}
block.setHighlighted(state);

View File

@@ -224,9 +224,9 @@ BlockExporterController.prototype.selectUsedBlocks = function() {
var unstoredCustomBlockTypes = [];
for (var i = 0, blockType; blockType = this.usedBlockTypes[i]; i++) {
if (storedBlockTypes.indexOf(blockType) !== -1) {
if (storedBlockTypes.includes(blockType)) {
sharedBlockTypes.push(blockType);
} else if (StandardCategories.coreBlockTypes.indexOf(blockType) === -1) {
} else if (!StandardCategories.coreBlockTypes.includes(blockType)) {
unstoredCustomBlockTypes.push(blockType);
}
}

View File

@@ -682,7 +682,7 @@ Blockly.Blocks['type_group'] = {
// Disconnect any children that don't belong.
for (var i = 0; i < this.typeCount_; i++) {
var connection = this.getInput('TYPE' + i).connection.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
if (connection && !connections.includes(connection)) {
connection.disconnect();
}
}

View File

@@ -238,7 +238,7 @@ BlockFactory.updatePreview = function() {
// Warn user only if their block type is already exists in Blockly's
// standard library.
var rootBlock = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace);
if (StandardCategories.coreBlockTypes.indexOf(blockType) !== -1) {
if (StandardCategories.coreBlockTypes.includes(blockType)) {
rootBlock.setWarningText('A core Blockly block already exists ' +
'under this name.');

View File

@@ -594,7 +594,7 @@ FactoryUtils.getOptTypesFrom = function(block, name) {
var types = FactoryUtils.getTypesFrom_(block, name);
if (types.length === 0) {
return undefined;
} else if (types.indexOf('null') !== -1) {
} else if (types.includes('null')) {
return 'null';
} else if (types.length === 1) {
return types[0];
@@ -771,7 +771,7 @@ FactoryUtils.parseJsBlockDefinitions = function(blockDefsString) {
var blockDefArray = [];
var defStart = blockDefsString.indexOf('Blockly.Blocks');
while (blockDefsString.indexOf('Blockly.Blocks', defStart) !== -1) {
while (blockDefsString.includes('Blockly.Blocks', defStart)) {
var nextStart = blockDefsString.indexOf('Blockly.Blocks', defStart + 1);
if (nextStart === -1) {
// This is the last block definition.

View File

@@ -369,7 +369,7 @@
// Manual JavaScript works but requires use of eval().
// TODO(#1269): Replace eval() with JS-Interpreter before
// re-enabling "Manual JavaScript" mode.
if (document.location.href.indexOf('file://') === 0) {
if (document.location.href.startsWith('file://')) {
document.write(
'<option value="Manual-JS">Manual JavaScript&hellip;</option>');
}

View File

@@ -395,7 +395,7 @@ WorkspaceFactoryModel.prototype.getAllUsedBlockTypes = function() {
// Add block types if not already in list.
for (var i = 0; i < blocks.length; i++) {
var type = blocks[i].getAttribute('type');
if (list.indexOf(type) === -1) {
if (!list.includes(type)) {
list.push(type);
}
}
@@ -444,9 +444,9 @@ WorkspaceFactoryModel.prototype.updateLibBlockTypes = function(blockTypes) {
*/
WorkspaceFactoryModel.prototype.isDefinedBlockType = function(blockType) {
var isStandardBlock =
StandardCategories.coreBlockTypes.indexOf(blockType) !== -1;
var isLibBlock = this.libBlockTypes.indexOf(blockType) !== -1;
var isImportedBlock = this.importedBlockTypes.indexOf(blockType) !== -1;
StandardCategories.coreBlockTypes.includes(blockType);
var isLibBlock = this.libBlockTypes.includes(blockType);
var isImportedBlock = this.importedBlockTypes.includes(blockType);
return (isStandardBlock || isLibBlock || isImportedBlock);
};

View File

@@ -106,7 +106,7 @@ Code.getLang = function() {
* @return {boolean} True if RTL, false if LTR.
*/
Code.isRtl = function() {
return Code.LANGUAGE_RTL.indexOf(Code.LANG) !== -1;
return Code.LANGUAGE_RTL.includes(Code.LANG);
};
/**
@@ -396,7 +396,7 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
for (var i = 0; i < blocks.length; i++) {
var blockType = blocks[i].type;
if (!generator.forBlock[blockType]) {
if (missingBlockGenerators.indexOf(blockType) === -1) {
if (!missingBlockGenerators.includes(blockType)) {
missingBlockGenerators.push(blockType);
}
}
@@ -450,7 +450,7 @@ Code.init = function() {
// TODO: Clean up the message files so this is done explicitly instead of
// through this for-loop.
for (var messageKey in MSG) {
if (messageKey.indexOf('cat') === 0) {
if (messageKey.startsWith('cat')) {
Blockly.Msg[messageKey.toUpperCase()] = MSG[messageKey];
}
}

View File

@@ -251,7 +251,6 @@ export class JavascriptGenerator extends CodeGenerator {
* @param code The JavaScript code created for this block.
* @param thisOnly True to generate code for only this statement.
* @returns JavaScript code with comments and subsequent blocks added.
* @protected
*/
scrub_(block: Block, code: string, thisOnly = false): string {
let commentCode = '';

View File

@@ -35,7 +35,7 @@ const CONTINUE_STATEMENT = 'goto continue\n';
* @returns Generated label or '' if unnecessary
*/
function addContinueLabel(branch: string, indent: string): string {
if (branch.indexOf(CONTINUE_STATEMENT) !== -1) {
if (branch.includes(CONTINUE_STATEMENT)) {
// False positives are possible (e.g. a string literal), but are harmless.
return branch + indent + '::continue::\n';
} else {

View File

@@ -27,7 +27,7 @@ export function procedures_defreturn(block: Block, generator: PhpGenerator) {
for (const variable of usedVariables) {
const varName = variable.name;
// getVars returns parameter names, not ids, for procedure blocks
if (block.getVars().indexOf(varName) === -1) {
if (!block.getVars().includes(varName)) {
globals.push(generator.getVariableName(varName));
}
}

View File

@@ -27,7 +27,7 @@ export function procedures_defreturn(block: Block, generator: PythonGenerator) {
for (const variable of usedVariables) {
const varName = variable.name;
// getVars returns parameter names, not ids, for procedure blocks
if (block.getVars().indexOf(varName) === -1) {
if (!block.getVars().includes(varName)) {
globals.push(generator.getVariableName(varName));
}
}

View File

@@ -243,8 +243,8 @@ export class PythonGenerator extends CodeGenerator {
// Follow the CPython behaviour of repr() for a non-byte string.
let quote = "'";
if (string.indexOf("'") !== -1) {
if (string.indexOf('"') === -1) {
if (string.includes("'")) {
if (!string.includes('"')) {
quote = '"';
} else {
string = string.replace(/'/g, "\\'");
@@ -276,7 +276,6 @@ export class PythonGenerator extends CodeGenerator {
* @param code The Python code created for this block.
* @param thisOnly True to generate code for only this statement.
* @returns Python code with comments and subsequent blocks added.
*/
scrub_(block: Block, code: string, thisOnly = false): string {
let commentCode = '';

8
package-lock.json generated
View File

@@ -48,7 +48,7 @@
"prettier": "3.2.5",
"readline-sync": "^1.4.10",
"rimraf": "^5.0.0",
"typescript": "^5.0.2",
"typescript": "^5.3.3",
"webdriverio": "^8.32.2",
"yargs": "^17.2.1"
},
@@ -11017,9 +11017,9 @@
"dev": true
},
"node_modules/typescript": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"version": "5.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz",
"integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==",
"dev": true,
"bin": {
"tsc": "bin/tsc",

View File

@@ -131,7 +131,7 @@
"prettier": "3.2.5",
"readline-sync": "^1.4.10",
"rimraf": "^5.0.0",
"typescript": "^5.0.2",
"typescript": "^5.3.3",
"webdriverio": "^8.32.2",
"yargs": "^17.2.1"
},

View File

@@ -131,7 +131,7 @@ function updateBetaVersion(done) {
const latestBetaVersion = execSync('npm show blockly version --tag beta').toString().trim();
while (!isValid) {
newVersion = readlineSync.question(`What is the new beta version? (latest beta version: ${latestBetaVersion})`);
const existsOnNpm = blocklyVersions.indexOf(newVersion) > -1;
const existsOnNpm = blocklyVersions.includes(newVersion);
const isFormatted = newVersion.search(re) > -1;
if (!existsOnNpm && isFormatted) {
isValid = true;

View File

@@ -41,10 +41,10 @@ export function createKeyDownEvent(keyCode, modifiers) {
keyCode: keyCode,
};
if (modifiers && modifiers.length > 0) {
event.altKey = modifiers.indexOf(KeyCodes.ALT) > -1;
event.ctrlKey = modifiers.indexOf(KeyCodes.CTRL) > -1;
event.metaKey = modifiers.indexOf(KeyCodes.META) > -1;
event.shiftKey = modifiers.indexOf(KeyCodes.SHIFT) > -1;
event.altKey = modifiers.includes(KeyCodes.ALT);
event.ctrlKey = modifiers.includes(KeyCodes.CTRL);
event.metaKey = modifiers.includes(KeyCodes.META);
event.shiftKey = modifiers.includes(KeyCodes.SHIFT);
}
return new KeyboardEvent('keydown', event);
}

View File

@@ -89,8 +89,7 @@ function workspaceToSvg_(workspace, callback, customCss) {
const css = [].slice
.call(document.head.querySelectorAll('style'))
.filter(
(el) =>
/\.blocklySvg/.test(el.innerText) || el.id.indexOf('blockly-') === 0,
(el) => /\.blocklySvg/.test(el.innerText) || el.id.startsWith('blockly-'),
)
.map((el) => el.innerText)
.join('\n');