@markuplint/parser-utils 4.8.11 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Token, ChildToken, QuoteSet, ParseOptions, ParserOptions, Tokenized, ValueType } from './types.js';
2
- import type { EndTagType, MLASTDocument, MLASTParentNode, MLParser, ParserAuthoredElementNameDistinguishing, MLASTElement, MLASTElementCloseTag, MLASTToken, MLASTNodeTreeItem, MLASTTag, MLASTText, MLASTAttr, MLASTChildNode, MLASTSpreadAttr, ElementType, Walker, MLASTHTMLAttr, MLASTPreprocessorSpecificBlockConditionalType } from '@markuplint/ml-ast';
2
+ import type { EndTagType, MLASTDocument, MLASTParentNode, MLParser, ParserAuthoredElementNameDistinguishing, MLASTElement, MLASTElementCloseTag, MLASTToken, MLASTNodeTreeItem, MLASTTag, MLASTText, MLASTAttr, MLASTChildNode, MLASTSpreadAttr, ElementType, Walker, MLASTHTMLAttr, MLASTBlockBehavior } from '@markuplint/ml-ast';
3
3
  import { AttrState } from './enums.js';
4
4
  import { ParserError } from './parser-error.js';
5
5
  /**
@@ -209,14 +209,13 @@ export declare abstract class Parser<Node extends {} = {}, State extends unknown
209
209
  * and recursively traversed child nodes. Handles ghost elements (empty raw),
210
210
  * self-closing tags, and nameless fragments (e.g., JSX `<>`).
211
211
  *
212
- * @param token - The child token with the element's node name and namespace
212
+ * @param token - The child token with the element's node name; namespace is auto-detected from tag name and parent node
213
213
  * @param childNodes - The language-specific child AST nodes to traverse
214
214
  * @param options - Controls end tag creation, fragment handling, and property overrides
215
215
  * @returns An array of AST nodes including the start tag, optional end tag, and any sibling nodes
216
216
  */
217
217
  visitElement(token: ChildToken & {
218
218
  readonly nodeName: string;
219
- readonly namespace: string;
220
219
  }, childNodes?: readonly Node[], options?: {
221
220
  readonly createEndTagToken?: (startTag: MLASTElement) => ChildToken | null;
222
221
  readonly namelessFragment?: boolean;
@@ -228,14 +227,14 @@ export declare abstract class Parser<Node extends {} = {}, State extends unknown
228
227
  *
229
228
  * @param token - The child token with the block's node name and fragment flag
230
229
  * @param childNodes - The language-specific child AST nodes to traverse
231
- * @param conditionalType - The conditional type if this is a conditional block (e.g., "if", "else")
230
+ * @param blockBehavior - The block behavior if this is a control-flow block (e.g., "if", "each")
232
231
  * @param originBlockNode - The original language-specific block node for reference
233
232
  * @returns An array of AST nodes including the block node and any sibling nodes
234
233
  */
235
234
  visitPsBlock(token: ChildToken & {
236
235
  readonly nodeName: string;
237
236
  readonly isFragment: boolean;
238
- }, childNodes?: readonly Node[], conditionalType?: MLASTPreprocessorSpecificBlockConditionalType, originBlockNode?: Node): readonly MLASTNodeTreeItem[];
237
+ }, childNodes?: readonly Node[], blockBehavior?: MLASTBlockBehavior | null, originBlockNode?: Node): readonly MLASTNodeTreeItem[];
239
238
  /**
240
239
  * Traverses a list of child nodes under the given parent, appending the resulting
241
240
  * child AST nodes to the parent and returning any sibling nodes that belong
@@ -285,18 +284,15 @@ export declare abstract class Parser<Node extends {} = {}, State extends unknown
285
284
  readonly namelessFragment?: boolean;
286
285
  }): (MLASTTag | MLASTText)[];
287
286
  /**
288
- * Updates the position and depth properties of an AST node, recalculating
289
- * end offsets, lines, and columns based on the new start values.
287
+ * Updates the position and depth properties of an AST node.
290
288
  *
291
289
  * @param node - The AST node whose location should be updated
292
290
  * @param props - The new position and depth values to apply (only provided values are changed)
293
291
  */
294
- updateLocation(node: MLASTNodeTreeItem, props: Partial<Pick<MLASTNodeTreeItem, 'startOffset' | 'startLine' | 'startCol' | 'depth'>>): void;
292
+ updateLocation(node: MLASTNodeTreeItem, props: Partial<Pick<MLASTNodeTreeItem, 'offset' | 'line' | 'col' | 'depth'>>): void;
295
293
  /**
296
294
  * Set new raw code to target node.
297
295
  *
298
- * Replace the raw code and update the start/end offset/line/column.
299
- *
300
296
  * @param node target node
301
297
  * @param raw new raw code
302
298
  */
@@ -329,17 +325,17 @@ export declare abstract class Parser<Node extends {} = {}, State extends unknown
329
325
  */
330
326
  detectElementType(nodeName: string, defaultPattern?: ParserAuthoredElementNameDistinguishing): ElementType;
331
327
  /**
332
- * Creates a new MLASTToken with a generated UUID and computed end position.
328
+ * Creates a new MLASTToken with a generated UUID.
333
329
  * Accepts either a Token object or a raw string with explicit start coordinates.
334
330
  *
335
331
  * @param token - A Token object or raw string to create the AST token from
336
- * @param startOffset - The byte offset where the token starts (required when token is a string)
337
- * @param startLine - The line number where the token starts (required when token is a string)
338
- * @param startCol - The column number where the token starts (required when token is a string)
339
- * @returns A fully populated AST token with UUID, start/end positions, and raw content
332
+ * @param offset - The zero-based byte offset where the token starts (required when token is a string)
333
+ * @param line - The one-based line number where the token starts (required when token is a string)
334
+ * @param col - The one-based column number where the token starts (required when token is a string)
335
+ * @returns An AST token with UUID, start position, and raw content
340
336
  */
341
337
  createToken(token: Token): MLASTToken;
342
- createToken(token: string, startOffset: number, startLine: number, startCol: number): MLASTToken;
338
+ createToken(token: string, offset: number, line: number, col: number): MLASTToken;
343
339
  /**
344
340
  * Extracts a Token from the current raw code at the given byte offset range,
345
341
  * computing the line and column from the source position.