fix(es/minifier): Preserve function length (#9389)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/9356
This commit is contained in:
Donny/강동윤 2024-08-07 16:14:24 +09:00 committed by GitHub
parent 7899f5fc33
commit 679682ce36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 19 deletions

View File

@ -11345,3 +11345,8 @@ fn issue_9184_2() {
"#,
);
}
#[test]
fn issue_9356() {
run_default_exec_test("console.log((function ({ } = 42) { }).length)");
}

View File

@ -314,15 +314,6 @@ impl VisitMut for Remover {
*p = *assign.left.take();
}
Pat::Assign(assign)
if match *assign.left {
Pat::Object(ref o) => o.props.is_empty(),
_ => false,
} && assign.right.is_number() =>
{
*p = *assign.left.take();
}
_ => {}
}
}

View File

@ -1452,16 +1452,6 @@ fn test_empty_key_in_object_pattern_removed() {
test_same("const {[foo()]: {}} = {};");
}
#[test]
fn test_empty_key_in_object_pattern_with_default_value_maybe_removed() {
test("const {f: {} = 0} = {};", "");
// In theory the following case could be reduced to `foo()`, but that gets more
// complicated to implement for object patterns with multiple keys with side
// effects. Instead the pass backs off for any default with a possible side
// effect
test_same("const {f: {} = foo()} = {};");
}
#[test]
fn test_empty_key_in_object_pattern_not_removed_with_object_rest() {
test_same("const {f: {}, ...g} = foo()");