From 1c4cf654d7fbc5246220563a49749049b46e76ee Mon Sep 17 00:00:00 2001 From: taichi221228 Date: Wed, 24 Apr 2024 10:00:13 +0900 Subject: [PATCH] Remove unnecessary stringFromCodePoint function polyfill in emoji_utils Removed the unnecessary stringFromCodePoint function polyfill from the emoji_utils.ts file. Instead, we use the built-in JavaScript function String.fromCodePoint to simplify the code. --- .../mastodon/features/emoji/emoji_utils.ts | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/app/javascript/mastodon/features/emoji/emoji_utils.ts b/app/javascript/mastodon/features/emoji/emoji_utils.ts index bdb8e301dec..e1c8bbda084 100644 --- a/app/javascript/mastodon/features/emoji/emoji_utils.ts +++ b/app/javascript/mastodon/features/emoji/emoji_utils.ts @@ -36,50 +36,6 @@ const buildSearch = (data: Data) => { /* eslint-disable */ -const _String = String; - -const stringFromCodePoint = - _String.fromCodePoint || - function () { - let MAX_SIZE = 0x4000; - let codeUnits = []; - let highSurrogate; - let lowSurrogate; - let index = -1; - let length = arguments.length; - if (!length) { - return ''; - } - let result = ''; - while (++index < length) { - let codePoint = Number(arguments[index]); - if ( - !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` - codePoint < 0 || // not a valid Unicode code point - codePoint > 0x10ffff || // not a valid Unicode code point - Math.floor(codePoint) !== codePoint // not an integer - ) { - throw RangeError('Invalid code point: ' + codePoint); - } - if (codePoint <= 0xffff) { - // BMP code point - codeUnits.push(codePoint); - } else { - // Astral code point; split in surrogate halves - // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - codePoint -= 0x10000; - highSurrogate = (codePoint >> 10) + 0xd800; - lowSurrogate = (codePoint % 0x400) + 0xdc00; - codeUnits.push(highSurrogate, lowSurrogate); - } - if (index + 1 === length || codeUnits.length > MAX_SIZE) { - result += String.fromCharCode.apply(null, codeUnits); - codeUnits.length = 0; - } - } - return result; - }; - const _JSON = JSON; const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/; @@ -91,7 +47,7 @@ function unifiedToNative(unified) { // @ts-expect-error codePoints = unicodes.map((u) => `0x${u}`); - return stringFromCodePoint.apply(null, codePoints); + return String.fromCodePoint(...codePoints); } // @ts-expect-error