Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Non-empty loops being collapsed if first node is EmptyStatement #57

Closed
jbt opened this issue May 13, 2017 · 1 comment · Fixed by #59
Closed

Non-empty loops being collapsed if first node is EmptyStatement #57

jbt opened this issue May 13, 2017 · 1 comment · Fixed by #59

Comments

@jbt
Copy link
Contributor

jbt commented May 13, 2017

e.g. while (a) { ; b(); } -> while(a);; (link)

I tried making some test-cases + fixing up the check for empty nodes by checking over every descendent node rather than just the first, but my do-while case is failing completely for magic-string reasons I don't fully understand.

Additionally, all cases where a curly-braced loop could be reduced to a single-statement body aren't working because I can't figure out how to trim leading/trailing EmptyStatements.

Incidentally it looks like there's a few more cases where leading empty statements in a block change the output (e.g. if (a) { b(); } vs if (a) { ; b(); }) but the loops are the only case where it's doing something it definitely shouldn't.

@Rich-Harris
Copy link
Owner

Thanks. It was operating under the incorrect assumption that if the first statement of the body was an EmptyStatement, the body itself was empty. It should really remove empty statements altogether — will get to that soon — but #59 generates correct if suboptimal code

Rich-Harris added a commit that referenced this issue May 13, 2017
handle blocks with leading empty statement
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants