mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -1043,7 +1043,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
|
||||
@@ -1288,7 +1288,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;
|
||||
}
|
||||
|
||||
@@ -829,7 +829,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1526,8 +1526,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'))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'))
|
||||
);
|
||||
|
||||
@@ -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!;
|
||||
|
||||
@@ -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 += '+';
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -225,9 +225,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -695,7 +695,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;
|
||||
}
|
||||
@@ -1306,7 +1306,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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.');
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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…</option>');
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -560,7 +560,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ function getOptTypesFrom(block, name) {
|
||||
var types = 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];
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function text_multiline(
|
||||
): [string, Order] {
|
||||
// Text value.
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ export function text_multiline(
|
||||
): [string, Order] {
|
||||
// Text value.
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -27,7 +27,7 @@ export function text_multiline(
|
||||
): [string, Order] {
|
||||
// Text value.
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export function text_multiline(
|
||||
): [string, Order] {
|
||||
// Text value.
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, "\\'");
|
||||
|
||||
@@ -32,7 +32,7 @@ export function text_multiline(
|
||||
): [string, Order] {
|
||||
// Text value.
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user