fix(es/minifier): Prevent convert_tpl_to_str when there's emoji under es5#11529
fix(es/minifier): Prevent convert_tpl_to_str when there's emoji under es5#11529
Conversation
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adjusts Pure::convert_tpl_to_str to avoid converting template literals into string literals in ES5/ES3 targets when non-BMP characters would cause string codegen to expand into long surrogate-pair escapes.
Changes:
- Add an early-exit in
convert_tpl_to_strfor targets< ES2015when encountering non-BMP characters. - Document the rationale (template output can be shorter than ES5 string escape output).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Binary Sizes
Commit: 2cee340 |
|
@claude Add enormous amount of unit tests in the swc_ecma_minifier that actually invokes swc_ecma_codegen to verify all possibly problematic input cases |
This comment has been minimized.
This comment has been minimized.
|
This PR looks good to me, but I'd prefer to have more e2e tests for this. |
Add 36 unit tests that verify template-to-string conversion behavior
with various character types, specifically testing the fix for non-BMP
characters in ES5/ES3 targets.
Test categories:
- Emoji/non-BMP characters (ES5 vs ES2015)
- Unicode escape sequences (\u{1F980})
- Mathematical/musical symbols (U+1D400-U+1D7FF)
- CJK Extension B characters (U+20000+)
- BMP characters (Chinese, Japanese, Korean)
- Edge cases (empty templates, boundary chars, newlines)
- Compound emojis (flags, skin tones, ZWJ sequences)
- Ancient scripts (hieroglyphs, cuneiform)
- Private Use Area characters
Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
|
|
This comment has been minimized.
This comment has been minimized.
|
@claude fix ci |
This comment has been minimized.
This comment has been minimized.
Inline format string variables in assert! macros to fix clippy::uninlined_format_args errors. Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
PR Review: fix(es/minifier): Prevent convert_tpl_to_str when there's emoji under ES5SummaryThis PR adds a check to prevent template literal to string conversion when targeting ES5 (or earlier) and the template contains non-BMP characters (code points > U+FFFF, such as emojis). This is a correctness fix that prevents output size regression. ✅ What's Good
💭 Suggestions for Consideration
🔍 Edge Cases VerifiedThe tests cover these edge cases well:
📋 Checklist
VerdictLGTM 👍 This is a well-implemented fix for a legitimate minification issue. The logic is sound, the tests are comprehensive, and the code is well-documented. The fix ensures that minifying code with emojis targeting ES5 won't produce longer output than the original. |
Description:
When the target environment is below ES2015, and non-BMP characters (like emojis) are encountered, we stop the conversion.
This is because:
🦀(may output directly in source code or require minimal escaping) -> shorter\uD83E\uDD80(escape sequence for surrogate pair) -> extremely longRelated issue (if exists):
#11415