@samitouri / QOS-React-2 / commits / 35e64cf2bc

[rust-compiler] Bail out on nested TypeScript `this` parameters (#37232)

## Summary Propagate errors returned while lowering block statements instead of discarding them and continuing with partially built HIR. The original issue was triggered by the SWC path, where a TypeScript `this` pseudo-parameter remains in the AST but is omitted from `ScopeInfo`. Lowering rejects the AST parameter, but the function-body block wrapper previously swallowed that error and returned a partial function. ```ts function Component() { useEffect(() => { const get = (): Val => { window.value = { count: 0, method(this: Val) {}, }; return window.value; }; get().count++; }, []); } ``` This could emit a partial transform with the assignment removed: ```js function Component() { useEffect(() => { const get = () => { return window.value; }; get().count++; }, []); } ``` ## How did you test this change? Added a [source-level reproduction against the SWC adapter](https://github.com/wbinnssmith/swc/blob/114e9c55b2/crates/swc_ecma_react_compiler/src/tests/integration.rs#L1563-L1591) using the same case above. - With the current lowering crate, the test fails because the adapter emits a partial program. - With this change patched into the lowering dependency, the test passes because compilation bails out. - `cargo test --manifest-path compiler/Cargo.toml -p react_compiler_lowering`

Will Binns-Smith committed Aug 24, 2026 at 15:23 UTC 35e64cf2bc4a980274ae0cb2a4bda11970560b7e
1 file changed +12 -4
compiler/crates/react_compiler_lowering/src/build_hir.rs
+12 -4
@@ -2589,8 +2589,12 @@ fn lower_block_statement(
2589 block: &react_compiler_ast::statements::BlockStatement,
2590 parent_scope: Option<react_compiler_ast::scope::ScopeId>,
2591 ) -> Result<(), CompilerError> {
2592 - let _ = lower_block_statement_inner(builder, block, None, parent_scope);
2593 - Ok(())
2592 + Ok(lower_block_statement_inner(
2593 + builder,
2594 + block,
2595 + None,
2596 + parent_scope,
2597 + )?)
2598 }
2599
2600 fn lower_block_statement_with_scope(
@@ -2598,8 +2602,12 @@ fn lower_block_statement_with_scope(
2602 block: &react_compiler_ast::statements::BlockStatement,
2603 scope_override: react_compiler_ast::scope::ScopeId,
2604 ) -> Result<(), CompilerError> {
2601 - let _ = lower_block_statement_inner(builder, block, Some(scope_override), None);
2602 - Ok(())
2605 + Ok(lower_block_statement_inner(
2606 + builder,
2607 + block,
2608 + Some(scope_override),
2609 + None,
2610 + )?)
2611 }
2612
2613 fn lower_block_statement_inner(