underctrl-io / commandkit

Only focus on what matters - Let CommandKit handle your commands and events in your Discord.js projects!
https://commandkit.js.org
MIT License
82 stars 9 forks source link

Compiler removes nested if statements #70

Open shimizu-izumi opened 3 months ago

shimizu-izumi commented 3 months ago

I have this if statement in a critical event in my bot which is used to lockdown posting tweets to a specific channel and tagging the bot in a message.

if (
    (message.channelId !== "1081589817680347186" &&
        !message.content.includes("<@1100024221339504733>")) ||
    message.author.bot
) return;

However, one of the server members pinged my bot and it posted his message on our twitter which is a huge problem for a 4.6K followers account which is used to publish information about a game. After looking at my and the compiled code I noticed that the compiler is the problem because the if in the resulting .mjs file is this

if (message.channelId !== "1081589817680347186" && !message.content.includes("<@1100024221339504733>") || message.author.bot) {
    return;
}
twlite commented 3 months ago

Why don't you try breaking down the statement into multiple statements to avoid confusion? I will see if there's an issue when I'm free.

notunderctrl commented 3 months ago

I've tried to reproduce the issue and can confirm this happens. Seems like an issue with the tsup transpiler. In the mean time I recommend breaking down your conditions into their own variables. Thanks for bringing this issue up!

twlite commented 3 months ago

@notunderctrl did you test this with latest version of tsup? The real compiler here is esbuild, gotta check if latest esbuild does this.