Skip to content

Commit

Permalink
Use replaceAll instead of RegExp with global flag (#3856)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 26, 2023
1 parent 7e6844c commit e171a14
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion integrationTests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const graphqlPackageJSON = JSON.parse(
);

const nodeVersions = graphqlPackageJSON.engines.node
.replaceAll('^', '')
.replaceAll('>=', '')
.split(' || ')
.map((version) => version.replace('^', '').replace('>=', ''))
.sort((a, b) => b.localeCompare(a));

for (const version of nodeVersions) {
Expand Down
2 changes: 1 addition & 1 deletion src/__testUtils__/dedent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function dedentString(string: string): string {
indent += char;
}

return trimmedStr.replace(RegExp('^' + indent, 'mg'), ''); // remove indent
return trimmedStr.replaceAll(RegExp('^' + indent, 'mg'), ''); // remove indent
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/__testUtils__/inspectStr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function inspectStr(str: Maybe<string>): string {
}
return JSON.stringify(str)
.replace(/^"|"$/g, '`')
.replace(/\\"/g, '"')
.replace(/\\\\/g, '\\');
.replaceAll('\\"', '"')
.replaceAll('\\\\', '\\');
}
2 changes: 1 addition & 1 deletion src/language/blockString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function printBlockString(
value: string,
options?: { minimize?: boolean },
): string {
const escapedValue = value.replace(/"""/g, '\\"""');
const escapedValue = value.replaceAll('"""', '\\"""');

// Expand a block string's raw value into independent lines.
const lines = escapedValue.split(/\r\n|[\n\r]/g);
Expand Down
2 changes: 1 addition & 1 deletion src/language/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function wrap(
}

function indent(str: string): string {
return wrap(' ', str.replace(/\n/g, '\n '));
return wrap(' ', str.replaceAll('\n', '\n '));
}

function hasMultilineItems(maybeArray: Maybe<ReadonlyArray<string>>): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/printSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,5 @@ function printDescription(
const prefix =
indentation && !firstInBlock ? '\n' + indentation : indentation;

return prefix + blockString.replace(/\n/g, '\n' + indentation) + '\n';
return prefix + blockString.replaceAll('\n', '\n' + indentation) + '\n';
}

0 comments on commit e171a14

Please sign in to comment.