-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Describe the bug
When escaping specific strings, SWC strips necessary escape characters in minified output. This results in the incorrect string being output. See the given input code and playground link for examples.
Input code
let str = "\\uD83D\\uDC68\\u200D\\uD83D\\uDE80";
let obj = {
"\\uD83D\\uDC68\\u200D\\uD83D\\uDE80": "wrong"
};Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "commonjs"
},
"minify": true,
"isModule": false
}Playground link
Expected behavior
SWC should not strip escape characters and produce the following output:
let str="\\uD83D\\uDC68\\u200D\\uD83D\\uDE80";let obj={"\\uD83D\\uDC68\\u200D\\uD83D\\uDE80":"wrong"};Actual behavior
SWC strips escape characters and produces the following output:
let str="\uD83D\uDC68\\u200D\uD83D\uDE80";let obj={"\uD83D\uDC68\\u200D\uD83D\uDE80":"wrong"};Note the missing \ before \uD83D (twice), \uDC68 and \uDE80.
Version
1.3.70
Additional context
As a workaround, the following produces the correct output:
let workaround = {
[`\\uD83D\\uDC68\\u200D\\uD83D\\uDE80`]: "correct",
};