aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates/template-patcher.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/templates/template-patcher.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/templates/template-patcher.js')
-rw-r--r--ext/js/templates/template-patcher.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/js/templates/template-patcher.js b/ext/js/templates/template-patcher.js
index 6bc012bc..33abb08e 100644
--- a/ext/js/templates/template-patcher.js
+++ b/ext/js/templates/template-patcher.js
@@ -18,12 +18,20 @@
export class TemplatePatcher {
constructor() {
+ /** @type {RegExp} */
this._diffPattern1 = /\n?\{\{<<<<<<<\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern2 = /\n\{\{=======\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern3 = /\n\{\{>>>>>>>\}\}\n*/g;
+ /** @type {RegExp} */
this._lookupMarkerPattern = /[ \t]*\{\{~?>\s*\(\s*lookup\s*\.\s*"marker"\s*\)\s*~?\}\}/g;
}
+ /**
+ * @param {string} content
+ * @returns {import('template-patcher').Patch}
+ */
parsePatch(content) {
const diffPattern1 = this._diffPattern1;
const diffPattern2 = this._diffPattern2;
@@ -61,6 +69,11 @@ export class TemplatePatcher {
return {addition: content, modifications};
}
+ /**
+ * @param {string} template
+ * @param {import('template-patcher').Patch} patch
+ * @returns {string}
+ */
applyPatch(template, patch) {
for (const {current, replacement} of patch.modifications) {
let fromIndex = 0;
@@ -77,6 +90,11 @@ export class TemplatePatcher {
// Private
+ /**
+ * @param {string} template
+ * @param {string} addition
+ * @returns {string}
+ */
_addFieldTemplatesBeforeEnd(template, addition) {
if (addition.length === 0) { return template; }
const newline = '\n';