Skip to content

Commit

Permalink
fix(es/minifier): Fix eval of toString of array with holes (#8727)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8717.
  • Loading branch information
kdy1 authored Mar 11, 2024
1 parent 2ff26e0 commit f3fbd9d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/swc_ecma_minifier/src/compress/pure/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ impl Pure<'_> {
return;
}

if self.options.unsafe_passes && &*method_name.sym == "toString" && arr.elems.len() == 1
if self.options.unsafe_passes
&& &*method_name.sym == "toString"
&& arr.elems.len() == 1
&& arr.elems[0].is_some()
{
report_change!("evaluate: Reducing array.toString() call");
self.changed = true;
Expand Down
48 changes: 48 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/8717/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"defaults": true,
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": true,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true,
"passes": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log([,].toString());
3 changes: 3 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/8717/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log([
,
].toString());

0 comments on commit f3fbd9d

Please sign in to comment.