diff --git a/crates/oxc_minifier/src/peephole/minimize_statements.rs b/crates/oxc_minifier/src/peephole/minimize_statements.rs index 8dde1caedbfc2..b087590ba4324 100644 --- a/crates/oxc_minifier/src/peephole/minimize_statements.rs +++ b/crates/oxc_minifier/src/peephole/minimize_statements.rs @@ -1605,6 +1605,17 @@ impl<'a> PeepholeOptimizations { ctx, ) { + if prop.shorthand && prop.key.is_specific_id("__proto__") { + // { __proto__ } -> { ['__proto__']: value } + prop.computed = true; + prop.key = + PropertyKey::from(ctx.ast.expression_string_literal( + prop.key.span(), + "__proto__", + None, + )); + } + prop.shorthand = false; return Some(changed); } } diff --git a/crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs b/crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs index c6642b2c473d8..cd52e9b0bf688 100644 --- a/crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs +++ b/crates/oxc_minifier/tests/peephole/inline_single_use_variable.rs @@ -212,6 +212,15 @@ fn test_inline_single_use_variable() { "function wrapper() { var x = a; for (let a of x) console.log(a) }", "function wrapper() { var x = a; for (let a of x) console.log(a) }", ); + + test( + "function wrapper() { var __proto__ = []; return { __proto__: __proto__ } }", + "function wrapper() { return { __proto__: [] } }", + ); + test( + "function wrapper() { var __proto__ = []; return { __proto__ } }", + "function wrapper() { return { ['__proto__']: [] } }", + ); } #[test] diff --git a/tasks/coverage/snapshots/minifier_node_compat.snap b/tasks/coverage/snapshots/minifier_node_compat.snap index 945b9b09f0dc0..346ba7cee65c2 100644 --- a/tasks/coverage/snapshots/minifier_node_compat.snap +++ b/tasks/coverage/snapshots/minifier_node_compat.snap @@ -2,11 +2,9 @@ commit: ed0d6ba5 minifier_node_compat Summary: AST Parsed : 938/938 (100.00%) -Positive Passed: 928/938 (98.93%) +Positive Passed: 929/938 (99.04%) execution_result: tasks/coverage/ES2015/annex b›__proto__ in object literals›basic support -execution_result: tasks/coverage/ES2015/annex b›__proto__ in object literals›not a shorthand property - execution_result: tasks/coverage/ES2015/built-ins›Proxy›"getOwnPropertyDescriptor" handler invariants execution_result: tasks/coverage/ES2015/misc›Proxy, internal 'get' calls›HasBinding