Skip to content

SWC minifier un-escapes unicode characters #10353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
slorber opened this issue Apr 10, 2025 · 1 comment · May be fixed by #10423
Open

SWC minifier un-escapes unicode characters #10353

slorber opened this issue Apr 10, 2025 · 1 comment · May be fixed by #10423
Assignees
Labels
Milestone

Comments

@slorber
Copy link
Contributor

slorber commented Apr 10, 2025

Describe the bug

For some code inputs containing escaped unicode emojis, SWC minifier will output unescaped unicode emojis.

Example input:

console.log("\\"\\\\uD83D\\\\uDE42\\"");

Input code

import swc from '@swc/core';

const input = `
console.log("\\"\\\\uD83D\\\\uDE42\\"");
`;

console.log('input');
console.log(input);
eval(input);

console.log('\n');
const output = await swc.minify(input);

console.log('output');
console.log(output.code);
eval(output.code);



Runnable playground: https://stackblitz.com/edit/stackblitz-starters-gpln2upu

Output:


 node index.js

input
console.log("\"\\uD83D\\uDE42\"");
"\uD83D\uDE42"


output
console.log('"\uD83D\uDE42"');
"🙂"

Config

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.11.18&code=H4sIAAAAAAAAA1OKiSl1sTB2UQIAWPmpCAkAAAA%3D&config=H4sIAAAAAAAAA1VQuW7DMAzd8xWC0KkorCBjpgxdM3YqMrAyfcGSDJJGawT590qOY8uT%2Fch3ifeDUsYo%2Fca2QQf6rHQjMvDZmI6DL55jlkBYBKoN%2F1qy%2BiOqNIeRLF5h4KgSGnGedmwjvMffCAYgRlpxEk1e4C%2FFyDQgW2oHme3mbYk2EMSw3FKpx%2FOjhcBzFcjljj3WYKfPl3InzC2vKFCCwIswr%2Ff2QDVK6oZ8Op6OS6%2F4Cmk4j7y4UI49snmP02%2B9odsae7HBV229MFaQEbgBwnIhrOC2a%2FQDjF%2FUp0qF4eXw83IJ3U6dzpl4NjgXfMd6Y7a%2Brab1Lo%2FDP5Tvfnb0AQAA

SWC Info output

After being minified, if the unicode chars are escaped, they should also be escaped in the output

\\uD83D is not equivalent to \uD83D

Expected behavior

\\uD83D should remain \\uD83D

Actual behavior

\\uD83D is unescaped to \uD83D

Version

1.11.18

Additional context

Prettier website bug: prettier/prettier#17308

Docusaurus bug report: facebook/docusaurus#11047

@slorber slorber added the C-bug label Apr 10, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2025
@kdy1 kdy1 added this to the Planned milestone Apr 10, 2025
@kdy1 kdy1 self-assigned this Apr 10, 2025
@swc-project swc-project deleted a comment from github-actions bot Apr 10, 2025
@kdy1 kdy1 removed the invalid link label Apr 10, 2025
@kdy1 kdy1 reopened this Apr 10, 2025
@swc-project swc-project unlocked this conversation Apr 10, 2025
@kdy1 kdy1 linked a pull request Apr 30, 2025 that will close this issue
@kdy1 kdy1 modified the milestones: Planned, v1.11.26 May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants