mirror of
https://github.com/google/blockly.git
synced 2026-02-28 02:10:15 +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:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user