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
fix(codegen): fix unicode escaping in es5 #3636
fix(codegen): fix unicode escaping in es5 #3636
Conversation
Just posting these links here for future reference https://mathiasbynens.be/notes/javascript-escapes#unicode https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae |
v: &str, | ||
target: EsVersion, | ||
single_quote: bool, | ||
emit_non_ascii_as_unicode: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting this to true
is equivalent to disabling jsesc
minimal
option
crates/swc_ecma_codegen/src/lib.rs
Outdated
} | ||
}; | ||
|
||
if target <= EsVersion::Es5 { | ||
let emit_non_ascii_as_unicode = UNICODE_CODEPOINT.is_match(&orig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only concern about this PR I have is the performance of this line.
Do we really need regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly LGTM.
swc-bump:
- swc_ecma_codegen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
swc-bump:
- swc_ecma_codegen
Description:
Fixes #3617
Babel has the logic
if target <= ES5 && original source string contains any unicode map all non-ascii to unicode
.It's a bit implicit as the logic is across a few plugins and also through the options passed to
jsesc
(that depend on target and babel version) but here babel setsnode.extra = undefined
if there's any unicode in string literalAnd here if
node.extra
exists it will return the string and otherwise process it withjsesc
> 0xFFFF
to surrogate pairs to support ES5.BREAKING CHANGE:
Related issue (if exists):
#3617