@markuplint/svelte-parser 4.7.6 → 4.7.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/lib/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { SvelteNode } from './svelte-parser/index.js';
2
- import type { MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTPreprocessorSpecificBlockConditionalType } from '@markuplint/ml-ast';
2
+ import type { MLASTNodeTreeItem, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTPreprocessorSpecificBlockConditionalType } from '@markuplint/ml-ast';
3
3
  import type { ChildToken, ParseOptions, Token } from '@markuplint/parser-utils';
4
4
  import { ParserError, Parser } from '@markuplint/parser-utils';
5
5
  export declare class SvelteParser extends Parser<SvelteNode> {
@@ -12,7 +12,8 @@ export declare class SvelteParser extends Parser<SvelteNode> {
12
12
  };
13
13
  parse(raw: string, options?: ParseOptions): import("@markuplint/ml-ast").MLASTDocument;
14
14
  parseError(error: any): ParserError;
15
- nodeize(originNode: SvelteNode, parentNode: MLASTParentNode | null, depth: number): readonly import("@markuplint/ml-ast").MLASTNodeTreeItem[];
15
+ visitText(token: ChildToken): readonly MLASTNodeTreeItem[];
16
+ nodeize(originNode: SvelteNode, parentNode: MLASTParentNode | null, depth: number): readonly MLASTNodeTreeItem[];
16
17
  visitPsBlock(token: ChildToken & {
17
18
  readonly nodeName: string;
18
19
  readonly isFragment: boolean;
package/lib/parser.js CHANGED
@@ -14,11 +14,10 @@ export class SvelteParser extends Parser {
14
14
  endTagType: 'xml',
15
15
  tagNameCaseSensitive: true,
16
16
  ignoreTags: [
17
- {
18
- type: 'Script',
19
- start: '<script',
20
- end: '</script>',
21
- },
17
+ // Fixed(Resolved) #2505
18
+ // The script tag needs to be passed with the lang attribute to the parser,
19
+ // so instead of excluding it, we convert it to PSBlock in visitText.
20
+ // Keep the style tag as is for now.
22
21
  {
23
22
  type: 'Style',
24
23
  start: '<style',
@@ -50,6 +49,22 @@ export class SvelteParser extends Parser {
50
49
  }
51
50
  return super.parseError(error);
52
51
  }
52
+ visitText(token) {
53
+ const nodes = super.visitText(token, {
54
+ researchTags: false,
55
+ invalidTagAsText: false,
56
+ });
57
+ return nodes.flatMap(node => {
58
+ if (node.nodeName === '#text' && /^<script[\s>]/i.test(node.raw)) {
59
+ return this.visitPsBlock({
60
+ ...node,
61
+ nodeName: 'Script',
62
+ isFragment: false,
63
+ });
64
+ }
65
+ return node;
66
+ });
67
+ }
53
68
  nodeize(
54
69
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
55
70
  originNode, parentNode, depth) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "4.7.6",
3
+ "version": "4.7.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>",
@@ -30,10 +30,10 @@
30
30
  "clean": "tsc --build --clean"
31
31
  },
32
32
  "dependencies": {
33
- "@markuplint/html-parser": "4.6.16",
33
+ "@markuplint/html-parser": "4.6.18",
34
34
  "@markuplint/ml-ast": "4.4.9",
35
- "@markuplint/parser-utils": "4.8.4",
36
- "svelte": "5.19.9"
35
+ "@markuplint/parser-utils": "4.8.6",
36
+ "svelte": "5.22.6"
37
37
  },
38
- "gitHead": "f9f6c415b8a3a231aac56181892bb393aeb8ae1a"
38
+ "gitHead": "04924b5471e60820d28c1f48c2f09a537a1e9825"
39
39
  }