@markuplint/parser-utils 3.0.0-canary.5 → 3.0.0-dev.176

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <details>
10
10
  <summary>If you are installing purposely, how below:</summary>
11
11
 
12
- ```sh
12
+ ```shell
13
13
  $ npm install @markuplint/parser-utils
14
14
 
15
15
  $ yarn add @markuplint/parser-utils
package/lib/const.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- export declare const MASK_CHAR = "\uE000";
1
+ export declare const MASK_CHAR = '\uE000';
2
2
  /**
3
3
  * SVG Element list
4
4
  *
5
5
  * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element
6
6
  */
7
7
  export declare const svgElementList: string[];
8
+ export declare const reTag: RegExp;
9
+ export declare const reTagName: RegExp;
10
+ export declare const reSplitterTag: RegExp;
package/lib/const.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.svgElementList = exports.MASK_CHAR = void 0;
3
+ exports.reSplitterTag = exports.reTagName = exports.reTag = exports.svgElementList = exports.MASK_CHAR = void 0;
4
4
  exports.MASK_CHAR = '\uE000';
5
5
  /**
6
6
  * SVG Element list
@@ -97,3 +97,7 @@ exports.svgElementList = [
97
97
  'tref',
98
98
  'vkern',
99
99
  ];
100
+ exports.reTag = /^<((?:.|\s|\n)+)>\s*$/;
101
+ // eslint-disable-next-line no-control-regex
102
+ exports.reTagName = /^(?:[a-z][^\u0000\u0009\u000A\u000C\u0020/>]*)/i;
103
+ exports.reSplitterTag = /<[^>]+>/g;
@@ -1,4 +1,9 @@
1
1
  import type { MLToken } from '@markuplint/ml-ast';
2
- export declare function tokenizer(raw: string | null, startLine: number, startCol: number, startOffset: number): MLToken;
2
+ export declare function tokenizer(
3
+ raw: string | null,
4
+ startLine: number,
5
+ startCol: number,
6
+ startOffset: number,
7
+ ): MLToken;
3
8
  export declare function createTokenFromRawCode(raw: string | null, startOffset: number, rawCode: string): MLToken;
4
9
  export declare function uuid(): string;
@@ -4,7 +4,7 @@ exports.uuid = exports.createTokenFromRawCode = exports.tokenizer = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const get_location_1 = require("./get-location");
6
6
  function tokenizer(raw, startLine, startCol, startOffset) {
7
- raw = raw || '';
7
+ raw = raw !== null && raw !== void 0 ? raw : '';
8
8
  const endLine = (0, get_location_1.getEndLine)(raw, startLine);
9
9
  const endCol = (0, get_location_1.getEndCol)(raw, startCol);
10
10
  const endOffset = startOffset + raw.length;
@@ -21,7 +21,7 @@ function tokenizer(raw, startLine, startCol, startOffset) {
21
21
  }
22
22
  exports.tokenizer = tokenizer;
23
23
  function createTokenFromRawCode(raw, startOffset, rawCode) {
24
- raw = raw || '';
24
+ raw = raw !== null && raw !== void 0 ? raw : '';
25
25
  const loc = (0, get_location_1.sliceFragment)(rawCode, startOffset, startOffset + raw.length);
26
26
  return {
27
27
  uuid: uuid(),
package/lib/debugger.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.attributesToDebugMaps = exports.nodeListToDebugMaps = void 0;
4
- function nodeListToDebugMaps(nodeList, withAttr = false) {
4
+ function nodeListToDebugMaps(
5
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
+ nodeList, withAttr = false) {
5
7
  return nodeList
6
8
  .map(n => {
7
9
  const r = [];
@@ -19,7 +21,9 @@ function nodeListToDebugMaps(nodeList, withAttr = false) {
19
21
  .flat();
20
22
  }
21
23
  exports.nodeListToDebugMaps = nodeListToDebugMaps;
22
- function attributesToDebugMaps(attributes) {
24
+ function attributesToDebugMaps(
25
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
26
+ attributes) {
23
27
  return attributes.map(n => {
24
28
  const r = [
25
29
  tokenDebug({
@@ -50,9 +54,10 @@ function attributesToDebugMaps(attributes) {
50
54
  }
51
55
  exports.attributesToDebugMaps = attributesToDebugMaps;
52
56
  function tokenDebug(n, type = '') {
57
+ var _a, _b, _c, _d;
53
58
  return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
54
59
  // @ts-ignore
55
- n.potentialName || n.nodeName || n.name || n.type || type}: ${visibleWhiteSpace(n.raw)}`;
60
+ (_d = (_c = (_b = (_a = n.potentialName) !== null && _a !== void 0 ? _a : n.nodeName) !== null && _b !== void 0 ? _b : n.name) !== null && _c !== void 0 ? _c : n.type) !== null && _d !== void 0 ? _d : type}: ${visibleWhiteSpace(n.raw)}`;
56
61
  }
57
62
  function visibleWhiteSpace(chars) {
58
63
  return chars.replace(/\n/g, '⏎').replace(/\t/g, '→').replace(/\s/g, '␣');
@@ -1,2 +1,6 @@
1
1
  import type { ElementType, ParserAuthoredElementNameDistinguishing } from '@markuplint/ml-ast';
2
- export declare function detectElementType(name: string, option?: ParserAuthoredElementNameDistinguishing, defaultPattern?: ParserAuthoredElementNameDistinguishing): ElementType;
2
+ export declare function detectElementType(
3
+ name: string,
4
+ option?: ParserAuthoredElementNameDistinguishing,
5
+ defaultPattern?: ParserAuthoredElementNameDistinguishing,
6
+ ): ElementType;
@@ -10,10 +10,10 @@ function detectElementType(name, option, defaultPattern) {
10
10
  }
11
11
  exports.detectElementType = detectElementType;
12
12
  function distinguishAuthoredName(name, pattern, defaultPattern) {
13
- if (pattern) {
13
+ if (pattern != null) {
14
14
  return _distinguishAuthoredName(name, pattern);
15
15
  }
16
- if (defaultPattern) {
16
+ if (defaultPattern != null) {
17
17
  return _distinguishAuthoredName(name, defaultPattern);
18
18
  }
19
19
  return false;
@@ -30,7 +30,7 @@ function _distinguishAuthoredName(name, patterns) {
30
30
  }
31
31
  function toRegexp(pattern) {
32
32
  const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
33
- if (matched) {
33
+ if (matched && matched[1]) {
34
34
  return new RegExp(matched[1], matched[2]);
35
35
  }
36
36
  return new RegExp(pattern);
@@ -0,0 +1,2 @@
1
+ import type { MLASTNode } from '@markuplint/ml-ast';
2
+ export declare function flattenNodes(nodeTree: MLASTNode[], rawHtml: string, createLastText?: boolean): MLASTNode[];
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenNodes = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const remove_deprecated_node_1 = require("./remove-deprecated-node");
6
+ const tag_splitter_1 = tslib_1.__importDefault(require("./tag-splitter"));
7
+ const parser_utils_1 = require("@markuplint/parser-utils");
8
+ function flattenNodes(
9
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
+ nodeTree, rawHtml, createLastText = true) {
11
+ var _a, _b, _c, _d;
12
+ const nodeOrders = arrayize(nodeTree, rawHtml);
13
+ {
14
+ /**
15
+ * Correction prev/next/parent
16
+ */
17
+ let prevToken = null;
18
+ for (const node of nodeOrders) {
19
+ if (!prevToken) {
20
+ prevToken = node;
21
+ continue;
22
+ }
23
+ if (node.type !== 'endtag') {
24
+ prevToken = node;
25
+ continue;
26
+ }
27
+ const endTag = node;
28
+ if (endTag.nodeName.toLowerCase() === 'body' && prevToken.type === 'text') {
29
+ const prevWreckagesText = prevToken;
30
+ const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
31
+ if (wreckages.length > 0 && wreckages[0]) {
32
+ // console.log('wreckages\n', wreckages);
33
+ const lastText = wreckages[0];
34
+ const raw = lastText.raw;
35
+ const startLine = lastText.line;
36
+ const startCol = lastText.col;
37
+ prevWreckagesText.raw = raw;
38
+ prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
39
+ prevWreckagesText.startLine = startLine;
40
+ prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
41
+ prevWreckagesText.startCol = startCol;
42
+ prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ (0, remove_deprecated_node_1.removeDeprecatedNode)(nodeOrders);
48
+ {
49
+ /**
50
+ * getting last node
51
+ */
52
+ let lastNode = null;
53
+ for (const node of nodeOrders) {
54
+ if (node.isGhost) {
55
+ continue;
56
+ }
57
+ lastNode = node;
58
+ }
59
+ if (lastNode) {
60
+ if (lastNode.type === 'text') {
61
+ // Correction for Parse5 AST
62
+ // prev node: ? -> html
63
+ lastNode.prevNode = (_b = (_a = lastNode.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) !== null && _b !== void 0 ? _b : lastNode.parentNode;
64
+ if (lastNode.prevNode) {
65
+ lastNode.prevNode.nextNode = lastNode;
66
+ }
67
+ // parent node: body -> null
68
+ lastNode.parentNode = null;
69
+ // next node: ? -> null
70
+ lastNode.nextNode = null;
71
+ }
72
+ else if (createLastText) {
73
+ /**
74
+ * create Last spaces
75
+ */
76
+ let lastOffset = 0;
77
+ nodeOrders.forEach((node, i) => {
78
+ lastOffset = Math.max(node.endOffset, lastOffset);
79
+ });
80
+ // console.log(lastOffset);
81
+ const lastTextContent = rawHtml.slice(lastOffset);
82
+ // console.log(`"${lastTextContent}"`);
83
+ if (lastTextContent) {
84
+ const line = (_c = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endLine) !== null && _c !== void 0 ? _c : 0;
85
+ const col = (_d = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endCol) !== null && _d !== void 0 ? _d : 0;
86
+ const lastTextNode = {
87
+ uuid: (0, parser_utils_1.uuid)(),
88
+ raw: lastTextContent,
89
+ startOffset: lastOffset,
90
+ endOffset: lastOffset + lastTextContent.length,
91
+ startLine: line,
92
+ endLine: (0, parser_utils_1.getEndLine)(lastTextContent, line),
93
+ startCol: col,
94
+ endCol: (0, parser_utils_1.getEndCol)(lastTextContent, col),
95
+ nodeName: '#text',
96
+ type: 'text',
97
+ parentNode: null,
98
+ prevNode: lastNode,
99
+ nextNode: null,
100
+ isFragment: false,
101
+ isGhost: false,
102
+ };
103
+ lastNode.nextNode = lastTextNode;
104
+ if ((lastNode.type === 'starttag' || lastNode.type === 'endtag') && lastNode.pearNode) {
105
+ lastNode.pearNode.nextNode = lastTextNode;
106
+ }
107
+ nodeOrders.push(lastTextNode);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ /**
113
+ * concat text nodes
114
+ */
115
+ const result = [];
116
+ nodeOrders.forEach(node => {
117
+ var _a, _b;
118
+ const prevNode = (_a = result[result.length - 1]) !== null && _a !== void 0 ? _a : null;
119
+ if (node.type === 'text' && (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'text') {
120
+ prevNode.raw = prevNode.raw + node.raw;
121
+ prevNode.endOffset = node.endOffset;
122
+ prevNode.endLine = node.endLine;
123
+ prevNode.endCol = node.endCol;
124
+ prevNode.nextNode = node.nextNode;
125
+ if (prevNode.parentNode) {
126
+ if (prevNode.parentNode.childNodes) {
127
+ if (prevNode.parentNode.childNodes.findIndex(currentChild => currentChild.uuid === prevNode.uuid) === -1) {
128
+ prevNode.parentNode.childNodes.unshift(prevNode);
129
+ }
130
+ else {
131
+ prevNode.parentNode.childNodes = [prevNode];
132
+ }
133
+ }
134
+ prevNode.parentNode.childNodes = (_b = prevNode.parentNode.childNodes) === null || _b === void 0 ? void 0 : _b.filter(n => n.uuid !== node.uuid);
135
+ }
136
+ if (node.nextNode) {
137
+ node.nextNode.prevNode = prevNode;
138
+ }
139
+ return;
140
+ }
141
+ result.push(node);
142
+ });
143
+ {
144
+ /**
145
+ * Correction prev/next/parent
146
+ */
147
+ let prevToken = null;
148
+ for (const node of result) {
149
+ if (!prevToken) {
150
+ prevToken = node;
151
+ continue;
152
+ }
153
+ if (((prevToken.type === 'endtag' && prevToken.nodeName.toLowerCase() === 'body') ||
154
+ prevToken.type === 'doctype') &&
155
+ node.type === 'text') {
156
+ const nextNode = prevToken.nextNode;
157
+ prevToken.nextNode = node;
158
+ if (prevToken.type === 'endtag' && prevToken.pearNode) {
159
+ prevToken.pearNode.nextNode = node;
160
+ }
161
+ node.prevNode = prevToken;
162
+ node.nextNode = nextNode;
163
+ node.parentNode = prevToken.parentNode;
164
+ }
165
+ // EndTag
166
+ if (node.type === 'starttag' && node.pearNode) {
167
+ const endTag = node.pearNode;
168
+ endTag.pearNode = node;
169
+ endTag.prevNode = node.prevNode;
170
+ endTag.nextNode = node.nextNode;
171
+ }
172
+ // Children
173
+ if (node.type === 'text') {
174
+ const parent = node.parentNode;
175
+ if (parent && parent.type === 'starttag' && parent.nodeName.toLowerCase() === 'html') {
176
+ if (parent.childNodes && !parent.childNodes.some(n => n.uuid === node.uuid)) {
177
+ parent.childNodes.push(node);
178
+ }
179
+ }
180
+ }
181
+ prevToken = node;
182
+ }
183
+ }
184
+ // console.log(nodeOrders.map((n, i) => `${i}: ${n.raw.trim()}`));
185
+ return result;
186
+ }
187
+ exports.flattenNodes = flattenNodes;
188
+ function arrayize(
189
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
190
+ nodeTree, rawHtml) {
191
+ const nodeOrders = [];
192
+ let prevLine = 1;
193
+ let prevCol = 1;
194
+ let currentEndOffset = 0;
195
+ /**
196
+ * pushing list
197
+ */
198
+ (0, parser_utils_1.walk)(nodeTree, node => {
199
+ var _a;
200
+ const diff = node.startOffset - currentEndOffset;
201
+ if (diff > 0) {
202
+ const html = rawHtml.slice(currentEndOffset, node.startOffset);
203
+ /**
204
+ * first white spaces
205
+ */
206
+ if (/^\s+$/.test(html)) {
207
+ const spaces = html;
208
+ const textNode = {
209
+ uuid: (0, parser_utils_1.uuid)(),
210
+ raw: spaces,
211
+ startOffset: currentEndOffset,
212
+ endOffset: currentEndOffset + spaces.length,
213
+ startLine: prevLine,
214
+ endLine: (0, parser_utils_1.getEndLine)(spaces, prevLine),
215
+ startCol: prevCol,
216
+ endCol: (0, parser_utils_1.getEndCol)(spaces, prevCol),
217
+ nodeName: '#text',
218
+ type: 'text',
219
+ parentNode: node.parentNode,
220
+ prevNode: node.prevNode,
221
+ nextNode: node,
222
+ isFragment: false,
223
+ isGhost: false,
224
+ };
225
+ node.prevNode = textNode;
226
+ if (node.parentNode && node.parentNode.childNodes) {
227
+ const newChildNodes = [...node.parentNode.childNodes];
228
+ if (newChildNodes.some(child => {
229
+ return (
230
+ // Out of start offset
231
+ textNode.endOffset < child.startOffset ||
232
+ // Out of end offset
233
+ child.endOffset < textNode.startOffset);
234
+ })) {
235
+ newChildNodes.push(textNode);
236
+ }
237
+ newChildNodes.sort((a, b) => a.startOffset - b.startOffset);
238
+ node.parentNode.childNodes = newChildNodes;
239
+ }
240
+ nodeOrders.push(textNode);
241
+ }
242
+ }
243
+ currentEndOffset = node.startOffset + node.raw.length;
244
+ prevLine = node.endLine;
245
+ prevCol = node.endCol;
246
+ // for ghost nodes
247
+ node.endOffset = (_a = node.endOffset) !== null && _a !== void 0 ? _a : currentEndOffset;
248
+ nodeOrders.push(node);
249
+ });
250
+ return nodeOrders.slice();
251
+ }
@@ -2,12 +2,16 @@ export declare function getLine(html: string, startOffset: number): number;
2
2
  export declare function getCol(html: string, startOffset: number): number;
3
3
  export declare function getEndLine(html: string, line: number): number;
4
4
  export declare function getEndCol(html: string, col: number): number;
5
- export declare function sliceFragment(rawHtml: string, start: number, end: number): {
6
- startOffset: number;
7
- endOffset: number;
8
- startLine: number;
9
- endLine: number;
10
- startCol: number;
11
- endCol: number;
12
- raw: string;
5
+ export declare function sliceFragment(
6
+ rawHtml: string,
7
+ start: number,
8
+ end: number,
9
+ ): {
10
+ startOffset: number;
11
+ endOffset: number;
12
+ startLine: number;
13
+ endLine: number;
14
+ startCol: number;
15
+ endCol: number;
16
+ raw: string;
13
17
  };
@@ -6,8 +6,9 @@ function getLine(html, startOffset) {
6
6
  }
7
7
  exports.getLine = getLine;
8
8
  function getCol(html, startOffset) {
9
+ var _a;
9
10
  const lines = html.slice(0, startOffset).split(/\n/g);
10
- return lines[lines.length - 1].length + 1;
11
+ return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
11
12
  }
12
13
  exports.getCol = getCol;
13
14
  function getEndLine(html, line) {
@@ -0,0 +1 @@
1
+ export declare function getSpaceBefore(offset: number, rawCode: string): import('@markuplint/ml-ast').MLToken;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpaceBefore = void 0;
4
+ const create_token_1 = require("./create-token");
5
+ function getSpaceBefore(offset, rawCode) {
6
+ var _a;
7
+ const aboveCode = rawCode.slice(0, offset);
8
+ const aboveAttrMatched = aboveCode.match(/\s+$/m);
9
+ const aboveAttrChar = (_a = aboveAttrMatched === null || aboveAttrMatched === void 0 ? void 0 : aboveAttrMatched[0]) !== null && _a !== void 0 ? _a : '';
10
+ const spacesBefore = (0, create_token_1.createTokenFromRawCode)(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
11
+ return spacesBefore;
12
+ }
13
+ exports.getSpaceBefore = getSpaceBefore;
@@ -1,4 +1,4 @@
1
1
  export declare function searchIDLAttribute(name: string): {
2
- idlPropName: string | undefined;
3
- contentAttrName: string | undefined;
2
+ idlPropName: string | undefined;
3
+ contentAttrName: string | undefined;
4
4
  };
@@ -108,6 +108,9 @@ const idlContentMap = {
108
108
  pattern: 'pattern',
109
109
  placeholder: 'placeholder',
110
110
  playsInline: 'playsinline',
111
+ popover: 'popover',
112
+ popoverTarget: 'popovertarget',
113
+ popoverTargetAction: 'popovertargetaction',
111
114
  poster: 'poster',
112
115
  preload: 'preload',
113
116
  profile: 'profile',
@@ -397,15 +400,32 @@ const idlContentMap = {
397
400
  yChannelSelector: 'yChannelSelector',
398
401
  z: 'z',
399
402
  zoomAndPan: 'zoomAndPan',
403
+ /**
404
+ * PerformanceElementTiming API
405
+ *
406
+ * @experimental
407
+ * @see https://wicg.github.io/element-timing/#sec-modifications-DOM
408
+ * @see https://wicg.github.io/element-timing/#sec-elements-exposed
409
+ */
410
+ elementTiming: 'elementtiming',
411
+ /**
412
+ * IFrame credentialless
413
+ *
414
+ * @experimental
415
+ * @warning No specification found
416
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/credentialless
417
+ */
418
+ credentialless: 'credentialless',
400
419
  };
401
420
  const list = Object.entries(idlContentMap);
402
421
  function searchIDLAttribute(name) {
422
+ var _a;
403
423
  const camelizedName = camelize(name);
404
- const [idlPropName, contentAttrName] = (/^on[a-z]/.test(name) && [name.toLowerCase(), name.toLowerCase()]) ||
405
- list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
424
+ const [idlPropName, contentAttrName] = /^on[a-z]/.test(name)
425
+ ? [name.toLowerCase(), name.toLowerCase()]
426
+ : (_a = list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
406
427
  contentAttrName.toLowerCase() === name.toLowerCase() ||
407
- hyphenize(idlPropName) === name.toLowerCase()) ||
408
- [];
428
+ hyphenize(idlPropName) === name.toLowerCase())) !== null && _a !== void 0 ? _a : [];
409
429
  return {
410
430
  idlPropName,
411
431
  contentAttrName,
@@ -413,7 +433,7 @@ function searchIDLAttribute(name) {
413
433
  }
414
434
  exports.searchIDLAttribute = searchIDLAttribute;
415
435
  function camelize(str) {
416
- return str.replace(/[:-][a-z]/g, $0 => $0[1].toUpperCase());
436
+ return str.replace(/[:-][a-z]/g, $0 => { var _a, _b; return (_b = (_a = $0[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : ''; });
417
437
  }
418
438
  function hyphenize(str) {
419
439
  return str.replace(/[A-Z]/g, $0 => `-${$0.toLowerCase()}`);
@@ -1,4 +1,4 @@
1
1
  import type { IgnoreBlock, IgnoreTag } from './types';
2
2
  import type { MLASTNode } from '@markuplint/ml-ast';
3
- export declare function ignoreBlock(source: string, tags: IgnoreTag[], maskChar?: string): IgnoreBlock;
3
+ export declare function ignoreBlock(source: string, tags: readonly IgnoreTag[], maskChar?: string): IgnoreBlock;
4
4
  export declare function restoreNode(nodeList: MLASTNode[], ignoreBlock: IgnoreBlock): MLASTNode[];
@@ -13,7 +13,7 @@ function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
13
13
  const attr = maskText(prepend(tag.start, '(?<=(?:"|\'))'), append(tag.end, '(?=(?:"|\'))'), replaced, (startTag, taggedCode, endTag) => {
14
14
  const mask = maskChar.repeat(startTag.length) +
15
15
  taggedCode.replace(/[^\n]/g, maskChar) +
16
- maskChar.repeat((endTag || '').length);
16
+ maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
17
17
  return mask;
18
18
  });
19
19
  replaced = attr.replaced;
@@ -22,7 +22,7 @@ function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
22
22
  const text = maskText(tag.start, tag.end, replaced, (startTag, taggedCode, endTag) => {
23
23
  const mask = maskChar.repeat(startTag.length) +
24
24
  taggedCode.replace(/[^\n]/g, maskChar) +
25
- maskChar.repeat((endTag || '').length);
25
+ maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
26
26
  const taggedMask = `<!${mask.slice(2).slice(0, -1)}>`;
27
27
  return taggedMask;
28
28
  });
@@ -52,19 +52,22 @@ function maskText(start, end, replaced, masking) {
52
52
  index,
53
53
  startTag,
54
54
  taggedCode,
55
- endTag: endTag || null,
55
+ endTag: endTag !== null && endTag !== void 0 ? endTag : null,
56
56
  });
57
57
  /**
58
58
  * It will not replace line breaks because detects line number.
59
59
  */
60
- replaced = above + masking(startTag, taggedCode, endTag) + (below || '');
60
+ replaced = above + masking(startTag, taggedCode, endTag) + (below !== null && below !== void 0 ? below : '');
61
61
  }
62
62
  return {
63
63
  replaced,
64
64
  stack,
65
65
  };
66
66
  }
67
- function restoreNode(nodeList, ignoreBlock) {
67
+ function restoreNode(
68
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
69
+ nodeList, ignoreBlock) {
70
+ var _a, _b, _c, _d, _e;
68
71
  nodeList = nodeList.slice();
69
72
  const { source, stack, maskChar } = ignoreBlock;
70
73
  for (const node of nodeList) {
@@ -80,7 +83,7 @@ function restoreNode(nodeList, ignoreBlock) {
80
83
  for (const tag of stack) {
81
84
  if (node.startOffset <= tag.index && tag.index < node.endOffset) {
82
85
  const start = tag.index - node.startOffset;
83
- const body = tag.startTag + tag.taggedCode + (tag.endTag || '');
86
+ const body = tag.startTag + tag.taggedCode + ((_a = tag.endTag) !== null && _a !== void 0 ? _a : '');
84
87
  const above = node.raw.slice(pointer, start);
85
88
  const below = text.slice(above.length + body.length);
86
89
  if (above) {
@@ -98,6 +101,12 @@ function restoreNode(nodeList, ignoreBlock) {
98
101
  startCol,
99
102
  endCol,
100
103
  };
104
+ if ((_b = node.prevNode) === null || _b === void 0 ? void 0 : _b.nextNode) {
105
+ node.prevNode.nextNode = textNode;
106
+ }
107
+ if ((_c = node.nextNode) === null || _c === void 0 ? void 0 : _c.prevNode) {
108
+ node.nextNode.prevNode = textNode;
109
+ }
101
110
  insertList.push(textNode);
102
111
  }
103
112
  if (body) {
@@ -120,6 +129,12 @@ function restoreNode(nodeList, ignoreBlock) {
120
129
  startCol,
121
130
  endCol,
122
131
  };
132
+ if ((_d = node.prevNode) === null || _d === void 0 ? void 0 : _d.nextNode) {
133
+ node.prevNode.nextNode = bodyNode;
134
+ }
135
+ if ((_e = node.nextNode) === null || _e === void 0 ? void 0 : _e.prevNode) {
136
+ node.nextNode.prevNode = bodyNode;
137
+ }
123
138
  insertList.push(bodyNode);
124
139
  }
125
140
  text = below;
package/lib/index.d.ts CHANGED
@@ -1,10 +1,16 @@
1
+ export * from './const';
2
+ export * from './create-token';
3
+ export * from './debugger';
1
4
  export * from './decision';
5
+ export * from './detect-element-type';
6
+ export * from './flatten-nodes';
2
7
  export * from './get-location';
3
- export * from './create-token';
8
+ export * from './get-space-before';
4
9
  export * from './idl-attributes';
5
- export * from './walker';
6
10
  export * from './ignore-block';
7
11
  export * from './ignore-front-matter';
8
- export * from './debugger';
12
+ export * from './parse-attr';
9
13
  export * from './parser-error';
10
- export * from './detect-element-type';
14
+ export * from './remove-deprecated-node';
15
+ export * from './tag-splitter';
16
+ export * from './walker';
package/lib/index.js CHANGED
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./const"), exports);
5
+ tslib_1.__exportStar(require("./create-token"), exports);
6
+ tslib_1.__exportStar(require("./debugger"), exports);
4
7
  tslib_1.__exportStar(require("./decision"), exports);
8
+ tslib_1.__exportStar(require("./detect-element-type"), exports);
9
+ tslib_1.__exportStar(require("./flatten-nodes"), exports);
5
10
  tslib_1.__exportStar(require("./get-location"), exports);
6
- tslib_1.__exportStar(require("./create-token"), exports);
11
+ tslib_1.__exportStar(require("./get-space-before"), exports);
7
12
  tslib_1.__exportStar(require("./idl-attributes"), exports);
8
- tslib_1.__exportStar(require("./walker"), exports);
9
13
  tslib_1.__exportStar(require("./ignore-block"), exports);
10
14
  tslib_1.__exportStar(require("./ignore-front-matter"), exports);
11
- tslib_1.__exportStar(require("./debugger"), exports);
15
+ tslib_1.__exportStar(require("./parse-attr"), exports);
12
16
  tslib_1.__exportStar(require("./parser-error"), exports);
13
- tslib_1.__exportStar(require("./detect-element-type"), exports);
17
+ tslib_1.__exportStar(require("./remove-deprecated-node"), exports);
18
+ tslib_1.__exportStar(require("./tag-splitter"), exports);
19
+ tslib_1.__exportStar(require("./walker"), exports);