babel / babel/minify

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

Open
#619 8 comments 10 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

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 `` tag.

Contributor guide

Open the contributing guide

Research direction

Start by tracing Babili's string-literal escaping and reproduce the Cyrillic example described in the issue, then compare the requested behavior with Closure's charset option. Done means introducing a charset-aware behavior that preserves supported characters while retaining a conservative default; the payload names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.