core-ast-ts-plugin-astro
v0.1.0
Published
Astro component parser plugin for core-ast-ts — parses .astro files using @astrojs/compiler and produces ESTree AST
Readme
core-ast-ts-plugin-astro
Astro component parser plugin for core-ast-ts.
Parses .astro files using @astrojs/compiler and produces an ESTree AST from the frontmatter script block, with the full Astro AST attached as meta.
Install
npm install core-ast-ts-plugin-astroUsage
import { coreAst } from 'core-ast-ts'
import astro from 'core-ast-ts-plugin-astro'
const ast = coreAst({ plugins: [astro()] })
const { ast: program, meta } = await ast.get('index.astro', source)
// meta.astroAst — full Astro AST from @astrojs/compiler
// meta.frontmatter — extracted frontmatter source (between --- delimiters)
// meta.componentName — derived from filename (e.g. 'index')
// meta.hasFrontmatter — whether frontmatter existsNote: The Astro plugin's
parse()is async (returns a Promise) because@astrojs/compiler'sparse()is async. Useawaitwhen callingast.get().
Options
import astro from 'core-ast-ts-plugin-astro'
const ast = coreAst({
plugins: [astro({
position: false, // include position data in AST (default: false)
})],
})| Option | Default | Description |
|--------|---------|-------------|
| position | false | Include position data in Astro AST |
How it works
- Calls
@astrojs/compilerparse()to get the Astro AST - Extracts frontmatter source (content between
---delimiters) - Parses frontmatter as JS/TS module via
core-ast-tscore parser - Returns
{ ast, source, meta }wheremetacontains the Astro AST and derived info
This keeps @astrojs/compiler as a dependency of this plugin only — core-ast-ts core stays lightweight.
License
MIT
