Skip to content

Commit 8b73b91

Browse files
webzwo0irhansen
andcommitted
Changeset: Use string templates
Co-authored-by: Richard Hansen <rhansen@rhansen.org>
1 parent cb95e59 commit 8b73b91

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/static/js/Changeset.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ exports.error = (msg) => {
4646
* throw an exception.
4747
*
4848
* @param {boolean} b - assertion condition
49-
* @param {...any} msgParts - error message to include in the exception
50-
* @type {(b: boolean, ...msgParts: any[]) => asserts b}
49+
* @param {string} msg - error message to include in the exception
50+
* @type {(b: boolean, msg: string) => asserts b}
5151
*/
52-
exports.assert = (b, ...msgParts) => {
53-
if (!b) {
54-
exports.error(`Failed assertion: ${msgParts.join('')}`);
55-
}
52+
exports.assert = (b, msg) => {
53+
if (!b) exports.error(`Failed assertion: ${msg}`);
5654
};
5755

5856
/**
@@ -282,13 +280,13 @@ exports.checkRep = (cs) => {
282280
break;
283281
case '-':
284282
oldPos += o.chars;
285-
exports.assert(oldPos <= oldLen, oldPos, ' > ', oldLen, ' in ', cs);
283+
exports.assert(oldPos <= oldLen, `${oldPos} > ${oldLen} in ${cs}`);
286284
break;
287285
case '+':
288286
{
289287
calcNewLen += o.chars;
290288
numInserted += o.chars;
291-
exports.assert(calcNewLen <= newLen, calcNewLen, ' > ', newLen, ' in ', cs);
289+
exports.assert(calcNewLen <= newLen, `${calcNewLen} > ${newLen} in ${cs}`);
292290
break;
293291
}
294292
}
@@ -538,7 +536,7 @@ exports.stringIterator = (str) => {
538536
const getnewLines = () => newLines;
539537

540538
const assertRemaining = (n) => {
541-
exports.assert(n <= remaining(), '!(', n, ' <= ', remaining(), ')');
539+
exports.assert(n <= remaining(), `!(${n} <= ${remaining()})`);
542540
};
543541

544542
const take = (n) => {
@@ -1066,8 +1064,8 @@ exports.pack = (oldLen, newLen, opsStr, bank) => {
10661064
*/
10671065
exports.applyToText = (cs, str) => {
10681066
const unpacked = exports.unpack(cs);
1069-
exports.assert(str.length === unpacked.oldLen, 'mismatched apply: ', str.length,
1070-
' / ', unpacked.oldLen);
1067+
exports.assert(
1068+
str.length === unpacked.oldLen, `mismatched apply: ${str.length} / ${unpacked.oldLen}`);
10711069
const csIter = exports.opIterator(unpacked.ops);
10721070
const bankIter = exports.stringIterator(unpacked.charBank);
10731071
const strIter = exports.stringIterator(str);
@@ -1338,7 +1336,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13381336
}
13391337
lineAssem.append(op);
13401338
if (op.lines > 0) {
1341-
exports.assert(op.lines === 1, "Can't have op.lines of ", op.lines, ' in attribution lines');
1339+
exports.assert(op.lines === 1, `Can't have op.lines of ${op.lines} in attribution lines`);
13421340
// ship it to the mut
13431341
mut.insert(lineAssem.toString(), 1);
13441342
lineAssem = null;

0 commit comments

Comments
 (0)