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

Can we remove enclosing braces from a single-statement block? #387

Closed
getify opened this issue Dec 26, 2013 · 2 comments
Closed

Can we remove enclosing braces from a single-statement block? #387

getify opened this issue Dec 26, 2013 · 2 comments

Comments

@getify
Copy link

getify commented Dec 26, 2013

I'm thinking, unless I'm missing something with the grammar or possibly with let block-scoping, that we can detect if a statement block delimited by { .. } (such as, specifically, the consequent clause of an if-statement) only has a single statement in it, and if so, it should be safe to remove the enclosing { } and instead just make sure it ends in a ;. Am I missing something?

if (foo) { return foo; }

currently minifies to:

if(foo){return foo}

but should be safe to instead go to:

if(foo)return foo;

which is one character less.

By contrast:

if (foo) return foo;

already safely minifies to:

if(foo)return foo;

Am I missing something that would make this unsafe or impossible?

@mishoo
Copy link
Owner

mishoo commented Dec 26, 2013

Am I missing something?

Perhaps you're missing the -c (--compress) flag? Also, try -m too. Without these flags you only get whitespace removal.

@mishoo mishoo closed this as completed Dec 26, 2013
@getify
Copy link
Author

getify commented Dec 26, 2013

Thanks, I was missing that. Sorry. Saves me about 350 pre-gzip bytes, but only about 15 post-gzip bytes. :)

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

2 participants