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
6 changes: 4 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,8 +1526,10 @@ impl<'a> Gen for ObjectProperty<'a> {

let mut shorthand = false;
if let PropertyKey::StaticIdentifier(key) = &self.key {
if let Expression::Identifier(ident) = self.value.without_parentheses() {
if key.name == p.get_identifier_reference_name(ident) && key.name != "__proto__" {
if key.name == "__proto__" {
shorthand = self.shorthand;
} else if let Expression::Identifier(ident) = self.value.without_parentheses() {
if key.name == p.get_identifier_reference_name(ident) {
shorthand = true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ fn shorthand() {
test("let { x } = y", "let { x } = y;\n");
test("({ x: (x) })", "({ x });\n");
test("({ x } = y)", "({x} = y);\n");
// https://github.com/tc39/test262/blob/main/test/language/expressions/object/__proto__-permitted-dup-shorthand.js
test("var obj = { __proto__, __proto__, };", "var obj = {\n\t__proto__,\n\t__proto__\n};\n");
test("var obj = { __proto__: __proto__, };", "var obj = { __proto__: __proto__ };\n");
}

#[test]
Expand Down
Loading