fix(es/minifier): Use UTF16 length for str.length (#7275)

**Related issue:**

 - Closes #7274.
This commit is contained in:
Donny/강동윤 2023-04-15 23:50:52 +09:00 committed by GitHub
parent d90d14fc23
commit 4c06a56e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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');
"###,
);
}

View File

@ -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,
})); }));