@markuplint/svelte-parser 3.12.0 → 4.0.0-alpha.10

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/nodeize.js DELETED
@@ -1,293 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodeize = void 0;
4
- const html_parser_1 = require("@markuplint/html-parser");
5
- const parser_utils_1 = require("@markuplint/parser-utils");
6
- const attr_1 = require("./attr");
7
- const parse_ctrl_block_1 = require("./parse-ctrl-block");
8
- const traverse_1 = require("./traverse");
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, _e, _f;
17
- const nextNode = null;
18
- const { startOffset, endOffset, startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, originNode.end);
19
- const parentNamespace = parentNode && 'namespace' in parentNode ? parentNode.namespace : 'http://www.w3.org/1999/xhtml';
20
- switch (originNode.type) {
21
- case 'Text': {
22
- const node = {
23
- uuid: (0, parser_utils_1.uuid)(),
24
- raw,
25
- startOffset,
26
- endOffset,
27
- startLine,
28
- endLine,
29
- startCol,
30
- endCol,
31
- nodeName: '#text',
32
- type: 'text',
33
- parentNode,
34
- prevNode,
35
- nextNode,
36
- isFragment: false,
37
- isGhost: false,
38
- };
39
- return node;
40
- }
41
- case 'MustacheTag': {
42
- return {
43
- uuid: (0, parser_utils_1.uuid)(),
44
- raw,
45
- startOffset,
46
- endOffset,
47
- startLine,
48
- endLine,
49
- startCol,
50
- endCol,
51
- nodeName: '#ps:MustacheTag',
52
- type: 'psblock',
53
- parentNode,
54
- prevNode,
55
- nextNode,
56
- isFragment: false,
57
- isGhost: false,
58
- };
59
- }
60
- case 'InlineComponent':
61
- case 'Element': {
62
- const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
63
- const reEndTag = new RegExp(`</${originNode.name}\\s*>$`, 'i');
64
- const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
65
- const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
66
- let endTag = null;
67
- if (reEndTag.test(raw)) {
68
- const endTagRawMatched = raw.match(reEndTag);
69
- if (!endTagRawMatched) {
70
- throw new Error('Parse error');
71
- }
72
- const endTagRaw = endTagRawMatched[0];
73
- const endTagStartOffset = startOffset + raw.lastIndexOf(endTagRaw);
74
- const endTagEndOffset = endTagStartOffset + endTagRaw.length;
75
- const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
76
- const namespace = (0, html_parser_1.getNamespace)(originNode.name, parentNamespace);
77
- endTag = {
78
- uuid: (0, parser_utils_1.uuid)(),
79
- raw: endTagRaw,
80
- startOffset: endTagStartOffset,
81
- endOffset: endTagEndOffset,
82
- startLine: endTagLocation.startLine,
83
- endLine: endTagLocation.endLine,
84
- startCol: endTagLocation.startCol,
85
- endCol: endTagLocation.endCol,
86
- nodeName: originNode.name,
87
- type: 'endtag',
88
- namespace,
89
- attributes: [],
90
- parentNode,
91
- prevNode,
92
- nextNode,
93
- pearNode: null,
94
- isFragment: false,
95
- isGhost: false,
96
- tagOpenChar: '</',
97
- tagCloseChar: '>',
98
- };
99
- }
100
- const directives = (_d = originNode.attributes.map(a => (0, attr_1.attr)(a, rawHtml))) !== null && _d !== void 0 ? _d : [];
101
- const attributes = directives.filter((d) => !('__spreadAttr' in d));
102
- const hasSpreadAttr = directives.some(d => '__spreadAttr' in d);
103
- const tagTokens = (0, html_parser_1.parseRawTag)(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset);
104
- const namespace = (0, html_parser_1.getNamespace)(originNode.name, parentNamespace);
105
- const startTag = {
106
- uuid: (0, parser_utils_1.uuid)(),
107
- ...startTagLocation,
108
- nodeName: originNode.name,
109
- type: 'starttag',
110
- namespace,
111
- elementType: (0, parser_utils_1.detectElementType)(originNode.name, options === null || options === void 0 ? void 0 : options.authoredElementName, /[A-Z]|\./),
112
- attributes,
113
- hasSpreadAttr,
114
- parentNode,
115
- prevNode,
116
- nextNode,
117
- pearNode: endTag,
118
- selfClosingSolidus: tagTokens.selfClosingSolidus,
119
- endSpace: tagTokens.endSpace,
120
- isFragment: false,
121
- isGhost: false,
122
- tagOpenChar: '<',
123
- tagCloseChar: '>',
124
- };
125
- if (endTag) {
126
- endTag.pearNode = startTag;
127
- }
128
- if (originNode.children) {
129
- startTag.childNodes = (0, traverse_1.traverse)(originNode.children, startTag, rawHtml, options);
130
- }
131
- return startTag;
132
- }
133
- case 'IfBlock': {
134
- const ifBlocks = (0, parse_ctrl_block_1.parseCtrlBlock)('if', originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options);
135
- return ifBlocks;
136
- }
137
- case 'EachBlock': {
138
- return (0, parse_ctrl_block_1.parseCtrlBlock)('each', originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options);
139
- }
140
- case 'AwaitBlock': {
141
- const pendingNode = originNode.pending;
142
- const pendingTag = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, pendingNode.start);
143
- const pending = {
144
- uuid: (0, parser_utils_1.uuid)(),
145
- ...pendingTag,
146
- nodeName: pendingNode.type,
147
- type: 'psblock',
148
- parentNode,
149
- prevNode,
150
- nextNode,
151
- isFragment: false,
152
- isGhost: false,
153
- };
154
- if (pendingNode.children) {
155
- pending.childNodes = (0, traverse_1.traverse)(pendingNode.children, pending, rawHtml, options);
156
- }
157
- let then = null;
158
- if (originNode.then) {
159
- const thenNode = originNode.then;
160
- const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_e = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _e !== void 0 ? _e : thenNode.end);
161
- then = {
162
- uuid: (0, parser_utils_1.uuid)(),
163
- ...thenTag,
164
- nodeName: thenNode.type,
165
- type: 'psblock',
166
- parentNode,
167
- prevNode,
168
- nextNode,
169
- isFragment: false,
170
- isGhost: false,
171
- };
172
- if (thenNode.children) {
173
- then.childNodes = (0, traverse_1.traverse)(thenNode.children, then, rawHtml, options);
174
- }
175
- }
176
- let awaitCatch = null;
177
- if (originNode.catch) {
178
- const awaitCatchNode = originNode.catch;
179
- const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_f = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _f !== void 0 ? _f : awaitCatchNode.end);
180
- awaitCatch = {
181
- uuid: (0, parser_utils_1.uuid)(),
182
- ...awaitCatchTag,
183
- nodeName: awaitCatchNode.type,
184
- type: 'psblock',
185
- parentNode,
186
- prevNode,
187
- nextNode,
188
- isFragment: false,
189
- isGhost: false,
190
- };
191
- if (awaitCatchNode.children) {
192
- awaitCatch.childNodes = (0, traverse_1.traverse)(awaitCatchNode.children, awaitCatch, rawHtml, options);
193
- }
194
- }
195
- const reEndTag = new RegExp('{/await}$', 'i');
196
- let endTag = null;
197
- if (reEndTag.test(raw)) {
198
- const endTagRawMatched = raw.match(reEndTag);
199
- if (!endTagRawMatched) {
200
- throw new Error('Parse error');
201
- }
202
- const endTagRaw = endTagRawMatched[0];
203
- const endTagStartOffset = startOffset + raw.indexOf(endTagRaw);
204
- const endTagEndOffset = endTagStartOffset + endTagRaw.length;
205
- const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
206
- endTag = {
207
- uuid: (0, parser_utils_1.uuid)(),
208
- raw: endTagRaw,
209
- startOffset: endTagStartOffset,
210
- endOffset: endTagEndOffset,
211
- startLine: endTagLocation.startLine,
212
- endLine: endTagLocation.endLine,
213
- startCol: endTagLocation.startCol,
214
- endCol: endTagLocation.endCol,
215
- nodeName: originNode.type,
216
- type: 'psblock',
217
- parentNode,
218
- prevNode,
219
- nextNode,
220
- isFragment: false,
221
- isGhost: false,
222
- };
223
- }
224
- const tags = [pending];
225
- if (then) {
226
- tags.push(then);
227
- }
228
- if (awaitCatch) {
229
- tags.push(awaitCatch);
230
- }
231
- if (endTag) {
232
- tags.push(endTag);
233
- }
234
- return tags;
235
- }
236
- default: {
237
- const startTag = {
238
- uuid: (0, parser_utils_1.uuid)(),
239
- raw,
240
- startOffset,
241
- endOffset,
242
- startLine,
243
- endLine,
244
- startCol,
245
- endCol,
246
- nodeName: originNode.name || originNode.type,
247
- type: 'psblock',
248
- parentNode,
249
- prevNode,
250
- nextNode,
251
- isFragment: false,
252
- isGhost: false,
253
- };
254
- let endTag = null;
255
- if (originNode.children) {
256
- startTag.childNodes = (0, traverse_1.traverse)(originNode.children, startTag, rawHtml, options);
257
- const firstChild = startTag.childNodes[0];
258
- if (firstChild) {
259
- startTag.endOffset = firstChild.startOffset;
260
- startTag.endLine = firstChild.startLine;
261
- startTag.endCol = firstChild.startCol;
262
- startTag.raw = rawHtml.slice(startTag.startOffset, startTag.endOffset);
263
- }
264
- const lastChild = startTag.childNodes[startTag.childNodes.length - 1];
265
- if (lastChild && lastChild.endOffset > startTag.endOffset) {
266
- const startOffset = lastChild.endOffset;
267
- const startLine = lastChild.endLine;
268
- const startCol = lastChild.endCol;
269
- const raw = rawHtml.slice(startOffset, endOffset);
270
- endTag = {
271
- uuid: (0, parser_utils_1.uuid)(),
272
- raw,
273
- startOffset,
274
- endOffset,
275
- startLine,
276
- endLine,
277
- startCol,
278
- endCol,
279
- nodeName: originNode.name || originNode.type,
280
- type: 'psblock',
281
- parentNode,
282
- prevNode,
283
- nextNode,
284
- isFragment: false,
285
- isGhost: false,
286
- };
287
- }
288
- }
289
- return endTag != null ? [startTag, endTag] : startTag;
290
- }
291
- }
292
- }
293
- exports.nodeize = nodeize;
@@ -1,13 +0,0 @@
1
- import type { SvelteNode } from './svelte-parser';
2
- import type { MLASTNode, MLASTParentNode, MLASTPreprocessorSpecificBlock, ParserOptions } from '@markuplint/ml-ast';
3
- export declare function parseCtrlBlock(
4
- ctrlName: 'if' | 'each',
5
- originNode: SvelteNode,
6
- raw: string,
7
- rawHtml: string,
8
- startOffset: number,
9
- parentNode: MLASTParentNode | null,
10
- prevNode: MLASTNode | null,
11
- nextNode: MLASTNode | null,
12
- options?: ParserOptions,
13
- ): MLASTPreprocessorSpecificBlock[];
@@ -1,175 +0,0 @@
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, _e;
16
- if (ctrlName === 'if') {
17
- return parseIfBlock(originNode, raw, rawHtml, startOffset, originNode.start, parentNode, prevNode, nextNode, options);
18
- }
19
- const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
20
- const reEndTag = new RegExp('{/each}$', 'i');
21
- const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
22
- const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
23
- const tag = {
24
- uuid: (0, parser_utils_1.uuid)(),
25
- ...startTagLocation,
26
- nodeName: originNode.type,
27
- type: 'psblock',
28
- parentNode,
29
- prevNode,
30
- nextNode,
31
- isFragment: false,
32
- isGhost: false,
33
- };
34
- if (originNode.children) {
35
- tag.childNodes = (0, traverse_1.traverse)(originNode.children, tag, rawHtml, options);
36
- }
37
- let elseTag = null;
38
- if (originNode.else) {
39
- const elseNode = originNode.else;
40
- const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
41
- const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
42
- elseTag = {
43
- uuid: (0, parser_utils_1.uuid)(),
44
- ...elseTagLocation,
45
- nodeName: elseNode.type,
46
- type: 'psblock',
47
- parentNode,
48
- prevNode,
49
- nextNode,
50
- isFragment: false,
51
- isGhost: false,
52
- };
53
- if (elseNode.children) {
54
- elseTag.childNodes = (0, traverse_1.traverse)(elseNode.children, elseTag, rawHtml, options);
55
- }
56
- }
57
- let endTag = null;
58
- const endTagRawMatched = raw.match(reEndTag);
59
- if (endTagRawMatched) {
60
- const endTagRaw = endTagRawMatched[0];
61
- const endTagStartOffset = originNode.end - endTagRaw.length;
62
- const endTagEndOffset = originNode.end;
63
- const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
64
- endTag = {
65
- uuid: (0, parser_utils_1.uuid)(),
66
- raw: endTagRaw,
67
- startOffset: endTagStartOffset,
68
- endOffset: endTagEndOffset,
69
- startLine: endTagLocation.startLine,
70
- endLine: endTagLocation.endLine,
71
- startCol: endTagLocation.startCol,
72
- endCol: endTagLocation.endCol,
73
- nodeName: originNode.type,
74
- type: 'psblock',
75
- parentNode,
76
- prevNode,
77
- nextNode,
78
- isFragment: false,
79
- isGhost: false,
80
- };
81
- }
82
- const tags = [tag];
83
- if (elseTag) {
84
- tags.push(elseTag);
85
- }
86
- if (endTag) {
87
- tags.push(endTag);
88
- }
89
- return tags;
90
- }
91
- exports.parseCtrlBlock = parseCtrlBlock;
92
- function parseIfBlock(
93
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
94
- originNode, raw, rawHtml, statementStartOffset, tokenStartOffset,
95
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
96
- parentNode,
97
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
98
- prevNode,
99
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
100
- nextNode, options) {
101
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
102
- const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
103
- const startTagEndOffset = (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : tokenStartOffset;
104
- const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, tokenStartOffset, startTagEndOffset);
105
- const tag = {
106
- uuid: (0, parser_utils_1.uuid)(),
107
- ...startTagLocation,
108
- nodeName: originNode.elseif ? 'ElseIfBlock' : originNode.type,
109
- type: 'psblock',
110
- parentNode,
111
- prevNode,
112
- nextNode,
113
- isFragment: false,
114
- isGhost: false,
115
- };
116
- if (originNode.children) {
117
- tag.childNodes = (0, traverse_1.traverse)(originNode.children, tag, rawHtml, options);
118
- }
119
- const elseOrElseIfTags = [];
120
- if (originNode.else) {
121
- const elseNode = originNode.else;
122
- const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
123
- const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
124
- if (elseNode.children) {
125
- if (elseNode.children.length === 1 && ((_f = elseNode.children[0]) === null || _f === void 0 ? void 0 : _f.type) === 'IfBlock') {
126
- const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (_j = (_h = (_g = originNode.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.end) !== null && _j !== void 0 ? _j : startTagLocation.endOffset, parentNode, null, null, options);
127
- elseOrElseIfTags.push(...elseIfTags);
128
- }
129
- else {
130
- const elseTag = {
131
- uuid: (0, parser_utils_1.uuid)(),
132
- ...elseTagLocation,
133
- nodeName: elseNode.type,
134
- type: 'psblock',
135
- parentNode,
136
- prevNode,
137
- nextNode,
138
- isFragment: false,
139
- isGhost: false,
140
- };
141
- elseTag.childNodes = (0, traverse_1.traverse)(elseNode.children, elseTag, rawHtml, options);
142
- elseOrElseIfTags.push(elseTag);
143
- }
144
- }
145
- }
146
- if (originNode.elseif) {
147
- return [tag, ...elseOrElseIfTags];
148
- }
149
- const endTagRawMatched = raw.match('{/if}');
150
- if (!endTagRawMatched) {
151
- throw new Error('Missing the end token `{/if}`');
152
- }
153
- const endTagRaw = endTagRawMatched[0];
154
- const endTagStartOffset = originNode.end - endTagRaw.length;
155
- const endTagEndOffset = originNode.end;
156
- const endTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, endTagStartOffset, endTagEndOffset);
157
- const endTag = {
158
- uuid: (0, parser_utils_1.uuid)(),
159
- raw: endTagRaw,
160
- startOffset: endTagStartOffset,
161
- endOffset: endTagEndOffset,
162
- startLine: endTagLocation.startLine,
163
- endLine: endTagLocation.endLine,
164
- startCol: endTagLocation.startCol,
165
- endCol: endTagLocation.endCol,
166
- nodeName: originNode.type,
167
- type: 'psblock',
168
- parentNode,
169
- prevNode,
170
- nextNode,
171
- isFragment: false,
172
- isGhost: false,
173
- };
174
- return [tag, ...elseOrElseIfTags, endTag];
175
- }
package/lib/parse.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Parse } from '@markuplint/ml-ast';
2
- export declare const parse: Parse;
package/lib/parse.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = void 0;
4
- const tslib_1 = require("tslib");
5
- const parser_utils_1 = require("@markuplint/parser-utils");
6
- const svelte_parser_1 = tslib_1.__importDefault(require("./svelte-parser"));
7
- const traverse_1 = require("./traverse");
8
- const parse = (rawCode, options) => {
9
- const blocks = (0, parser_utils_1.ignoreBlock)(rawCode, [
10
- {
11
- type: 'Script',
12
- start: /<script/,
13
- end: /<\/script>/,
14
- },
15
- {
16
- type: 'Style',
17
- start: /<style/,
18
- end: /<\/style>/,
19
- },
20
- ], '-');
21
- let ast;
22
- try {
23
- ast = (0, svelte_parser_1.default)(blocks.replaced);
24
- }
25
- catch (err) {
26
- if (err instanceof Error && 'start' in err && 'end' in err && 'frame' in err) {
27
- // @ts-ignore
28
- const raw = rawCode.slice(err.start.character, err.end.character);
29
- throw new parser_utils_1.ParserError(
30
- // @ts-ignore
31
- err.message + '\n' + err.frame, {
32
- // @ts-ignore
33
- line: err.start.line,
34
- // @ts-ignore
35
- col: err.start.column,
36
- raw,
37
- });
38
- }
39
- return {
40
- nodeList: [],
41
- isFragment: true,
42
- parseError: err instanceof Error ? err.message : new Error(`${err}`).message,
43
- };
44
- }
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
- return {
48
- nodeList,
49
- isFragment: true,
50
- };
51
- };
52
- exports.parse = parse;
package/lib/traverse.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { SvelteNode } from './svelte-parser';
2
- import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
3
- export declare function traverse(
4
- astNodes: readonly SvelteNode[],
5
- parentNode: MLASTParentNode | null | undefined,
6
- rawHtml: string,
7
- options?: ParserOptions,
8
- ): MLASTNode[];
package/lib/traverse.js DELETED
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverse = void 0;
4
- const nodeize_1 = require("./nodeize");
5
- function traverse(
6
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
- astNodes, parentNode = null, rawHtml, options) {
8
- const nodeList = [];
9
- let prevNode = null;
10
- for (const astNode of astNodes) {
11
- const nodes = (0, nodeize_1.nodeize)(astNode, prevNode, parentNode, rawHtml, options);
12
- if (!nodes) {
13
- continue;
14
- }
15
- let node;
16
- if (Array.isArray(nodes)) {
17
- const lastNode = nodes[nodes.length - 1];
18
- if (!lastNode) {
19
- continue;
20
- }
21
- node = lastNode;
22
- }
23
- else {
24
- node = nodes;
25
- }
26
- if (prevNode) {
27
- if (node.type !== 'endtag') {
28
- prevNode.nextNode = node;
29
- }
30
- node.prevNode = prevNode;
31
- }
32
- prevNode = node;
33
- if (Array.isArray(nodes)) {
34
- nodeList.push(...nodes);
35
- }
36
- else {
37
- nodeList.push(nodes);
38
- }
39
- }
40
- return nodeList;
41
- }
42
- exports.traverse = traverse;