@markuplint/parser-utils 4.5.0 → 4.6.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/attr-tokenizer.js +3 -1
- package/lib/debugger.js +1 -1
- package/lib/ignore-block.js +2 -0
- package/lib/parser.d.ts +2 -2
- package/lib/parser.js +2 -1
- package/lib/script-parser.d.ts +2 -1
- package/lib/script-parser.js +14 -11
- package/lib/types.d.ts +2 -0
- package/package.json +9 -6
package/lib/attr-tokenizer.js
CHANGED
|
@@ -23,6 +23,7 @@ export function attrTokenizer(raw, quoteSet = defaultQuoteSet, startState = Attr
|
|
|
23
23
|
let quoteStart = '';
|
|
24
24
|
let attrValue = '';
|
|
25
25
|
let valueType = noQuoteValueType;
|
|
26
|
+
let parser;
|
|
26
27
|
let quoteEnd = '';
|
|
27
28
|
const isBeforeValueStarted = startState === AttrState.BeforeValue;
|
|
28
29
|
const chars = [...raw];
|
|
@@ -105,6 +106,7 @@ export function attrTokenizer(raw, quoteSet = defaultQuoteSet, startState = Attr
|
|
|
105
106
|
if (quote) {
|
|
106
107
|
quoteStart = quote.start;
|
|
107
108
|
valueType = quote.type;
|
|
109
|
+
parser = quote.parser;
|
|
108
110
|
state = AttrState.Value;
|
|
109
111
|
break;
|
|
110
112
|
}
|
|
@@ -125,7 +127,7 @@ export function attrTokenizer(raw, quoteSet = defaultQuoteSet, startState = Attr
|
|
|
125
127
|
}
|
|
126
128
|
if (valueType === 'script') {
|
|
127
129
|
const raw = char + chars.join('');
|
|
128
|
-
const { validScript } = safeScriptParser(raw);
|
|
130
|
+
const { validScript } = safeScriptParser(raw, parser);
|
|
129
131
|
attrValue += validScript;
|
|
130
132
|
chars.splice(0, validScript.length - 1);
|
|
131
133
|
break;
|
package/lib/debugger.js
CHANGED
|
@@ -62,7 +62,7 @@ function tokenDebug(n, type = '') {
|
|
|
62
62
|
}
|
|
63
63
|
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
|
|
64
64
|
// @ts-ignore
|
|
65
|
-
n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}${'isGhost' in n && n.isGhost ? '(👻)' : ''}${'isBogus' in n && n.isBogus ? '(👿)' : ''}: ${visibleWhiteSpace(n.raw)}`;
|
|
65
|
+
n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}${'isGhost' in n && n.isGhost ? '(👻)' : ''}${'isBogus' in n && n.isBogus ? '(👿)' : ''}${'conditionalType' in n && n.conditionalType ? ` (${n.conditionalType})` : ''}: ${visibleWhiteSpace(n.raw)}`;
|
|
66
66
|
}
|
|
67
67
|
function visibleWhiteSpace(chars) {
|
|
68
68
|
return chars.replaceAll('\n', '⏎').replaceAll('\t', '→').replaceAll(/\s/g, '␣');
|
package/lib/ignore-block.js
CHANGED
|
@@ -73,6 +73,7 @@ ignoreBlock, throwErrorWhenTagHasUnresolved = true) {
|
|
|
73
73
|
const psNode = {
|
|
74
74
|
...token,
|
|
75
75
|
type: 'psblock',
|
|
76
|
+
conditionalType: null,
|
|
76
77
|
depth: node.depth,
|
|
77
78
|
nodeName: `#ps:${tag.type}`,
|
|
78
79
|
parentNode: node.parentNode,
|
|
@@ -102,6 +103,7 @@ ignoreBlock, throwErrorWhenTagHasUnresolved = true) {
|
|
|
102
103
|
const psNode = {
|
|
103
104
|
...token,
|
|
104
105
|
type: 'psblock',
|
|
106
|
+
conditionalType: null,
|
|
105
107
|
depth: node.depth,
|
|
106
108
|
nodeName: `#ps:${tag.type}`,
|
|
107
109
|
parentNode: node.parentNode,
|
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 } from '@markuplint/ml-ast';
|
|
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';
|
|
3
3
|
import { AttrState } from './enums.js';
|
|
4
4
|
import { ParserError } from './parser-error.js';
|
|
5
5
|
export declare abstract class Parser<Node extends {} = {}, State extends unknown = null> implements MLParser {
|
|
@@ -71,7 +71,7 @@ export declare abstract class Parser<Node extends {} = {}, State extends unknown
|
|
|
71
71
|
}): readonly MLASTNodeTreeItem[];
|
|
72
72
|
visitPsBlock(token: ChildToken & {
|
|
73
73
|
readonly nodeName: string;
|
|
74
|
-
}, childNodes?: readonly Node[], originBlockNode?: Node): readonly MLASTNodeTreeItem[];
|
|
74
|
+
}, childNodes?: readonly Node[], conditionalType?: MLASTPreprocessorSpecificBlockConditionalType, originBlockNode?: Node): readonly MLASTNodeTreeItem[];
|
|
75
75
|
visitChildren(children: readonly Node[], parentNode: MLASTParentNode | null): readonly MLASTNodeTreeItem[];
|
|
76
76
|
visitSpreadAttr(token: Token): MLASTSpreadAttr | null;
|
|
77
77
|
visitAttr(token: Token, options?: {
|
package/lib/parser.js
CHANGED
|
@@ -308,11 +308,12 @@ export class Parser {
|
|
|
308
308
|
}
|
|
309
309
|
return [startTag, ...siblings];
|
|
310
310
|
}
|
|
311
|
-
visitPsBlock(token, childNodes = [], originBlockNode) {
|
|
311
|
+
visitPsBlock(token, childNodes = [], conditionalType = null, originBlockNode) {
|
|
312
312
|
const block = {
|
|
313
313
|
...token,
|
|
314
314
|
...this.createToken(token),
|
|
315
315
|
type: 'psblock',
|
|
316
|
+
conditionalType,
|
|
316
317
|
nodeName: `#ps:${token.nodeName}`,
|
|
317
318
|
childNodes: [],
|
|
318
319
|
isBogus: false,
|
package/lib/script-parser.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CustomParser } from './types.js';
|
|
1
2
|
export declare function scriptParser(script: string): ScriptTokenType[];
|
|
2
|
-
export declare function safeScriptParser(script: string): {
|
|
3
|
+
export declare function safeScriptParser(script: string, parse?: CustomParser): {
|
|
3
4
|
validScript: string;
|
|
4
5
|
leftover: string;
|
|
5
6
|
};
|
package/lib/script-parser.js
CHANGED
|
@@ -10,19 +10,19 @@ export function scriptParser(script) {
|
|
|
10
10
|
value: token.value,
|
|
11
11
|
}));
|
|
12
12
|
}
|
|
13
|
-
export function safeScriptParser(script) {
|
|
14
|
-
let { validScript, leftover } = safeParse(script);
|
|
13
|
+
export function safeScriptParser(script, parse = defaultParse) {
|
|
14
|
+
let { validScript, leftover } = safeParse(script, parse);
|
|
15
15
|
// Support for object literal
|
|
16
16
|
if (leftover.trim()) {
|
|
17
17
|
const assignment = '$=';
|
|
18
|
-
({ validScript } = safeParse(`${assignment}${script}
|
|
18
|
+
({ validScript } = safeParse(`${assignment}${script}`, parse));
|
|
19
19
|
validScript = validScript.length > assignment.length ? validScript.slice(assignment.length) : '';
|
|
20
20
|
}
|
|
21
21
|
// Support for spread operator
|
|
22
22
|
if (validScript.trim() === '') {
|
|
23
23
|
const coverStart = '$={';
|
|
24
24
|
const coverEnd = '}';
|
|
25
|
-
({ validScript } = safeParse(`${coverStart}${script}${coverEnd}
|
|
25
|
+
({ validScript } = safeParse(`${coverStart}${script}${coverEnd}`, parse));
|
|
26
26
|
const coverEndLastIndex = validScript.lastIndexOf(coverEnd);
|
|
27
27
|
validScript =
|
|
28
28
|
validScript.length > coverStart.length + coverEnd.length
|
|
@@ -35,16 +35,11 @@ export function safeScriptParser(script) {
|
|
|
35
35
|
leftover,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function safeParse(script) {
|
|
38
|
+
function safeParse(script, parse) {
|
|
39
39
|
let validScript;
|
|
40
40
|
let leftover;
|
|
41
41
|
try {
|
|
42
|
-
parse(script
|
|
43
|
-
ecmaVersion: 'latest',
|
|
44
|
-
ecmaFeatures: {
|
|
45
|
-
jsx: true,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
42
|
+
parse(script);
|
|
48
43
|
validScript = script;
|
|
49
44
|
leftover = '';
|
|
50
45
|
}
|
|
@@ -67,3 +62,11 @@ function safeParse(script) {
|
|
|
67
62
|
leftover,
|
|
68
63
|
};
|
|
69
64
|
}
|
|
65
|
+
function defaultParse(script) {
|
|
66
|
+
parse(script, {
|
|
67
|
+
ecmaVersion: 'latest',
|
|
68
|
+
ecmaFeatures: {
|
|
69
|
+
jsx: true,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/parser-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Utility module for markuplint parser plugin",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -27,14 +27,17 @@
|
|
|
27
27
|
"clean": "tsc --build --clean"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@markuplint/ml-ast": "4.
|
|
31
|
-
"@markuplint/ml-spec": "4.
|
|
32
|
-
"@markuplint/types": "4.
|
|
30
|
+
"@markuplint/ml-ast": "4.3.0",
|
|
31
|
+
"@markuplint/ml-spec": "4.5.0",
|
|
32
|
+
"@markuplint/types": "4.4.0",
|
|
33
33
|
"@types/uuid": "9.0.8",
|
|
34
34
|
"debug": "4.3.4",
|
|
35
35
|
"espree": "10.0.1",
|
|
36
|
-
"type-fest": "4.
|
|
36
|
+
"type-fest": "4.18.1",
|
|
37
37
|
"uuid": "9.0.1"
|
|
38
38
|
},
|
|
39
|
-
"
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@typescript-eslint/typescript-estree": "7.8.0"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "b8d7bae9bdcdad63ff79abe21b88be12abde3633"
|
|
40
43
|
}
|