Skip to content

SFC AST node reference ​

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

Node types ​

VDocumentFragment ​

The root of the entire SFC. The sfcAST parameter points to this node. Its children include top-level <template>, <script>, and <style> elements.

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

VElement ​

An HTML element or a Vue component.

template
<div>...</div>
<MyComponent />
PropertyTypeDescription
type'VElement'
namestringNormalized by the parser; HTML-namespace tags, including components, are lowercase
rawNamestringThe tag name as written in the source
namespaceNamespaceUsually NS.HTML
startTagVStartTag
children(VElement | VText | VExpressionContainer)[]
endTagVEndTag | nullnull for self-closing elements 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 /> and <MyComponent />

VAttribute ​

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

template
<div class="container" id="app" disabled>
     ^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^
PropertyTypeDescription
type'VAttribute'
directivefalseHow to tell this node apart from a VDirective node
keyVIdentifierThe attribute name
valueVLiteral | nullnull for boolean attributes such as disabled

VDirective ​

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

WARNING

The AST type of a directive is 'VAttribute', not 'VDirective'. To tell a directive apart from a static attribute, check for directive: true.

template
<div v-if="show" :class="classes" @click="handler" v-model.trim="value">
     ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
PropertyTypeDescription
type'VAttribute'The 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 the = sign.

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, and so on
argumentVExpressionContainer | VIdentifier | nullA static argument is a VIdentifier, and a dynamic [arg] is a VExpressionContainer
modifiersVIdentifier[].prevent, .stop, .trim, and so on

The following table lists the 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 in a directive value (v-if="expr"), text interpolation (), or dynamic directive argument (:[key]="value").

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, such as Identifier, BinaryExpression, or MemberExpression. The exceptions are the Vue expression types described in Special expression types.

VIdentifier ​

Used for attribute names, directive names, directive arguments, and directive modifiers. A VIdentifier node isn't the same as a JavaScript Identifier node.

template
<div class="foo" v-on:click.prevent="handler">
     ^^^^^         ^^ ^^^^^ ^^^^^^^
PropertyTypeDescription
type'VIdentifier'
namestringThe normalized name
rawNamestringThe name as written in the source — for example, ':' for the 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. Self-closing elements and void elements don't have one.

PropertyTypeDescription
type'VEndTag'

HtmlComment ​

An HTML comment. To attach a comment to another node, set the leadingComment property of that node.

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

Special expression types ​

The following node types appear inside a VExpressionContainer for certain directives.

VForExpression ​

The parsed v-for expression.

template
<div v-for="(item, index) in items">
             ^^^^  ^^^^^     ^^^^^
             left            right
PropertyTypeDescription
type'VForExpression'
leftPatternKind[]The iteration variables, such as item and index
rightExpressionKindThe collection that's iterated over

VOnExpression ​

Used when v-on has more than one statement.

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

VSlotScopeExpression ​

The slot scope parameters.

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

VFilterSequenceExpression and VFilter ​

Vue 2 filter syntax. Vue 3 doesn't support filters.

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

Find nodes ​

The following examples show common findAll patterns:

ts
// All <MyComponent> elements
astHelpers.findAll(sfcAST, { type: 'VElement', rawName: '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' },
});