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.
This commit is contained in:
dotCooCoo committed 2026-11-28 01:35:28 -08:00
1 parent 7b1885dab9
commit 88766dea66
2 files changed
+8 -3

No files matched your search

+5
View File
@@ -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",
);
+3 -3
View File
@@ -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)),
}
}