Optimizer or minifier ?
See original GitHub issueThis is more of a question than an issue.
Is the Optimizer more an optimizer or a minifier? Or both at the same time?
Currently, the Optimizer does some “optimizations” that actually increase the length of the regexp, like:
/aa/
(2) -> /a{2}/
(4)
/a|b/
(3) -> /[ab]/
(4)
/aa+/
(3) -> /a{2,}/
(5)
If it’s supposed to be a minifier, we should try to avoid those cases. (Note that this could be tricky sometimes, since an optimization might not seem worth it at first, but work well with following optimizations)
Also, if we really want minification, we could add additional transforms like:
find the shortest representation of a char:
/\u0010/
(6) -> /\x10/
(4)
/\u0000/
(6) -> /\0/
(2)
convert all coded chars to their printable equivalent (even outside of basic printable ASCII range):
/\u{dd}/u
(6) -> /Ý/
(1)
reorder class ranges in a way to avoid escaping:
/[\^a]/
(5) -> /[a^]/
(4)
/[,\-.]/
(6) -> /[,.-]/
(5)
and so on.
What’s your opinion on this?
I intend to start working on actual options for the optimizer. The whitelist is a good start, but it’s kind of verbose and does not really allow for “optional” transforms. I think an object of options with default values would be more appropriate (something like the compress options in UglifyJS).
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (10 by maintainers)
Top GitHub Comments
@Golmote, yep, agreed; all good points! I am fully supportive here.
@Golmote,
Sounds good to me, yeah, we can probably exclude the one @swernerx mentions with the single chars.