Files
scriptc/tests/corpus/super-comma-sequence-js.js
T
Malte UblandClaude Opus 5.5 18033dc42d Compile derived constructors whose super() call leads a comma statement
Minifiers join a derived constructor's statements into one comma
expression (`super(message, options), this.name = ..., ...;`), which jose
6.2.12 ships in its error classes. The statement lowering already runs
each operand of a statement-level comma as its own statement, so super()
is accepted when only parentheses and comma operators separate it from
its expression statement. Every other expression position keeps the
SC1090 refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:57:35 -07:00

50 lines
1.4 KiB
JavaScript

// The JavaScript side of super-comma-sequence.ts: a statement-level comma
// expression containing super(...) runs its operands in source order, with
// the base constructor and the derived field initializers at the super()
// call, as the separate statements a minifier joined would.
function log(label, value) {
console.log(" " + label);
return value;
}
class Base {
constructor(origin) {
console.log(" Base body", origin);
this.origin = origin;
}
}
class Joined extends Base {
first = log("field first", 1);
second = this.first + 1;
constructor(origin) {
super(log("super argument", origin)), log("after super", 0), this.tag = `${this.origin}:${this.second}`;
}
}
class Leading extends Base {
value = log("field value", "v");
constructor(origin) {
log("before super", 0), super(origin), log("after super " + this.value, 0);
}
}
class Again extends Joined {
extra = log("field extra", "e");
constructor() {
super("again"), this.tag = this.tag + "!", this.extra = this.extra + this.tag;
}
}
console.log("joined:");
const joined = new Joined("j");
console.log(joined.origin, joined.first, joined.second, joined.tag);
console.log("leading:");
const leading = new Leading("l");
console.log(leading.origin, leading.value);
console.log("again:");
const again = new Again();
console.log(again.origin, again.tag, again.extra, again instanceof Joined, again instanceof Base);