From 8b73b911c943fe7162d6047388d551b200520be6 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 17 Oct 2021 20:33:53 +0200 Subject: [PATCH] Changeset: Use string templates Co-authored-by: Richard Hansen --- src/static/js/Changeset.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 0d3d9991c..f43a236cf 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -46,13 +46,11 @@ exports.error = (msg) => { * throw an exception. * * @param {boolean} b - assertion condition - * @param {...any} msgParts - error message to include in the exception - * @type {(b: boolean, ...msgParts: any[]) => asserts b} + * @param {string} msg - error message to include in the exception + * @type {(b: boolean, msg: string) => asserts b} */ -exports.assert = (b, ...msgParts) => { - if (!b) { - exports.error(`Failed assertion: ${msgParts.join('')}`); - } +exports.assert = (b, msg) => { + if (!b) exports.error(`Failed assertion: ${msg}`); }; /** @@ -282,13 +280,13 @@ exports.checkRep = (cs) => { break; case '-': oldPos += o.chars; - exports.assert(oldPos <= oldLen, oldPos, ' > ', oldLen, ' in ', cs); + exports.assert(oldPos <= oldLen, `${oldPos} > ${oldLen} in ${cs}`); break; case '+': { calcNewLen += o.chars; numInserted += o.chars; - exports.assert(calcNewLen <= newLen, calcNewLen, ' > ', newLen, ' in ', cs); + exports.assert(calcNewLen <= newLen, `${calcNewLen} > ${newLen} in ${cs}`); break; } } @@ -538,7 +536,7 @@ exports.stringIterator = (str) => { const getnewLines = () => newLines; const assertRemaining = (n) => { - exports.assert(n <= remaining(), '!(', n, ' <= ', remaining(), ')'); + exports.assert(n <= remaining(), `!(${n} <= ${remaining()})`); }; const take = (n) => { @@ -1066,8 +1064,8 @@ exports.pack = (oldLen, newLen, opsStr, bank) => { */ exports.applyToText = (cs, str) => { const unpacked = exports.unpack(cs); - exports.assert(str.length === unpacked.oldLen, 'mismatched apply: ', str.length, - ' / ', unpacked.oldLen); + exports.assert( + str.length === unpacked.oldLen, `mismatched apply: ${str.length} / ${unpacked.oldLen}`); const csIter = exports.opIterator(unpacked.ops); const bankIter = exports.stringIterator(unpacked.charBank); const strIter = exports.stringIterator(str); @@ -1338,7 +1336,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => { } lineAssem.append(op); if (op.lines > 0) { - exports.assert(op.lines === 1, "Can't have op.lines of ", op.lines, ' in attribution lines'); + exports.assert(op.lines === 1, `Can't have op.lines of ${op.lines} in attribution lines`); // ship it to the mut mut.insert(lineAssem.toString(), 1); lineAssem = null;