@markuplint/parser-utils 4.0.0-alpha.1 → 4.0.0-alpha.11

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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/lib/attr-tokenizer.d.ts +18 -0
  3. package/lib/attr-tokenizer.js +169 -0
  4. package/lib/const.d.ts +8 -1
  5. package/lib/const.js +9 -3
  6. package/lib/debug.d.ts +4 -0
  7. package/lib/debug.js +6 -0
  8. package/lib/debugger.d.ts +3 -2
  9. package/lib/debugger.js +38 -33
  10. package/lib/detect-element-type.js +1 -1
  11. package/lib/enums.d.ts +16 -0
  12. package/lib/enums.js +18 -0
  13. package/lib/get-location.d.ts +4 -13
  14. package/lib/get-location.js +11 -22
  15. package/lib/idl-attributes.js +2 -2
  16. package/lib/ignore-block.d.ts +3 -2
  17. package/lib/ignore-block.js +69 -119
  18. package/lib/ignore-front-matter.d.ts +4 -1
  19. package/lib/ignore-front-matter.js +14 -5
  20. package/lib/index.d.ts +4 -13
  21. package/lib/index.js +4 -13
  22. package/lib/parser-error.d.ts +1 -0
  23. package/lib/parser-error.js +1 -0
  24. package/lib/parser.d.ts +108 -0
  25. package/lib/parser.js +1078 -0
  26. package/lib/script-parser.d.ts +5 -0
  27. package/lib/script-parser.js +12 -0
  28. package/lib/sort-nodes.d.ts +2 -0
  29. package/lib/sort-nodes.js +18 -0
  30. package/lib/types.d.ts +40 -2
  31. package/package.json +13 -8
  32. package/lib/create-token.d.ts +0 -4
  33. package/lib/create-token.js +0 -29
  34. package/lib/flatten-nodes.d.ts +0 -2
  35. package/lib/flatten-nodes.js +0 -245
  36. package/lib/get-space-before.d.ts +0 -1
  37. package/lib/get-space-before.js +0 -8
  38. package/lib/parse-attr.d.ts +0 -24
  39. package/lib/parse-attr.js +0 -144
  40. package/lib/remove-deprecated-node.d.ts +0 -7
  41. package/lib/remove-deprecated-node.js +0 -39
  42. package/lib/siblings-correction.d.ts +0 -9
  43. package/lib/siblings-correction.js +0 -21
  44. package/lib/tag-splitter.d.ts +0 -7
  45. package/lib/tag-splitter.js +0 -89
  46. package/lib/walker.d.ts +0 -2
  47. package/lib/walker.js +0 -18
@@ -1,21 +0,0 @@
1
- /**
2
- * Correct the references to prevNode and nextNode in the order listed.
3
- *
4
- * @param nodeList
5
- * @affects nodeList[].prevNode
6
- * @affects nodeList[].nextNode
7
- */
8
- export function siblingsCorrection(
9
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
- nodeList) {
11
- for (let i = 0; i < nodeList.length; i++) {
12
- const prevNode = nodeList[i - 1] ?? null;
13
- const node = nodeList[i];
14
- if (!node) {
15
- continue;
16
- }
17
- const nextNode = nodeList[i + 1] ?? null;
18
- node.prevNode = prevNode;
19
- node.nextNode = nextNode;
20
- }
21
- }
@@ -1,7 +0,0 @@
1
- export interface N {
2
- type: 'text' | 'starttag' | 'endtag' | 'comment' | 'boguscomment';
3
- raw: string;
4
- line: number;
5
- col: number;
6
- }
7
- export default function tagSplitter(raw: string, line: number, col: number): N[];
@@ -1,89 +0,0 @@
1
- import { reSplitterTag, reTagName } from './const.js';
2
- import { getEndCol, getEndLine } from '@markuplint/parser-utils';
3
- export default function tagSplitter(raw, line, col) {
4
- return withLocation(tagSplitterAsString(raw), line, col);
5
- }
6
- function tagSplitterAsString(raw) {
7
- const tagMatches = raw.match(reSplitterTag);
8
- if (!tagMatches) {
9
- return [raw];
10
- }
11
- const tokens = Array.from(tagMatches);
12
- tokens.unshift(); // remove all match
13
- const nodes = [];
14
- let rest = raw;
15
- for (const token of tokens) {
16
- const index = rest.indexOf(token);
17
- let length = token.length;
18
- if (index > 0) {
19
- const text = rest.slice(0, index);
20
- nodes.push(text);
21
- length += text.length;
22
- }
23
- nodes.push(token);
24
- rest = rest.slice(length);
25
- }
26
- if (rest) {
27
- nodes.push(rest);
28
- }
29
- return nodes;
30
- }
31
- function withLocation(nodes, line, col) {
32
- const result = [];
33
- for (const node of nodes) {
34
- if (node[0] !== '<') {
35
- result.push({
36
- type: 'text',
37
- raw: node,
38
- line,
39
- col,
40
- });
41
- }
42
- else {
43
- const label = node.slice(1).slice(0, -1);
44
- if (reTagName.test(label)) {
45
- result.push({
46
- type: 'starttag',
47
- raw: node,
48
- line,
49
- col,
50
- });
51
- }
52
- else if (label[0] === '/') {
53
- result.push({
54
- type: 'endtag',
55
- raw: node,
56
- line,
57
- col,
58
- });
59
- }
60
- else if (label[0] === '!') {
61
- result.push({
62
- type: 'comment',
63
- raw: node,
64
- line,
65
- col,
66
- });
67
- }
68
- else if (label[0] === '?') {
69
- result.push({
70
- type: 'boguscomment',
71
- raw: node,
72
- line,
73
- col,
74
- });
75
- }
76
- else {
77
- result.push({
78
- type: 'text',
79
- raw: node,
80
- line,
81
- col,
82
- });
83
- }
84
- }
85
- line = getEndLine(node, line);
86
- col = getEndCol(node, col);
87
- }
88
- return result;
89
- }
package/lib/walker.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { MLASTNode, Walker } from '@markuplint/ml-ast';
2
- export declare function walk(nodeList: readonly MLASTNode[], walker: Walker, depth?: number): void;
package/lib/walker.js DELETED
@@ -1,18 +0,0 @@
1
- export function walk(
2
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
3
- nodeList, walker, depth = 0) {
4
- for (const node of nodeList) {
5
- walker(node, depth);
6
- if ('childNodes' in node) {
7
- if (node.type === 'endtag') {
8
- continue;
9
- }
10
- if (node.childNodes && node.childNodes.length > 0) {
11
- walk(node.childNodes, walker, depth + 1);
12
- }
13
- if ('pearNode' in node && node.pearNode) {
14
- walker(node.pearNode, depth);
15
- }
16
- }
17
- }
18
- }