@markuplint/svelte-parser 3.5.0 → 3.6.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.
- package/lib/attr.d.ts +8 -3
- package/lib/directive-tokenizer.d.ts +7 -1
- package/lib/directive-tokenizer.js +5 -5
- package/lib/index.d.ts +1 -1
- package/lib/nodeize.d.ts +7 -1
- package/lib/nodeize.js +6 -8
- package/lib/parse-ctrl-block.d.ts +11 -1
- package/lib/parse-ctrl-block.js +10 -16
- package/lib/svelte-parser/index.js +2 -1
- package/lib/traverse.d.ts +6 -1
- package/package.json +4 -4
package/lib/attr.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { SvelteDirective } from './svelte-parser';
|
|
2
2
|
import type { MLASTAttr } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function attr(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function attr(
|
|
4
|
+
attr: SvelteDirective,
|
|
5
|
+
rawHTML: string,
|
|
6
|
+
):
|
|
7
|
+
| MLASTAttr
|
|
8
|
+
| {
|
|
9
|
+
__spreadAttr: true;
|
|
10
|
+
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
|
|
2
|
-
export default function directiveTokenizer(
|
|
2
|
+
export default function directiveTokenizer(
|
|
3
|
+
raw: string,
|
|
4
|
+
rawValue: string,
|
|
5
|
+
line: number,
|
|
6
|
+
col: number,
|
|
7
|
+
startOffset: number,
|
|
8
|
+
): MLASTHTMLAttr;
|
|
@@ -9,7 +9,7 @@ const reBeforeStructure = /^(\s*)([^\x00-\x1f\x7f-\x9f {>/=]+)(\s*)(=)(\s*){(\s*
|
|
|
9
9
|
const reBeforeStructureWithoutName = /^{(\s*)$/;
|
|
10
10
|
const reAfterStructure = /(\s*)}/;
|
|
11
11
|
function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
12
|
-
var _a, _b, _c, _d, _e;
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
13
13
|
let spacesBeforeAttrString = '';
|
|
14
14
|
let nameChars = '';
|
|
15
15
|
let spacesBeforeEqualChars = '';
|
|
@@ -24,12 +24,12 @@ function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
|
24
24
|
spacesBeforeAttrString = (_a = beforeMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
|
|
25
25
|
nameChars = (_b = beforeMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
|
|
26
26
|
spacesBeforeEqualChars = (_c = beforeMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
|
|
27
|
-
equalChars = beforeMatchedMap[4]
|
|
28
|
-
spacesAfterEqualChars = (
|
|
29
|
-
valueChars = ((
|
|
27
|
+
equalChars = (_d = beforeMatchedMap[4]) !== null && _d !== void 0 ? _d : null;
|
|
28
|
+
spacesAfterEqualChars = (_e = beforeMatchedMap[5]) !== null && _e !== void 0 ? _e : '';
|
|
29
|
+
valueChars = ((_f = beforeMatchedMap[6]) !== null && _f !== void 0 ? _f : '') + rawValue + ((_g = afterMatchedMap[1]) !== null && _g !== void 0 ? _g : '');
|
|
30
30
|
}
|
|
31
31
|
else if (beforeWithoutNameMatchedMap && afterMatchedMap) {
|
|
32
|
-
valueChars = (beforeWithoutNameMatchedMap[1]
|
|
32
|
+
valueChars = ((_h = beforeWithoutNameMatchedMap[1]) !== null && _h !== void 0 ? _h : '') + rawValue + ((_j = afterMatchedMap[1]) !== null && _j !== void 0 ? _j : '');
|
|
33
33
|
}
|
|
34
34
|
else if (reNameOnly.test(raw)) {
|
|
35
35
|
const token = (0, html_parser_1.attrTokenizer)(raw, line, col, startOffset);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { parse } from './parse';
|
|
2
|
-
export declare const endTag =
|
|
2
|
+
export declare const endTag = 'xml';
|
package/lib/nodeize.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { SvelteNode } from './svelte-parser';
|
|
2
2
|
import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function nodeize(
|
|
3
|
+
export declare function nodeize(
|
|
4
|
+
originNode: SvelteNode,
|
|
5
|
+
prevNode: MLASTNode | null,
|
|
6
|
+
parentNode: MLASTParentNode | null,
|
|
7
|
+
rawHtml: string,
|
|
8
|
+
options?: ParserOptions,
|
|
9
|
+
): MLASTNode | MLASTNode[] | null;
|
package/lib/nodeize.js
CHANGED
|
@@ -13,7 +13,7 @@ originNode,
|
|
|
13
13
|
prevNode,
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
15
15
|
parentNode, rawHtml, options) {
|
|
16
|
-
var _a, _b, _c, _d;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
17
|
const nextNode = null;
|
|
18
18
|
const { startOffset, endOffset, startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, originNode.end);
|
|
19
19
|
const parentNamespace = parentNode && 'namespace' in parentNode ? parentNode.namespace : 'http://www.w3.org/1999/xhtml';
|
|
@@ -58,11 +58,9 @@ parentNode, rawHtml, options) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
case 'Element': {
|
|
61
|
-
const children = originNode.children
|
|
61
|
+
const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
|
|
62
62
|
const reEndTag = new RegExp(`</${originNode.name}\\s*>$`, 'i');
|
|
63
|
-
const startTagEndOffset = children.length
|
|
64
|
-
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
65
|
-
: raw.replace(reEndTag, '').length + startOffset;
|
|
63
|
+
const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
|
|
66
64
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
67
65
|
let endTag = null;
|
|
68
66
|
if (reEndTag.test(raw)) {
|
|
@@ -98,7 +96,7 @@ parentNode, rawHtml, options) {
|
|
|
98
96
|
tagCloseChar: '>',
|
|
99
97
|
};
|
|
100
98
|
}
|
|
101
|
-
const directives = originNode.attributes.map(a => (0, attr_1.attr)(a, rawHtml))
|
|
99
|
+
const directives = (_d = originNode.attributes.map(a => (0, attr_1.attr)(a, rawHtml))) !== null && _d !== void 0 ? _d : [];
|
|
102
100
|
const attributes = directives.filter((d) => !('__spreadAttr' in d));
|
|
103
101
|
const hasSpreadAttr = directives.some(d => '__spreadAttr' in d);
|
|
104
102
|
const tagTokens = (0, html_parser_1.parseRawTag)(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset);
|
|
@@ -158,7 +156,7 @@ parentNode, rawHtml, options) {
|
|
|
158
156
|
let then = null;
|
|
159
157
|
if (originNode.then) {
|
|
160
158
|
const thenNode = originNode.then;
|
|
161
|
-
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (
|
|
159
|
+
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_e = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _e !== void 0 ? _e : thenNode.end);
|
|
162
160
|
then = {
|
|
163
161
|
uuid: (0, parser_utils_1.uuid)(),
|
|
164
162
|
...thenTag,
|
|
@@ -177,7 +175,7 @@ parentNode, rawHtml, options) {
|
|
|
177
175
|
let awaitCatch = null;
|
|
178
176
|
if (originNode.catch) {
|
|
179
177
|
const awaitCatchNode = originNode.catch;
|
|
180
|
-
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (
|
|
178
|
+
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_f = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _f !== void 0 ? _f : awaitCatchNode.end);
|
|
181
179
|
awaitCatch = {
|
|
182
180
|
uuid: (0, parser_utils_1.uuid)(),
|
|
183
181
|
...awaitCatchTag,
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import type { SvelteNode } from './svelte-parser';
|
|
2
2
|
import type { MLASTNode, MLASTParentNode, MLASTPreprocessorSpecificBlock, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function parseCtrlBlock(
|
|
3
|
+
export declare function parseCtrlBlock(
|
|
4
|
+
ctrlName: 'if' | 'each',
|
|
5
|
+
originNode: SvelteNode,
|
|
6
|
+
raw: string,
|
|
7
|
+
rawHtml: string,
|
|
8
|
+
startOffset: number,
|
|
9
|
+
parentNode: MLASTParentNode | null,
|
|
10
|
+
prevNode: MLASTNode | null,
|
|
11
|
+
nextNode: MLASTNode | null,
|
|
12
|
+
options?: ParserOptions,
|
|
13
|
+
): MLASTPreprocessorSpecificBlock[];
|
package/lib/parse-ctrl-block.js
CHANGED
|
@@ -12,15 +12,13 @@ parentNode,
|
|
|
12
12
|
prevNode,
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
14
14
|
nextNode, options) {
|
|
15
|
-
var _a, _b, _c, _d;
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
16
|
if (ctrlName === 'if') {
|
|
17
17
|
return parseIfBlock(originNode, raw, rawHtml, startOffset, originNode.start, parentNode, prevNode, nextNode, options);
|
|
18
18
|
}
|
|
19
|
-
const children = originNode.children
|
|
19
|
+
const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
|
|
20
20
|
const reEndTag = new RegExp('{/each}$', 'i');
|
|
21
|
-
const startTagEndOffset = children.length
|
|
22
|
-
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
23
|
-
: raw.replace(reEndTag, '').length + startOffset;
|
|
21
|
+
const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
|
|
24
22
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
25
23
|
const tag = {
|
|
26
24
|
uuid: (0, parser_utils_1.uuid)(),
|
|
@@ -39,9 +37,7 @@ nextNode, options) {
|
|
|
39
37
|
let elseTag = null;
|
|
40
38
|
if (originNode.else) {
|
|
41
39
|
const elseNode = originNode.else;
|
|
42
|
-
const elseTagStartOffset = children.length
|
|
43
|
-
? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
|
|
44
|
-
: startTagLocation.endOffset;
|
|
40
|
+
const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
|
|
45
41
|
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
46
42
|
elseTag = {
|
|
47
43
|
uuid: (0, parser_utils_1.uuid)(),
|
|
@@ -102,9 +98,9 @@ parentNode,
|
|
|
102
98
|
prevNode,
|
|
103
99
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
104
100
|
nextNode, options) {
|
|
105
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
106
|
-
const children = originNode.children
|
|
107
|
-
const startTagEndOffset = (
|
|
101
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
102
|
+
const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
|
|
103
|
+
const startTagEndOffset = (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : tokenStartOffset;
|
|
108
104
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, tokenStartOffset, startTagEndOffset);
|
|
109
105
|
const tag = {
|
|
110
106
|
uuid: (0, parser_utils_1.uuid)(),
|
|
@@ -123,13 +119,11 @@ nextNode, options) {
|
|
|
123
119
|
const elseOrElseIfTags = [];
|
|
124
120
|
if (originNode.else) {
|
|
125
121
|
const elseNode = originNode.else;
|
|
126
|
-
const elseTagStartOffset = children.length
|
|
127
|
-
? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
|
|
128
|
-
: startTagLocation.endOffset;
|
|
122
|
+
const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
|
|
129
123
|
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
130
124
|
if (elseNode.children) {
|
|
131
|
-
if (elseNode.children.length === 1 && ((
|
|
132
|
-
const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (
|
|
125
|
+
if (elseNode.children.length === 1 && ((_f = elseNode.children[0]) === null || _f === void 0 ? void 0 : _f.type) === 'IfBlock') {
|
|
126
|
+
const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (_j = (_h = (_g = originNode.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.end) !== null && _j !== void 0 ? _j : startTagLocation.endOffset, parentNode, null, null, options);
|
|
133
127
|
elseOrElseIfTags.push(...elseIfTags);
|
|
134
128
|
}
|
|
135
129
|
else {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const compiler_1 = require("svelte/compiler");
|
|
4
4
|
function svelteParse(template) {
|
|
5
|
+
var _a;
|
|
5
6
|
const ast = (0, compiler_1.parse)(template, { customElement: true });
|
|
6
7
|
const start = ast.html.start;
|
|
7
|
-
const children = ast.html.children
|
|
8
|
+
const children = (_a = ast.html.children) !== null && _a !== void 0 ? _a : [];
|
|
8
9
|
if (children[0] && children[0].end === start) {
|
|
9
10
|
children.shift();
|
|
10
11
|
}
|
package/lib/traverse.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { SvelteNode } from './svelte-parser';
|
|
2
2
|
import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
-
export declare function traverse(
|
|
3
|
+
export declare function traverse(
|
|
4
|
+
astNodes: readonly SvelteNode[],
|
|
5
|
+
parentNode: MLASTParentNode | null | undefined,
|
|
6
|
+
rawHtml: string,
|
|
7
|
+
options?: ParserOptions,
|
|
8
|
+
): MLASTNode[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/svelte-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Svelte parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"clean": "tsc --build --clean"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@markuplint/html-parser": "3.
|
|
19
|
+
"@markuplint/html-parser": "3.6.0",
|
|
20
20
|
"@markuplint/ml-ast": "3.1.0",
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
21
|
+
"@markuplint/parser-utils": "3.6.0",
|
|
22
22
|
"svelte": "^3.57.0",
|
|
23
23
|
"tslib": "^2.4.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
|
|
26
26
|
}
|