@markuplint/parser-utils 4.0.0-dev.28 → 4.0.0-rc.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.
Files changed (45) 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 +41 -19
  10. package/lib/enums.d.ts +16 -0
  11. package/lib/enums.js +18 -0
  12. package/lib/get-location.d.ts +4 -13
  13. package/lib/get-location.js +10 -21
  14. package/lib/ignore-block.d.ts +3 -2
  15. package/lib/ignore-block.js +68 -118
  16. package/lib/ignore-front-matter.d.ts +4 -1
  17. package/lib/ignore-front-matter.js +13 -4
  18. package/lib/index.d.ts +4 -13
  19. package/lib/index.js +4 -13
  20. package/lib/parser-error.d.ts +1 -0
  21. package/lib/parser-error.js +1 -0
  22. package/lib/parser.d.ts +112 -0
  23. package/lib/parser.js +1120 -0
  24. package/lib/script-parser.d.ts +5 -0
  25. package/lib/script-parser.js +12 -0
  26. package/lib/sort-nodes.d.ts +2 -0
  27. package/lib/sort-nodes.js +18 -0
  28. package/lib/types.d.ts +40 -2
  29. package/package.json +12 -6
  30. package/lib/create-token.d.ts +0 -4
  31. package/lib/create-token.js +0 -29
  32. package/lib/flatten-nodes.d.ts +0 -2
  33. package/lib/flatten-nodes.js +0 -247
  34. package/lib/get-space-before.d.ts +0 -1
  35. package/lib/get-space-before.js +0 -8
  36. package/lib/parse-attr.d.ts +0 -24
  37. package/lib/parse-attr.js +0 -144
  38. package/lib/remove-deprecated-node.d.ts +0 -7
  39. package/lib/remove-deprecated-node.js +0 -39
  40. package/lib/siblings-correction.d.ts +0 -9
  41. package/lib/siblings-correction.js +0 -21
  42. package/lib/tag-splitter.d.ts +0 -7
  43. package/lib/tag-splitter.js +0 -96
  44. package/lib/walker.d.ts +0 -2
  45. package/lib/walker.js +0 -18
@@ -0,0 +1,5 @@
1
+ export declare function scriptParser(script: string): ScriptTokenType[];
2
+ export type ScriptTokenType = {
3
+ type: 'Identifier' | 'Boolean' | 'Numeric' | 'String' | 'Template' | 'Punctuator';
4
+ value: string;
5
+ };
@@ -0,0 +1,12 @@
1
+ // @ts-ignore
2
+ import { tokenize } from 'espree';
3
+ export function scriptParser(script) {
4
+ const tokens = tokenize(script, {
5
+ ecmaVersion: 'latest',
6
+ loc: false,
7
+ });
8
+ return tokens.map((token) => ({
9
+ type: token.type,
10
+ value: token.value,
11
+ }));
12
+ }
@@ -0,0 +1,2 @@
1
+ import type { MLASTNodeTreeItem } from '@markuplint/ml-ast';
2
+ export declare function sortNodes(a: MLASTNodeTreeItem, b: MLASTNodeTreeItem): 1 | -1 | 0;
@@ -0,0 +1,18 @@
1
+ export function sortNodes(a, b) {
2
+ if (a.startOffset === b.startOffset) {
3
+ return sort(a, b, 'endOffset');
4
+ }
5
+ return sort(a, b, 'startOffset');
6
+ }
7
+ function sort(a, b, key) {
8
+ if (Number.isNaN(a[key]) || Number.isNaN(b[key])) {
9
+ return 0;
10
+ }
11
+ if (a[key] < b[key]) {
12
+ return -1;
13
+ }
14
+ if (a[key] > b[key]) {
15
+ return 1;
16
+ }
17
+ return 0;
18
+ }
package/lib/types.d.ts CHANGED
@@ -1,14 +1,48 @@
1
+ import type { EndTagType, MLASTParentNode, ParserOptions as ConfigParserOptions } from '@markuplint/ml-ast';
2
+ export type ParserOptions = {
3
+ readonly booleanish?: boolean;
4
+ readonly endTagType?: EndTagType;
5
+ readonly ignoreTags?: readonly IgnoreTag[];
6
+ readonly maskChar?: string;
7
+ readonly tagNameCaseSensitive?: boolean;
8
+ readonly selfCloseType?: SelfCloseType;
9
+ readonly spaceChars?: readonly string[];
10
+ readonly rawTextElements?: readonly string[];
11
+ };
12
+ export type ParseOptions = ConfigParserOptions & {
13
+ readonly offsetOffset?: number;
14
+ readonly offsetLine?: number;
15
+ readonly offsetColumn?: number;
16
+ readonly depth?: number;
17
+ };
18
+ export type Tokenized<N extends {} = {}, State extends unknown = null> = {
19
+ readonly ast: N[];
20
+ readonly isFragment: boolean;
21
+ readonly state?: State;
22
+ };
23
+ export type Token = {
24
+ readonly raw: string;
25
+ readonly startOffset: number;
26
+ readonly startLine: number;
27
+ readonly startCol: number;
28
+ };
29
+ export type ChildToken = Token & {
30
+ readonly depth: number;
31
+ readonly parentNode: MLASTParentNode | null;
32
+ };
33
+ export type SelfCloseType = 'html' | 'xml' | 'html+xml';
1
34
  export type Code = {
2
35
  readonly type: string;
3
36
  readonly index: number;
4
37
  readonly startTag: string;
5
38
  readonly taggedCode: string;
6
39
  readonly endTag: string | null;
40
+ resolved: boolean;
7
41
  };
8
42
  export type IgnoreTag = {
9
43
  readonly type: string;
10
- readonly start: Readonly<RegExp>;
11
- readonly end: Readonly<RegExp>;
44
+ readonly start: Readonly<RegExp> | string;
45
+ readonly end: Readonly<RegExp> | string;
12
46
  };
13
47
  export type IgnoreBlock = {
14
48
  readonly source: string;
@@ -16,3 +50,7 @@ export type IgnoreBlock = {
16
50
  readonly stack: readonly Code[];
17
51
  readonly maskChar: string;
18
52
  };
53
+ export type QuoteSet = {
54
+ readonly start: string;
55
+ readonly end: string;
56
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/parser-utils",
3
- "version": "4.0.0-dev.28+0131de5e",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "Utility module for markuplint parser plugin",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -10,6 +10,9 @@
10
10
  "exports": {
11
11
  ".": {
12
12
  "import": "./lib/index.js"
13
+ },
14
+ "./location": {
15
+ "import": "./lib/get-location.js"
13
16
  }
14
17
  },
15
18
  "types": "lib/index.d.ts",
@@ -24,11 +27,14 @@
24
27
  "clean": "tsc --build --clean"
25
28
  },
26
29
  "dependencies": {
27
- "@markuplint/ml-ast": "4.0.0-dev.28+0131de5e",
28
- "@markuplint/types": "4.0.0-dev.28+0131de5e",
29
- "@types/uuid": "^9.0.6",
30
- "type-fest": "^4.5.0",
30
+ "@markuplint/ml-ast": "4.0.0-rc.0",
31
+ "@markuplint/ml-spec": "4.0.0-rc.0",
32
+ "@markuplint/types": "4.0.0-rc.0",
33
+ "@types/uuid": "^9.0.8",
34
+ "debug": "^4.3.4",
35
+ "espree": "^10.0.0",
36
+ "type-fest": "^4.10.2",
31
37
  "uuid": "^9.0.1"
32
38
  },
33
- "gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
39
+ "gitHead": "3fdeb45cb69ed52b3a215a7520cea1181601443f"
34
40
  }
@@ -1,4 +0,0 @@
1
- import type { MLToken } from '@markuplint/ml-ast';
2
- export declare function tokenizer(raw: string | null, startLine: number, startCol: number, startOffset: number): MLToken;
3
- export declare function createTokenFromRawCode(raw: string | null, startOffset: number, rawCode: string): MLToken;
4
- export declare function uuid(): string;
@@ -1,29 +0,0 @@
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);
7
- const endOffset = startOffset + raw.length;
8
- return {
9
- uuid: uuid(),
10
- raw,
11
- startOffset,
12
- endOffset,
13
- startLine,
14
- endLine,
15
- startCol,
16
- endCol,
17
- };
18
- }
19
- export function createTokenFromRawCode(raw, startOffset, rawCode) {
20
- raw = raw ?? '';
21
- const loc = sliceFragment(rawCode, startOffset, startOffset + raw.length);
22
- return {
23
- uuid: uuid(),
24
- ...loc,
25
- };
26
- }
27
- export function uuid() {
28
- return uuid4();
29
- }
@@ -1,2 +0,0 @@
1
- import type { MLASTNode } from '@markuplint/ml-ast';
2
- export declare function flattenNodes(nodeTree: MLASTNode[], rawHtml: string, createLastText?: boolean): MLASTNode[];
@@ -1,247 +0,0 @@
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(
7
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
- nodeTree, rawHtml, createLastText = true) {
9
- const nodeOrders = arrayize(nodeTree, rawHtml);
10
- {
11
- /**
12
- * Correction prev/next/parent
13
- */
14
- let prevToken = null;
15
- for (const node of nodeOrders) {
16
- if (!prevToken) {
17
- prevToken = node;
18
- continue;
19
- }
20
- if (node.type !== 'endtag') {
21
- prevToken = node;
22
- continue;
23
- }
24
- const endTag = node;
25
- if (endTag.nodeName.toLowerCase() === 'body' && prevToken.type === 'text') {
26
- const prevWreckagesText = prevToken;
27
- const wreckages = tagSplitter(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
28
- if (wreckages.length > 0 && wreckages[0]) {
29
- // console.log('wreckages\n', wreckages);
30
- const lastText = wreckages[0];
31
- const raw = lastText.raw;
32
- const startLine = lastText.line;
33
- const startCol = lastText.col;
34
- prevWreckagesText.raw = raw;
35
- prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
36
- prevWreckagesText.startLine = startLine;
37
- prevWreckagesText.endLine = getEndLine(raw, startLine);
38
- prevWreckagesText.startCol = startCol;
39
- prevWreckagesText.endCol = getEndCol(raw, startCol);
40
- }
41
- }
42
- }
43
- }
44
- removeDeprecatedNode(nodeOrders);
45
- {
46
- /**
47
- * getting last node
48
- */
49
- let lastNode = null;
50
- for (const node of nodeOrders) {
51
- if (node.isGhost) {
52
- continue;
53
- }
54
- lastNode = node;
55
- }
56
- if (lastNode) {
57
- if (lastNode.type === 'text') {
58
- // Correction for Parse5 AST
59
- // prev node: ? -> html
60
- lastNode.prevNode = lastNode.parentNode?.parentNode ?? lastNode.parentNode;
61
- if (lastNode.prevNode) {
62
- lastNode.prevNode.nextNode = lastNode;
63
- }
64
- // parent node: body -> null
65
- lastNode.parentNode = null;
66
- // next node: ? -> null
67
- lastNode.nextNode = null;
68
- }
69
- else if (createLastText) {
70
- /**
71
- * create Last spaces
72
- */
73
- let lastOffset = 0;
74
- for (const node of nodeOrders) {
75
- lastOffset = Math.max(node.endOffset, lastOffset);
76
- }
77
- // console.log(lastOffset);
78
- const lastTextContent = rawHtml.slice(lastOffset);
79
- // console.log(`"${lastTextContent}"`);
80
- if (lastTextContent) {
81
- const line = lastNode?.endLine ?? 0;
82
- const col = lastNode?.endCol ?? 0;
83
- const lastTextNode = {
84
- uuid: uuid(),
85
- raw: lastTextContent,
86
- startOffset: lastOffset,
87
- endOffset: lastOffset + lastTextContent.length,
88
- startLine: line,
89
- endLine: getEndLine(lastTextContent, line),
90
- startCol: col,
91
- endCol: getEndCol(lastTextContent, col),
92
- nodeName: '#text',
93
- type: 'text',
94
- parentNode: null,
95
- prevNode: lastNode,
96
- nextNode: null,
97
- isFragment: false,
98
- isGhost: false,
99
- };
100
- lastNode.nextNode = lastTextNode;
101
- if ((lastNode.type === 'starttag' || lastNode.type === 'endtag') && lastNode.pearNode) {
102
- lastNode.pearNode.nextNode = lastTextNode;
103
- }
104
- nodeOrders.push(lastTextNode);
105
- }
106
- }
107
- }
108
- }
109
- /**
110
- * concat text nodes
111
- */
112
- const result = [];
113
- for (const node of nodeOrders) {
114
- const prevNode = result.at(-1) ?? null;
115
- if (node.type === 'text' && prevNode?.type === 'text') {
116
- prevNode.raw = prevNode.raw + node.raw;
117
- prevNode.endOffset = node.endOffset;
118
- prevNode.endLine = node.endLine;
119
- prevNode.endCol = node.endCol;
120
- prevNode.nextNode = node.nextNode;
121
- if (prevNode.parentNode) {
122
- if (prevNode.parentNode.childNodes) {
123
- if (prevNode.parentNode.childNodes.findIndex(currentChild => currentChild.uuid === prevNode.uuid) === -1) {
124
- prevNode.parentNode.childNodes.unshift(prevNode);
125
- }
126
- else {
127
- prevNode.parentNode.childNodes = [prevNode];
128
- }
129
- }
130
- prevNode.parentNode.childNodes = prevNode.parentNode.childNodes?.filter(n => n.uuid !== node.uuid);
131
- }
132
- if (node.nextNode) {
133
- node.nextNode.prevNode = prevNode;
134
- }
135
- continue;
136
- }
137
- result.push(node);
138
- }
139
- {
140
- /**
141
- * Correction prev/next/parent
142
- */
143
- let prevToken = null;
144
- for (const node of result) {
145
- if (!prevToken) {
146
- prevToken = node;
147
- continue;
148
- }
149
- if (((prevToken.type === 'endtag' && prevToken.nodeName.toLowerCase() === 'body') ||
150
- prevToken.type === 'doctype') &&
151
- node.type === 'text') {
152
- const nextNode = prevToken.nextNode;
153
- prevToken.nextNode = node;
154
- if (prevToken.type === 'endtag' && prevToken.pearNode) {
155
- prevToken.pearNode.nextNode = node;
156
- }
157
- node.prevNode = prevToken;
158
- node.nextNode = nextNode;
159
- node.parentNode = prevToken.parentNode;
160
- }
161
- // EndTag
162
- if (node.type === 'starttag' && node.pearNode) {
163
- const endTag = node.pearNode;
164
- endTag.pearNode = node;
165
- endTag.prevNode = node.prevNode;
166
- endTag.nextNode = node.nextNode;
167
- }
168
- // Children
169
- if (node.type === 'text') {
170
- const parent = node.parentNode;
171
- if (parent &&
172
- parent.type === 'starttag' &&
173
- parent.nodeName.toLowerCase() === 'html' &&
174
- parent.childNodes &&
175
- !parent.childNodes.some(n => n.uuid === node.uuid)) {
176
- parent.childNodes.push(node);
177
- }
178
- }
179
- prevToken = node;
180
- }
181
- }
182
- // console.log(nodeOrders.map((n, i) => `${i}: ${n.raw.trim()}`));
183
- return result;
184
- }
185
- function arrayize(
186
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
187
- nodeTree, rawHtml) {
188
- const nodeOrders = [];
189
- let prevLine = 1;
190
- let prevCol = 1;
191
- let currentEndOffset = 0;
192
- /**
193
- * pushing list
194
- */
195
- walk(nodeTree, node => {
196
- const diff = node.startOffset - currentEndOffset;
197
- if (diff > 0) {
198
- const html = rawHtml.slice(currentEndOffset, node.startOffset);
199
- /**
200
- * first white spaces
201
- */
202
- if (/^\s+$/.test(html)) {
203
- const spaces = html;
204
- const textNode = {
205
- uuid: uuid(),
206
- raw: spaces,
207
- startOffset: currentEndOffset,
208
- endOffset: currentEndOffset + spaces.length,
209
- startLine: prevLine,
210
- endLine: getEndLine(spaces, prevLine),
211
- startCol: prevCol,
212
- endCol: getEndCol(spaces, prevCol),
213
- nodeName: '#text',
214
- type: 'text',
215
- parentNode: node.parentNode,
216
- prevNode: node.prevNode,
217
- nextNode: node,
218
- isFragment: false,
219
- isGhost: false,
220
- };
221
- node.prevNode = textNode;
222
- if (node.parentNode && node.parentNode.childNodes) {
223
- const newChildNodes = [...node.parentNode.childNodes];
224
- if (newChildNodes.some(child => {
225
- return (
226
- // Out of start offset
227
- textNode.endOffset < child.startOffset ||
228
- // Out of end offset
229
- child.endOffset < textNode.startOffset);
230
- })) {
231
- newChildNodes.push(textNode);
232
- }
233
- newChildNodes.sort((a, b) => a.startOffset - b.startOffset);
234
- node.parentNode.childNodes = newChildNodes;
235
- }
236
- nodeOrders.push(textNode);
237
- }
238
- }
239
- currentEndOffset = node.startOffset + node.raw.length;
240
- prevLine = node.endLine;
241
- prevCol = node.endCol;
242
- // for ghost nodes
243
- node.endOffset = node.endOffset ?? currentEndOffset;
244
- nodeOrders.push(node);
245
- });
246
- return [...nodeOrders];
247
- }
@@ -1 +0,0 @@
1
- export declare function getSpaceBefore(offset: number, rawCode: string): import("packages/@markuplint/ml-ast/lib/types.js").MLToken;
@@ -1,8 +0,0 @@
1
- import { createTokenFromRawCode } from './create-token.js';
2
- export function getSpaceBefore(offset, rawCode) {
3
- const aboveCode = rawCode.slice(0, offset);
4
- const aboveAttrMatched = aboveCode.match(/\s+$/m);
5
- const aboveAttrChar = aboveAttrMatched?.[0] ?? '';
6
- const spacesBefore = createTokenFromRawCode(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
7
- return spacesBefore;
8
- }
@@ -1,24 +0,0 @@
1
- import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
2
- type ParseAttrOptions = {
3
- readonly booleanish?: boolean;
4
- readonly valueDelimiters?: readonly ValueDelimiter[];
5
- readonly equal?: string;
6
- };
7
- type ValueDelimiter = {
8
- readonly start: string;
9
- readonly end: string;
10
- };
11
- export declare const defaultValueDelimiters: readonly ValueDelimiter[];
12
- export declare function parseAttr(raw: string, offset: number, html: string, options?: ParseAttrOptions): MLASTHTMLAttr;
13
- export declare function tokenize(raw: string, options?: ParseAttrOptions): {
14
- beforeName: string;
15
- name: string;
16
- afterName: string;
17
- equal: string;
18
- beforeValue: string;
19
- startQuote: string;
20
- value: string;
21
- endQuote: string;
22
- afterAttr: string;
23
- };
24
- export {};
package/lib/parse-attr.js DELETED
@@ -1,144 +0,0 @@
1
- import { createTokenFromRawCode, tokenizer, uuid } from './create-token.js';
2
- export const defaultValueDelimiters = [
3
- {
4
- start: "'",
5
- end: "'",
6
- },
7
- {
8
- start: '"',
9
- end: '"',
10
- },
11
- ];
12
- const defaultEqual = '=';
13
- const spaceRegex = /^\s$/;
14
- export function parseAttr(raw, offset, html, options) {
15
- const tokens = tokenize(raw, options);
16
- tokens.beforeName;
17
- const attrToken = createTokenFromRawCode(raw, offset, html);
18
- const spacesBeforeName = tokenizer(tokens.beforeName, attrToken.startLine, attrToken.startCol, attrToken.startOffset);
19
- const name = tokenizer(tokens.name, spacesBeforeName.endLine, spacesBeforeName.endCol, spacesBeforeName.endOffset);
20
- const spacesBeforeEqual = tokenizer(tokens.afterName, name.endLine, name.endCol, name.endOffset);
21
- const equal = tokenizer(tokens.equal, spacesBeforeEqual.endLine, spacesBeforeEqual.endCol, spacesBeforeEqual.endOffset);
22
- const spacesAfterEqual = tokenizer(tokens.beforeValue, equal.endLine, equal.endCol, equal.endOffset);
23
- const startQuote = tokenizer(tokens.startQuote, spacesAfterEqual.endLine, spacesAfterEqual.endCol, spacesAfterEqual.endOffset);
24
- const value = tokenizer(tokens.value, startQuote.endLine, startQuote.endCol, startQuote.endOffset);
25
- const endQuote = tokenizer(tokens.endQuote, value.endLine, value.endCol, value.endOffset);
26
- const attr = {
27
- type: 'html-attr',
28
- uuid: uuid(),
29
- raw: attrToken.raw,
30
- startOffset: attrToken.startOffset,
31
- endOffset: attrToken.endOffset,
32
- startLine: attrToken.startLine,
33
- endLine: attrToken.endLine,
34
- startCol: attrToken.startCol,
35
- endCol: attrToken.endCol,
36
- spacesBeforeName,
37
- name,
38
- spacesBeforeEqual,
39
- equal,
40
- spacesAfterEqual,
41
- startQuote,
42
- value,
43
- endQuote,
44
- isDuplicatable: false,
45
- nodeName: name.raw,
46
- parentNode: null,
47
- nextNode: null,
48
- prevNode: null,
49
- isFragment: false,
50
- isGhost: false,
51
- };
52
- return attr;
53
- }
54
- export function tokenize(raw, options) {
55
- const valueDelimiters = options?.valueDelimiters ?? defaultValueDelimiters;
56
- const equalDelimiter = options?.equal ?? defaultEqual;
57
- let state = 'b-name';
58
- const charactors = [...raw];
59
- let beforeName = '';
60
- let name = '';
61
- let afterName = '';
62
- let equal = '';
63
- let valueDelimiter = null;
64
- let beforeValue = '';
65
- let startQuote = '';
66
- let value = '';
67
- let endQuote = '';
68
- let afterAttr = '';
69
- while (charactors.length > 0) {
70
- const charactor = charactors.shift();
71
- if (state === 'b-name') {
72
- if (spaceRegex.test(charactor)) {
73
- beforeName += charactor;
74
- continue;
75
- }
76
- name += charactor;
77
- state = 'name';
78
- continue;
79
- }
80
- if (state === 'name') {
81
- if (equalDelimiter === charactor) {
82
- equal = equalDelimiter;
83
- state = 'value-start';
84
- continue;
85
- }
86
- if (spaceRegex.test(charactor)) {
87
- afterName += charactor;
88
- state = 'a-name';
89
- continue;
90
- }
91
- name += charactor;
92
- continue;
93
- }
94
- if (state === 'a-name') {
95
- if (equalDelimiter === charactor) {
96
- equal = equalDelimiter;
97
- state = 'value-start';
98
- continue;
99
- }
100
- if (spaceRegex.test(charactor)) {
101
- afterName += charactor;
102
- continue;
103
- }
104
- break;
105
- }
106
- if (state === 'value-start') {
107
- if (spaceRegex.test(charactor)) {
108
- beforeValue += charactor;
109
- continue;
110
- }
111
- valueDelimiter = valueDelimiters.find(d => d.start === charactor) ?? null;
112
- if (valueDelimiter) {
113
- startQuote += valueDelimiter.start;
114
- }
115
- else {
116
- value += beforeValue + charactor;
117
- beforeValue = '';
118
- }
119
- state = 'value';
120
- continue;
121
- }
122
- if (state !== 'value') {
123
- throw new Error('ParseError: unknown parse state in the attribute');
124
- }
125
- value += charactor;
126
- }
127
- if (valueDelimiter) {
128
- const endQuoteIndex = value.lastIndexOf(valueDelimiter.end);
129
- endQuote = value.slice(endQuoteIndex, endQuoteIndex + 1);
130
- afterAttr = value.slice(endQuoteIndex + 1);
131
- value = value.slice(0, endQuoteIndex);
132
- }
133
- return {
134
- beforeName,
135
- name,
136
- afterName,
137
- equal,
138
- beforeValue,
139
- startQuote,
140
- value,
141
- endQuote,
142
- afterAttr,
143
- };
144
- }
@@ -1,7 +0,0 @@
1
- import type { MLASTNode } from '@markuplint/ml-ast';
2
- /**
3
- *
4
- * @disruptive
5
- * @param nodeOrders [Disruptive change]
6
- */
7
- export declare function removeDeprecatedNode(nodeOrders: MLASTNode[]): void;
@@ -1,39 +0,0 @@
1
- /**
2
- *
3
- * @disruptive
4
- * @param nodeOrders [Disruptive change]
5
- */
6
- export function removeDeprecatedNode(
7
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
- nodeOrders) {
9
- /**
10
- * sorting
11
- */
12
- nodeOrders.sort((a, b) => {
13
- if (a.isGhost || b.isGhost) {
14
- return 0;
15
- }
16
- return a.startOffset - b.startOffset;
17
- });
18
- /**
19
- * remove duplicated node
20
- */
21
- const stack = {};
22
- const removeIndexes = [];
23
- for (const [i, node] of nodeOrders.entries()) {
24
- if (node.isGhost) {
25
- continue;
26
- }
27
- const id = `${node.startLine}:${node.startCol}:${node.endLine}:${node.endCol}`;
28
- if (stack[id] != null) {
29
- removeIndexes.push(i);
30
- }
31
- stack[id] = i;
32
- }
33
- let r = nodeOrders.length;
34
- while (r-- > 0) {
35
- if (removeIndexes.includes(r)) {
36
- nodeOrders.splice(r, 1);
37
- }
38
- }
39
- }
@@ -1,9 +0,0 @@
1
- import type { MLASTNode } from '@markuplint/ml-ast';
2
- /**
3
- * Correct the references to prevNode and nextNode in the order listed.
4
- *
5
- * @param nodeList
6
- * @affects nodeList[].prevNode
7
- * @affects nodeList[].nextNode
8
- */
9
- export declare function siblingsCorrection(nodeList: MLASTNode[]): void;