Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler removes nested if statements #70

Open
shimizu-izumi opened this issue Apr 9, 2024 · 3 comments
Open

Compiler removes nested if statements #70

shimizu-izumi opened this issue Apr 9, 2024 · 3 comments

Comments

@shimizu-izumi
Copy link

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
Copy link
Collaborator

twlite commented Apr 9, 2024

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
Copy link
Member

notunderctrl commented Apr 11, 2024

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
Copy link
Collaborator

twlite commented Apr 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants