Skip to content

Fix strict lookup in compat mode#2150

Merged
kibertoad merged 1 commit intohandlebars-lang:masterfrom
theodorejb:fix-compat-strict-lookup
Apr 21, 2026
Merged

Fix strict lookup in compat mode#2150
kibertoad merged 1 commit intohandlebars-lang:masterfrom
theodorejb:fix-compat-strict-lookup

Conversation

@theodorejb
Copy link
Copy Markdown
Contributor

@theodorejb theodorejb commented Apr 15, 2026

Fixes #2149, fixes #1741

@theodorejb theodorejb force-pushed the fix-compat-strict-lookup branch 2 times, most recently from c5900c7 to 0b0f7b3 Compare April 15, 2026 20:02
@theodorejb theodorejb changed the title Fix compiling of strict lookup in compat mode Fix strict lookup in compat mode Apr 15, 2026
@theodorejb theodorejb force-pushed the fix-compat-strict-lookup branch 2 times, most recently from a6dd9a6 to 2f55d99 Compare April 15, 2026 22:37
@jaylinski jaylinski requested a review from Copilot April 19, 2026 16:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect strict lookups when compat mode is enabled, preventing TypeError crashes and restoring expected strict error behavior.

Changes:

  • Added strict+compat regression tests covering boolean block contexts, each item lookups, recursion, and null handling.
  • Introduced a runtime helper (container.strictLookup) to safely traverse depths for strict property resolution in compat scenarios.
  • Updated the JS compiler to emit container.strictLookup(...) when compat mode has already performed a depthed lookup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
spec/strict.js Adds test coverage for strict+compat mode behaviors and regressions.
lib/handlebars/runtime.js Adds container.strictLookup to safely resolve strict properties across depths in compat mode.
lib/handlebars/compiler/javascript-compiler.js Emits container.strictLookup(...) in the strict+compat codegen path to avoid in operator crashes on primitives.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/strict.js
Comment thread lib/handlebars/runtime.js Outdated
@theodorejb theodorejb force-pushed the fix-compat-strict-lookup branch from 2f55d99 to 255ef4c Compare April 19, 2026 19:48
@kibertoad
Copy link
Copy Markdown
Contributor

One suggestion: add a direct "{{v}} with strict+compat where v doesn't exist at any depth" test. Your "still throw when a property is missing at all depths" covers the same code path but via {{#each items}}, and a minimal top-level case would more clearly regress-guard the originally reported form.

@theodorejb theodorejb force-pushed the fix-compat-strict-lookup branch from 255ef4c to cd47c94 Compare April 21, 2026 19:16
@theodorejb
Copy link
Copy Markdown
Contributor Author

@kibertoad I rebased now and added a test case for a simple {{v}} template where the variable is missing.

@kibertoad kibertoad merged commit 3105ca7 into handlebars-lang:master Apr 21, 2026
8 checks passed
@kibertoad
Copy link
Copy Markdown
Contributor

thank you!

@theodorejb theodorejb deleted the fix-compat-strict-lookup branch April 21, 2026 19:34
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.

Strict lookup doesn't work correctly in compat mode Exception when the strict and compat compiler options are used together

3 participants