mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
fix(minifier): do not remove undefined for destructuring patterns (#6828)
This commit is contained in:
parent
5928f043b5
commit
22355f73f3
2 changed files with 7 additions and 14 deletions
|
|
@ -298,7 +298,8 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax {
|
||||||
decl: &mut VariableDeclarator<'a>,
|
decl: &mut VariableDeclarator<'a>,
|
||||||
ctx: Ctx<'a, 'b>,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if decl.init.as_ref().is_some_and(|init| ctx.is_expression_undefined(init)) {
|
if decl.init.as_ref().is_some_and(|init| ctx.is_expression_undefined(init)) {
|
||||||
|
|
@ -592,6 +593,10 @@ mod test {
|
||||||
|
|
||||||
// shadowd
|
// shadowd
|
||||||
test_same("(function(undefined) { let x = typeof undefined; })()");
|
test_same("(function(undefined) { let x = typeof undefined; })()");
|
||||||
|
|
||||||
|
// destructuring throw error side effect
|
||||||
|
test_same("var {} = void 0");
|
||||||
|
test_same("var [] = void 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ commit: 06454619
|
||||||
|
|
||||||
runtime Summary:
|
runtime Summary:
|
||||||
AST Parsed : 18444/18444 (100.00%)
|
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
|
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
|
minify error: Test262Error: Expected SameValue(«function f(){}», «undefined») to be true
|
||||||
|
|
||||||
|
|
@ -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
|
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
|
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
|
tasks/coverage/test262/test/language/statements/for-of/string-astral-truncated.js
|
||||||
codegen error: Test262Error: Expected SameValue(«"\\"», «"\\ud801"») to be true
|
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
|
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.
|
minify error: Test262Error: Actual [] and expected [has:Object] should have the same contents.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue