jsx-parser-maintenance
Perform maintenance tasks for @markuplint/jsx-parser: add IDL attribute mappings,
handle new JSX/TypeScript AST node types, and modify element type detection.
Input
$ARGUMENTS specifies the task. Supported tasks:
| Task | Description |
|---|---|
add-idl-attribute-mapping | Add a new IDL-to-content attribute mapping |
add-jsx-node-type-handling | Handle a new AST node type in recursiveSearchJSXElements |
modify-element-type-detection | Modify the element type detection regex |
If omitted, defaults to add-jsx-node-type-handling.
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, JSX AST extraction, nodeize dispatch, and attribute processing - •
src/parser.ts-- JSXParser class (source of truth for override methods) - •
src/jsx.ts-- JSX AST extraction utilities (source of truth for recursiveSearchJSXElements)
Task: add-idl-attribute-mapping
Add a new IDL-to-content attribute mapping for JSX. Follow recipe #1 in docs/maintenance.md.
Step 1: Add the mapping
- •Read
@markuplint/parser-utils/src/idl-attributes.ts - •Add the new entry to the
idlContentMapobject (key = IDL property name, value = content attribute name) - •The
searchIDLAttribute()function will automatically pick up the new mapping
Step 2: Verify
- •Build:
yarn build --scope @markuplint/parser-utils --scope @markuplint/jsx-parser - •Add a test case in
src/index.spec.tsusingattributesToDebugMapsto verify thepotentialNameis set correctly - •Test:
yarn test --scope @markuplint/jsx-parser
Task: add-jsx-node-type-handling
Handle a new AST node type in recursiveSearchJSXElements(). Follow recipe #2 in docs/maintenance.md.
Step 1: Identify the new node type
- •Read
src/jsx.tsand locate therecursiveSearchJSXElements()function - •Identify the new
AST_NODE_TYPESvalue from@typescript-eslint/types - •Determine which properties of the node may contain JSX (check the TSESTree type definition)
Step 2: Add the case
- •Add a new
case AST_NODE_TYPES.NewType:in the appropriate position within the switch - •Recurse into the properties that can contain JSX elements:
- •Array properties:
recursiveSearchJSXElements(node.someArray, parentId) - •Nullable single properties:
recursiveSearchJSXElements([node.someProp ?? null], parentId)
- •Array properties:
- •End with
continue;
Step 3: Verify
- •Build:
yarn build --scope @markuplint/jsx-parser - •Add a test case in
src/index.spec.tswith source code that uses the new syntax - •Test:
yarn test --scope @markuplint/jsx-parser
Task: modify-element-type-detection
Modify the element type detection regex. Follow recipe #3 in docs/maintenance.md.
Step 1: Understand the current regex
- •Read
src/parser.tsand locate thedetectElementType()method - •The current regex is
/^[A-Z]|\./(uppercase start = component, dot = member expression)
Step 2: Modify the regex
- •Update the regex pattern passed to
super.detectElementType(nodeName, pattern) - •Consider the three element types:
html,authored,web-component
Step 3: Verify
- •Build:
yarn build --scope @markuplint/jsx-parser - •Update the
isCustomElementtest insrc/index.spec.ts - •Test:
yarn test --scope @markuplint/jsx-parser
Rules
- •Use
@typescript-eslint/typescript-estreefor parsing -- never use a custom JSX parser or regex-based approach. - •Use
searchIDLAttribute()for attribute mapping -- IDL-to-content attribute mappings live in@markuplint/parser-utils, not in this package. - •Test with
nodeListToDebugMaps-- all integration tests use this pattern for snapshot-style assertions. - •Handle all AST node types exhaustively --
recursiveSearchJSXElements()must handle everyAST_NODE_TYPESvalue; unhandled types throw'Unsupported node'. - •Preserve
#parentIdMaptracking -- every nodeize branch must register created nodes in the WeakMap for correct parent-child rebuilding. - •Add JSDoc comments to all new public methods and properties.