@markuplint/svelte-parser 4.6.2 → 4.6.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.6.3](https://github.com/markuplint/markuplint/compare/@markuplint/svelte-parser@4.6.2...@markuplint/svelte-parser@4.6.3) (2024-05-28)
7
+
8
+ **Note:** Version bump only for package @markuplint/svelte-parser
9
+
6
10
  ## [4.6.2](https://github.com/markuplint/markuplint/compare/@markuplint/svelte-parser@4.6.1...@markuplint/svelte-parser@4.6.2) (2024-05-12)
7
11
 
8
12
  **Note:** Version bump only for package @markuplint/svelte-parser
@@ -0,0 +1,8 @@
1
+ /// <reference types="svelte" />
2
+ import type { SvelteParser } from './parser.js';
3
+ import type { ChildToken, Token } from '@markuplint/parser-utils';
4
+ import type { Block } from 'svelte/compiler';
5
+ export declare function parseBlock(parser: SvelteParser, token: ChildToken, originBlockNode: Block): {
6
+ openToken: Token;
7
+ closeToken: Token;
8
+ };
@@ -0,0 +1,47 @@
1
+ export function parseBlock(
2
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
3
+ parser, token,
4
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
5
+ originBlockNode) {
6
+ const range = token.raw;
7
+ /**
8
+ * `{#xxx}...{:xxx}...{/xxx}`
9
+ * find___^
10
+ */
11
+ // eslint-disable-next-line regexp/strict
12
+ const eachCloseStartIndex = range.match(/{\s*\/[a-z]+\s*}$/)?.index;
13
+ if (eachCloseStartIndex == null) {
14
+ throw new SyntaxError('Block close tag not found');
15
+ }
16
+ /**
17
+ * `{/xxx}`
18
+ */
19
+ const closeToken = parser.sliceFragment(token.startOffset + eachCloseStartIndex, originBlockNode.end);
20
+ const fragment = originBlockNode.type === 'IfBlock'
21
+ ? originBlockNode.consequent.nodes
22
+ : originBlockNode.type === 'AwaitBlock'
23
+ ? originBlockNode.pending?.nodes
24
+ : originBlockNode.type === 'KeyBlock'
25
+ ? originBlockNode.fragment.nodes
26
+ : originBlockNode.body.nodes;
27
+ const fragStart = fragment?.at(0)?.start;
28
+ const fragEnd = fragment?.at(-1)?.end;
29
+ /**
30
+ * This token does not guarantee an open tag.
31
+ * For example, it might include `:then` or `:else`.
32
+ * Therefore, this variable is not used in
33
+ * `EachBlock` or `AwaitBlock`.
34
+ * It is only used in `KeyBlock` and `SnippetBlock`.
35
+ */
36
+ let openToken;
37
+ if (fragStart != null && fragEnd != null) {
38
+ openToken = parser.sliceFragment(token.startOffset, fragStart);
39
+ }
40
+ else {
41
+ openToken = parser.sliceFragment(token.startOffset, eachCloseStartIndex);
42
+ }
43
+ return {
44
+ openToken,
45
+ closeToken,
46
+ };
47
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="svelte" />
2
+ import type { SvelteParser } from './parser.js';
3
+ import type { ChildToken, Token } from '@markuplint/parser-utils';
4
+ import type { Block } from 'svelte/compiler';
5
+ export declare function parseBlock(parser: SvelteParser, token: ChildToken, originBlockNode: Block): {
6
+ openToken: Token;
7
+ closeToken: Token;
8
+ };
@@ -0,0 +1,47 @@
1
+ export function parseBlock(
2
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
3
+ parser, token,
4
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
5
+ originBlockNode) {
6
+ const range = token.raw;
7
+ /**
8
+ * `{#xxx}...{:xxx}...{/xxx}`
9
+ * find___^
10
+ */
11
+ // eslint-disable-next-line regexp/strict
12
+ const eachCloseStartIndex = range.match(/{\s*\/[a-z]+\s*}$/)?.index;
13
+ if (eachCloseStartIndex == null) {
14
+ throw new SyntaxError('Block close tag not found');
15
+ }
16
+ /**
17
+ * `{/xxx}`
18
+ */
19
+ const closeToken = parser.sliceFragment(token.startOffset + eachCloseStartIndex, originBlockNode.end);
20
+ const fragment = originBlockNode.type === 'IfBlock'
21
+ ? originBlockNode.consequent.nodes
22
+ : originBlockNode.type === 'AwaitBlock'
23
+ ? originBlockNode.pending?.nodes
24
+ : originBlockNode.type === 'KeyBlock'
25
+ ? originBlockNode.fragment.nodes
26
+ : originBlockNode.body.nodes;
27
+ const fragStart = fragment?.at(0)?.start;
28
+ const fragEnd = fragment?.at(-1)?.end;
29
+ /**
30
+ * This token does not guarantee an open tag.
31
+ * For example, it might include `:then` or `:else`.
32
+ * Therefore, this variable is not used in
33
+ * `EachBlock` or `AwaitBlock`.
34
+ * It is only used in `KeyBlock` and `SnippetBlock`.
35
+ */
36
+ let openToken;
37
+ if (fragStart != null && fragEnd != null) {
38
+ openToken = parser.sliceFragment(token.startOffset, fragStart);
39
+ }
40
+ else {
41
+ openToken = parser.sliceFragment(token.startOffset, eachCloseStartIndex);
42
+ }
43
+ return {
44
+ openToken,
45
+ closeToken,
46
+ };
47
+ }
package/lib/parser.d.ts CHANGED
@@ -16,6 +16,7 @@ declare class SvelteParser extends Parser<SvelteNode> {
16
16
  nodeize(originNode: SvelteNode, parentNode: MLASTParentNode | null, depth: number): readonly import("@markuplint/ml-ast").MLASTNodeTreeItem[];
17
17
  visitPsBlock(token: ChildToken & {
18
18
  readonly nodeName: string;
19
+ readonly isFragment: boolean;
19
20
  }, childNodes?: readonly SvelteNode[], conditionalType?: MLASTPreprocessorSpecificBlockConditionalType): readonly [MLASTPreprocessorSpecificBlock];
20
21
  visitChildren(children: readonly SvelteNode[], parentNode: MLASTParentNode | null): never[];
21
22
  visitAttr(token: Token): (import("@markuplint/ml-ast").MLASTSpreadAttr & {
package/lib/parser.js CHANGED
@@ -75,6 +75,7 @@ class SvelteParser extends Parser {
75
75
  depth,
76
76
  parentNode,
77
77
  nodeName: 'MustacheTag',
78
+ isFragment: false,
78
79
  });
79
80
  }
80
81
  case 'InlineComponent':
@@ -213,6 +214,7 @@ class SvelteParser extends Parser {
213
214
  depth: token.depth,
214
215
  parentNode: token.parentNode,
215
216
  nodeName: ifElseBlock.nodeName,
217
+ isFragment: false,
216
218
  }, ifElseBlock.children, {
217
219
  if: 'if',
218
220
  elseif: 'if:elseif',
@@ -285,6 +287,7 @@ class SvelteParser extends Parser {
285
287
  depth: token.depth,
286
288
  parentNode: token.parentNode,
287
289
  nodeName: type ?? blockType,
290
+ isFragment: false,
288
291
  }, node.children, type)[0];
289
292
  expressions.push(expression);
290
293
  }
@@ -299,6 +302,7 @@ class SvelteParser extends Parser {
299
302
  depth: token.depth,
300
303
  parentNode: token.parentNode,
301
304
  nodeName: '/' + blockType,
305
+ isFragment: false,
302
306
  }, [], 'end')[0];
303
307
  expressions.push(expression);
304
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "4.6.2",
3
+ "version": "4.6.3",
4
4
  "description": "Svelte parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -24,10 +24,10 @@
24
24
  "clean": "tsc --build --clean"
25
25
  },
26
26
  "dependencies": {
27
- "@markuplint/html-parser": "4.6.2",
28
- "@markuplint/ml-ast": "4.3.1",
29
- "@markuplint/parser-utils": "4.6.2",
30
- "svelte": "4.2.16"
27
+ "@markuplint/html-parser": "4.6.3",
28
+ "@markuplint/ml-ast": "4.4.0",
29
+ "@markuplint/parser-utils": "4.6.3",
30
+ "svelte": "4.2.17"
31
31
  },
32
- "gitHead": "ca7dc6bf40eac4f2813e492878f889eb77751a70"
32
+ "gitHead": "bf70c41b1d2497e85b73c9ecd5551eb522e6bdfc"
33
33
  }