You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do not escape characters in string literals when they are supported by the specified encoding #619
I was experimenting with babili and found that the minified code it produces is significantly larger than closure (100 KiB vs 120 KiB). As it turns out, the problem is caused by the way babili handles (unicode) string literals.
Suppose that the code contains the string "теѕт" (all Cyrillic characters). Then babili converts it to "\u0442\u0435\u0455\u0442". OTOH, closure with the --charset utf8 option leaves the string in the original form. In fact, with that flag, closure converts "\u0442\u0435\u0455\u0442" to "теѕт".
So I propose to introduce to babili an option similar to closure's --charset. Of course, this should use a conservative setting by default (eg ascii), because otherwise the minified script would then require to be loaded with charset="..." in the <script> tag.
Reacted by Jed Fox, Dannii Willis, Koki Takahashi, Josh Duff, Pavel Aleksandrov, Dmytro, Ali Rahbari, Eugene Medvedev, Alex and Ferdinand Prantl
It shouldn't matter what the output of babel-core is. If babel-minify sees in its input a sting literal like "\u0442\u0435\u0455\u0442", and if it was told in its configuration that utf-8 output is acceptable, it should simply output "теѕт".
I understand that you are only suggesting a workaround, I just wanted to clear up any possible misconception that this may not be a babel-minify bug.
Actually minify makes code larger for utf-8 files, for now you can use this: code = code.replace(/\\u([\d\w]{4})/gi, (m, g) => String.fromCharCode(parseInt(g, 16)))
This seems to be something babel-core is doing, rather than babel-minify.
Your workaround helps, however, babel-minify does this also, if babel-core did not. At least, when used as part of babel-minify-webpack-plugin, when minification becomes a separate stage...
Activity
j-f1 commentedon Jul 6, 2017
Good idea!
Internally, there could be a cost function:
string => number. For UTF-8 and UTF-16, the cost ofтеѕтwould be8:For ASCII, it would be
24:Babili could potentially run the script through all of the encodings to determine which is shortest.
TehShrike commentedon Sep 13, 2017
How do I disable this string-literal-mangling feature? It's bloating my data-heavy files by a significant amount.
TehShrike commentedon Sep 13, 2017
This file balloons up monstrously when run through babel-minify: https://github.com/TehShrike/majority-text-family-35-revelation/blob/master/revelation.json
dmythro commentedon Jan 28, 2018
Any chances it will be added before
v1.0? Significantly increases the bundle size by escaping UTF-8 chars in strings.Cyp commentedon May 14, 2018
This seems to be something babel-core is doing, rather than babel-minify. If using the
'minify'preset, it setsminified: trueby default.Passing
{"presets": ["minify", "env"], "minified": false}instead of
{"presets": ["minify", "env"]}seems to be a workaround, although it results in more spaces in the output.
tyrak commentedon May 14, 2018
It shouldn't matter what the output of
babel-coreis. Ifbabel-minifysees in its input a sting literal like"\u0442\u0435\u0455\u0442", and if it was told in its configuration thatutf-8output is acceptable, it should simply output"теѕт".I understand that you are only suggesting a workaround, I just wanted to clear up any possible misconception that this may not be a
babel-minifybug.rahbari commentedon Jul 28, 2018
Actually minify makes code larger for utf-8 files, for now you can use this:
code = code.replace(/\\u([\d\w]{4})/gi, (m, g) => String.fromCharCode(parseInt(g, 16)))Mihara commentedon Oct 4, 2018
Your workaround helps, however,
babel-minifydoes this also, ifbabel-coredid not. At least, when used as part ofbabel-minify-webpack-plugin, when minification becomes a separate stage...fix: Ensure, that minified output does not contain escaped Unicode se…