mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +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,
|
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;
|
self.changed = true;
|
||||||
|
|
||||||
*expr = Expr::Lit(Lit::Num(Number {
|
*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,
|
span: *span,
|
||||||
raw: None,
|
raw: None,
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user