@markuplint/svelte-parser 4.0.0-alpha.6 → 4.0.0-alpha.8
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/README.md +12 -0
- package/lib/nodeize.js +1 -1
- package/lib/parse-ctrl-block.js +3 -2
- package/lib/parse.js +1 -1
- package/lib/sveltekit-parser.d.ts +2 -0
- package/lib/sveltekit-parser.js +14 -0
- package/package.json +9 -6
package/LICENSE
CHANGED
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/nodeize.js
CHANGED
|
@@ -190,7 +190,7 @@ parentNode, rawHtml, options) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
// eslint-disable-next-line regexp/strict
|
|
193
|
-
const reEndTag = /{
|
|
193
|
+
const reEndTag = /{\s*\/await\s*}$/i;
|
|
194
194
|
let endTag = null;
|
|
195
195
|
if (reEndTag.test(raw)) {
|
|
196
196
|
const endTagRawMatched = raw.match(reEndTag);
|
package/lib/parse-ctrl-block.js
CHANGED
|
@@ -14,7 +14,7 @@ nextNode, options) {
|
|
|
14
14
|
}
|
|
15
15
|
const children = originNode.children ?? [];
|
|
16
16
|
// eslint-disable-next-line regexp/strict
|
|
17
|
-
const reEndTag = /{
|
|
17
|
+
const reEndTag = /{\s*\/each\s*}$/i;
|
|
18
18
|
const startTagEndOffset = children.length > 0 ? children[0]?.start ?? 0 : raw.replace(reEndTag, '').length + startOffset;
|
|
19
19
|
const startTagLocation = sliceFragment(rawHtml, startOffset, startTagEndOffset);
|
|
20
20
|
const tag = {
|
|
@@ -141,7 +141,8 @@ nextNode, options) {
|
|
|
141
141
|
if (originNode.elseif) {
|
|
142
142
|
return [tag, ...elseOrElseIfTags];
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
// eslint-disable-next-line regexp/strict
|
|
145
|
+
const endTagRawMatched = raw.match(/{\s*\/if\s*}/);
|
|
145
146
|
if (!endTagRawMatched) {
|
|
146
147
|
throw new Error('Missing the end token `{/if}`');
|
|
147
148
|
}
|
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.8",
|
|
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
|
-
"svelte": "^4.2.
|
|
27
|
+
"@markuplint/html-parser": "4.0.0-alpha.8",
|
|
28
|
+
"@markuplint/ml-ast": "4.0.0-alpha.8",
|
|
29
|
+
"@markuplint/parser-utils": "4.0.0-alpha.8",
|
|
30
|
+
"svelte": "^4.2.8"
|
|
28
31
|
},
|
|
29
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "5bcd25f13ff804af0d09aaabd87e495af668e6a8"
|
|
30
33
|
}
|