Skip to content

Commit

Permalink
Don't use the nullish coalescing assignment ??=
Browse files Browse the repository at this point in the history
This is not supported by Sucrase and would break Node 14 attempts to build the client: alangpierce/sucrase#550
  • Loading branch information
AnnikaCodes committed Nov 5, 2022
1 parent 40cd8b4 commit c1718e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions data/mods/gen1/scripts.ts
Expand Up @@ -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;

This comment has been minimized.

Copy link
@pyuk-bot

pyuk-bot Nov 5, 2022

Contributor

I thought there was a lint rule against initializing a variable as undefined


if (target) {
hitResult = this.battle.singleEvent('TryHit', moveData, {}, target, pokemon, move);
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 13 additions & 8 deletions server/chat-commands/avatars.tsx
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit c1718e0

Please sign in to comment.