Repository navigation
fix: resolve a Map entry in strict mode - #2196
Open
superbot-helper wants to merge 1 commit into
Open
superbot-helper wants to merge 1 commit into
superbot-helper wants to merge 1 commit into
Conversation
A Map holds its entries as entries, not as properties, so `name in Object(obj)`
is false for a key the map answers. `lookupProperty` and `lookup` both take the
Map branch; `strict` was the one lookup that did not, so strict mode threw
'"name" not defined in [object Map]' on a key that resolved outside strict mode
and through {{lookup}}. Strict mode is meant to reject a name the context does
not have, and a Map does have it.
strict now asks the map, exactly as its siblings do, and still throws for a key
the map does not hold.
Adds two specs: a present Map key resolves in strict mode, and an absent one
still throws.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The strict-mode Map lookup change has no active review issues.
No open issues 🎉
What changed in this PR
This PR aligns strict-mode Map lookups with Handlebars’ existing Map-aware lookup behavior, allowing present entries to resolve while preserving errors for missing keys.
Changes:
- Use
Map.has()to check entry existence in strict mode, leaving non-Map checks unchanged. - Add regression tests for nested and root-context Map entries, plus a missing-key error case.
| File | Description |
|---|---|
spec/strict.js |
Tests strict-mode resolution of Map entries and rejection of missing keys. |
lib/handlebars/runtime.js |
Adds a Map-aware existence check to strict lookup. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happens
A Map holds its entries as entries, not as properties, so name in Object(obj) is false for a key the map answers. lookupProperty and lookup both take the Map branch; strict was the one lookup that did not.
Same context, same key:
Strict mode is meant to reject a name the context does not have. A Map does have it, and three sibling lookups already say so.
The change
strict asks the map, exactly as its siblings do:
It still throws for a key the map does not hold.
Tests
Two specs in spec/strict.js: a present Map key resolves in strict mode, both as a property path and with the map as the root; an absent one still throws. The first fails on master and passes with the change. Across strict, basic, security, runtime, helpers and partials: 283 passed, 1 skipped, 0 failed. oxfmt and oxlint are clean on both files.
Not a duplicate
No open pull request and no issue in this repository matches a strict-mode Map lookup. The nearest tracker items are about {{#each}} over Maps and about compat-mode recursion, neither of which touches strict.
Scope
Only the strict lookup changes. Nothing about what a template may read changes; a non-strict lookup, the lookup helper and the compiled fallback are all untouched.