chore: Use .includes and .startsWith, not .indexOf (#7936)

Easier to read than the diverse collection of `=== 0` and `!== -1` and `> -1` tests.
This commit is contained in:
Neil Fraser
2024-03-15 00:03:55 +01:00
committed by GitHub
parent 81e2203f7f
commit 0ecbcde9fc
42 changed files with 62 additions and 64 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -172,7 +172,7 @@ export class ComponentManager {
capability = `${capability}`.toLowerCase(); capability = `${capability}`.toLowerCase();
return ( return (
this.componentData.has(id) && 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. // Find any intersection in the check lists.
for (let i = 0; i < checkArrayOne.length; i++) { for (let i = 0; i < checkArrayOne.length; i++) {
if (checkArrayTwo.indexOf(checkArrayOne[i]) !== -1) { if (checkArrayTwo.includes(checkArrayOne[i])) {
return true; return true;
} }
} }
@@ -298,7 +298,7 @@ export class ConnectionChecker implements IConnectionChecker {
} }
// Don't let blocks try to connect to themselves or ones they nest. // 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; return false;
} }
@@ -321,7 +321,7 @@ export class ConnectionChecker implements IConnectionChecker {
} }
// Don't let blocks try to connect to themselves or ones they nest. // 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; return false;
} }

View File

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

View File

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

View File

