aboutsummaryrefslogtreecommitdiff
path: root/ext/js/general/regex-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/general/regex-util.js')
-rw-r--r--ext/js/general/regex-util.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/js/general/regex-util.js b/ext/js/general/regex-util.js
index 298189d4..62248968 100644
--- a/ext/js/general/regex-util.js
+++ b/ext/js/general/regex-util.js
@@ -25,7 +25,7 @@ export class RegexUtil {
* Applies string.replace using a regular expression and replacement string as arguments.
* A source map of the changes is also maintained.
* @param {string} text A string of the text to replace.
- * @param {TextSourceMap} sourceMap An instance of `TextSourceMap` which corresponds to `text`.
+ * @param {import('./text-source-map.js').TextSourceMap} sourceMap An instance of `TextSourceMap` which corresponds to `text`.
* @param {RegExp} pattern A regular expression to use as the replacement.
* @param {string} replacement A replacement string that follows the format of the standard
* JavaScript regular expression replacement string.
@@ -61,7 +61,7 @@ export class RegexUtil {
* Applies the replacement string for a given regular expression match.
* @param {string} replacement The replacement string that follows the format of the standard
* JavaScript regular expression replacement string.
- * @param {object} match A match object returned from RegExp.match.
+ * @param {RegExpMatchArray} match A match object returned from RegExp.match.
* @returns {string} A new string with the pattern replacement applied.
*/
static applyMatchReplacement(replacement, match) {
@@ -79,11 +79,13 @@ export class RegexUtil {
return groups[g2];
}
} else {
+ let {index} = match;
+ if (typeof index !== 'number') { index = 0; }
switch (g0) {
case '$': return '$';
case '&': return match[0];
- case '`': return replacement.substring(0, match.index);
- case '\'': return replacement.substring(match.index + g0.length);
+ case '`': return replacement.substring(0, index);
+ case '\'': return replacement.substring(index + g0.length);
}
}
return g0;