Skip to content

SFC AST Node Reference

This is a quick reference for the <template> AST node types that vue-eslint-parser produces.

Node Types

VDocumentFragment

The root of the template AST. This is what sfcAST points to.

template
<template>
  <div>Hello</div>
</template>
PropertyTypeDescription
type'VDocumentFragment'
children(VElement | VText | VExpressionContainer | VStyleElement)[]Top-level nodes
parentnullAlways null

VElement

An HTML element or Vue component.

template
<div>...</div>
<MyComponent />
PropertyTypeDescription
type'VElement'
namestringLowercased for HTML elements, original case for components
rawNamestringTag name as written in source
namespaceNamespaceUsually NS.HTML
startTagVStartTag
children(VElement | VText | VExpressionContainer)[]
endTagVEndTag | nullNull for self-closing and void elements

VStartTag

The opening tag, including all attributes and directives.

template
<div id="app" v-if="show">
PropertyTypeDescription
type'VStartTag'
attributes(VAttribute | VDirective)[]Both static attributes and directives
selfClosingbooleantrue for <br />, <MyComponent />

VAttribute

A static attribute — no v- prefix, no : or @ shorthand.

template
<div class="container" id="app" disabled>
     ^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^
PropertyTypeDescription
type'VAttribute'
directivefalseThis is how you tell it apart from VDirective
keyVIdentifierAttribute name
valueVLiteral | nullNull for boolean attributes like disabled

VDirective

A Vue directive. :prop, @click, and #slot are all directives too — they're shorthands for v-bind, v-on, and v-slot.

Watch out: the AST type is 'VAttribute', not 'VDirective'. You need to check directive: true to tell them apart from static attributes.

template
<div v-if="show" :class="classes" @click="handler" v-model.trim="value">
     ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
PropertyTypeDescription
type'VAttribute'Same as VAttribute — check directive
directivetrue
keyVDirectiveKeyThe directive name, argument, and modifiers
valueVExpressionContainer | nullThe expression in quotes

VDirectiveKey

The name, argument, and modifiers of a directive — everything to the left of =.

v-on:click.prevent.stop
^^^^                      name     → VIdentifier (name: 'on')
     ^^^^^                argument → VIdentifier (name: 'click')
           ^^^^^^^ ^^^^   modifiers → VIdentifier[] (['prevent', 'stop'])
PropertyTypeDescription
type'VDirectiveKey'
nameVIdentifierif, bind, on, model, slot, etc.
argumentVExpressionContainer | VIdentifier | nullStatic arg = VIdentifier, dynamic [arg] = VExpressionContainer
modifiersVIdentifier[].prevent, .stop, .trim, etc.

Shorthands and their name values:

Syntaxkey.name.namekey.name.rawName
v-if'if''if'
v-for'for''for'
v-model'model''model'
:prop'bind'':'
@click'on''@'
#default'slot''#'

VExpressionContainer

Wraps a JavaScript expression. You'll see these in two places: directive values (v-if="expr") and text interpolation ().

template
<div v-if="count > 0">{{ message }}</div>
           ^^^^^^^^^    ^^^^^^^^^^^
PropertyTypeDescription
type'VExpressionContainer'
expressionJS expression | VForExpression | VOnExpression | VSlotScopeExpression | null

The expression inside is a regular JavaScript AST node (Identifier, BinaryExpression, MemberExpression, etc.), except for the special Vue expression types described below.

VIdentifier

Used for attribute names, directive names, directive arguments, and directive modifiers. This is not the same as a JavaScript Identifier.

template
<div class="foo" v-on:click.prevent="handler">
     ^^^^^         ^^ ^^^^^ ^^^^^^^
PropertyTypeDescription
type'VIdentifier'
namestringNormalized name
rawNamestringAs written in source (e.g. ':' for v-bind shorthand)

VLiteral

The quoted value of a static attribute.

template
<div class="container">
           ^^^^^^^^^^^
PropertyTypeDescription
type'VLiteral'
valuestring

VText

Plain text inside an element.

template
<p>Hello, world!</p>
   ^^^^^^^^^^^^^
PropertyTypeDescription
type'VText'
valuestring

VEndTag

The closing tag of an element. Not present on self-closing or void elements.

PropertyTypeDescription
type'VEndTag'

HtmlComment

An HTML comment. Can be attached to other nodes via their leadingComment property.

template
<!-- TODO: fix this -->
<div>content</div>
PropertyTypeDescription
type'HtmlComment'
valuestringThe comment text

Special Expression Types

These show up inside VExpressionContainer for certain directives.

VForExpression

The parsed v-for expression.

template
<div v-for="(item, index) in items">
             ^^^^  ^^^^^     ^^^^^
             left            right
PropertyTypeDescription
type'VForExpression'
leftPatternKind[]Iteration variables (item, index, etc.)
rightExpressionKindThe collection being iterated

VOnExpression

Used when v-on has multiple statements.

template
<button @click="doA(); doB()">
PropertyTypeDescription
type'VOnExpression'
bodyStatementKind[]

VSlotScopeExpression

The slot scope parameters.

template
<template #default="{ item, index }">
PropertyTypeDescription
type'VSlotScopeExpression'
paramsPatternKind[]

VFilterSequenceExpression / VFilter

Vue 2 filter syntax. Probably not relevant if you're working with Vue 3.

template
{{ message | capitalize | truncate(50) }}

Finding Nodes

Some common findAll patterns:

ts
// All <MyComponent> elements
astHelpers.findAll(sfcAST, { type: 'VElement', name: 'MyComponent' });

// All v-if directives
astHelpers.findAll(sfcAST, {
  type: 'VAttribute',
  directive: true,
  key: { type: 'VDirectiveKey', name: { name: 'if' } },
});

// All :prop bindings (v-bind shorthand)
astHelpers.findAll(sfcAST, {
  type: 'VAttribute',
  directive: true,
  key: { type: 'VDirectiveKey', name: { name: 'bind' } },
});

// All @click handlers
astHelpers.findAll(sfcAST, {
  type: 'VAttribute',
  directive: true,
  key: {
    type: 'VDirectiveKey',
    name: { name: 'on' },
    argument: { type: 'VIdentifier', name: 'click' },
  },
});

// All static class="..." attributes
astHelpers.findAll(sfcAST, {
  type: 'VAttribute',
  directive: false,
  key: { name: 'class' },
});