commandkit icon indicating copy to clipboard operation
commandkit copied to clipboard

Compiler removes nested if statements

Open shimizu-izumi opened this issue 1 year ago • 3 comments

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;
}

shimizu-izumi avatar Apr 09 '24 16:04 shimizu-izumi

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.

twlite avatar Apr 09 '24 17:04 twlite

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!

notunderctrl avatar Apr 11 '24 08:04 notunderctrl

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

twlite avatar Apr 11 '24 09:04 twlite