Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/oxc_minifier/src/peephole/minimize_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions tasks/coverage/snapshots/minifier_node_compat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading