@markuplint/parser-utils 3.11.0 → 4.0.0-alpha.2

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/const.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reSplitterTag = exports.reTagName = exports.reTag = exports.svgElementList = exports.MASK_CHAR = void 0;
4
- exports.MASK_CHAR = '\uE000';
1
+ export const MASK_CHAR = '\uE000';
5
2
  /**
6
3
  * SVG Element list
7
4
  *
8
5
  * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element
9
6
  */
10
- exports.svgElementList = [
7
+ export const svgElementList = [
11
8
  'a',
12
9
  'animate',
13
10
  'animateMotion',
@@ -97,7 +94,7 @@ exports.svgElementList = [
97
94
  'tref',
98
95
  'vkern',
99
96
  ];
100
- exports.reTag = /^<((?:.|\s|\n)+)>\s*$/;
97
+ export const reTag = /^<((?:.|\s|\n)+)>\s*$/;
101
98
  // eslint-disable-next-line no-control-regex
102
- exports.reTagName = /^(?:[a-z][^\u0000\u0009\u000A\u000C\u0020/>]*)/i;
103
- exports.reSplitterTag = /<[^>]+>/g;
99
+ export const reTagName = /^(?:[a-z][^\u0000\u0009\u000A\u000C\u0020/>]*)/i;
100
+ export const reSplitterTag = /<[^>]+>/g;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuid = exports.createTokenFromRawCode = exports.tokenizer = void 0;
4
- const uuid_1 = require("uuid");
5
- const get_location_1 = require("./get-location");
6
- function tokenizer(raw, startLine, startCol, startOffset) {
7
- raw = raw !== null && raw !== void 0 ? raw : '';
8
- const endLine = (0, get_location_1.getEndLine)(raw, startLine);
9
- const endCol = (0, get_location_1.getEndCol)(raw, startCol);
1
+ import { v4 as uuid4 } from 'uuid';
2
+ import { getEndCol, getEndLine, sliceFragment } from './get-location.js';
3
+ export function tokenizer(raw, startLine, startCol, startOffset) {
4
+ raw = raw ?? '';
5
+ const endLine = getEndLine(raw, startLine);
6
+ const endCol = getEndCol(raw, startCol);
10
7
  const endOffset = startOffset + raw.length;
11
8
  return {
12
9
  uuid: uuid(),
@@ -19,17 +16,14 @@ function tokenizer(raw, startLine, startCol, startOffset) {
19
16
  endCol,
20
17
  };
21
18
  }
22
- exports.tokenizer = tokenizer;
23
- function createTokenFromRawCode(raw, startOffset, rawCode) {
24
- raw = raw !== null && raw !== void 0 ? raw : '';
25
- const loc = (0, get_location_1.sliceFragment)(rawCode, startOffset, startOffset + raw.length);
19
+ export function createTokenFromRawCode(raw, startOffset, rawCode) {
20
+ raw = raw ?? '';
21
+ const loc = sliceFragment(rawCode, startOffset, startOffset + raw.length);
26
22
  return {
27
23
  uuid: uuid(),
28
24
  ...loc,
29
25
  };
30
26
  }
31
- exports.createTokenFromRawCode = createTokenFromRawCode;
32
- function uuid() {
33
- return (0, uuid_1.v4)();
27
+ export function uuid() {
28
+ return uuid4();
34
29
  }
35
- exports.uuid = uuid;
package/lib/debugger.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attributesToDebugMaps = exports.nodeListToDebugMaps = void 0;
4
- function nodeListToDebugMaps(
1
+ export function nodeListToDebugMaps(
5
2
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
6
3
  nodeList, withAttr = false) {
7
4
  return nodeList
@@ -20,8 +17,7 @@ nodeList, withAttr = false) {
20
17
  })
21
18
  .flat();
22
19
  }
23
- exports.nodeListToDebugMaps = nodeListToDebugMaps;
24
- function attributesToDebugMaps(
20
+ export function attributesToDebugMaps(
25
21
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
26
22
  attributes) {
27
23
  return attributes.map(n => {
@@ -52,12 +48,10 @@ attributes) {
52
48
  return r;
53
49
  });
54
50
  }
55
- exports.attributesToDebugMaps = attributesToDebugMaps;
56
51
  function tokenDebug(n, type = '') {
57
- var _a, _b, _c, _d;
58
52
  return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${
59
53
  // @ts-ignore
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)}`;
54
+ n.potentialName ?? n.nodeName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
61
55
  }
62
56
  function visibleWhiteSpace(chars) {
63
57
  return chars.replace(/\n/g, '⏎').replace(/\t/g, '→').replace(/\s/g, '␣');
package/lib/decision.js CHANGED
@@ -1,20 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPotentialCustomElementName = exports.isSVGElement = void 0;
4
- const types_1 = require("@markuplint/types");
5
- const const_1 = require("./const");
1
+ import { isCustomElementName } from '@markuplint/types';
2
+ import { svgElementList } from './const.js';
6
3
  /**
7
4
  *
8
5
  *
9
6
  * @param nodeName
10
7
  * @returns
11
8
  */
12
- function isSVGElement(nodeName) {
13
- return const_1.svgElementList.includes(nodeName);
9
+ export function isSVGElement(nodeName) {
10
+ return svgElementList.includes(nodeName);
14
11
  }
15
- exports.isSVGElement = isSVGElement;
16
- const isCEN = (0, types_1.isCustomElementName)();
17
- function isPotentialCustomElementName(tagName) {
12
+ const isCEN = isCustomElementName();
13
+ export function isPotentialCustomElementName(tagName) {
18
14
  return isCEN(tagName);
19
15
  }
20
- exports.isPotentialCustomElementName = isPotentialCustomElementName;
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectElementType = void 0;
4
- const decision_1 = require("./decision");
5
- function detectElementType(name, option, defaultPattern) {
1
+ import { isPotentialCustomElementName } from './decision.js';
2
+ export function detectElementType(name, option, defaultPattern) {
6
3
  if (distinguishAuthoredName(name, option, defaultPattern)) {
7
4
  return 'authored';
8
5
  }
9
- return (0, decision_1.isPotentialCustomElementName)(name) ? 'web-component' : 'html';
6
+ return isPotentialCustomElementName(name) ? 'web-component' : 'html';
10
7
  }
11
- exports.detectElementType = detectElementType;
12
8
  function distinguishAuthoredName(name, pattern, defaultPattern) {
13
9
  if (pattern != null) {
14
10
  return _distinguishAuthoredName(name, pattern);
@@ -1,14 +1,11 @@
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(
1
+ import { uuid } from './create-token.js';
2
+ import { getEndCol, getEndLine } from './get-location.js';
3
+ import { removeDeprecatedNode } from './remove-deprecated-node.js';
4
+ import tagSplitter from './tag-splitter.js';
5
+ import { walk } from './walker.js';
6
+ export function flattenNodes(
9
7
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
8
  nodeTree, rawHtml, createLastText = true) {
11
- var _a, _b, _c, _d;
12
9
  const nodeOrders = arrayize(nodeTree, rawHtml);
13
10
  {
14
11
  /**
@@ -27,7 +24,7 @@ nodeTree, rawHtml, createLastText = true) {
27
24
  const endTag = node;
28
25
  if (endTag.nodeName.toLowerCase() === 'body' && prevToken.type === 'text') {
29
26
  const prevWreckagesText = prevToken;
30
- const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
27
+ const wreckages = tagSplitter(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
31
28
  if (wreckages.length > 0 && wreckages[0]) {
32
29
  // console.log('wreckages\n', wreckages);
33
30
  const lastText = wreckages[0];
@@ -37,14 +34,14 @@ nodeTree, rawHtml, createLastText = true) {
37
34
  prevWreckagesText.raw = raw;
38
35
  prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
39
36
  prevWreckagesText.startLine = startLine;
40
- prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
37
+ prevWreckagesText.endLine = getEndLine(raw, startLine);
41
38
  prevWreckagesText.startCol = startCol;
42
- prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
39
+ prevWreckagesText.endCol = getEndCol(raw, startCol);
43
40
  }
44
41
  }
45
42
  }
46
43
  }
47
- (0, remove_deprecated_node_1.removeDeprecatedNode)(nodeOrders);
44
+ removeDeprecatedNode(nodeOrders);
48
45
  {
49
46
  /**
50
47
  * getting last node
@@ -60,7 +57,7 @@ nodeTree, rawHtml, createLastText = true) {
60
57
  if (lastNode.type === 'text') {
61
58
  // Correction for Parse5 AST
62
59
  // 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;
60
+ lastNode.prevNode = lastNode.parentNode?.parentNode ?? lastNode.parentNode;
64
61
  if (lastNode.prevNode) {
65
62
  lastNode.prevNode.nextNode = lastNode;
66
63
  }
@@ -81,17 +78,17 @@ nodeTree, rawHtml, createLastText = true) {
81
78
  const lastTextContent = rawHtml.slice(lastOffset);
82
79
  // console.log(`"${lastTextContent}"`);
83
80
  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;
81
+ const line = lastNode?.endLine ?? 0;
82
+ const col = lastNode?.endCol ?? 0;
86
83
  const lastTextNode = {
87
- uuid: (0, parser_utils_1.uuid)(),
84
+ uuid: uuid(),
88
85
  raw: lastTextContent,
89
86
  startOffset: lastOffset,
90
87
  endOffset: lastOffset + lastTextContent.length,
91
88
  startLine: line,
92
- endLine: (0, parser_utils_1.getEndLine)(lastTextContent, line),
89
+ endLine: getEndLine(lastTextContent, line),
93
90
  startCol: col,
94
- endCol: (0, parser_utils_1.getEndCol)(lastTextContent, col),
91
+ endCol: getEndCol(lastTextContent, col),
95
92
  nodeName: '#text',
96
93
  type: 'text',
97
94
  parentNode: null,
@@ -114,9 +111,8 @@ nodeTree, rawHtml, createLastText = true) {
114
111
  */
115
112
  const result = [];
116
113
  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') {
114
+ const prevNode = result[result.length - 1] ?? null;
115
+ if (node.type === 'text' && prevNode?.type === 'text') {
120
116
  prevNode.raw = prevNode.raw + node.raw;
121
117
  prevNode.endOffset = node.endOffset;
122
118
  prevNode.endLine = node.endLine;
@@ -131,7 +127,7 @@ nodeTree, rawHtml, createLastText = true) {
131
127
  prevNode.parentNode.childNodes = [prevNode];
132
128
  }
133
129
  }
134
- prevNode.parentNode.childNodes = (_b = prevNode.parentNode.childNodes) === null || _b === void 0 ? void 0 : _b.filter(n => n.uuid !== node.uuid);
130
+ prevNode.parentNode.childNodes = prevNode.parentNode.childNodes?.filter(n => n.uuid !== node.uuid);
135
131
  }
136
132
  if (node.nextNode) {
137
133
  node.nextNode.prevNode = prevNode;
@@ -184,7 +180,6 @@ nodeTree, rawHtml, createLastText = true) {
184
180
  // console.log(nodeOrders.map((n, i) => `${i}: ${n.raw.trim()}`));
185
181
  return result;
186
182
  }
187
- exports.flattenNodes = flattenNodes;
188
183
  function arrayize(
189
184
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
190
185
  nodeTree, rawHtml) {
@@ -195,8 +190,7 @@ nodeTree, rawHtml) {
195
190
  /**
196
191
  * pushing list
197
192
  */
198
- (0, parser_utils_1.walk)(nodeTree, node => {
199
- var _a;
193
+ walk(nodeTree, node => {
200
194
  const diff = node.startOffset - currentEndOffset;
201
195
  if (diff > 0) {
202
196
  const html = rawHtml.slice(currentEndOffset, node.startOffset);
@@ -206,14 +200,14 @@ nodeTree, rawHtml) {
206
200
  if (/^\s+$/.test(html)) {
207
201
  const spaces = html;
208
202
  const textNode = {
209
- uuid: (0, parser_utils_1.uuid)(),
203
+ uuid: uuid(),
210
204
  raw: spaces,
211
205
  startOffset: currentEndOffset,
212
206
  endOffset: currentEndOffset + spaces.length,
213
207
  startLine: prevLine,
214
- endLine: (0, parser_utils_1.getEndLine)(spaces, prevLine),
208
+ endLine: getEndLine(spaces, prevLine),
215
209
  startCol: prevCol,
216
- endCol: (0, parser_utils_1.getEndCol)(spaces, prevCol),
210
+ endCol: getEndCol(spaces, prevCol),
217
211
  nodeName: '#text',
218
212
  type: 'text',
219
213
  parentNode: node.parentNode,
@@ -244,7 +238,7 @@ nodeTree, rawHtml) {
244
238
  prevLine = node.endLine;
245
239
  prevCol = node.endCol;
246
240
  // for ghost nodes
247
- node.endOffset = (_a = node.endOffset) !== null && _a !== void 0 ? _a : currentEndOffset;
241
+ node.endOffset = node.endOffset ?? currentEndOffset;
248
242
  nodeOrders.push(node);
249
243
  });
250
244
  return nodeOrders.slice();
@@ -1,28 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sliceFragment = exports.getEndCol = exports.getEndLine = exports.getCol = exports.getLine = void 0;
4
- function getLine(html, startOffset) {
1
+ export function getLine(html, startOffset) {
5
2
  return html.slice(0, startOffset).split(/\n/g).length;
6
3
  }
7
- exports.getLine = getLine;
8
- function getCol(html, startOffset) {
9
- var _a;
4
+ export function getCol(html, startOffset) {
10
5
  const lines = html.slice(0, startOffset).split(/\n/g);
11
- return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
6
+ return (lines[lines.length - 1] ?? '').length + 1;
12
7
  }
13
- exports.getCol = getCol;
14
- function getEndLine(html, line) {
8
+ export function getEndLine(html, line) {
15
9
  return html.split(/\r?\n/).length - 1 + line;
16
10
  }
17
- exports.getEndLine = getEndLine;
18
- function getEndCol(html, col) {
11
+ export function getEndCol(html, col) {
19
12
  const lines = html.split(/\r?\n/);
20
13
  const lineCount = lines.length;
21
14
  const lastLine = lines.pop();
22
15
  return lineCount > 1 ? lastLine.length + 1 : col + html.length;
23
16
  }
24
- exports.getEndCol = getEndCol;
25
- function sliceFragment(rawHtml, start, end) {
17
+ export function sliceFragment(rawHtml, start, end) {
26
18
  const raw = rawHtml.slice(start, end);
27
19
  return {
28
20
  startOffset: start,
@@ -34,4 +26,3 @@ function sliceFragment(rawHtml, start, end) {
34
26
  raw,
35
27
  };
36
28
  }
37
- exports.sliceFragment = sliceFragment;
@@ -1 +1 @@
1
- export declare function getSpaceBefore(offset: number, rawCode: string): import("@markuplint/ml-ast").MLToken;
1
+ export declare function getSpaceBefore(offset: number, rawCode: string): import("packages/@markuplint/ml-ast/lib/types.js").MLToken;
@@ -1,13 +1,8 @@
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;
1
+ import { createTokenFromRawCode } from './create-token.js';
2
+ export function getSpaceBefore(offset, rawCode) {
7
3
  const aboveCode = rawCode.slice(0, offset);
8
4
  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);
5
+ const aboveAttrChar = aboveAttrMatched?.[0] ?? '';
6
+ const spacesBefore = createTokenFromRawCode(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
11
7
  return spacesBefore;
12
8
  }
13
- exports.getSpaceBefore = getSpaceBefore;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchIDLAttribute = void 0;
4
1
  /**
5
2
  * IDL attributes VS Content attributes
6
3
  *
@@ -418,22 +415,20 @@ const idlContentMap = {
418
415
  credentialless: 'credentialless',
419
416
  };
420
417
  const list = Object.entries(idlContentMap);
421
- function searchIDLAttribute(name) {
422
- var _a;
418
+ export function searchIDLAttribute(name) {
423
419
  const camelizedName = camelize(name);
424
420
  const [idlPropName, contentAttrName] = /^on[a-z]/.test(name)
425
421
  ? [name.toLowerCase(), name.toLowerCase()]
426
- : (_a = list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
422
+ : list.find(([idlPropName, contentAttrName]) => idlPropName.toLowerCase() === camelizedName.toLowerCase() ||
427
423
  contentAttrName.toLowerCase() === name.toLowerCase() ||
428
- hyphenize(idlPropName) === name.toLowerCase())) !== null && _a !== void 0 ? _a : [];
424
+ hyphenize(idlPropName) === name.toLowerCase()) ?? [];
429
425
  return {
430
426
  idlPropName,
431
427
  contentAttrName,
432
428
  };
433
429
  }
434
- exports.searchIDLAttribute = searchIDLAttribute;
435
430
  function camelize(str) {
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 : ''; });
431
+ return str.replace(/[:-][a-z]/g, $0 => $0[1]?.toUpperCase() ?? '');
437
432
  }
438
433
  function hyphenize(str) {
439
434
  return str.replace(/[A-Z]/g, $0 => `-${$0.toLowerCase()}`);
@@ -1,4 +1,4 @@
1
- import type { IgnoreBlock, IgnoreTag } from './types';
1
+ import type { IgnoreBlock, IgnoreTag } from './types.js';
2
2
  import type { MLASTNode } from '@markuplint/ml-ast';
3
3
  export declare function ignoreBlock(source: string, tags: readonly IgnoreTag[], maskChar?: string): IgnoreBlock;
4
4
  export declare function restoreNode(nodeList: MLASTNode[], ignoreBlock: IgnoreBlock): MLASTNode[];
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.restoreNode = exports.ignoreBlock = void 0;
4
- const const_1 = require("./const");
5
- const create_token_1 = require("./create-token");
6
- const get_location_1 = require("./get-location");
7
- const siblings_correction_1 = require("./siblings-correction");
8
- function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
1
+ import { MASK_CHAR } from './const.js';
2
+ import { uuid } from './create-token.js';
3
+ import { sliceFragment } from './get-location.js';
4
+ import { siblingsCorrection } from './siblings-correction.js';
5
+ export function ignoreBlock(source, tags, maskChar = MASK_CHAR) {
9
6
  let replaced = source;
10
7
  const stack = [];
11
8
  for (const tag of tags) {
@@ -13,7 +10,7 @@ function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
13
10
  const attr = maskText(prepend(tag.start, '(?<=(?:"|\'))'), append(tag.end, '(?=(?:"|\'))'), replaced, (startTag, taggedCode, endTag) => {
14
11
  const mask = maskChar.repeat(startTag.length) +
15
12
  taggedCode.replace(/[^\n]/g, maskChar) +
16
- maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
13
+ maskChar.repeat((endTag ?? '').length);
17
14
  return mask;
18
15
  });
19
16
  replaced = attr.replaced;
@@ -22,7 +19,7 @@ function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
22
19
  const text = maskText(tag.start, tag.end, replaced, (startTag, taggedCode, endTag) => {
23
20
  const mask = maskChar.repeat(startTag.length) +
24
21
  taggedCode.replace(/[^\n]/g, maskChar) +
25
- maskChar.repeat((endTag !== null && endTag !== void 0 ? endTag : '').length);
22
+ maskChar.repeat((endTag ?? '').length);
26
23
  const taggedMask = `<!${mask.slice(2).slice(0, -1)}>`;
27
24
  return taggedMask;
28
25
  });
@@ -37,7 +34,6 @@ function ignoreBlock(source, tags, maskChar = const_1.MASK_CHAR) {
37
34
  maskChar,
38
35
  };
39
36
  }
40
- exports.ignoreBlock = ignoreBlock;
41
37
  function maskText(start, end, replaced, masking) {
42
38
  const stack = [];
43
39
  start = removeGlobalOption(start);
@@ -52,22 +48,21 @@ function maskText(start, end, replaced, masking) {
52
48
  index,
53
49
  startTag,
54
50
  taggedCode,
55
- endTag: endTag !== null && endTag !== void 0 ? endTag : null,
51
+ endTag: endTag ?? null,
56
52
  });
57
53
  /**
58
54
  * It will not replace line breaks because detects line number.
59
55
  */
60
- replaced = above + masking(startTag, taggedCode, endTag) + (below !== null && below !== void 0 ? below : '');
56
+ replaced = above + masking(startTag, taggedCode, endTag) + (below ?? '');
61
57
  }
62
58
  return {
63
59
  replaced,
64
60
  stack,
65
61
  };
66
62
  }
67
- function restoreNode(
63
+ export function restoreNode(
68
64
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
69
65
  nodeList, ignoreBlock) {
70
- var _a, _b, _c, _d, _e;
71
66
  nodeList = nodeList.slice();
72
67
  const { source, stack, maskChar } = ignoreBlock;
73
68
  for (const node of nodeList) {
@@ -83,15 +78,15 @@ nodeList, ignoreBlock) {
83
78
  for (const tag of stack) {
84
79
  if (node.startOffset <= tag.index && tag.index < node.endOffset) {
85
80
  const start = tag.index - node.startOffset;
86
- const body = tag.startTag + tag.taggedCode + ((_a = tag.endTag) !== null && _a !== void 0 ? _a : '');
81
+ const body = tag.startTag + tag.taggedCode + (tag.endTag ?? '');
87
82
  const above = node.raw.slice(pointer, start);
88
83
  const below = text.slice(above.length + body.length);
89
84
  if (above) {
90
85
  const offset = node.startOffset + pointer;
91
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + above.length);
86
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + above.length);
92
87
  const textNode = {
93
88
  ...node,
94
- uuid: (0, create_token_1.uuid)(),
89
+ uuid: uuid(),
95
90
  type: 'text',
96
91
  raw,
97
92
  startOffset,
@@ -101,19 +96,19 @@ nodeList, ignoreBlock) {
101
96
  startCol,
102
97
  endCol,
103
98
  };
104
- if ((_b = node.prevNode) === null || _b === void 0 ? void 0 : _b.nextNode) {
99
+ if (node.prevNode?.nextNode) {
105
100
  node.prevNode.nextNode = textNode;
106
101
  }
107
- if ((_c = node.nextNode) === null || _c === void 0 ? void 0 : _c.prevNode) {
102
+ if (node.nextNode?.prevNode) {
108
103
  node.nextNode.prevNode = textNode;
109
104
  }
110
105
  insertList.push(textNode);
111
106
  }
112
107
  if (body) {
113
108
  const offset = node.startOffset + pointer + above.length;
114
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + body.length);
109
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + body.length);
115
110
  const bodyNode = {
116
- uuid: (0, create_token_1.uuid)(),
111
+ uuid: uuid(),
117
112
  type: 'psblock',
118
113
  nodeName: `#ps:${tag.type}`,
119
114
  raw,
@@ -129,10 +124,10 @@ nodeList, ignoreBlock) {
129
124
  startCol,
130
125
  endCol,
131
126
  };
132
- if ((_d = node.prevNode) === null || _d === void 0 ? void 0 : _d.nextNode) {
127
+ if (node.prevNode?.nextNode) {
133
128
  node.prevNode.nextNode = bodyNode;
134
129
  }
135
- if ((_e = node.nextNode) === null || _e === void 0 ? void 0 : _e.prevNode) {
130
+ if (node.nextNode?.prevNode) {
136
131
  node.nextNode.prevNode = bodyNode;
137
132
  }
138
133
  insertList.push(bodyNode);
@@ -143,10 +138,10 @@ nodeList, ignoreBlock) {
143
138
  }
144
139
  if (text) {
145
140
  const offset = node.endOffset - text.length;
146
- const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = (0, get_location_1.sliceFragment)(source, offset, offset + text.length);
141
+ const { raw, startOffset, endOffset, startLine, endLine, startCol, endCol } = sliceFragment(source, offset, offset + text.length);
147
142
  const textNode = {
148
143
  ...node,
149
- uuid: (0, create_token_1.uuid)(),
144
+ uuid: uuid(),
150
145
  type: 'text',
151
146
  raw,
152
147
  startOffset,
@@ -158,7 +153,7 @@ nodeList, ignoreBlock) {
158
153
  };
159
154
  insertList.push(textNode);
160
155
  }
161
- (0, siblings_correction_1.siblingsCorrection)(insertList);
156
+ siblingsCorrection(insertList);
162
157
  if (parentNode) {
163
158
  parentNode.childNodes = insertList;
164
159
  }
@@ -185,7 +180,6 @@ nodeList, ignoreBlock) {
185
180
  }
186
181
  return nodeList;
187
182
  }
188
- exports.restoreNode = restoreNode;
189
183
  function snap(str, reg) {
190
184
  const matched = reg.exec(str);
191
185
  if (!matched) {
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ignoreFrontMatter = void 0;
4
- function ignoreFrontMatter(code) {
1
+ export function ignoreFrontMatter(code) {
5
2
  const reStart = /^(?:\s*\r?\n)?---\r?\n/.exec(code);
6
3
  if (!reStart) {
7
4
  return code;
@@ -18,4 +15,3 @@ function ignoreFrontMatter(code) {
18
15
  const masked = frontMatter.replace(/[^\r\n]/g, ' ');
19
16
  return masked + afterCode;
20
17
  }
21
- exports.ignoreFrontMatter = ignoreFrontMatter;
package/lib/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export * from './const';
2
- export * from './create-token';
3
- export * from './debugger';
4
- export * from './decision';
5
- export * from './detect-element-type';
6
- export * from './flatten-nodes';
7
- export * from './get-location';
8
- export * from './get-space-before';
9
- export * from './idl-attributes';
10
- export * from './ignore-block';
11
- export * from './ignore-front-matter';
12
- export * from './parse-attr';
13
- export * from './parser-error';
14
- export * from './remove-deprecated-node';
15
- export * from './tag-splitter';
16
- export * from './walker';
1
+ export * from './const.js';
2
+ export * from './create-token.js';
3
+ export * from './debugger.js';
4
+ export * from './decision.js';
5
+ export * from './detect-element-type.js';
6
+ export * from './flatten-nodes.js';
7
+ export * from './get-location.js';
8
+ export * from './get-space-before.js';
9
+ export * from './idl-attributes.js';
10
+ export * from './ignore-block.js';
11
+ export * from './ignore-front-matter.js';
12
+ export * from './parse-attr.js';
13
+ export * from './parser-error.js';
14
+ export * from './remove-deprecated-node.js';
15
+ export * from './tag-splitter.js';
16
+ export * from './walker.js';
package/lib/index.js CHANGED
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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);
7
- tslib_1.__exportStar(require("./decision"), exports);
8
- tslib_1.__exportStar(require("./detect-element-type"), exports);
9
- tslib_1.__exportStar(require("./flatten-nodes"), exports);
10
- tslib_1.__exportStar(require("./get-location"), exports);
11
- tslib_1.__exportStar(require("./get-space-before"), exports);
12
- tslib_1.__exportStar(require("./idl-attributes"), exports);
13
- tslib_1.__exportStar(require("./ignore-block"), exports);
14
- tslib_1.__exportStar(require("./ignore-front-matter"), exports);
15
- tslib_1.__exportStar(require("./parse-attr"), exports);
16
- tslib_1.__exportStar(require("./parser-error"), 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);
1
+ export * from './const.js';
2
+ export * from './create-token.js';
3
+ export * from './debugger.js';
4
+ export * from './decision.js';
5
+ export * from './detect-element-type.js';
6
+ export * from './flatten-nodes.js';
7
+ export * from './get-location.js';
8
+ export * from './get-space-before.js';
9
+ export * from './idl-attributes.js';
10
+ export * from './ignore-block.js';
11
+ export * from './ignore-front-matter.js';
12
+ export * from './parse-attr.js';
13
+ export * from './parser-error.js';
14
+ export * from './remove-deprecated-node.js';
15
+ export * from './tag-splitter.js';
16
+ export * from './walker.js';