ml-ast-maintenance
Perform maintenance tasks for @markuplint/ml-ast: add AST node types,
add fields to existing nodes, add conditional type values, and update the parser interface.
Input
$ARGUMENTS specifies the task. Supported tasks:
| Task | Description |
|---|---|
add-node-type <name> | Add a new AST node type |
add-field <node> <field> | Add a field to an existing node type |
add-conditional-type <value> | Add a conditional type value for psblock nodes |
update-parser-interface | Modify the MLParser interface |
If omitted, defaults to add-node-type.
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:
- •
docs/node-reference.md-- Detailed documentation of each AST node type - •
ARCHITECTURE.md-- Package overview, type hierarchy, and integration points
Task: add-node-type
Add a new AST node type. Follow recipe #1 in docs/maintenance.md.
Step 1: Define the type
- •Read
src/types.tsto understand the existing type hierarchy - •Add the type value to
MLASTNodeType - •Define the interface extending
MLASTAbstractNode - •Add to relevant union types (
MLASTNode,MLASTChildNode, etc.)
Step 2: Update downstream
- •Update
ml-core'screateNode()inpackages/@markuplint/ml-core/src/ml-dom/helper/create-node.ts - •Add a
casefor the new type value in theswitchstatement - •Create or reuse an appropriate DOM node class
Step 3: Build and verify
- •Build:
yarn build --scope @markuplint/ml-ast - •Build:
yarn build --scope @markuplint/ml-core - •Check the downstream impact checklist in
docs/maintenance.md
Task: add-field
Add a field to an existing node type. Follow recipe #2 in docs/maintenance.md.
Step 1: Add the field
- •Read
src/types.tsand find the target interface - •Add the field (prefer optional
?for backward compatibility) - •Add JSDoc documentation for the new field
Step 2: Update consumers
- •Update parsers that should populate the new field
- •Update
ml-coreif the field affects DOM node creation
Step 3: Build and verify
- •Build:
yarn build --scope @markuplint/ml-ast - •Build affected packages
- •Check the downstream impact checklist in
docs/maintenance.md
Task: add-conditional-type
Add a conditional type value for preprocessor-specific blocks. Follow recipe #4 in docs/maintenance.md.
Step 1: Add the value
- •Read
src/types.tsand findMLASTPreprocessorSpecificBlockConditionalType - •Add the new value to the union type
- •Document the value's semantic meaning in the JSDoc comment
Step 2: Update parsers
- •Update the parser that produces blocks with this conditional type
- •Verify the value follows the naming convention (
category:variant, e.g.,if:elseif)
Step 3: Build and verify
- •Build:
yarn build --scope @markuplint/ml-ast - •Build the affected parser package
Task: update-parser-interface
Modify the MLParser interface. Follow recipe #5 in docs/maintenance.md.
Step 1: Make changes
- •Read
src/types.tsand findMLParser - •Make changes (prefer adding optional fields for backward compatibility)
- •Update
MLMarkupLanguageParser(deprecated) if needed for consistency
Step 2: Update all parsers
- •Update all parser implementations (see the list in
docs/maintenance.mdrecipe #5) - •Update
@markuplint/parser-utilsif it provides shared implementation
Step 3: Build and verify
- •Build all packages:
yarn build - •Run all tests:
yarn test
Rules
- •All node types extend
MLASTAbstractNode(except attributes which extendMLASTToken). - •Use
readonlyfor all interface fields. The AST is immutable after parsing. - •Prefer optional fields when adding to existing interfaces for backward compatibility.
- •Always update
createNode()inml-corewhen adding new node types. - •Follow the discriminated union pattern. Every node must have a unique
typeliteral value. - •Add JSDoc comments to all new exported types and fields.