@markuplint/svelte-parser 4.0.0-alpha.7 → 4.0.0-alpha.9
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/README.md +12 -0
- package/lib/attr.js +1 -6
- package/lib/directive-tokenizer.d.ts +1 -1
- package/lib/directive-tokenizer.js +1 -1
- package/lib/nodeize.js +2 -1
- package/lib/parse.js +1 -1
- package/lib/sveltekit-parser.d.ts +2 -0
- package/lib/sveltekit-parser.js +14 -0
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -23,3 +23,15 @@ Add `parser` option to your [configuration](https://markuplint.dev/configuration
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
|
+
|
|
27
|
+
### Use with [SvelteKit](https://kit.svelte.dev/)
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
{
|
|
31
|
+
"parser": {
|
|
32
|
+
-- ".svelte$": "@markuplint/svelte-parser"
|
|
33
|
+
++ ".svelte$": "@markuplint/svelte-parser",
|
|
34
|
+
++ ".html$": "@markuplint/svelte-parser/kit"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
package/lib/attr.js
CHANGED
|
@@ -26,12 +26,7 @@ attr, rawHTML) {
|
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
const { raw, startLine, startCol, startOffset } = sliceFragment(rawHTML, start, end);
|
|
29
|
-
|
|
30
|
-
? attr.name
|
|
31
|
-
: attr.expression && 'start' in attr.expression && 'end' in attr.expression
|
|
32
|
-
? sliceFragment(rawHTML, attr.expression.start, attr.expression.end).raw
|
|
33
|
-
: '';
|
|
34
|
-
token = directiveTokenizer(raw, valueToken, startLine, startCol, startOffset);
|
|
29
|
+
token = directiveTokenizer(raw, startLine, startCol, startOffset);
|
|
35
30
|
}
|
|
36
31
|
if (!specificBindDirective.has(token.name.raw) && /^bind:/i.test(token.name.raw)) {
|
|
37
32
|
// Remove "bind:"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
|
|
2
|
-
export declare function directiveTokenizer(raw: string,
|
|
2
|
+
export declare function directiveTokenizer(raw: string, line: number, col: number, startOffset: number): MLASTHTMLAttr;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AttrState, attrTokenizer } from '@markuplint/parser-utils';
|
|
2
|
-
export function directiveTokenizer(raw,
|
|
2
|
+
export function directiveTokenizer(raw, line, col, startOffset) {
|
|
3
3
|
const nameOnly = raw.trim().startsWith('{') && raw.trim().endsWith('}');
|
|
4
4
|
const directiveToken = attrTokenizer(raw, line, col, startOffset, [
|
|
5
5
|
{ start: '"', end: '"' },
|
package/lib/nodeize.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getNamespace } from '@markuplint/html-parser';
|
|
2
2
|
import { detectElementType, sliceFragment, uuid, tagParser } from '@markuplint/parser-utils';
|
|
3
3
|
import { attr } from './attr.js';
|
|
4
|
+
import { directiveTokenizer } from './directive-tokenizer.js';
|
|
4
5
|
import { parseCtrlBlock } from './parse-ctrl-block.js';
|
|
5
6
|
import { traverse } from './traverse.js';
|
|
6
7
|
export function nodeize(
|
|
@@ -96,7 +97,7 @@ parentNode, rawHtml, options) {
|
|
|
96
97
|
const directives = originNode.attributes.map(a => attr(a, rawHtml)) ?? [];
|
|
97
98
|
const attributes = directives.filter((d) => !('__spreadAttr' in d));
|
|
98
99
|
const hasSpreadAttr = directives.some(d => '__spreadAttr' in d);
|
|
99
|
-
const tagTokens = tagParser(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset);
|
|
100
|
+
const tagTokens = tagParser(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset, undefined, undefined, undefined, undefined, directiveTokenizer);
|
|
100
101
|
const namespace = getNamespace(originNode.name, parentNamespace);
|
|
101
102
|
const startTag = {
|
|
102
103
|
uuid: uuid(),
|
package/lib/parse.js
CHANGED
|
@@ -39,7 +39,7 @@ export const parse = (rawCode, options) => {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
const nodes = traverse(ast, null, blocks.replaced, options);
|
|
42
|
-
const nodeList = restoreNode(flattenNodes(nodes, blocks.replaced), blocks);
|
|
42
|
+
const nodeList = restoreNode(flattenNodes(nodes, blocks.replaced), blocks, false);
|
|
43
43
|
return {
|
|
44
44
|
nodeList,
|
|
45
45
|
isFragment: true,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parse as htmlParse } from '@markuplint/html-parser';
|
|
2
|
+
import { ignoreBlock, restoreNode } from '@markuplint/parser-utils';
|
|
3
|
+
export const parse = (rawCode, options) => {
|
|
4
|
+
const blocks = ignoreBlock(rawCode, [
|
|
5
|
+
{
|
|
6
|
+
type: 'sveltekit-placeholder',
|
|
7
|
+
start: '%sveltekit.',
|
|
8
|
+
end: '%',
|
|
9
|
+
},
|
|
10
|
+
]);
|
|
11
|
+
const doc = htmlParse(blocks.replaced, options);
|
|
12
|
+
doc.nodeList = restoreNode(doc.nodeList, blocks);
|
|
13
|
+
return doc;
|
|
14
|
+
};
|
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.9",
|
|
4
4
|
"description": "Svelte parser for markuplint",
|
|
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
|
+
"./kit": {
|
|
15
|
+
"import": "./lib/sveltekit-parser.js"
|
|
13
16
|
}
|
|
14
17
|
},
|
|
15
18
|
"types": "lib/index.d.ts",
|
|
@@ -21,10 +24,10 @@
|
|
|
21
24
|
"clean": "tsc --build --clean"
|
|
22
25
|
},
|
|
23
26
|
"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.
|
|
27
|
+
"@markuplint/html-parser": "4.0.0-alpha.9",
|
|
28
|
+
"@markuplint/ml-ast": "4.0.0-alpha.9",
|
|
29
|
+
"@markuplint/parser-utils": "4.0.0-alpha.9",
|
|
27
30
|
"svelte": "^4.2.8"
|
|
28
31
|
},
|
|
29
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "c86b754700aaf61b561a64dbd0c87424e772f619"
|
|
30
33
|
}
|