@markuplint/svelte-parser 3.3.0 → 3.4.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/attr.js +1 -1
- package/lib/directive-tokenizer.d.ts +7 -1
- package/lib/directive-tokenizer.js +9 -8
- package/lib/index.d.ts +1 -1
- package/lib/nodeize.d.ts +7 -1
- package/lib/nodeize.js +11 -6
- package/lib/traverse.d.ts +6 -1
- package/lib/traverse.js +5 -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
|
+
};
|
package/lib/attr.js
CHANGED
|
@@ -46,7 +46,7 @@ function attr(attr, rawHTML) {
|
|
|
46
46
|
token.isDynamicValue = true;
|
|
47
47
|
}
|
|
48
48
|
const [baseName, subName] = token.name.raw.split(':');
|
|
49
|
-
if (baseName.toLowerCase() === 'class') {
|
|
49
|
+
if ((baseName === null || baseName === void 0 ? void 0 : baseName.toLowerCase()) === 'class') {
|
|
50
50
|
token.isDuplicatable = true;
|
|
51
51
|
if (subName) {
|
|
52
52
|
token.potentialName = 'class';
|
|
@@ -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,6 +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
13
|
let spacesBeforeAttrString = '';
|
|
13
14
|
let nameChars = '';
|
|
14
15
|
let spacesBeforeEqualChars = '';
|
|
@@ -16,16 +17,16 @@ function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
|
|
16
17
|
let spacesAfterEqualChars = '';
|
|
17
18
|
let valueChars = '';
|
|
18
19
|
const [before, after] = raw.split(rawValue);
|
|
19
|
-
const beforeMatchedMap = before.match(reBeforeStructure);
|
|
20
|
-
const beforeWithoutNameMatchedMap = before.match(reBeforeStructureWithoutName);
|
|
21
|
-
const afterMatchedMap = after.match(reAfterStructure);
|
|
20
|
+
const beforeMatchedMap = before === null || before === void 0 ? void 0 : before.match(reBeforeStructure);
|
|
21
|
+
const beforeWithoutNameMatchedMap = before === null || before === void 0 ? void 0 : before.match(reBeforeStructureWithoutName);
|
|
22
|
+
const afterMatchedMap = after === null || after === void 0 ? void 0 : after.match(reAfterStructure);
|
|
22
23
|
if (beforeMatchedMap && afterMatchedMap) {
|
|
23
|
-
spacesBeforeAttrString = beforeMatchedMap[1];
|
|
24
|
-
nameChars = beforeMatchedMap[2];
|
|
25
|
-
spacesBeforeEqualChars = beforeMatchedMap[3]
|
|
24
|
+
spacesBeforeAttrString = (_a = beforeMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
|
|
25
|
+
nameChars = (_b = beforeMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
|
|
26
|
+
spacesBeforeEqualChars = (_c = beforeMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
|
|
26
27
|
equalChars = beforeMatchedMap[4] || null;
|
|
27
|
-
spacesAfterEqualChars = beforeMatchedMap[5]
|
|
28
|
-
valueChars = (beforeMatchedMap[6]
|
|
28
|
+
spacesAfterEqualChars = (_d = beforeMatchedMap[5]) !== null && _d !== void 0 ? _d : '';
|
|
29
|
+
valueChars = ((_e = beforeMatchedMap[6]) !== null && _e !== void 0 ? _e : '') + rawValue + (afterMatchedMap[1] || '');
|
|
29
30
|
}
|
|
30
31
|
else if (beforeWithoutNameMatchedMap && afterMatchedMap) {
|
|
31
32
|
valueChars = (beforeWithoutNameMatchedMap[1] || '') + rawValue + (afterMatchedMap[1] || '');
|
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
|
@@ -6,7 +6,7 @@ const parser_utils_1 = require("@markuplint/parser-utils");
|
|
|
6
6
|
const attr_1 = require("./attr");
|
|
7
7
|
const traverse_1 = require("./traverse");
|
|
8
8
|
function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
9
|
-
var _a, _b;
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
10
|
const nextNode = null;
|
|
11
11
|
const { startOffset, endOffset, startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, originNode.end);
|
|
12
12
|
const parentNamespace = parentNode && 'namespace' in parentNode ? parentNode.namespace : 'http://www.w3.org/1999/xhtml';
|
|
@@ -54,7 +54,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
54
54
|
const children = originNode.children || [];
|
|
55
55
|
const reEndTag = new RegExp(`</${originNode.name}\\s*>$`, 'i');
|
|
56
56
|
const startTagEndOffset = children.length
|
|
57
|
-
? children[0].start
|
|
57
|
+
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
58
58
|
: raw.replace(reEndTag, '').length + startOffset;
|
|
59
59
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
60
60
|
let endTag = null;
|
|
@@ -150,7 +150,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
150
150
|
let then = null;
|
|
151
151
|
if (originNode.then) {
|
|
152
152
|
const thenNode = originNode.then;
|
|
153
|
-
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (
|
|
153
|
+
const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_c = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _c !== void 0 ? _c : thenNode.end);
|
|
154
154
|
then = {
|
|
155
155
|
uuid: (0, parser_utils_1.uuid)(),
|
|
156
156
|
...thenTag,
|
|
@@ -169,7 +169,7 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
169
169
|
let awaitCatch = null;
|
|
170
170
|
if (originNode.catch) {
|
|
171
171
|
const awaitCatchNode = originNode.catch;
|
|
172
|
-
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (
|
|
172
|
+
const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_d = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _d !== void 0 ? _d : awaitCatchNode.end);
|
|
173
173
|
awaitCatch = {
|
|
174
174
|
uuid: (0, parser_utils_1.uuid)(),
|
|
175
175
|
...awaitCatchTag,
|
|
@@ -249,9 +249,12 @@ function nodeize(originNode, prevNode, parentNode, rawHtml, options) {
|
|
|
249
249
|
}
|
|
250
250
|
exports.nodeize = nodeize;
|
|
251
251
|
function solveCtrlBlock(ctrlName, originNode, raw, rawHtml, startOffset, parentNode, prevNode, nextNode, options) {
|
|
252
|
+
var _a, _b, _c, _d;
|
|
252
253
|
const children = originNode.children || [];
|
|
253
254
|
const reEndTag = new RegExp(`{/${ctrlName}}$`, 'i');
|
|
254
|
-
const startTagEndOffset = children.length
|
|
255
|
+
const startTagEndOffset = children.length
|
|
256
|
+
? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
|
|
257
|
+
: raw.replace(reEndTag, '').length + startOffset;
|
|
255
258
|
const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
|
|
256
259
|
let endTag = null;
|
|
257
260
|
const endTagRawMatched = raw.match(reEndTag);
|
|
@@ -281,7 +284,9 @@ function solveCtrlBlock(ctrlName, originNode, raw, rawHtml, startOffset, parentN
|
|
|
281
284
|
let elseTag = null;
|
|
282
285
|
if (originNode.else) {
|
|
283
286
|
const elseNode = originNode.else;
|
|
284
|
-
const elseTagStartOffset = children.length
|
|
287
|
+
const elseTagStartOffset = children.length
|
|
288
|
+
? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
|
|
289
|
+
: startTagLocation.endOffset;
|
|
285
290
|
const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
|
|
286
291
|
elseTag = {
|
|
287
292
|
uuid: (0, parser_utils_1.uuid)(),
|
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: SvelteNode[],
|
|
5
|
+
parentNode: MLASTParentNode | null | undefined,
|
|
6
|
+
rawHtml: string,
|
|
7
|
+
options?: ParserOptions,
|
|
8
|
+
): MLASTNode[];
|
package/lib/traverse.js
CHANGED
|
@@ -12,7 +12,11 @@ function traverse(astNodes, parentNode = null, rawHtml, options) {
|
|
|
12
12
|
}
|
|
13
13
|
let node;
|
|
14
14
|
if (Array.isArray(nodes)) {
|
|
15
|
-
|
|
15
|
+
const lastNode = nodes[nodes.length - 1];
|
|
16
|
+
if (!lastNode) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
node = lastNode;
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
22
|
node = nodes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/svelte-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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.4.0",
|
|
20
20
|
"@markuplint/ml-ast": "3.0.0",
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
21
|
+
"@markuplint/parser-utils": "3.4.0",
|
|
22
22
|
"svelte": "^3.55.0",
|
|
23
23
|
"tslib": "^2.4.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
|
|
26
26
|
}
|