vue-parser-maintenance
Perform maintenance tasks for @markuplint/vue-parser: add Vue directives, modify element type
detection, update vue-eslint-parser version support, and fix comment injection.
Input
$ARGUMENTS specifies the task. Supported tasks:
| Task | Description |
|---|---|
add-directive | Add or modify a Vue directive in visitAttr() |
modify-element-type-detection | Update detectElementType() matchers |
update-vue-version-support | Handle vue-eslint-parser API changes |
fix-comment-injection | Fix template comment injection in flattenNodes() |
If omitted, defaults to add-directive.
Reference
Before executing any task, read docs/maintenance.md (or docs/maintenance.ja.md)
for the full guide. The recipes there are the source of truth for procedures.
Also read:
- •
ARCHITECTURE.md-- Package overview, directive processing, and element type detection - •
src/parser.ts-- VueParser class (source of truth for all override methods)
Task: add-directive
Add or modify a Vue directive in visitAttr(). Follow recipe #1 in docs/maintenance.md.
Step 1: Understand the directive
- •Read
src/parser.tsand find thevisitAttr()method - •Identify where in the priority chain the new directive should be processed
- •Determine whether the directive needs
potentialName,isDirective, orisDynamicValue
Step 2: Add the directive pattern
- •Create a new regex block following the existing pattern (scoped block with destructuring)
- •Use
attr.name.raw.match()to extract the directive prefix and value - •Set the appropriate metadata:
- •
potentialName— maps the directive to an equivalent HTML attribute name - •
isDirective— marks as a Vue-only directive with no HTML equivalent - •
isDynamicValue— indicates the attribute value is a JavaScript expression
- •
- •Check if the attribute should be in
duplicatableAttrs(e.g., class, style)
Step 3: Verify
- •Build:
yarn build --scope @markuplint/vue-parser - •Add test cases to
src/index.spec.tscovering:- •The directive with its full form (e.g.,
v-bind:prop) - •The shorthand form if applicable (e.g.,
:prop) - •Edge cases with modifiers (e.g.,
.stop,.lazy)
- •The directive with its full form (e.g.,
- •Test:
yarn test --scope @markuplint/vue-parser
Task: modify-element-type-detection
Update detectElementType() matchers. Follow recipe #2 in docs/maintenance.md.
Step 1: Understand current matchers
- •Read the
detectElementType()method insrc/parser.ts - •Review the matcher array: string literals for built-in components, regex for PascalCase
Step 2: Make the change
- •To add a new built-in component: add the component name as a string to the matcher array
- •To add a new pattern: add a regex to the matcher array
- •Components matching any entry return
'authored'element type
Step 3: Verify
- •Build:
yarn build --scope @markuplint/vue-parser - •Add test cases to the
elementTypetest block insrc/index.spec.ts - •Test:
yarn test --scope @markuplint/vue-parser
Task: update-vue-version-support
Handle vue-eslint-parser API changes. Follow recipe #3 in docs/maintenance.md.
Step 1: Understand the change
- •Read
src/vue-parser/index.ts— the wrapper around vue-eslint-parser - •Check the vue-eslint-parser changelog for breaking changes
- •Verify the
ASTNodeandASTCommenttype exports still match
Step 2: Make the change
- •Update
vueParse()if theparse()API signature changed - •Update type exports (
ASTNode,ASTComment,VueTokens) if AST types changed - •Update
tokenize()insrc/parser.tsiftemplateBodystructure changed
Step 3: Verify
- •Build:
yarn build --scope @markuplint/vue-parser - •Test:
yarn test --scope @markuplint/vue-parser - •Test with real Vue SFC files to ensure correct parsing
Task: fix-comment-injection
Fix template comment injection in flattenNodes(). Follow recipe #4 in docs/maintenance.md.
Step 1: Understand the issue
- •Read the
flattenNodes()method insrc/parser.ts - •Understand the two-pass approach: first flatten, then inject comments
- •Check how
this.state.commentsis populated intokenize()
Step 2: Fix the injection logic
- •Verify the comment range check:
lastOffset <= comment.range[0] && comment.range[1] <= node.startOffset - •Verify
this.visitComment()is called with the correctisBogusflag - •Verify
this.appendChild()correctly attaches the comment to the parent
Step 3: Verify
- •Build:
yarn build --scope @markuplint/vue-parser - •Test with Vue templates containing HTML comments (
<!-- -->), bogus comments (<!...>), and mixed content - •Test:
yarn test --scope @markuplint/vue-parser
Rules
- •Use vue-eslint-parser for all template parsing — never parse Vue templates manually.
- •Use
potentialNamefor directives that map to HTML attributes (e.g.,@click->onclick). - •Use
isDirective: truefor directives with no HTML equivalent (e.g.,v-if,v-for). - •Test with
nodeListToDebugMaps— this is the standard assertion pattern for parser tests. - •Add JSDoc comments to all new public methods and properties.
- •Preserve directive priority order in
visitAttr()—v-onbeforev-bindbeforev-modelbeforev-slotbefore genericv-.