-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Conversation
add this to the preset ? dependency and in index.js |
@boopathi added |
`); | ||
|
||
const expected = unpad(` | ||
[10, 100, 1e3, 1e4, -2, -3e4, 1e3, -1e4, 1e-5, 1.5e12, 1.23456, .1]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
@hzoo added more tests; good suggestions, found an optimization with |
There was a problem hiding this 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.
I'd keep it separate. Granularity is good. |
|
||
source = '[+0.000000000001, -0.00000000001];'; | ||
// TODO: this seems to be specific to how Babel outputs number | ||
// for some reason it adds + in the beginning |
There was a problem hiding this comment.
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
No description provided.