From c1718e0a2bf47a792141c1035d3eb5908ef1b50b Mon Sep 17 00:00:00 2001 From: Annika <56906084+AnnikaCodes@users.noreply.github.com> Date: Sat, 5 Nov 2022 13:57:24 -0700 Subject: [PATCH] Don't use the nullish coalescing assignment `??=` This is not supported by Sucrase and would break Node 14 attempts to build the client: https://github.com/alangpierce/sucrase/issues/550 --- data/mods/gen1/scripts.ts | 4 ++-- server/chat-commands/avatars.tsx | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/data/mods/gen1/scripts.ts b/data/mods/gen1/scripts.ts index fa1c25e92cc1..c2e704632494 100644 --- a/data/mods/gen1/scripts.ts +++ b/data/mods/gen1/scripts.ts @@ -425,7 +425,7 @@ export const Scripts: ModdedBattleScriptsData = { // We get the sub to the target to see if it existed const targetSub = (target) ? target.volatiles['substitute'] : false; const targetHadSub = (targetSub !== null && targetSub !== false && (typeof targetSub !== 'undefined')); - let targetHasSub: boolean; + let targetHasSub: boolean | undefined = undefined; if (target) { hitResult = this.battle.singleEvent('TryHit', moveData, {}, target, pokemon, move); @@ -588,7 +588,7 @@ export const Scripts: ModdedBattleScriptsData = { return false; } } - targetHasSub ??= !!(target?.volatiles['substitute']); + if (targetHasSub === undefined) targetHasSub = !!(target?.volatiles['substitute']); // Here's where self effects are applied. const doSelf = (targetHadSub && targetHasSub) || !targetHadSub; diff --git a/server/chat-commands/avatars.tsx b/server/chat-commands/avatars.tsx index 1fea2d5eca10..d0e0ca4c5ba4 100644 --- a/server/chat-commands/avatars.tsx +++ b/server/chat-commands/avatars.tsx @@ -52,7 +52,7 @@ try { if (Config.allowedavatars) { for (const avatar in Config.customavatars) { for (const userid of Config.customavatars[avatar]) { - customAvatars[userid] ??= {allowed: [null]}; + if (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]}; customAvatars[userid].allowed.push(avatar); } } @@ -141,8 +141,9 @@ export const Avatars = new class { /** does not include validation */ setDefault(userid: ID, avatar: AvatarID | null) { if (avatar === this.getDefault(userid)) return; + if (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]}; + const entry = customAvatars[userid]; - const entry = (customAvatars[userid] ??= {allowed: [null]}); if (avatar === entry.allowed[0]) { delete entry.default; } else { @@ -151,11 +152,12 @@ export const Avatars = new class { saveCustomAvatars(); } addAllowed(userid: ID, avatar: AvatarID | null) { - const entry = (customAvatars[userid] ??= {allowed: [null]}); - if (entry.allowed.includes(avatar)) return false; + if (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]}; - entry.allowed.push(avatar); - entry.notNotified = true; + if (customAvatars[userid].allowed.includes(avatar)) return false; + + customAvatars[userid].allowed.push(avatar); + customAvatars[userid].notNotified = true; this.tryNotify(Users.get(userid)); return true; } @@ -172,7 +174,9 @@ export const Avatars = new class { return true; } addPersonal(userid: ID, avatar: AvatarID | null) { - const entry = (customAvatars[userid] ??= {allowed: [null]}); + if (!customAvatars[userid]) customAvatars[userid] = {allowed: [null]}; + const entry = customAvatars[userid]; + if (entry.allowed.includes(avatar)) return false; entry.timeReceived ||= Date.now(); @@ -951,7 +955,8 @@ export const commands: Chat.ChatCommands = { if (!/[A-Za-z0-9]/.test(arg.charAt(0)) || !/[A-Za-z]/.test(arg)) { throw new Chat.ErrorMessage(`Invalid username "${arg}"`); } - (toUpdate[curAvatar] ??= new Set()).add(toID(arg)); + if (!toUpdate[curAvatar]) toUpdate[curAvatar] = new Set(); + toUpdate[curAvatar].add(toID(arg)); } }