From 0b7791c103508e4b23d57717a97644993edf76d5 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 10 Apr 2020 12:25:24 -0400 Subject: [PATCH] Fix source map for characters collapsed at the start of a string --- ext/bg/js/japanese.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ext/bg/js/japanese.js b/ext/bg/js/japanese.js index e8b258cb..71fbebb5 100644 --- a/ext/bg/js/japanese.js +++ b/ext/bg/js/japanese.js @@ -377,11 +377,11 @@ // Miscellaneous - function collapseEmphaticSequences(sourceText, fullCollapse, sourceMap=null) { + function collapseEmphaticSequences(text, fullCollapse, sourceMap=null) { let result = ''; let collapseCodePoint = -1; const hasSourceMap = (sourceMap !== null); - for (const char of sourceText) { + for (const char of text) { const c = char.codePointAt(0); if (c === HIRAGANA_SMALL_TSU_CODE_POINT || c === KATAKANA_SMALL_TSU_CODE_POINT) { if (collapseCodePoint !== c) { @@ -398,10 +398,7 @@ } if (hasSourceMap) { - const index = result.length; - if (index > 0) { - sourceMap.combine(index - 1, 1); - } + sourceMap.combine(Math.max(0, result.length - 1), 1); } } return result;