@markuplint/svelte-parser 3.3.1 → 3.5.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.d.ts +3 -8
- package/lib/attr.js +4 -2
- package/lib/directive-tokenizer.d.ts +1 -7
- package/lib/directive-tokenizer.js +9 -8
- package/lib/index.d.ts +1 -1
- package/lib/nodeize.d.ts +1 -7
- package/lib/nodeize.js +15 -80
- package/lib/parse-ctrl-block.d.ts +3 -0
- package/lib/parse-ctrl-block.js +181 -0
- package/lib/parse.js +2 -2
- package/lib/traverse.d.ts +1 -6
- package/lib/traverse.js +8 -2
- package/package.json +6 -6
package/lib/attr.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { SvelteDirective } from './svelte-parser';
|
|
2
2
|
import type { MLASTAttr } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function attr(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
):
|
|
7
|
-
| MLASTAttr
|
|
8
|
-
| {
|
|
9
|
-
__spreadAttr: true;
|
|
10
|
-
};
|
|
3
|
+
export declare function attr(attr: SvelteDirective, rawHTML: string): MLASTAttr | {
|
|
4
|
+
__spreadAttr: true;
|
|
5
|
+
};
|
package/lib/attr.js
CHANGED
|
@@ -6,7 +6,9 @@ const html_parser_1 = require("@markuplint/html-parser");
|
|
|
6
6
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
7
7
|
const directive_tokenizer_1 = tslib_1.__importDefault(require("./directive-tokenizer"));
|
|
8
8
|
const specificBindDirective = ['bind:group', 'bind:this'];
|
|
9
|
-
function attr(
|
|
9
|
+
function attr(
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
|
+
attr, rawHTML) {
|
|
10
12
|
const isShorthand = attr.value && Array.isArray(attr.value)
|
|
11
13
|
? attr.value.some((val) => val.type === 'AttributeShorthand')
|
|
12
14
|
: false;
|
|
@@ -46,7 +48,7 @@ function attr(attr, rawHTML) {
|
|
|
46
48
|
token.isDynamicValue = true;
|
|
47
49
|
}
|
|
48
50
|
const [baseName, subName] = token.name.raw.split(':');
|
|
49
|
-
if (baseName.toLowerCase() === 'class') {
|
|
51
|
+
if ((baseName === null || baseName === void 0 ? void 0 : baseName.toLowerCase()) === 'class') {
|
|
50
52
|
token.isDuplicatable = true;
|
|
51
53
|
if (subName) {
|
|
52
54
|
token.potentialName = 'class';
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
|
|
2
|
-
export default function directiveTokenizer(
|
|
3
|
-
raw: string,
|
|
4
|
-
rawValue: string,
|
|
5
|
-
line: number,
|
|
6
|
-
col: number,
|
|
7
|
-
startOffset: number,
|
|
8
|
-
): MLASTHTMLAttr;
|
|
2
|
+
export default function directiveTokenizer(raw: string, rawValue: string, line: number, col: number, startOffset: number): MLASTHTMLAttr;
|
|
@@ -9,6 +9,7 @@ const reBeforeStructure = /^(\s*)([^\x00-\x1f\x7f-\x9f {>/=]+)(\s*)(=)(\s*){(\s*
|
|
|
9
9
|
const reBeforeStructureWithoutName = /^{(\s*)$/;
|
|
10
10
|
const reAfterStructure = /(\s*)}/;
|
|
11
11
|
function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
12
|
+
var _a, _b, _c, _d, _e;
|
|
12
13
|
let spacesBeforeAttrString = '';
|
|
13
14
|
let nameChars = '';
|
|
14
15
|
let spacesBeforeEqualChars = '';
|
|
@@ -16,16 +17,16 @@ function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
|
16
17
|
let spacesAfterEqualChars = '';
|
|
17
18
|
let valueChars = '';
|
|
18
19
|
const [before, after] = raw.split(rawValue);
|
|
19
|
-
const beforeMatchedMap = before.match(reBeforeStructure);
|
|
20
|
-
const beforeWithoutNameMatchedMap = before.match(reBeforeStructureWithoutName);
|
|
21
|
-
const afterMatchedMap = after.match(reAfterStructure);
|
|
20
|
+
const beforeMatchedMap = before === null || before === void 0 ? void 0 : before.match(reBeforeStructure);
|
|
21
|
+
const beforeWithoutNameMatchedMap = before === null || before === void 0 ? void 0 : before.match(reBeforeStructureWithoutName);
|
|
22
|
+
const afterMatchedMap = after === null || after === void 0 ? void 0 : after.match(reAfterStructure);
|
|
22
23
|
if (beforeMatchedMap && afterMatchedMap) {
|
|
23
|
-
spacesBeforeAttrString = beforeMatchedMap[1];
|
|
24
|
-
nameChars = beforeMatchedMap[2];
|
|
25
|
-
spacesBeforeEqualChars = beforeMatchedMap[3]
|
|
24
|
+
spacesBeforeAttrString = (_a = beforeMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
|
|
25
|
+
nameChars = (_b = beforeMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
|
|
26
|
+
spacesBeforeEqualChars = (_c = beforeMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
|
|
26
27
|
equalChars = beforeMatchedMap[4] || null;
|
|
27
|
-
spacesAfterEqualChars = beforeMatchedMap[5]
|
|
28
|
-
valueChars = (beforeMatchedMap[6]
|
|
28
|
+
spacesAfterEqualChars = (_d = beforeMatchedMap[5]) !== null && _d !== void 0 ? _d : '';
|
|
29
|
+
valueChars = ((_e = beforeMatchedMap[6]) !== null && _e !== void 0 ? _e : '') + rawValue + (afterMatchedMap[1] || '');
|
|
29
30
|
}
|
|
30
31
|
else if (beforeWithoutNameMatchedMap && afterMatchedMap) {
|
|
31
32
|
valueChars = (beforeWithoutNameMatchedMap[1] || '') + rawValue + (afterMatchedMap[1] || '');
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse } from './parse';
|
|
2
|
-
export declare const endTag =
|
|
2
|
+
export declare const endTag = "xml";
|
package/lib/nodeize.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import type { SvelteNode } from './svelte-parser';
|
|
2
2
|
import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function nodeize(
|
|
4
|
-
originNode: SvelteNode,
|
|
5
|
-
prevNode: MLASTNode | null,
|
|
6
|
-
parentNode: MLASTParentNode | null,
|
|
7
|
-
rawHtml: string,
|
|
8
|
-
options?: ParserOptions,
|
|
9
|
-
): MLASTNode | MLASTNode[] | null;
|
|
3
|
+
export declare function nodeize(originNode: SvelteNode, prevNode: MLASTNode | null, parentNode: MLASTParentNode | null, rawHtml: string, options?: ParserOptions): MLASTNode | MLASTNode[] | null;
|
package/lib/nodeize.js
CHANGED
|
@@ -4,9 +4,16 @@ exports.nodeize = void 0;
|
|
|
4
4
|
const html_parser_1 = require("@markuplint/html-parser");
|
|
5
5
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
6
6
|
const attr_1 = require("./attr");
|
|
7
|
+
const parse_ctrl_block_1 = require("./parse-ctrl-block");
|
|
7
8
|
const traverse_1 = require("./traverse");
|
|
8
|
-
function nodeize(
|
|
9
|
-
|
|
9
|
+
function nodeize(
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
|
+
originNode,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
13
|
+
prevNode,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
15
|
+
parentNode, rawHtml, options) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
10
17
|
const nextNode = null;
|
|
11
18
|
const { startOffset, endOffset, startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, originNode.end);
|
|
12
19
|
const parentNamespace = parentNode && 'namespace' in parentNode ? parentNode.namespace : 'http://www.w3.org/1999/xhtml';
|
|
@@ -54,7 +61,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
54
61
|
const children = originNode.children || [];
|
|
55
62
|
const reEndTag = new RegExp(`</${originNode.name}\\s*>$`, 'i');
|
|
56
63
|
const startTagEndOffset = children.length
|
|
57
|
-
? children[0].start
|
|
64
|
+
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
58
65
|
: raw.replace(reEndTag, '').length + startOffset;
|
|
59
66
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
60
67
|
let endTag = null;
|
|
@@ -125,10 +132,11 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
125
132
|
return startTag;
|
|
126
133
|
}
|
|
127
134
|
case 'IfBlock': {
|
|
128
|
-
|
|
135
|
+
const ifBlocks = (0, parse_ctrl_block_1.parseCtrlBlock)('if', originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options);
|
|
136
|
+
return ifBlocks;
|
|
129
137
|
}
|
|
130
138
|
case 'EachBlock': {
|
|
131
|
-
return
|
|
139
|
+
return (0, parse_ctrl_block_1.parseCtrlBlock)('each', originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options);
|
|
132
140
|
}
|
|
133
141
|
case 'AwaitBlock': {
|
|
134
142
|
const pendingNode = originNode.pending;
|
|
@@ -150,7 +158,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
150
158
|
let then = null;
|
|
151
159
|
if (originNode.then) {
|
|
152
160
|
const thenNode = originNode.then;
|
|
153
|
-
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (
|
|
161
|
+
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_c = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _c !== void 0 ? _c : thenNode.end);
|
|
154
162
|
then = {
|
|
155
163
|
uuid: (0, parser_utils_1.uuid)(),
|
|
156
164
|
...thenTag,
|
|
@@ -169,7 +177,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
169
177
|
let awaitCatch = null;
|
|
170
178
|
if (originNode.catch) {
|
|
171
179
|
const awaitCatchNode = originNode.catch;
|
|
172
|
-
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (
|
|
180
|
+
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_d = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _d !== void 0 ? _d : awaitCatchNode.end);
|
|
173
181
|
awaitCatch = {
|
|
174
182
|
uuid: (0, parser_utils_1.uuid)(),
|
|
175
183
|
...awaitCatchTag,
|
|
@@ -248,76 +256,3 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
248
256
|
}
|
|
249
257
|
}
|
|
250
258
|
exports.nodeize = nodeize;
|
|
251
|
-
function solveCtrlBlock(ctrlName, originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options) {
|
|
252
|
-
const children = originNode.children || [];
|
|
253
|
-
const reEndTag = new RegExp(`{/${ctrlName}}$`, 'i');
|
|
254
|
-
const startTagEndOffset = children.length ? children[0].start : raw.replace(reEndTag, '').length + startOffset;
|
|
255
|
-
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
256
|
-
let endTag = null;
|
|
257
|
-
const endTagRawMatched = raw.match(reEndTag);
|
|
258
|
-
if (endTagRawMatched) {
|
|
259
|
-
const endTagRaw = endTagRawMatched[0];
|
|
260
|
-
const endTagStartOffset = originNode.end - endTagRaw.length;
|
|
261
|
-
const endTagEndOffset = originNode.end;
|
|
262
|
-
const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
|
|
263
|
-
endTag = {
|
|
264
|
-
uuid: (0, parser_utils_1.uuid)(),
|
|
265
|
-
raw: endTagRaw,
|
|
266
|
-
startOffset: endTagStartOffset,
|
|
267
|
-
endOffset: endTagEndOffset,
|
|
268
|
-
startLine: endTagLocation.startLine,
|
|
269
|
-
endLine: endTagLocation.endLine,
|
|
270
|
-
startCol: endTagLocation.startCol,
|
|
271
|
-
endCol: endTagLocation.endCol,
|
|
272
|
-
nodeName: originNode.type,
|
|
273
|
-
type: 'psblock',
|
|
274
|
-
parentNode,
|
|
275
|
-
prevNode,
|
|
276
|
-
nextNode,
|
|
277
|
-
isFragment: false,
|
|
278
|
-
isGhost: false,
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
let elseTag = null;
|
|
282
|
-
if (originNode.else) {
|
|
283
|
-
const elseNode = originNode.else;
|
|
284
|
-
const elseTagStartOffset = children.length ? children[children.length - 1].end : startTagLocation.endOffset;
|
|
285
|
-
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
286
|
-
elseTag = {
|
|
287
|
-
uuid: (0, parser_utils_1.uuid)(),
|
|
288
|
-
...elseTagLocation,
|
|
289
|
-
nodeName: elseNode.type,
|
|
290
|
-
type: 'psblock',
|
|
291
|
-
parentNode,
|
|
292
|
-
prevNode,
|
|
293
|
-
nextNode,
|
|
294
|
-
isFragment: false,
|
|
295
|
-
isGhost: false,
|
|
296
|
-
};
|
|
297
|
-
if (elseNode.children) {
|
|
298
|
-
elseTag.childNodes = (0, traverse_1.traverse)(elseNode.children, elseTag, rawHtml, options);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const tag = {
|
|
302
|
-
uuid: (0, parser_utils_1.uuid)(),
|
|
303
|
-
...startTagLocation,
|
|
304
|
-
nodeName: originNode.type,
|
|
305
|
-
type: 'psblock',
|
|
306
|
-
parentNode,
|
|
307
|
-
prevNode,
|
|
308
|
-
nextNode,
|
|
309
|
-
isFragment: false,
|
|
310
|
-
isGhost: false,
|
|
311
|
-
};
|
|
312
|
-
if (originNode.children) {
|
|
313
|
-
tag.childNodes = (0, traverse_1.traverse)(originNode.children, tag, rawHtml, options);
|
|
314
|
-
}
|
|
315
|
-
const tags = [tag];
|
|
316
|
-
if (elseTag) {
|
|
317
|
-
tags.push(elseTag);
|
|
318
|
-
}
|
|
319
|
-
if (endTag) {
|
|
320
|
-
tags.push(endTag);
|
|
321
|
-
}
|
|
322
|
-
return tags;
|
|
323
|
-
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SvelteNode } from './svelte-parser';
|
|
2
|
+
import type { MLASTNode, MLASTParentNode, MLASTPreprocessorSpecificBlock, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
+
export declare function parseCtrlBlock(ctrlName: 'if' | 'each', originNode: SvelteNode, raw: string, rawHtml: string, startOffset: number, parentNode: MLASTParentNode | null, prevNode: MLASTNode | null, nextNode: MLASTNode | null, options?: ParserOptions): MLASTPreprocessorSpecificBlock[];
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCtrlBlock = void 0;
|
|
4
|
+
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
5
|
+
const traverse_1 = require("./traverse");
|
|
6
|
+
function parseCtrlBlock(ctrlName,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
originNode, raw, rawHtml, startOffset,
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
|
+
parentNode,
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
12
|
+
prevNode,
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
14
|
+
nextNode, options) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
if (ctrlName === 'if') {
|
|
17
|
+
return parseIfBlock(originNode, raw, rawHtml, startOffset, originNode.start, parentNode, prevNode, nextNode, options);
|
|
18
|
+
}
|
|
19
|
+
const children = originNode.children || [];
|
|
20
|
+
const reEndTag = new RegExp('{/each}$', 'i');
|
|
21
|
+
const startTagEndOffset = children.length
|
|
22
|
+
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
23
|
+
: raw.replace(reEndTag, '').length + startOffset;
|
|
24
|
+
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
25
|
+
const tag = {
|
|
26
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
27
|
+
...startTagLocation,
|
|
28
|
+
nodeName: originNode.type,
|
|
29
|
+
type: 'psblock',
|
|
30
|
+
parentNode,
|
|
31
|
+
prevNode,
|
|
32
|
+
nextNode,
|
|
33
|
+
isFragment: false,
|
|
34
|
+
isGhost: false,
|
|
35
|
+
};
|
|
36
|
+
if (originNode.children) {
|
|
37
|
+
tag.childNodes = (0, traverse_1.traverse)(originNode.children, tag, rawHtml, options);
|
|
38
|
+
}
|
|
39
|
+
let elseTag = null;
|
|
40
|
+
if (originNode.else) {
|
|
41
|
+
const elseNode = originNode.else;
|
|
42
|
+
const elseTagStartOffset = children.length
|
|
43
|
+
? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
|
|
44
|
+
: startTagLocation.endOffset;
|
|
45
|
+
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
46
|
+
elseTag = {
|
|
47
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
48
|
+
...elseTagLocation,
|
|
49
|
+
nodeName: elseNode.type,
|
|
50
|
+
type: 'psblock',
|
|
51
|
+
parentNode,
|
|
52
|
+
prevNode,
|
|
53
|
+
nextNode,
|
|
54
|
+
isFragment: false,
|
|
55
|
+
isGhost: false,
|
|
56
|
+
};
|
|
57
|
+
if (elseNode.children) {
|
|
58
|
+
elseTag.childNodes = (0, traverse_1.traverse)(elseNode.children, elseTag, rawHtml, options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let endTag = null;
|
|
62
|
+
const endTagRawMatched = raw.match(reEndTag);
|
|
63
|
+
if (endTagRawMatched) {
|
|
64
|
+
const endTagRaw = endTagRawMatched[0];
|
|
65
|
+
const endTagStartOffset = originNode.end - endTagRaw.length;
|
|
66
|
+
const endTagEndOffset = originNode.end;
|
|
67
|
+
const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
|
|
68
|
+
endTag = {
|
|
69
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
70
|
+
raw: endTagRaw,
|
|
71
|
+
startOffset: endTagStartOffset,
|
|
72
|
+
endOffset: endTagEndOffset,
|
|
73
|
+
startLine: endTagLocation.startLine,
|
|
74
|
+
endLine: endTagLocation.endLine,
|
|
75
|
+
startCol: endTagLocation.startCol,
|
|
76
|
+
endCol: endTagLocation.endCol,
|
|
77
|
+
nodeName: originNode.type,
|
|
78
|
+
type: 'psblock',
|
|
79
|
+
parentNode,
|
|
80
|
+
prevNode,
|
|
81
|
+
nextNode,
|
|
82
|
+
isFragment: false,
|
|
83
|
+
isGhost: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const tags = [tag];
|
|
87
|
+
if (elseTag) {
|
|
88
|
+
tags.push(elseTag);
|
|
89
|
+
}
|
|
90
|
+
if (endTag) {
|
|
91
|
+
tags.push(endTag);
|
|
92
|
+
}
|
|
93
|
+
return tags;
|
|
94
|
+
}
|
|
95
|
+
exports.parseCtrlBlock = parseCtrlBlock;
|
|
96
|
+
function parseIfBlock(
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
98
|
+
originNode, raw, rawHtml, statementStartOffset, tokenStartOffset,
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
100
|
+
parentNode,
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
102
|
+
prevNode,
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
104
|
+
nextNode, options) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
106
|
+
const children = originNode.children || [];
|
|
107
|
+
const startTagEndOffset = (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : tokenStartOffset;
|
|
108
|
+
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, tokenStartOffset, startTagEndOffset);
|
|
109
|
+
const tag = {
|
|
110
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
111
|
+
...startTagLocation,
|
|
112
|
+
nodeName: originNode.elseif ? 'ElseIfBlock' : originNode.type,
|
|
113
|
+
type: 'psblock',
|
|
114
|
+
parentNode,
|
|
115
|
+
prevNode,
|
|
116
|
+
nextNode,
|
|
117
|
+
isFragment: false,
|
|
118
|
+
isGhost: false,
|
|
119
|
+
};
|
|
120
|
+
if (originNode.children) {
|
|
121
|
+
tag.childNodes = (0, traverse_1.traverse)(originNode.children, tag, rawHtml, options);
|
|
122
|
+
}
|
|
123
|
+
const elseOrElseIfTags = [];
|
|
124
|
+
if (originNode.else) {
|
|
125
|
+
const elseNode = originNode.else;
|
|
126
|
+
const elseTagStartOffset = children.length
|
|
127
|
+
? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
|
|
128
|
+
: startTagLocation.endOffset;
|
|
129
|
+
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
130
|
+
if (elseNode.children) {
|
|
131
|
+
if (elseNode.children.length === 1 && ((_e = elseNode.children[0]) === null || _e === void 0 ? void 0 : _e.type) === 'IfBlock') {
|
|
132
|
+
const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (_h = (_g = (_f = originNode.children) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.end) !== null && _h !== void 0 ? _h : startTagLocation.endOffset, parentNode, null, null, options);
|
|
133
|
+
elseOrElseIfTags.push(...elseIfTags);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const elseTag = {
|
|
137
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
138
|
+
...elseTagLocation,
|
|
139
|
+
nodeName: elseNode.type,
|
|
140
|
+
type: 'psblock',
|
|
141
|
+
parentNode,
|
|
142
|
+
prevNode,
|
|
143
|
+
nextNode,
|
|
144
|
+
isFragment: false,
|
|
145
|
+
isGhost: false,
|
|
146
|
+
};
|
|
147
|
+
elseTag.childNodes = (0, traverse_1.traverse)(elseNode.children, elseTag, rawHtml, options);
|
|
148
|
+
elseOrElseIfTags.push(elseTag);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (originNode.elseif) {
|
|
153
|
+
return [tag, ...elseOrElseIfTags];
|
|
154
|
+
}
|
|
155
|
+
const endTagRawMatched = raw.match('{/if}');
|
|
156
|
+
if (!endTagRawMatched) {
|
|
157
|
+
throw new Error('Missing the end token `{/if}`');
|
|
158
|
+
}
|
|
159
|
+
const endTagRaw = endTagRawMatched[0];
|
|
160
|
+
const endTagStartOffset = originNode.end - endTagRaw.length;
|
|
161
|
+
const endTagEndOffset = originNode.end;
|
|
162
|
+
const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
|
|
163
|
+
const endTag = {
|
|
164
|
+
uuid: (0, parser_utils_1.uuid)(),
|
|
165
|
+
raw: endTagRaw,
|
|
166
|
+
startOffset: endTagStartOffset,
|
|
167
|
+
endOffset: endTagEndOffset,
|
|
168
|
+
startLine: endTagLocation.startLine,
|
|
169
|
+
endLine: endTagLocation.endLine,
|
|
170
|
+
startCol: endTagLocation.startCol,
|
|
171
|
+
endCol: endTagLocation.endCol,
|
|
172
|
+
nodeName: originNode.type,
|
|
173
|
+
type: 'psblock',
|
|
174
|
+
parentNode,
|
|
175
|
+
prevNode,
|
|
176
|
+
nextNode,
|
|
177
|
+
isFragment: false,
|
|
178
|
+
isGhost: false,
|
|
179
|
+
};
|
|
180
|
+
return [tag, ...elseOrElseIfTags, endTag];
|
|
181
|
+
}
|
package/lib/parse.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const html_parser_1 = require("@markuplint/html-parser");
|
|
6
5
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
7
6
|
const svelte_parser_1 = tslib_1.__importDefault(require("./svelte-parser"));
|
|
8
7
|
const traverse_1 = require("./traverse");
|
|
@@ -43,7 +42,8 @@ const parse = (rawCode, options) => {
|
|
|
43
42
|
parseError: err instanceof Error ? err.message : new Error(`${err}`).message,
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
const
|
|
45
|
+
const nodes = (0, traverse_1.traverse)(ast, null, blocks.replaced, options);
|
|
46
|
+
const nodeList = (0, parser_utils_1.restoreNode)((0, parser_utils_1.flattenNodes)(nodes, blocks.replaced), blocks);
|
|
47
47
|
return {
|
|
48
48
|
nodeList,
|
|
49
49
|
isFragment: true,
|
package/lib/traverse.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { SvelteNode } from './svelte-parser';
|
|
2
2
|
import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function traverse(
|
|
4
|
-
astNodes: SvelteNode[],
|
|
5
|
-
parentNode: MLASTParentNode | null | undefined,
|
|
6
|
-
rawHtml: string,
|
|
7
|
-
options?: ParserOptions,
|
|
8
|
-
): MLASTNode[];
|
|
3
|
+
export declare function traverse(astNodes: readonly SvelteNode[], parentNode: MLASTParentNode | null | undefined, rawHtml: string, options?: ParserOptions): MLASTNode[];
|
package/lib/traverse.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.traverse = void 0;
|
|
4
4
|
const nodeize_1 = require("./nodeize");
|
|
5
|
-
function traverse(
|
|
5
|
+
function traverse(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
7
|
+
astNodes, parentNode = null, rawHtml, options) {
|
|
6
8
|
const nodeList = [];
|
|
7
9
|
let prevNode = null;
|
|
8
10
|
for (const astNode of astNodes) {
|
|
@@ -12,7 +14,11 @@ function traverse(astNodes, parentNode = null, rawHtml, options) {
|
|
|
12
14
|
}
|
|
13
15
|
let node;
|
|
14
16
|
if (Array.isArray(nodes)) {
|
|
15
|
-
|
|
17
|
+
const lastNode = nodes[nodes.length - 1];
|
|
18
|
+
if (!lastNode) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
node = lastNode;
|
|
16
22
|
}
|
|
17
23
|
else {
|
|
18
24
|
node = nodes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/svelte-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Svelte parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"clean": "tsc --build --clean"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@markuplint/html-parser": "3.
|
|
20
|
-
"@markuplint/ml-ast": "3.
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
22
|
-
"svelte": "^3.
|
|
19
|
+
"@markuplint/html-parser": "3.5.0",
|
|
20
|
+
"@markuplint/ml-ast": "3.1.0",
|
|
21
|
+
"@markuplint/parser-utils": "3.5.0",
|
|
22
|
+
"svelte": "^3.57.0",
|
|
23
23
|
"tslib": "^2.4.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
|
|
26
26
|
}
|