aboutsummaryrefslogtreecommitdiff
path: root/ext/js/general/regex-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-24 23:47:57 -0500
committerGitHub <noreply@github.com>2024-02-25 04:47:57 +0000
commit73169f06dff767020718a5715eba97d3575ba7e1 (patch)
tree99d458f9d2ca74e67dbb4bccd148ef549f7ce2cf /ext/js/general/regex-util.js
parenta21948daf6210f67955ae4f98a81e21b8cf9f1f2 (diff)
Turn on @typescript-eslint/no-unsafe-argument (#728)24.2.26.0
Diffstat (limited to 'ext/js/general/regex-util.js')
-rw-r--r--ext/js/general/regex-util.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/js/general/regex-util.js b/ext/js/general/regex-util.js
index f6eca3b6..e0982154 100644
--- a/ext/js/general/regex-util.js
+++ b/ext/js/general/regex-util.js
@@ -46,7 +46,9 @@ export function applyTextReplacement(text, sourceMap, pattern, replacement) {
pattern.lastIndex += delta;
if (actualReplacementLength > 0) {
- sourceMap.insert(index, ...(new Array(actualReplacementLength).fill(0)));
+ /** @type {number[]} */
+ const zeroes = new Array(actualReplacementLength).fill(0);
+ sourceMap.insert(index, ...zeroes);
sourceMap.combine(index - 1 + actualReplacementLength, matchText.length);
} else {
sourceMap.combine(index, matchText.length);
@@ -65,7 +67,13 @@ export function applyTextReplacement(text, sourceMap, pattern, replacement) {
export function applyMatchReplacement(replacement, match) {
const pattern = matchReplacementPattern;
pattern.lastIndex = 0;
- return replacement.replace(pattern, (g0, g1, g2) => {
+ /**
+ * @param {string} g0
+ * @param {string} g1
+ * @param {string} g2
+ * @returns {string}
+ */
+ const replacer = (g0, g1, g2) => {
if (typeof g1 !== 'undefined') {
const matchIndex = Number.parseInt(g1, 10);
if (matchIndex >= 1 && matchIndex <= match.length) {
@@ -87,5 +95,6 @@ export function applyMatchReplacement(replacement, match) {
}
}
return g0;
- });
+ };
+ return replacement.replace(pattern, replacer);
}