fix(es/utils): Fix string evaluation of array literals (#7731)

**Related issue:**

 - Closes #7714.
This commit is contained in:
Donny/강동윤 2023-07-31 12:31:37 +09:00 committed by GitHub
parent ffe99a9665
commit e8c58cfd77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 5 deletions

View File

@ -0,0 +1,4 @@
{
"defaults": true,
"evaluate": true
}

View File

@ -0,0 +1 @@
console.log(`${[1, 1]}`)

View File

@ -0,0 +1 @@
console.log("1,1");

View File

@ -1032,10 +1032,11 @@ pub trait ExprExt {
Unknown => return Value::Unknown,
})),
Expr::Array(ArrayLit { ref elems, .. }) => {
let mut first = true;
let mut buf = String::new();
let len = elems.len();
// null, undefined is "" in array literal.
for elem in elems {
for (idx, elem) in elems.iter().enumerate() {
let last = idx == len - 1;
let e = match *elem {
Some(ref elem) => {
let ExprOrSpread { ref expr, .. } = *elem;
@ -1055,9 +1056,7 @@ pub trait ExprExt {
};
buf.push_str(&e);
if first {
first = false;
} else {
if !last {
buf.push(',');
}
}