From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- ext/js/templates/template-patcher.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ext/js/templates/template-patcher.js') 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'; -- cgit v1.2.3