From 88766dea6600ed51e989b21fcf25a25cec2ef017 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 01:35:28 -0800 Subject: [PATCH] Scripts: super properties are destructuring and for-of targets `[super.x] = [1]`, `({ a: super.a } = o)` and `for (super.x of xs)` were syntax errors. The branch made super properties assignment targets in `check_target`, but destructuring and for-of check their targets with `check_simple_target` (from main's destructuring), which still rejected them. The compiler already writes to super properties on both paths. --- crates/js/src/es2015_tests.rs | 5 +++++ crates/js/src/parser/pattern.rs | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/js/src/es2015_tests.rs b/crates/js/src/es2015_tests.rs index 3b19e772d2..ddbb808a0f 100644 --- a/crates/js/src/es2015_tests.rs +++ b/crates/js/src/es2015_tests.rs @@ -1290,6 +1290,11 @@ fn subclasses_inherit_and_reach_the_superclass_through_super() { truth("class A { constructor(...a) { this.n = a.length; } } class B extends A {} new B(1, 2, 3).n === 3"); truth("class A { static s() { return 1; } } class B extends A { static s() { return super.s() + 1; } } B.s() === 2"); truth("class A {} class B extends A { m() { super.x = 5; return this.x; } } var b = new B(); b.m() === 5 && !A.prototype.hasOwnProperty('x')"); + // A super property is a target of destructuring and of `for-of` as well. + truth( + "class A {} class B extends A { m() { [super.x, super['y']] = [1, 2]; ({ z: super.z } = { z: 3 }); for (super.w of [4]) {} \ + return this.x * 1000 + this.y * 100 + this.z * 10 + this.w; } } new B().m() === 1234 && !A.prototype.hasOwnProperty('x')", + ); truth( "class A { get v() { return this.w; } } class B extends A { constructor() { super(); this.w = 7; } get v() { return super.v + 1; } } new B().v === 8", ); diff --git a/crates/js/src/parser/pattern.rs b/crates/js/src/parser/pattern.rs index 560b0798bd..b25350549a 100644 --- a/crates/js/src/parser/pattern.rs +++ b/crates/js/src/parser/pattern.rs @@ -209,8 +209,8 @@ impl Parser<'_> { } /// An assignment's, `++`'s or `--`'s target without the call that ECMAScript 5.1 code may - /// assign to: an identifier (in strict code neither `eval` nor `arguments`), a property or an - /// E4X name standing alone. + /// assign to: an identifier (in strict code neither `eval` nor `arguments`), a property (a + /// super property included) or an E4X name standing alone. fn check_simple_target(&self, expr: ExprId, message: &str) -> Result<()> { let inner = self.ast.unparenthesized(expr); match self.ast.expr(inner) { @@ -220,7 +220,7 @@ impl Parser<'_> { } Ok(()) } - Some(Expr::Member { .. } | Expr::Index { .. } | Expr::XmlScopeName(_)) => Ok(()), + Some(Expr::Member { .. } | Expr::Index { .. } | Expr::XmlScopeName(_) | Expr::SuperMember(_) | Expr::SuperIndex(_)) => Ok(()), _ => Err(self.error_at_offset(self.ast.expr_span(expr).start, message)), } }