mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/minifier): Use UTF16 length for str.length
(#7275)
**Related issue:** - Closes #7274.
This commit is contained in:
parent
d90d14fc23
commit
4c06a56e52
@ -10931,3 +10931,22 @@ fn issue_6914_3() {
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_7274() {
|
||||
run_default_exec_test(
|
||||
r###"
|
||||
if (
|
||||
// incorrect:
|
||||
"😋📋👌".length === 3
|
||||
|
||||
// correct:
|
||||
// "😋📋👌".length === 6
|
||||
) {
|
||||
// side effect
|
||||
new Response(123);
|
||||
}
|
||||
console.log('PASS');
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ impl SimplifyExpr {
|
||||
self.changed = true;
|
||||
|
||||
*expr = Expr::Lit(Lit::Num(Number {
|
||||
value: value.chars().count() as f64,
|
||||
value: value.chars().map(|c| c.len_utf16()).sum::<usize>() as _,
|
||||
span: *span,
|
||||
raw: None,
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user