From 1150f343b5fe24c6e5dea12480c4cf72a405a0e3 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 23 May 2023 17:34:07 -0400 Subject: [PATCH] refactor(marshal): Use String#replace rather than replaceAll Fixes failures on Node.js v14 --- packages/marshal/src/encodePassable.js | 38 ++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/marshal/src/encodePassable.js b/packages/marshal/src/encodePassable.js index 1f920d1591..fac07d7771 100644 --- a/packages/marshal/src/encodePassable.js +++ b/packages/marshal/src/encodePassable.js @@ -242,28 +242,26 @@ stringEscapes['^'.charCodeAt(0)] = '_@'; stringEscapes['_'.charCodeAt(0)] = '__'; const encodeStringWithEscapes = str => - `s${str.replaceAll(/[\0-!^_]/g, ch => stringEscapes[ch.charCodeAt(0)])}`; + `s${str.replace(/[\0-!^_]/g, ch => stringEscapes[ch.charCodeAt(0)])}`; const decodeStringWithEscapes = encoded => { - return encoded - .slice(1) - .replaceAll(/([!_])(.|\n)?/g, (esc, prefix, suffix) => { - switch (esc) { - case '!_': - return ' '; - case '!|': - return '!'; - case '_@': - return '^'; - case '__': - return '_'; - default: { - const ch = /** @type {string} */ (suffix); - (prefix === '!' && ch >= '!' && ch <= '@') || - Fail`invalid string escape: ${q(esc)}`; - return String.fromCharCode(ch.charCodeAt(0) - 0x21); - } + return encoded.slice(1).replace(/([!_])(.|\n)?/g, (esc, prefix, suffix) => { + switch (esc) { + case '!_': + return ' '; + case '!|': + return '!'; + case '_@': + return '^'; + case '__': + return '_'; + default: { + const ch = /** @type {string} */ (suffix); + (prefix === '!' && ch >= '!' && ch <= '@') || + Fail`invalid string escape: ${q(esc)}`; + return String.fromCharCode(ch.charCodeAt(0) - 0x21); } - }); + } + }); }; const encodeStringWithoutEscapes = str => `s${str}`;