Skip to content

Add onTemplateError so one bad template does not abort the parse - #80

Closed
NullVoxPopuli-ai-agent wants to merge 2 commits into
NullVoxPopuli:mainfrom
NullVoxPopuli-ai-agent:template-splice-fixes
Closed

NullVoxPopuli-ai-agent wants to merge 2 commits into
NullVoxPopuli:mainfrom
NullVoxPopuli-ai-agent:template-splice-fixes

Conversation

@NullVoxPopuli-ai-agent

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #82: this branch includes #82's commit, so the diff here shrinks to onTemplateError only once #82 merges (GitHub won't accept a fork branch as base). The last commit on the branch is the one to review.

A handlebars error in any <template> throws out of toTree mid-walk, so earlier visitor callbacks have fired and later ones never do. New option:

toTree(source, {
  onTemplateError(error, { range, contentRange, path }) { /* collect */ },
});

When provided, the failing template is left as its placeholder and the walk continues; path is the visitor path its GlimmerTemplate would have had. Without the option, behaviour is unchanged (still throws). Documented in README / index.d.ts, with tests.

Context: glint's standalone transform (typed-ember/glint#1226) parses each template itself and reports the error there; it only needs toTree to not abort.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FsXgxh6vNRWMCNcAQ3g6TN

@NullVoxPopuli-ai-agent
NullVoxPopuli-ai-agent force-pushed the template-splice-fixes branch 2 times, most recently from 79cbe27 to 1c2443a Compare August 25, 2026 05:37
NullVoxPopuli-ai-agent added a commit to NullVoxPopuli-ai-agent/glint that referenced this pull request Aug 25, 2026
Address review: no hand-rolled tree walk. Import bindings and template
placement come from `ImportDeclaration` / `GlimmerTemplate` visitor
callbacks, with `onTemplateError` (NullVoxPopuli/ember-estree#80)
supplying the path of a template that fails to parse so it is placed
like any other. The `this`-binding resolution is shared with the TS path
(`thisBindingFromAncestors`); each path only maps its own AST to the
ancestor kinds.

Also drop the generic `templateLocation` fallback in
`calculateTaggedTemplateSpans`: the only environment transform always
records it, so assert instead.

Needs ember-estree with typed-ember#80 (export default wrapper kept; onTemplateError).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsXgxh6vNRWMCNcAQ3g6TN
@NullVoxPopuli NullVoxPopuli added bug Something isn't working enhancement New feature or request labels Aug 25, 2026
`export default <template>...</template>` spliced the GlimmerTemplate in
place of the whole ExportDefaultDeclaration, so the tree and `print()`
both lost the `export default`. The declaration is now what gets spliced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsXgxh6vNRWMCNcAQ3g6TN
A handlebars error in any `<template>` threw out of `toTree` mid-walk,
taking every other template and visitor callback with it. When the new
`onTemplateError(error, { range, contentRange, path })` option is
provided, that template is left as its placeholder and the walk
continues; without it, behaviour is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsXgxh6vNRWMCNcAQ3g6TN
@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent changed the title Keep the export default wrapper and add onTemplateError Add onTemplateError so one bad template does not abort the parse Aug 25, 2026
@NullVoxPopuli-ai-agent

Copy link
Copy Markdown
Contributor Author

Not needed after all. Glint only wants the script analysis and parses templates itself, so it now blanks each template body (same length, tags kept) before calling toTree; ember-estree then never sees a handlebars error. #82 + #81 are sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants