mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 12:18:08 +03:00
fix(es/utils): Fix string evaluation of array literals (#7731)
**Related issue:** - Closes #7714.
This commit is contained in:
parent
ffe99a9665
commit
e8c58cfd77
@ -0,0 +1,4 @@
|
||||
{
|
||||
"defaults": true,
|
||||
"evaluate": true
|
||||
}
|
@ -0,0 +1 @@
|
||||
console.log(`${[1, 1]}`)
|
@ -0,0 +1 @@
|
||||
console.log("1,1");
|
@ -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(',');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user