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

Add numeric literals minification #222

Merged
merged 6 commits into from
Oct 26, 2016
Merged

Add numeric literals minification #222

merged 6 commits into from
Oct 26, 2016

Conversation

kangax
Copy link
Member

@kangax kangax commented Oct 25, 2016

No description provided.

@kangax kangax added this to the 0.0.7 milestone Oct 25, 2016
@boopathi
Copy link
Member

boopathi commented Oct 26, 2016

add this to the preset ? dependency and in index.js

@kangax
Copy link
Member Author

kangax commented Oct 26, 2016

@boopathi added

`);

const expected = unpad(`
[10, 100, 1e3, 1e4, -2, -3e4, 1e3, -1e4, 1e-5, 1.5e12, 1.23456, .1];
Copy link
Member

@hzoo hzoo Oct 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add test cases for 0o, 0x, 0b? binary/octal/hex, positive/negative
maybe also for +0.000000000001, -0.00000000001;

and fractions? 1/1000 -> 1/1e3 and could be 1e-3 but dono if we need to make that logic

was just testing in http://astexplorer.net/#/z6eNdGL0Zm

Copy link
Member

@boopathi boopathi Oct 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't fractions already be evaluated to something smaller if possible by constant-folding plugin. Should we consider adding this in constant folding plugin instead ?

@kangax
Copy link
Member Author

kangax commented Oct 26, 2016

@hzoo added more tests; good suggestions, found an optimization with e0.

Copy link
Member

@boopathi boopathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'm thinking if we should add it to https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-constant-folding . Otherwise we can keep it a separate plugin only.

@kangax
Copy link
Member Author

kangax commented Oct 26, 2016

I'd keep it separate. Granularity is good.

@kangax kangax merged commit 8d17070 into master Oct 26, 2016
@kangax kangax deleted the numeric-literals branch October 26, 2016 19:08

source = '[+0.000000000001, -0.00000000001];';
// TODO: this seems to be specific to how Babel outputs number
// for some reason it adds + in the beginning
Copy link
Member

@chicoxyzzy chicoxyzzy Oct 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because + is unary operator here so result of +something should be evaluated in runtime. However if something is a number literal than Babili could drop + operator

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

Successfully merging this pull request may close these issues.

4 participants