Skip to content

Commit

Permalink
fix(minifier): do not remove undefined for destructuring patterns (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 23, 2024
1 parent 5928f04 commit 22355f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax {
decl: &mut VariableDeclarator<'a>,
ctx: Ctx<'a, 'b>,
) {
if decl.kind.is_const() {
// Destructuring Pattern has error throwing side effect.
if decl.kind.is_const() || decl.id.kind.is_destructuring_pattern() {
return;
}
if decl.init.as_ref().is_some_and(|init| ctx.is_expression_undefined(init)) {
Expand Down Expand Up @@ -592,6 +593,10 @@ mod test {

// shadowd
test_same("(function(undefined) { let x = typeof undefined; })()");

// destructuring throw error side effect
test_same("var {} = void 0");
test_same("var [] = void 0");
}

#[test]
Expand Down
14 changes: 1 addition & 13 deletions tasks/coverage/snapshots/runtime.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 06454619

runtime Summary:
AST Parsed : 18444/18444 (100.00%)
Positive Passed: 18194/18444 (98.64%)
Positive Passed: 18198/18444 (98.67%)
tasks/coverage/test262/test/annexB/language/function-code/if-decl-else-decl-a-func-existing-block-fn-no-init.js
minify error: Test262Error: Expected SameValue(«function f(){}», «undefined») to be true

Expand Down Expand Up @@ -735,21 +735,9 @@ codegen error: Test262Error: Expected SameValue(«"B"», «"A"») to be true
tasks/coverage/test262/test/language/statements/async-generator/return-undefined-implicit-and-explicit.js
minify error: Test262Error: Actual [tick 1, g1 ret, g2 ret, g3 ret, g4 ret, tick 2] and expected [tick 1, g1 ret, g2 ret, tick 2, g3 ret, g4 ret] should have the same contents. Ticks for implicit and explicit return undefined

tasks/coverage/test262/test/language/statements/for/dstr/let-obj-init-undefined.js
minify error: SyntaxError: Missing initializer in destructuring declaration

tasks/coverage/test262/test/language/statements/for/dstr/var-obj-init-undefined.js
minify error: SyntaxError: Missing initializer in destructuring declaration

tasks/coverage/test262/test/language/statements/for-of/string-astral-truncated.js
codegen error: Test262Error: Expected SameValue"\\"», «"\\ud801"») to be true

tasks/coverage/test262/test/language/statements/let/dstr/obj-init-undefined.js
minify error: SyntaxError: Missing initializer in destructuring declaration

tasks/coverage/test262/test/language/statements/variable/dstr/obj-init-undefined.js
minify error: SyntaxError: Missing initializer in destructuring declaration

tasks/coverage/test262/test/language/statements/with/has-binding-call-with-proxy-env.js
minify error: Test262Error: Actual [] and expected [has:Object] should have the same contents.

0 comments on commit 22355f7

Please sign in to comment.