Repository navigation
docs: fix broken JavaScriptCompiler subclass example - #2173
Hashim1999164 wants to merge 3 commits into
Conversation
The previous example called a registered helper from nameLookup, which breaks since Handlebars 4.6 because helper wrappers treat the last argument as options. Generate lookupProperty calls with a lowercased name instead. Fixes handlebars-lang#1912.
There was a problem hiding this comment.
Pull request overview
Updates the JavaScriptCompiler subclassing example in docs/compiler-api.md to work on Handlebars 4.6+ by avoiding the older helper-based nameLookup approach and illustrating how to generate case-insensitive context lookups.
Changes:
- Rewrites the example narrative and updates the sample to lower-case context path parts at compile time.
- Switches the subclass prototype setup to
Object.create(...)and removes the helper registration approach. - Documents why calling a registered helper from
nameLookupis unreliable since 4.6.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Updated the compiler example to lowercase the context name and then call the base |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are documentation-only and the updated example is aligned with current compiler internals, with only minor nits noted.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
|
|
||
| This example changes all lookups of properties are performed by a helper (`lookupLowerCase`) which looks for `test` if `{{Test}}` occurs in the template. This is just to illustrate how compiler behavior can be change. | ||
| This example makes context property lookups case-insensitive by lowercasing the | ||
| name at compile time, so `{{#each Test}}` / `{{Value}}` resolve `test` / `value`. |
| Handlebars.JavaScriptCompiler.apply(this, arguments); | ||
| } | ||
| MyCompiler.prototype = new Handlebars.JavaScriptCompiler(); | ||
| MyCompiler.prototype = Object.create(Handlebars.JavaScriptCompiler.prototype); |
|
Addressed the latest Copilot notes. The example now says the compiler should resolve to the context, and MyCompiler.prototype.constructor is set after Object.create so the subclass still points at MyCompiler. |
Summary
docs/compiler-api.mdso it works on Handlebars 4.6+.lookupProperty(...)with a lowercased name instead of calling a registered helper fromnameLookup.Object.createfor the prototype and note why the old helper-based approach fails.Fixes #1912
Test plan