@markuplint/svelte-parser 4.0.0-alpha.2 → 4.0.0-dev.28
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.js +2 -2
- package/lib/directive-tokenizer.js +2 -2
- package/lib/nodeize.js +2 -2
- package/lib/parse-ctrl-block.js +2 -2
- package/lib/parse.js +7 -7
- package/lib/traverse.js +1 -1
- package/package.json +6 -7
package/lib/attr.js
CHANGED
|
@@ -4,7 +4,7 @@ const mustacheTag = {
|
|
|
4
4
|
start: '{',
|
|
5
5
|
end: '}',
|
|
6
6
|
};
|
|
7
|
-
const specificBindDirective = ['bind:group', 'bind:this'];
|
|
7
|
+
const specificBindDirective = new Set(['bind:group', 'bind:this']);
|
|
8
8
|
export function attr(
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
10
|
attr, rawHTML) {
|
|
@@ -33,7 +33,7 @@ attr, rawHTML) {
|
|
|
33
33
|
: '';
|
|
34
34
|
token = directiveTokenizer(raw, valueToken, startLine, startCol, startOffset);
|
|
35
35
|
}
|
|
36
|
-
if (!specificBindDirective.
|
|
36
|
+
if (!specificBindDirective.has(token.name.raw) && /^bind:/i.test(token.name.raw)) {
|
|
37
37
|
// Remove "bind:"
|
|
38
38
|
token.potentialName = token.name.raw.slice(5);
|
|
39
39
|
token.isDirective = undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { attrTokenizer } from '@markuplint/html-parser';
|
|
2
2
|
import { tokenizer, uuid } from '@markuplint/parser-utils';
|
|
3
3
|
// eslint-disable-next-line no-control-regex
|
|
4
|
-
const reNameOnly = /^[^\
|
|
4
|
+
const reNameOnly = /^[^\u0000-\u001F /=>{\u007F-\u009F]+/;
|
|
5
5
|
// eslint-disable-next-line no-control-regex
|
|
6
|
-
const reBeforeStructure = /^(\s*)([^\
|
|
6
|
+
const reBeforeStructure = /^(\s*)([^\u0000-\u001F /=>{\u007F-\u009F]+)(\s*)(=)(\s*){(\s*)$/;
|
|
7
7
|
const reBeforeStructureWithoutName = /^{(\s*)$/;
|
|
8
8
|
const reAfterStructure = /(\s*)}/;
|
|
9
9
|
export default function directiveTokenizer(raw, rawValue, line, col, startOffset) {
|
package/lib/nodeize.js
CHANGED
|
@@ -258,7 +258,7 @@ parentNode, rawHtml, options) {
|
|
|
258
258
|
startTag.endCol = firstChild.startCol;
|
|
259
259
|
startTag.raw = rawHtml.slice(startTag.startOffset, startTag.endOffset);
|
|
260
260
|
}
|
|
261
|
-
const lastChild = startTag.childNodes
|
|
261
|
+
const lastChild = startTag.childNodes.at(-1);
|
|
262
262
|
if (lastChild && lastChild.endOffset > startTag.endOffset) {
|
|
263
263
|
const startOffset = lastChild.endOffset;
|
|
264
264
|
const startLine = lastChild.endLine;
|
|
@@ -283,7 +283,7 @@ parentNode, rawHtml, options) {
|
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
return endTag
|
|
286
|
+
return endTag == null ? startTag : [startTag, endTag];
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
}
|
package/lib/parse-ctrl-block.js
CHANGED
|
@@ -33,7 +33,7 @@ nextNode, options) {
|
|
|
33
33
|
let elseTag = null;
|
|
34
34
|
if (originNode.else) {
|
|
35
35
|
const elseNode = originNode.else;
|
|
36
|
-
const elseTagStartOffset = children.length > 0 ? children
|
|
36
|
+
const elseTagStartOffset = children.length > 0 ? children.at(-1)?.end ?? 0 : startTagLocation.endOffset;
|
|
37
37
|
const elseTagLocation = sliceFragment(rawHtml, elseTagStartOffset, elseNode.start);
|
|
38
38
|
elseTag = {
|
|
39
39
|
uuid: uuid(),
|
|
@@ -113,7 +113,7 @@ nextNode, options) {
|
|
|
113
113
|
const elseOrElseIfTags = [];
|
|
114
114
|
if (originNode.else) {
|
|
115
115
|
const elseNode = originNode.else;
|
|
116
|
-
const elseTagStartOffset = children.length > 0 ? children
|
|
116
|
+
const elseTagStartOffset = children.length > 0 ? children.at(-1)?.end ?? 0 : startTagLocation.endOffset;
|
|
117
117
|
const elseTagLocation = sliceFragment(rawHtml, elseTagStartOffset, elseNode.start);
|
|
118
118
|
if (elseNode.children) {
|
|
119
119
|
if (elseNode.children.length === 1 && elseNode.children[0]?.type === 'IfBlock') {
|
package/lib/parse.js
CHANGED
|
@@ -18,24 +18,24 @@ export const parse = (rawCode, options) => {
|
|
|
18
18
|
try {
|
|
19
19
|
ast = svelteParse(blocks.replaced);
|
|
20
20
|
}
|
|
21
|
-
catch (
|
|
22
|
-
if (
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof Error && 'start' in error && 'end' in error && 'frame' in error) {
|
|
23
23
|
// @ts-ignore
|
|
24
|
-
const raw = rawCode.slice(
|
|
24
|
+
const raw = rawCode.slice(error.start.character, error.end.character);
|
|
25
25
|
throw new ParserError(
|
|
26
26
|
// @ts-ignore
|
|
27
|
-
|
|
27
|
+
error.message + '\n' + error.frame, {
|
|
28
28
|
// @ts-ignore
|
|
29
|
-
line:
|
|
29
|
+
line: error.start.line,
|
|
30
30
|
// @ts-ignore
|
|
31
|
-
col:
|
|
31
|
+
col: error.start.column,
|
|
32
32
|
raw,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
nodeList: [],
|
|
37
37
|
isFragment: true,
|
|
38
|
-
parseError:
|
|
38
|
+
parseError: error instanceof Error ? error.message : new Error(`${error}`).message,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
const nodes = traverse(ast, null, blocks.replaced, options);
|
package/lib/traverse.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/svelte-parser",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-dev.28+0131de5e",
|
|
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,11 +21,10 @@
|
|
|
21
21
|
"clean": "tsc --build --clean"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@markuplint/html-parser": "4.0.0-
|
|
25
|
-
"@markuplint/ml-ast": "4.0.0-
|
|
26
|
-
"@markuplint/parser-utils": "4.0.0-
|
|
27
|
-
"svelte": "^4.2.
|
|
28
|
-
"tslib": "^2.6.2"
|
|
24
|
+
"@markuplint/html-parser": "4.0.0-dev.28+0131de5e",
|
|
25
|
+
"@markuplint/ml-ast": "4.0.0-dev.28+0131de5e",
|
|
26
|
+
"@markuplint/parser-utils": "4.0.0-dev.28+0131de5e",
|
|
27
|
+
"svelte": "^4.2.2"
|
|
29
28
|
},
|
|
30
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
|
|
31
30
|
}
|