From 956adf5fa268640fe035164251c4ab90306fc264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ralph=20K=C3=BCpper?= Date: Sat, 13 Jun 2026 18:47:51 +0200 Subject: [PATCH] fix(stream): wire `class X extends Writable/Readable/Duplex/Transform` (node:stream classic subclassing) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User classes extending the classic node:stream base classes threw `TypeError: Class extends value is not a constructor` at `new`. The complete codegen path (`lower_node_stream_super_init`) and runtime helpers (`js_node_stream_*_subclass_init`, which install the native stream methods directly onto `this` and pick up the subclass `_write`/ `_read` override) were already built, but the HIR `class_decl` lowering never recognised these bare names as native parents — so they fell to the unknown-Ident `extends_expr` path, which emits a dynamic parent-registration that rejects the (callable but non-constructor) node:stream export. Fix is the missing HIR wiring: add Readable/Writable/Duplex/Transform to both `native_parent` match arms in `class_decl.rs` (module tag `node_stream`, inert in the only `lookup_class_native_extends` consumer, which gates on the Web Streams tags). Also complete both `node_stream_kind` super-call arms in `this_super_call.rs` so all four bases reach `lower_node_stream_super_init` regardless of which parent-resolution branch fires. Flips console/console-class/stream-errors.ts (custom Writable subclass + ignoreErrors + ERR_CONSOLE_WRITABLE_STREAM) to byte-for-byte parity, and the 6 dedicated stream/extends-* subclass tests (previously throwing) now pass. No new dispatch entry / FFI, so no API_MANIFEST row. Refs #1545. --- .../perry-codegen/src/expr/this_super_call.rs | 2 ++ crates/perry-hir/src/lower_decl/class_decl.rs | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/perry-codegen/src/expr/this_super_call.rs b/crates/perry-codegen/src/expr/this_super_call.rs index 7fccc034570..e9fdfecf2bb 100644 --- a/crates/perry-codegen/src/expr/this_super_call.rs +++ b/crates/perry-codegen/src/expr/this_super_call.rs @@ -289,6 +289,7 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { } } let node_stream_kind = match parent_name.as_str() { + "Readable" => Some("readable"), "Writable" => Some("writable"), "Duplex" => Some("duplex"), "Transform" => Some("transform"), @@ -336,6 +337,7 @@ pub(crate) fn lower(ctx: &mut FnCtx<'_>, expr: &Expr) -> Result { } let node_stream_kind = match parent_name.as_str() { "Readable" => Some("readable"), + "Writable" => Some("writable"), "Duplex" => Some("duplex"), "Transform" => Some("transform"), _ => None, diff --git a/crates/perry-hir/src/lower_decl/class_decl.rs b/crates/perry-hir/src/lower_decl/class_decl.rs index 6a718d3beee..4d319bb5f6c 100644 --- a/crates/perry-hir/src/lower_decl/class_decl.rs +++ b/crates/perry-hir/src/lower_decl/class_decl.rs @@ -215,6 +215,21 @@ pub fn lower_class_decl( "transform_stream".to_string(), "TransformStream".to_string(), )), + // #1545: classic node:stream base classes. Recognising them + // as native parents (rather than letting the unknown-Ident + // arm capture `extends_expr`) avoids the dynamic + // parent-registration throw ("Class extends value is not a + // constructor") — a node:stream export is a callable but not + // a registered class constructor. The `super(opts)` codegen + // arm (`lower_node_stream_super_init`) and the runtime + // `js_node_stream_*_subclass_init` helpers, which install the + // native stream methods directly onto `this`, were already + // built; this is the missing HIR wiring. Keep in lockstep + // with the parallel arm in `lower_class_from_ast` below. + "Readable" => Some(("node_stream".to_string(), "Readable".to_string())), + "Writable" => Some(("node_stream".to_string(), "Writable".to_string())), + "Duplex" => Some(("node_stream".to_string(), "Duplex".to_string())), + "Transform" => Some(("node_stream".to_string(), "Transform".to_string())), _ => None, }; if native_parent.is_some() { @@ -1215,6 +1230,12 @@ pub fn lower_class_from_ast( "transform_stream".to_string(), "TransformStream".to_string(), )), + // #1545: classic node:stream base classes — keep in lockstep + // with the parallel arm in `lower_class_decl` above. + "Readable" => Some(("node_stream".to_string(), "Readable".to_string())), + "Writable" => Some(("node_stream".to_string(), "Writable".to_string())), + "Duplex" => Some(("node_stream".to_string(), "Duplex".to_string())), + "Transform" => Some(("node_stream".to_string(), "Transform".to_string())), _ => None, }; if native_parent.is_some() {