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

Context: what if we're calling a method on the literal? #2

Closed
qntm opened this issue Jun 10, 2017 · 1 comment
Closed

Context: what if we're calling a method on the literal? #2

qntm opened this issue Jun 10, 2017 · 1 comment

Comments

@qntm
Copy link
Owner

qntm commented Jun 10, 2017

Currently minify-numeric-literal consistently behaves like so:

mnl("45e2") // "4500"

However, it is not always appropriate to replace the numeric literal "45e2" with "4500" in source code. See here:

45e2.toString()  // OK
4500.toString()  // This is a syntax error
4500..toString() // OK and equivalent to the first line
4500 .toString() // OK and equivalent to the first line
4500. toString() // Syntax error

So, to avoid introducing a syntax error, mnl("45e2") should return "45e2" in this situation, rather than the usual "4500".

In general, then, minify-numeric-literal needs to accept a small amount of information about the context in which the numeric literal is going to be used before it can carry out the minification, and it should return different output depending on that context.

A full list of possible contexts in which a numeric literal may be found (as well as quite a few places where a numeric literal cannot be found) is here.

@qntm
Copy link
Owner Author

qntm commented Jun 10, 2017

Resolved by 3fe14c4.

@qntm qntm closed this as completed Jun 10, 2017
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

1 participant