@@ -1201,7 +1201,7 @@ export abstract class Flyout
private filterForCapacity() { private filterForCapacity() {
const blocks = this.workspace_.getTopBlocks(false); const blocks = this.workspace_.getTopBlocks(false);
for (let i = 0, block; (block = blocks[i]); i++) { 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( const enable = this.targetWorkspace.isCapacityAvailable(
common.getBlockTypeCounts(block), common.getBlockTypeCounts(block),
); );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -62,7 +62,7 @@ export function getRelativeXY(element: Element): Coordinate {
// Then check for style = transform: translate(...) or translate3d(...) // Then check for style = transform: translate(...) or translate3d(...)
const style = element.getAttribute('style'); const style = element.getAttribute('style');
if (style && style.indexOf('translate') > -1) { if (style && style.includes('translate')) {
const styleComponents = style.match(XY_STYLE_REGEX); const styleComponents = style.match(XY_STYLE_REGEX);
if (styleComponents) { if (styleComponents) {
xy.x += Number(styleComponents[1]); xy.x += Number(styleComponents[1]);
@@ -90,7 +90,7 @@ export function getInjectionDivXY(element: Element): Coordinate {
x = x + xy.x; x = x + xy.x;
y = y + xy.y; y = y + xy.y;
const classes = element.getAttribute('class') || ''; const classes = element.getAttribute('class') || '';
if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) { if ((' ' + classes + ' ').includes(' injectionDiv ')) {
break; break;
} }
element = element.parentNode as Element; 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 // AnyDuringMigration because: Property 'attributes' does not exist on type
// 'Node'. // 'Node'.
const attr = (node as AnyDuringMigration).attributes[j]; const attr = (node as AnyDuringMigration).attributes[j];
if (attr.nodeName.indexOf('css-') > -1) { if (attr.nodeName.includes('css-')) {
obj['cssconfig'] = obj['cssconfig'] || {}; obj['cssconfig'] = obj['cssconfig'] || {};
obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value; obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value;
} else { } else {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -238,7 +238,7 @@ BlockFactory.updatePreview = function() {
// Warn user only if their block type is already exists in Blockly's // Warn user only if their block type is already exists in Blockly's
// standard library. // standard library.
var rootBlock = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace); 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 ' + rootBlock.setWarningText('A core Blockly block already exists ' +
'under this name.'); 'under this name.');

View File

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

View File

@@ -369,7 +369,7 @@
// Manual JavaScript works but requires use of eval(). // Manual JavaScript works but requires use of eval().
// TODO(#1269): Replace eval() with JS-Interpreter before // TODO(#1269): Replace eval() with JS-Interpreter before
// re-enabling "Manual JavaScript" mode. // re-enabling "Manual JavaScript" mode.
if (document.location.href.indexOf('file://') === 0) { if (document.location.href.startsWith('file://')) {
document.write( document.write(
'<option value="Manual-JS">Manual JavaScript&hellip;</option>'); '<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. // Add block types if not already in list.
for (var i = 0; i < blocks.length; i++) { for (var i = 0; i < blocks.length; i++) {
var type = blocks[i].getAttribute('type'); var type = blocks[i].getAttribute('type');
if (list.indexOf(type) === -1) { if (!list.includes(type)) {
list.push(type); list.push(type);
} }
} }
@@ -444,9 +444,9 @@ WorkspaceFactoryModel.prototype.updateLibBlockTypes = function(blockTypes) {
*/ */
WorkspaceFactoryModel.prototype.isDefinedBlockType = function(blockType) { WorkspaceFactoryModel.prototype.isDefinedBlockType = function(blockType) {
var isStandardBlock = var isStandardBlock =
StandardCategories.coreBlockTypes.indexOf(blockType) !== -1; StandardCategories.coreBlockTypes.includes(blockType);
var isLibBlock = this.libBlockTypes.indexOf(blockType) !== -1; var isLibBlock = this.libBlockTypes.includes(blockType);
var isImportedBlock = this.importedBlockTypes.indexOf(blockType) !== -1; var isImportedBlock = this.importedBlockTypes.includes(blockType);
return (isStandardBlock || isLibBlock || isImportedBlock); return (isStandardBlock || isLibBlock || isImportedBlock);
}; };

View File

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

View File

@@ -490,7 +490,7 @@ function getOptTypesFrom(block, name) {
var types = getTypesFrom_(block, name); var types = getTypesFrom_(block, name);
if (types.length === 0) { if (types.length === 0) {
return undefined; return undefined;
} else if (types.indexOf('null') !== -1) { } else if (types.includes('null')) {
return 'null'; return 'null';
} else if (types.length === 1) { } else if (types.length === 1) {
return types[0]; return types[0];

View File

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

View File

@@ -29,7 +29,7 @@ export function text_multiline(
): [string, Order] { ): [string, Order] {
// Text value. // Text value.
const code = generator.multiline_quote_(block.getFieldValue('TEXT')); const code = generator.multiline_quote_(block.getFieldValue('TEXT'));
const order = code.indexOf('+') !== -1 ? Order.ADDITIVE : Order.ATOMIC; const order = code.includes('+') ? Order.ADDITIVE : Order.ATOMIC;
return [code, order]; return [code, order];
} }

View File

@@ -72,7 +72,7 @@ export function text_multiline(
): [string, Order] { ): [string, Order] {
// Text value. // Text value.
const code = generator.multiline_quote_(block.getFieldValue('TEXT')); const code = generator.multiline_quote_(block.getFieldValue('TEXT'));
const order = code.indexOf('+') !== -1 ? Order.ADDITION : Order.ATOMIC; const order = code.includes('+') ? Order.ADDITION : Order.ATOMIC;
return [code, order]; return [code, order];
} }

View File

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

View File

@@ -27,7 +27,7 @@ export function text_multiline(
): [string, Order] { ): [string, Order] {
// Text value. // Text value.
const code = generator.multiline_quote_(block.getFieldValue('TEXT')); const code = generator.multiline_quote_(block.getFieldValue('TEXT'));
const order = code.indexOf('..') !== -1 ? Order.CONCATENATION : Order.ATOMIC; const order = code.includes('..') ? Order.CONCATENATION : Order.ATOMIC;
return [code, order]; return [code, order];
} }

View File

@@ -27,7 +27,7 @@ export function procedures_defreturn(block: Block, generator: PhpGenerator) {
for (const variable of usedVariables) { for (const variable of usedVariables) {
const varName = variable.name; const varName = variable.name;
// getVars returns parameter names, not ids, for procedure blocks // 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)); globals.push(generator.getVariableName(varName));
} }
} }

View File

@@ -27,7 +27,7 @@ export function text_multiline(
): [string, Order] { ): [string, Order] {
// Text value. // Text value.
const code = generator.multiline_quote_(block.getFieldValue('TEXT')); const code = generator.multiline_quote_(block.getFieldValue('TEXT'));
const order = code.indexOf('.') !== -1 ? Order.STRING_CONCAT : Order.ATOMIC; const order = code.includes('.') ? Order.STRING_CONCAT : Order.ATOMIC;
return [code, order]; return [code, order];
} }

View File

@@ -27,7 +27,7 @@ export function procedures_defreturn(block: Block, generator: PythonGenerator) {
for (const variable of usedVariables) { for (const variable of usedVariables) {
const varName = variable.name; const varName = variable.name;
// getVars returns parameter names, not ids, for procedure blocks // 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)); 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. // Follow the CPython behaviour of repr() for a non-byte string.
let quote = "'"; let quote = "'";
if (string.indexOf("'") !== -1) { if (string.includes("'")) {
if (string.indexOf('"') === -1) { if (!string.includes('"')) {
quote = '"'; quote = '"';
} else { } else {
string = string.replace(/'/g, "\\'"); string = string.replace(/'/g, "\\'");

View File

@@ -32,7 +32,7 @@ export function text_multiline(
): [string, Order] { ): [string, Order] {
// Text value. // Text value.
const code = generator.multiline_quote_(block.getFieldValue('TEXT')); const code = generator.multiline_quote_(block.getFieldValue('TEXT'));
const order = code.indexOf('+') !== -1 ? Order.ADDITIVE : Order.ATOMIC; const order = code.includes('+') ? Order.ADDITIVE : Order.ATOMIC;
return [code, order]; return [code, order];
} }

View File

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

View File

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

View File

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