From 40f6c3b14aacdb96e1b20b4c2e3e1365ccd372c4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 19 Apr 2021 11:55:03 -0300 Subject: fix incorrect iEnd values on text nodes The iEnd value (which marks the position a node's length ends at in input text) is only used for tag nodes at the moment, 8ut it's still nice to have the right values everywhere, in case we do use it for something else later (and to just have code that functions like we want, lol). --- upd8.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/upd8.js b/upd8.js index 2be0eaa..de6af97 100755 --- a/upd8.js +++ b/upd8.js @@ -1021,6 +1021,7 @@ const replacerSpec = { stopped = false; const pushTextNode = () => { + string = input.slice(iString, i); if (string.length) { nodes.push({i: iString, iEnd: i, type: 'text', data: string}); string = ''; @@ -1053,7 +1054,7 @@ const replacerSpec = { if (!match) { iString = i; - string = input.slice(i, input.length); + i = input.length; pushTextNode(); break; } @@ -1062,17 +1063,17 @@ const replacerSpec = { const closestMatchIndex = i + match.index; iString = i; - string = input.slice(i, closestMatchIndex); + i = closestMatchIndex; pushTextNode(); - i = closestMatchIndex + closestMatch.length; + i += closestMatch.length; if (closestMatch !== tagBeginning) { stopped = true; stop_iMatch = closestMatchIndex; stop_iParse = i; stop_literal = closestMatch; - return nodes; + break; } if (closestMatch === tagBeginning) { -- cgit 1.3.0-6-gf8a5