@markuplint/svelte-parser 4.0.0-alpha.4 → 4.0.0-alpha.5
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/LICENSE +1 -1
- package/lib/attr.js +1 -1
- package/lib/directive-tokenizer.d.ts +1 -1
- package/lib/directive-tokenizer.js +15 -100
- package/lib/nodeize.js +7 -6
- package/lib/parse-ctrl-block.js +2 -1
- package/lib/parse.js +5 -5
- package/lib/svelte-parser/index.d.ts +1 -1
- package/lib/svelte-parser/index.js +1 -1
- package/package.json +5 -5
package/LICENSE
CHANGED
package/lib/attr.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
|
|
2
|
-
export
|
|
2
|
+
export declare function directiveTokenizer(raw: string, rawValue: string, line: number, col: number, startOffset: number): MLASTHTMLAttr;
|
|
@@ -1,101 +1,16 @@
|
|
|
1
|
-
import { attrTokenizer } from '@markuplint/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const [before, after] = raw.split(rawValue);
|
|
17
|
-
const beforeMatchedMap = before?.match(reBeforeStructure);
|
|
18
|
-
const beforeWithoutNameMatchedMap = before?.match(reBeforeStructureWithoutName);
|
|
19
|
-
const afterMatchedMap = after?.match(reAfterStructure);
|
|
20
|
-
if (beforeMatchedMap && afterMatchedMap) {
|
|
21
|
-
spacesBeforeAttrString = beforeMatchedMap[1] ?? '';
|
|
22
|
-
nameChars = beforeMatchedMap[2] ?? '';
|
|
23
|
-
spacesBeforeEqualChars = beforeMatchedMap[3] ?? '';
|
|
24
|
-
equalChars = beforeMatchedMap[4] ?? null;
|
|
25
|
-
spacesAfterEqualChars = beforeMatchedMap[5] ?? '';
|
|
26
|
-
valueChars = (beforeMatchedMap[6] ?? '') + rawValue + (afterMatchedMap[1] ?? '');
|
|
27
|
-
}
|
|
28
|
-
else if (beforeWithoutNameMatchedMap && afterMatchedMap) {
|
|
29
|
-
valueChars = (beforeWithoutNameMatchedMap[1] ?? '') + rawValue + (afterMatchedMap[1] ?? '');
|
|
30
|
-
}
|
|
31
|
-
else if (reNameOnly.test(raw)) {
|
|
32
|
-
const token = attrTokenizer(raw, line, col, startOffset);
|
|
33
|
-
token.isDirective = true;
|
|
34
|
-
return token;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw new SyntaxError('Illegal attribute token');
|
|
38
|
-
}
|
|
39
|
-
let offset = startOffset;
|
|
40
|
-
const attrToken = tokenizer(raw, line, col, offset);
|
|
41
|
-
const spacesBeforeName = tokenizer(spacesBeforeAttrString, line, col, offset);
|
|
42
|
-
line = spacesBeforeName.endLine;
|
|
43
|
-
col = spacesBeforeName.endCol;
|
|
44
|
-
offset = spacesBeforeName.endOffset;
|
|
45
|
-
const name = tokenizer(nameChars, line, col, offset);
|
|
46
|
-
line = name.endLine;
|
|
47
|
-
col = name.endCol;
|
|
48
|
-
offset = name.endOffset;
|
|
49
|
-
const spacesBeforeEqual = tokenizer(spacesBeforeEqualChars, line, col, offset);
|
|
50
|
-
line = spacesBeforeEqual.endLine;
|
|
51
|
-
col = spacesBeforeEqual.endCol;
|
|
52
|
-
offset = spacesBeforeEqual.endOffset;
|
|
53
|
-
const equal = tokenizer(equalChars, line, col, offset);
|
|
54
|
-
line = equal.endLine;
|
|
55
|
-
col = equal.endCol;
|
|
56
|
-
offset = equal.endOffset;
|
|
57
|
-
const spacesAfterEqual = tokenizer(spacesAfterEqualChars, line, col, offset);
|
|
58
|
-
line = spacesAfterEqual.endLine;
|
|
59
|
-
col = spacesAfterEqual.endCol;
|
|
60
|
-
offset = spacesAfterEqual.endOffset;
|
|
61
|
-
const startQuote = tokenizer('{', line, col, offset);
|
|
62
|
-
line = startQuote.endLine;
|
|
63
|
-
col = startQuote.endCol;
|
|
64
|
-
offset = startQuote.endOffset;
|
|
65
|
-
const value = tokenizer(valueChars, line, col, offset);
|
|
66
|
-
line = value.endLine;
|
|
67
|
-
col = value.endCol;
|
|
68
|
-
offset = value.endOffset;
|
|
69
|
-
const endQuote = tokenizer('}', line, col, offset);
|
|
70
|
-
line = endQuote.endLine;
|
|
71
|
-
col = endQuote.endCol;
|
|
72
|
-
offset = endQuote.endOffset;
|
|
73
|
-
const result = {
|
|
74
|
-
type: 'html-attr',
|
|
75
|
-
uuid: uuid(),
|
|
76
|
-
raw: attrToken.raw,
|
|
77
|
-
startOffset: attrToken.startOffset,
|
|
78
|
-
endOffset: attrToken.endOffset,
|
|
79
|
-
startLine: attrToken.startLine,
|
|
80
|
-
endLine: attrToken.endLine,
|
|
81
|
-
startCol: attrToken.startCol,
|
|
82
|
-
endCol: attrToken.endCol,
|
|
83
|
-
spacesBeforeName,
|
|
84
|
-
name,
|
|
85
|
-
spacesBeforeEqual,
|
|
86
|
-
equal,
|
|
87
|
-
spacesAfterEqual,
|
|
88
|
-
startQuote,
|
|
89
|
-
value,
|
|
90
|
-
endQuote,
|
|
91
|
-
isDirective: true,
|
|
92
|
-
isDuplicatable: false,
|
|
93
|
-
nodeName: name.raw,
|
|
94
|
-
parentNode: null,
|
|
95
|
-
nextNode: null,
|
|
96
|
-
prevNode: null,
|
|
97
|
-
isFragment: false,
|
|
98
|
-
isGhost: false,
|
|
99
|
-
};
|
|
100
|
-
return result;
|
|
1
|
+
import { AttrState, attrTokenizer } from '@markuplint/parser-utils';
|
|
2
|
+
export function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
3
|
+
const nameOnly = raw.trim().startsWith('{') && raw.trim().endsWith('}');
|
|
4
|
+
const directiveToken = attrTokenizer(raw, line, col, startOffset, [
|
|
5
|
+
{ start: '"', end: '"' },
|
|
6
|
+
{ start: "'", end: "'" },
|
|
7
|
+
{ start: '{', end: '}' },
|
|
8
|
+
], nameOnly ? AttrState.BeforeValue : AttrState.BeforeName, [
|
|
9
|
+
{ start: '"', end: '"' },
|
|
10
|
+
{ start: "'", end: "'" },
|
|
11
|
+
{ start: '`', end: '`' },
|
|
12
|
+
{ start: '${', end: '}' },
|
|
13
|
+
]);
|
|
14
|
+
directiveToken.isDirective = true;
|
|
15
|
+
return directiveToken;
|
|
101
16
|
}
|
package/lib/nodeize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getNamespace
|
|
2
|
-
import { detectElementType, sliceFragment, uuid } from '@markuplint/parser-utils';
|
|
1
|
+
import { getNamespace } from '@markuplint/html-parser';
|
|
2
|
+
import { detectElementType, sliceFragment, uuid, tagParser } from '@markuplint/parser-utils';
|
|
3
3
|
import { attr } from './attr.js';
|
|
4
4
|
import { parseCtrlBlock } from './parse-ctrl-block.js';
|
|
5
5
|
import { traverse } from './traverse.js';
|
|
@@ -96,7 +96,7 @@ parentNode, rawHtml, options) {
|
|
|
96
96
|
const directives = originNode.attributes.map(a => attr(a, rawHtml)) ?? [];
|
|
97
97
|
const attributes = directives.filter((d) => !('__spreadAttr' in d));
|
|
98
98
|
const hasSpreadAttr = directives.some(d => '__spreadAttr' in d);
|
|
99
|
-
const tagTokens =
|
|
99
|
+
const tagTokens = tagParser(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset);
|
|
100
100
|
const namespace = getNamespace(originNode.name, parentNamespace);
|
|
101
101
|
const startTag = {
|
|
102
102
|
uuid: uuid(),
|
|
@@ -104,7 +104,7 @@ parentNode, rawHtml, options) {
|
|
|
104
104
|
nodeName: originNode.name,
|
|
105
105
|
type: 'starttag',
|
|
106
106
|
namespace,
|
|
107
|
-
elementType: detectElementType(originNode.name, options?.authoredElementName, /[A-Z]
|
|
107
|
+
elementType: detectElementType(originNode.name, options?.authoredElementName, /[.A-Z]/),
|
|
108
108
|
attributes,
|
|
109
109
|
hasSpreadAttr,
|
|
110
110
|
parentNode,
|
|
@@ -112,7 +112,7 @@ parentNode, rawHtml, options) {
|
|
|
112
112
|
nextNode,
|
|
113
113
|
pearNode: endTag,
|
|
114
114
|
selfClosingSolidus: tagTokens.selfClosingSolidus,
|
|
115
|
-
endSpace: tagTokens.
|
|
115
|
+
endSpace: tagTokens.afterAttrSpaces,
|
|
116
116
|
isFragment: false,
|
|
117
117
|
isGhost: false,
|
|
118
118
|
tagOpenChar: '<',
|
|
@@ -189,7 +189,8 @@ parentNode, rawHtml, options) {
|
|
|
189
189
|
awaitCatch.childNodes = traverse(awaitCatchNode.children, awaitCatch, rawHtml, options);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
// eslint-disable-next-line regexp/strict
|
|
193
|
+
const reEndTag = /{\/await}$/i;
|
|
193
194
|
let endTag = null;
|
|
194
195
|
if (reEndTag.test(raw)) {
|
|
195
196
|
const endTagRawMatched = raw.match(reEndTag);
|
package/lib/parse-ctrl-block.js
CHANGED
|
@@ -13,7 +13,8 @@ nextNode, options) {
|
|
|
13
13
|
return parseIfBlock(originNode, raw, rawHtml, startOffset, originNode.start, parentNode, prevNode, nextNode, options);
|
|
14
14
|
}
|
|
15
15
|
const children = originNode.children ?? [];
|
|
16
|
-
|
|
16
|
+
// eslint-disable-next-line regexp/strict
|
|
17
|
+
const reEndTag = /{\/each}$/i;
|
|
17
18
|
const startTagEndOffset = children.length > 0 ? children[0]?.start ?? 0 : raw.replace(reEndTag, '').length + startOffset;
|
|
18
19
|
const startTagLocation = sliceFragment(rawHtml, startOffset, startTagEndOffset);
|
|
19
20
|
const tag = {
|
package/lib/parse.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { flattenNodes, ParserError, ignoreBlock, restoreNode } from '@markuplint/parser-utils';
|
|
2
|
-
import svelteParse from './svelte-parser/index.js';
|
|
2
|
+
import { svelteParse } from './svelte-parser/index.js';
|
|
3
3
|
import { traverse } from './traverse.js';
|
|
4
4
|
export const parse = (rawCode, options) => {
|
|
5
5
|
const blocks = ignoreBlock(rawCode, [
|
|
6
6
|
{
|
|
7
7
|
type: 'Script',
|
|
8
|
-
start:
|
|
9
|
-
end:
|
|
8
|
+
start: '<script',
|
|
9
|
+
end: '</script>',
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
type: 'Style',
|
|
13
|
-
start:
|
|
14
|
-
end:
|
|
13
|
+
start: '<style',
|
|
14
|
+
end: '</style>',
|
|
15
15
|
},
|
|
16
16
|
], '-');
|
|
17
17
|
let ast;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Directive, TemplateNode, Attribute, SpreadAttribute } from 'svelte/types/compiler/interfaces';
|
|
2
2
|
export type SvelteNode = TemplateNode;
|
|
3
|
-
export
|
|
3
|
+
export declare function svelteParse(template: string): SvelteNode[];
|
|
4
4
|
export type SvelteDirective = Directive | Attribute | SpreadAttribute;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/svelte-parser",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
4
|
"description": "Svelte parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"clean": "tsc --build --clean"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@markuplint/html-parser": "4.0.0-alpha.
|
|
25
|
-
"@markuplint/ml-ast": "4.0.0-alpha.
|
|
26
|
-
"@markuplint/parser-utils": "4.0.0-alpha.
|
|
24
|
+
"@markuplint/html-parser": "4.0.0-alpha.5",
|
|
25
|
+
"@markuplint/ml-ast": "4.0.0-alpha.5",
|
|
26
|
+
"@markuplint/parser-utils": "4.0.0-alpha.5",
|
|
27
27
|
"svelte": "^4.2.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "0c3e4690662edf1765bcc4b6411ec5507c1e2ea3"
|
|
30
30
|
}
|