Skip to content

docs: fix broken JavaScriptCompiler subclass example - #2173

Open
Hashim1999164 wants to merge 3 commits into
handlebars-lang:masterfrom
Hashim1999164:fix/compiler-api-docs-example
Open

Hashim1999164 wants to merge 3 commits into
handlebars-lang:masterfrom
Hashim1999164:fix/compiler-api-docs-example

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Jul 22, 2026 •

Copy link
Copy Markdown

Summary

  • Update the JavaScriptCompiler subclass example in docs/compiler-api.md so it works on Handlebars 4.6+.
  • Generate lookupProperty(...) with a lowercased name instead of calling a registered helper from nameLookup.
  • Use Object.create for the prototype and note why the old helper-based approach fails.

Fixes #1912

Test plan

  • Confirm the compiler-api docs example matches current Handlebars compiler internals
  • Spot-check that the documented approach works on Handlebars 4.6+

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 nameLookup is unreliable since 4.6.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/compiler-api.md Outdated
Comment thread docs/compiler-api.md Outdated
Co-authored-by: Cursor <cursoragent@cursor.com>
@Hashim1999164

Copy link
Copy Markdown
Author

Updated the compiler example to lowercase the context name and then call the base nameLookup, and changed the description to use {{#each Test}} / {{Value}} instead of {{Test}}.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

Comment thread docs/compiler-api.md Outdated

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`.
Comment thread docs/compiler-api.md
Handlebars.JavaScriptCompiler.apply(this, arguments);
}
MyCompiler.prototype = new Handlebars.JavaScriptCompiler();
MyCompiler.prototype = Object.create(Handlebars.JavaScriptCompiler.prototype);
@Hashim1999164

Copy link
Copy Markdown
Author

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.

@jaylinski
jaylinski requested a lite review from Copilot September 10, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

The JavaScriptCompiler API docs sample code is broken as of 4.6

2 participants