@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/ARCHITECTURE.ja.md +6 -6
- package/ARCHITECTURE.md +5 -5
- package/CHANGELOG.md +31 -0
- package/docs/parser-class.ja.md +6 -6
- package/docs/parser-class.md +6 -6
- package/lib/debug.js +8 -24
- package/lib/debugger.js +9 -4
- package/lib/get-location.d.ts +31 -0
- package/lib/get-location.js +33 -0
- package/lib/get-namespace.d.ts +9 -0
- package/lib/get-namespace.js +9 -0
- package/lib/ignore-block.js +15 -14
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/parser-error.js +8 -3
- package/lib/parser.d.ts +12 -16
- package/lib/parser.js +502 -552
- package/lib/sort-nodes.d.ts +8 -0
- package/lib/sort-nodes.js +11 -3
- package/lib/types.d.ts +3 -3
- package/package.json +10 -9
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,
|
|
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
|
|
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
|
|
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[],
|
|
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
|
|
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, '
|
|
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
|
|
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
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @returns
|
|
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,
|
|
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.
|