question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not escape characters in string literals when they are supported by the specified encoding

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rahbaricommented, 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)))

0reactions
Miharacommented, Oct 4, 2018

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

The string data type - Azure Data Explorer
There are several ways to encode literals of the string data type in a ... Multi-line string literals do not support escaped characters....
Read more >
C String Literal Required Escape Characters
You should encode non-ASCII characters using the hexadecimal escape code, e.g. \x80 . It is implementation defined if you have non-ASCII ...
Read more >
String literal
If a character lacks representation in the associated character encoding,. if the string literal is an ordinary string literal or wide string ...
Read more >
MySQL 8.0 Reference Manual :: 9.1.1 String Literals
For all other escape sequences, backslash is ignored. That is, the escaped character is interpreted as if it was not escaped. For example,...
Read more >
Escape sequences in C
An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found