diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 0d9532ffaad4e..b15abc4982270 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -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; } } diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 312ae41805e44..d104e8989bd2c 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -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] diff --git a/tasks/coverage/snapshots/runtime.snap b/tasks/coverage/snapshots/runtime.snap index d83abddd38605..04fe844c075f1 100644 --- a/tasks/coverage/snapshots/runtime.snap +++ b/tasks/coverage/snapshots/runtime.snap @@ -2,7 +2,7 @@ commit: 06454619 runtime Summary: AST Parsed : 18446/18446 (100.00%) -Positive Passed: 17184/18446 (93.16%) +Positive Passed: 17119/18446 (92.81%) tasks/coverage/test262/test/annexB/language/function-code/block-decl-func-block-scoping.js minify error: ReferenceError: f is not defined @@ -444,6 +444,33 @@ minify error: Test262Error: Expected SameValue(«"undefined"», «"function"») tasks/coverage/test262/test/language/expressions/addition/S11.6.1_A4_T5.js minify error: Test262Error: #1.1: -0 + -0 === - 0. Actual: +0 +tasks/coverage/test262/test/language/expressions/addition/bigint-and-number.js +minify error: Test262Error: 1n + 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/bigint-errors.js +minify error: Test262Error: 0n + Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/bigint-toprimitive.js +minify error: Test262Error: 0n + {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/coerce-symbol-to-prim-err.js +minify error: Test262Error: error thrown by left-hand side Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/coerce-symbol-to-prim-invocation.js +minify error: Test262Error: methods invoked in correct sequence Expected SameValue(«""», «"leftright"») to be true + +tasks/coverage/test262/test/language/expressions/addition/coerce-symbol-to-prim-return-obj.js +minify error: Test262Error: ordinary object value, right-hand side Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/coerce-symbol-to-prim-return-prim.js +minify error: Test262Error: ToNumber(Symbol): right-hand side Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/get-symbol-to-prim-err.js +minify error: Test262Error: error from property access of left-hand side Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/addition/symbol-to-string.js +minify error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/array/spread-err-mult-err-obj-unresolvable.js transform error: ReferenceError: require is not defined @@ -732,6 +759,33 @@ transform error: ReferenceError: require is not defined tasks/coverage/test262/test/language/expressions/async-generator/yield-spread-obj.js transform error: ReferenceError: require is not defined +tasks/coverage/test262/test/language/expressions/bitwise-and/bigint-and-number.js +minify error: Test262Error: 1n & 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-and/bigint-errors.js +minify error: Test262Error: 0n & Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-and/bigint-toprimitive.js +minify error: Test262Error: 0n & {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-or/bigint-and-number.js +minify error: Test262Error: 1n | 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-or/bigint-errors.js +minify error: Test262Error: 0n | Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-or/bigint-toprimitive.js +minify error: Test262Error: 0n | {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-xor/bigint-and-number.js +minify error: Test262Error: 1n ^ 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-xor/bigint-errors.js +minify error: Test262Error: 0n ^ Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/bitwise-xor/bigint-toprimitive.js +minify error: Test262Error: 0n ^ {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/call/eval-spread-empty-leading.js minify error: Test262Error: Expected SameValue(«"local"», «0») to be true @@ -1551,6 +1605,18 @@ minify error: Test262Error: Expected SameValue(«0», «1») to be true tasks/coverage/test262/test/language/expressions/division/S11.5.2_A4_T8.js minify error: Test262Error: #1.2: -0 / 1 === - 0. Actual: +0 +tasks/coverage/test262/test/language/expressions/division/bigint-and-number.js +minify error: Test262Error: 1n / 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/division/bigint-complex-infinity.js +minify error: Test262Error: 1n / 0n throws RangeError Expected a RangeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/division/bigint-errors.js +minify error: Test262Error: 0n / Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/division/bigint-toprimitive.js +minify error: Test262Error: 0n / {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/does-not-equals/bigint-and-object.js minify error: Test262Error: The result of (0n != {valueOf: function() {return 0n;}}) is false Expected SameValue(«true», «false») to be true @@ -1593,9 +1659,30 @@ codegen error: Test262Error: constructor is %Promise% Expected SameValue(«[obje tasks/coverage/test262/test/language/expressions/equals/bigint-and-object.js minify error: Test262Error: The result of (0n == {valueOf: function() {return 0n;}}) is true Expected SameValue(«false», «true») to be true +tasks/coverage/test262/test/language/expressions/equals/coerce-symbol-to-prim-err.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/equals/coerce-symbol-to-prim-invocation.js +minify error: Test262Error: method invoked exactly once Expected SameValue(«0», «1») to be true + +tasks/coverage/test262/test/language/expressions/equals/coerce-symbol-to-prim-return-obj.js +minify error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/equals/get-symbol-to-prim-err.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/exponentiation/bigint-and-number.js +minify error: Test262Error: 1n ** 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/exponentiation/bigint-errors.js +minify error: Test262Error: 0n ** Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/exponentiation/bigint-negative-exponent-throws.js transform error: Test262Error: (-1n) ** -1n throws RangeError Expected a RangeError but got a TypeError +tasks/coverage/test262/test/language/expressions/exponentiation/bigint-toprimitive.js +minify error: Test262Error: 0n ** {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/function/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js minify error: Test262Error: Expected SameValue(«"c"», «"arrow"») to be true @@ -1755,12 +1842,42 @@ transform error: ReferenceError: require is not defined tasks/coverage/test262/test/language/expressions/greater-than/bigint-and-incomparable-string.js minify error: Test262Error: The result of (1n > "0.") is false Expected SameValue(«true», «false») to be true +tasks/coverage/test262/test/language/expressions/greater-than/bigint-and-symbol.js +minify error: Test262Error: 3n > Symbol("2") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/greater-than-or-equal/bigint-and-incomparable-string.js minify error: Test262Error: The result of (1n >= "0.") is false Expected SameValue(«true», «false») to be true +tasks/coverage/test262/test/language/expressions/instanceof/primitive-prototype-with-object.js +minify error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/instanceof/prototype-getter-with-object-throws.js +minify error: Test262Error: Expected a DummyError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/instanceof/symbol-hasinstance-get-err.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/instanceof/symbol-hasinstance-invocation.js +minify error: Test262Error: Expected SameValue(«0», «1») to be true + +tasks/coverage/test262/test/language/expressions/instanceof/symbol-hasinstance-not-callable.js +minify error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/left-shift/bigint-and-number.js +minify error: Test262Error: 1n << 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/left-shift/bigint-errors.js +minify error: Test262Error: 0n << Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/left-shift/bigint-toprimitive.js +minify error: Test262Error: 0n << {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/less-than/bigint-and-incomparable-string.js minify error: Test262Error: The result of ("0." < 1n) is false Expected SameValue(«true», «false») to be true +tasks/coverage/test262/test/language/expressions/less-than/bigint-and-symbol.js +minify error: Test262Error: 3n < Symbol("2") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/less-than-or-equal/bigint-and-incomparable-string.js minify error: Test262Error: The result of ("0." <= 1n) is false Expected SameValue(«true», «false») to be true @@ -1779,9 +1896,30 @@ minify error: Test262Error: #2.2: -1 % -1 === - 0. Actual: +0 tasks/coverage/test262/test/language/expressions/modulus/S11.5.3_A4_T6.js minify error: Test262Error: #3.2: -0 % 1 === - 0. Actual: +0 +tasks/coverage/test262/test/language/expressions/modulus/bigint-and-number.js +minify error: Test262Error: 1n % 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/modulus/bigint-errors.js +minify error: Test262Error: 0n % Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/modulus/bigint-modulo-zero.js +minify error: Test262Error: 1n % 0n throws RangeError Expected a RangeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/modulus/bigint-toprimitive.js +minify error: Test262Error: 0n % {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/multiplication/S11.5.1_A4_T2.js minify error: Test262Error: #6.2: 0 * -0 === - 0. Actual: +0 +tasks/coverage/test262/test/language/expressions/multiplication/bigint-and-number.js +minify error: Test262Error: 1n * 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/multiplication/bigint-errors.js +minify error: Test262Error: 0n * Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/multiplication/bigint-toprimitive.js +minify error: Test262Error: 0n * {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/new/spread-err-mult-err-obj-unresolvable.js transform error: ReferenceError: require is not defined @@ -1840,7 +1978,7 @@ tasks/coverage/test262/test/language/expressions/new/spread-sngl-obj-ident.js transform error: ReferenceError: require is not defined tasks/coverage/test262/test/language/expressions/object/__proto__-permitted-dup-shorthand.js -codegen error: SyntaxError: Duplicate __proto__ fields are not allowed in object literals +codegen error: Test262Error: Expected SameValue(«[object Object]», «2») to be true tasks/coverage/test262/test/language/expressions/object/accessor-name-computed-err-to-prop-key.js minify error: Test262Error: `get` accessor Expected a TypeError to be thrown but no exception was thrown at all @@ -2082,9 +2220,27 @@ minify error: Test262Error: Expected a SyntaxError to be thrown but no exception tasks/coverage/test262/test/language/expressions/optional-chaining/member-expression.js minify error: Test262Error: Expected SameValue(«"a"», «"m"») to be true +tasks/coverage/test262/test/language/expressions/right-shift/bigint-and-number.js +minify error: Test262Error: 1n >> 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/right-shift/bigint-errors.js +minify error: Test262Error: 0n >> Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/right-shift/bigint-toprimitive.js +minify error: Test262Error: 0n >> {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/subtraction/S11.6.2_A4_T5.js minify error: Test262Error: #3.2: -0 - 0 === - 0. Actual: +0 +tasks/coverage/test262/test/language/expressions/subtraction/bigint-and-number.js +minify error: Test262Error: 1n - 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/subtraction/bigint-errors.js +minify error: Test262Error: 0n - Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/subtraction/bigint-toprimitive.js +minify error: Test262Error: 0n - {[Symbol.toPrimitive]: 1} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/super/call-spread-err-mult-err-obj-unresolvable.js transform error: ReferenceError: require is not defined @@ -2145,6 +2301,15 @@ transform error: ReferenceError: require is not defined tasks/coverage/test262/test/language/expressions/tagged-template/cache-eval-inner-function.js minify error: ReferenceError: a is not defined +tasks/coverage/test262/test/language/expressions/template-literal/literal-expr-tostr-error.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/template-literal/middle-list-many-expr-tostr-error.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/template-literal/middle-list-one-expr-tostr-error.js +minify error: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/unary-plus/S11.4.6_A3_T3.js minify error: Test262Error: #4: +"INFINITY" === Not-a-Number. Actual: Infinity @@ -2154,6 +2319,24 @@ minify error: Test262Error: #3.2: +(-0) === -0. Actual: +0 tasks/coverage/test262/test/language/expressions/unary-plus/bigint-throws.js minify error: Test262Error: +0n throws TypeError Expected a TypeError to be thrown but no exception was thrown at all +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint-and-number.js +minify error: Test262Error: 1n >>> 1 throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint-errors.js +minify error: Test262Error: 0n >>> Symbol("1") throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint-non-primitive.js +minify error: Test262Error: ({valueOf: function() {return 0b101n;}, toString: err}) >>> 1n throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint-toprimitive.js +minify error: Test262Error: 0n >>> {[Symbol.toPrimitive]: function() {return 2n;}, valueOf: err, toString: err} throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint-wrapped-values.js +minify error: Test262Error: 0n >>> Object(2n) throws TypeError Expected a TypeError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/expressions/unsigned-right-shift/bigint.js +minify error: Test262Error: bigint >>> bigint throws a TypeError Expected a TypeError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/expressions/void/S11.4.2_A2_T2.js minify error: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all @@ -2172,6 +2355,18 @@ minify error: Test262Error: #1: Scope chain disturbed tasks/coverage/test262/test/language/identifier-resolution/S10.2.2_A1_T8.js minify error: Test262Error: #1: Scope chain disturbed +tasks/coverage/test262/test/language/literals/numeric/S7.8.3_A4.1_T3.js +minify error: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/literals/numeric/S7.8.3_A4.1_T4.js +minify error: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/literals/numeric/S7.8.3_A4.1_T5.js +minify error: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all + +tasks/coverage/test262/test/language/literals/numeric/S7.8.3_A4.1_T6.js +minify error: Test262Error: Expected a ReferenceError to be thrown but no exception was thrown at all + tasks/coverage/test262/test/language/literals/regexp/u-surrogate-pairs-atom-escape-decimal.js codegen error: Test262Error: Expected SameValue(«true», «false») to be true