Skip to content

Integrate Glint for current-file TS transform (Phase 2)#157

Draft
wagenet wants to merge 3 commits intoember-tooling:mainfrom
wagenet:glint-phase-2
Draft

Integrate Glint for current-file TS transform (Phase 2)#157
wagenet wants to merge 3 commits intoember-tooling:mainfrom
wagenet:glint-phase-2

Conversation

@wagenet
Copy link
Contributor

@wagenet wagenet commented Mar 4, 2026

Summary

  • Adds a Glint-based parsing path for .gts/.gjs files that uses Glint's transform to produce __glintDSL__ calls TypeScript understands, then remaps AST positions back to original source and splices in Glimmer AST
  • New remap.js module handles offset mapping from Glint's transformed-space back to original-space for both AST nodes and tokens
  • Refactors preprocessGlimmerTemplates into a shared processGlimmerTemplates core, with a new preprocessGlimmerTemplatesFromCharOffsets variant for the Glint path
  • Extends convertAst with matchByRangeOnly option to handle Glint's different node types (CallExpression vs TemplateLiteral)
  • Falls back gracefully to the existing non-Glint path on failure

Test plan

  • Verify existing tests still pass (non-Glint path unchanged)
  • Test with a project that has Glint configured to validate the new path
  • Add unit tests for remapOffset, remapAstPositions, remapTokens
  • Add integration test for parseWithGlint with a simple .gts file

🤖 Generated with Claude Code

wagenet and others added 3 commits February 26, 2026 18:04
When @glint/ember-tsc is installed and a glint environment is configured
in tsconfig, use Glint's rewriteModule() instead of transformForLint()
to generate virtual .mts/.mjs file contents in the TS patch. This gives
TypeScript proper type understanding of imported .gts/.gjs modules.

Falls back to the existing transformForLint path when Glint is
unavailable (not installed, Node < 22.12, no glint config, or transform
error).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a Glint-based code path in parseForESLint that uses
rewriteModule() for the file being linted, giving the TS type
checker full understanding of template semantics. Positions are
remapped from Glint's transformed-space back to original-space
using correlatedSpans, then Glimmer AST is spliced in.

- Create src/parser/remap.js with position remapping utilities
- Add buildTemplateInfoFromGlint to glint-utils.js
- Refactor preprocessGlimmerTemplates; add char-offset variant
- Add matchByRangeOnly option to convertAst for Glint node types
- Export ts instance from ts-patch.js
- Add parseWithGlint orchestration in gjs-gts-parser.js

Falls back to existing transformForLint path when Glint is
unavailable or rewriteModule returns null.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove orphaned JSDoc block from transforms.js
- Restore removed "why" comments in processGlimmerTemplates
- Narrow matchByRangeOnly to Glint-specific node types instead
  of matching all AST nodes
- Guard token splice against findIndex returning -1
- Deduplicate buildTemplateInfoFromGlint by originalStart offset
- Remove unused templateNodes collection from remap.js
- Log e.stack instead of e.message in Glint fallback catch
- Remove unused preprocessedResult.code assignment

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wagenet wagenet marked this pull request as draft March 4, 2026 15:22
@NullVoxPopuli
Copy link
Member

conflicts!

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.

2 participants