core-ast-ts-plugin-vue3
v0.1.0
Published
Vue 3 SFC plugin for core-ast-ts — parses .vue files using @vue/compiler-sfc and produces ESTree AST
Readme
@core-ast-ts/plugin-vue3
Vue 3 Single File Component parser plugin for core-ast-ts.
Parses .vue files using @vue/compiler-sfc and produces an ESTree AST from the <script> / <script setup> block, with the full SFC descriptor attached as meta.
Install
npm install @core-ast-ts/plugin-vue3Usage
import { coreAst } from 'core-ast-ts'
import vue3 from '@core-ast-ts/plugin-vue3'
const ast = coreAst({ plugins: [vue3()] })
const { ast: program, meta } = ast.get('App.vue', source)
// meta.sfcDescriptor — full SFC descriptor from @vue/compiler-sfc
// meta.scriptContent — extracted script block source
// meta.componentName — derived from filename (e.g. 'App')
// meta.isSetup — whether <script setup> is used
// meta.lang — script language (e.g. 'ts', 'js')Options
import vue3 from '@core-ast-ts/plugin-vue3'
const ast = coreAst({
plugins: [vue3({
includeTemplate: true, // attach template content to meta
includeStyles: true, // attach style info to meta
})],
})| Option | Default | Description |
|--------|---------|-------------|
| includeTemplate | false | Attach meta.templateContent and meta.templateLang |
| includeStyles | false | Attach meta.styles array with content, lang, scoped |
How it works
- Calls
@vue/compiler-sfcparse()to get the SFC descriptor - Extracts the
<script setup>or<script>block content - Parses the script content into an ESTree AST via
core-ast-tscore parser - Returns
{ ast, source, meta }wheremetacontains the SFC descriptor and derived info
This keeps @vue/compiler-sfc as a dependency of this plugin only — core-ast-ts core stays lightweight.
License
MIT
