ESTree-compatible AST parser for Ember's .gjs and .gts files.
Parses <template> tags into Glimmer AST nodes that are embedded directly in the ESTree, so tools like linters and codemods can work with both the JavaScript/TypeScript and template portions of a single file.
pnpm add ember-estreetoTree returns a File node whose .program is a standard ESTree Program, with any <template> regions represented as Glimmer* AST nodes.
import { toTree } from "ember-estree";
let ast = toTree(`
import Component from "@glimmer/component";
export default class Demo extends Component {
<template>Hello, {{this.name}}!</template>
}
`);
console.log(ast.type); // "File"
console.log(ast.program.body.length); // 2 — ImportDeclaration + ClassDeclarationparse is a lower-level alternative that returns the Program node directly.
import { parse } from "ember-estree";
let program = parse(`const x = <template>hi</template>;`);
console.log(program.type); // "Program"print converts an AST node (ESTree or Glimmer) back to source code.
import { print } from "ember-estree";
print({ type: "Identifier", name: "foo" });
// => "foo"
print({
type: "GlimmerTemplate",
body: [{ type: "GlimmerTextNode", chars: "Hello" }],
});
// => "<template>Hello</template>"The examples/ directory contains ready-to-run integrations:
| Example | Description |
|---|---|
eslint-parser |
Custom ESLint parser that understands <template> |
zmod |
Codemod toolkit using zmod |
MIT