Skip to content

test: cover rendering with interpreted expression trees (Blazor WASM / iOS / NativeAOT) - #698

Merged
stencil-harness[bot] merged 1 commit into
masterfrom
robot/issue-345
Nov 22, 2026
Merged

stencil-harness[bot] merged 1 commit into
masterfrom
robot/issue-345

Conversation

@stencil-harness

Copy link
Copy Markdown
Contributor

Refs #345

Why

On runtimes without dynamic code generation (Blazor WebAssembly, iOS/tvOS/Mac Catalyst, NativeAOT), Expression<T>.Compile() no longer emits IL. Since .NET 6 it always runs through the System.Linq.Expressions interpreter. The crash in #345 (NullReferenceException inside ILGenerator.Emit after the 2020-era Mono linker had stripped Reflection.Emit) can't happen on those runtimes anymore. What matters now is whether Handlebars.Net renders correctly when interpreted, and until now nothing tested that.

What

Adds source/Handlebars.Test/ExpressionInterpretationTests.cs, which is test-only, with no library or public API change:

  • It registers an IFeature through the existing public CompileTimeConfiguration.Features extension point. The feature swaps in an IExpressionCompiler that runs the configured expression middlewares and then calls Compile(preferInterpretation: true). This is the same code path the WASM/AOT runtimes take.
  • It renders 17 representative templates in both compiled and interpreted environments and asserts identical, expected output. The templates cover paths, escaping, if/unless/else, each over arrays and dictionaries (with @index/@key/else), with + @root, lookup, subexpressions, block helpers with inverse, partials with hash args, partial blocks with fallback, inline partials, and ../ parent access.
  • It asserts that compile errors are reported the same way in both modes.
  • It asserts that the interpreting compiler was actually used.

Verification

dotnet test source/Handlebars.Test/Handlebars.Test.csproj on net10.0: 2344 passed, 0 failed.

Not in this PR (reported on #345 for a maintainer decision)

  • I also ran the whole existing suite with the default compiler temporarily forced to interpret. The recursion-limit tests (RecursionUnboundedPartial, RecursionBounded*AboveLimit*) stack-overflow before reaching the default PartialRecursionDepthLimit of 100, because interpreted frames are much deeper.
  • CompileTimeConfiguration.ExpressionCompiler is a public settable property, but nothing reads it.

🤖 Generated with Claude Code

Closes #345

Blazor WebAssembly, iOS and NativeAOT run Expression.Compile() through the
System.Linq.Expressions interpreter. Add coverage that templates render the
same when the expression compiler interprets instead of emitting IL.

Refs #345

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@stencil-harness
stencil-harness Bot merged commit 2939312 into master Nov 22, 2026
7 checks passed
@stencil-harness
stencil-harness Bot deleted the robot/issue-345 branch November 22, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using Handlebars.Net in a Blazor WASM throws error when using ".Compile()"

0 participants