@markuplint/svelte-parser 4.1.1 → 4.2.0

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
@@ -4,6 +4,7 @@ import type { MLASTParentNode, MLASTPreprocessorSpecificBlock } from '@markuplin
4
4
  import type { ChildToken, ParseOptions, Token } from '@markuplint/parser-utils';
5
5
  import { ParserError, Parser } from '@markuplint/parser-utils';
6
6
  declare class SvelteParser extends Parser<SvelteNode> {
7
+ #private;
7
8
  readonly specificBindDirective: ReadonlySet<string>;
8
9
  constructor();
9
10
  tokenize(): {
package/lib/parser.js CHANGED
@@ -1,3 +1,9 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _SvelteParser_instances, _SvelteParser_traverseIfBlock;
1
7
  import { getNamespace } from '@markuplint/html-parser';
2
8
  import { ParserError, Parser, AttrState } from '@markuplint/parser-utils';
3
9
  import { svelteParse } from './svelte-parser/index.js';
@@ -20,6 +26,7 @@ class SvelteParser extends Parser {
20
26
  ],
21
27
  maskChar: '-',
22
28
  });
29
+ _SvelteParser_instances.add(this);
23
30
  this.specificBindDirective = new Set(['group', 'this']);
24
31
  }
25
32
  tokenize() {
@@ -205,6 +212,19 @@ class SvelteParser extends Parser {
205
212
  originBlockNode) {
206
213
  const props = ['', 'else', 'pending', 'then', 'catch'];
207
214
  const expressions = [];
215
+ if (originBlockNode.type === 'IfBlock') {
216
+ const ifElseBlocks = __classPrivateFieldGet(this, _SvelteParser_instances, "m", _SvelteParser_traverseIfBlock).call(this, originBlockNode);
217
+ for (const ifElseBlock of ifElseBlocks) {
218
+ const expression = this.visitPsBlock({
219
+ ...ifElseBlock,
220
+ depth: token.depth,
221
+ parentNode: token.parentNode,
222
+ nodeName: ifElseBlock.nodeName,
223
+ }, ifElseBlock.children)[0];
224
+ expressions.push(expression);
225
+ }
226
+ return expressions;
227
+ }
208
228
  const blockType = originBlockNode.type.toLowerCase().replace('block', '');
209
229
  const nodeList = new Map();
210
230
  for (const prop of props) {
@@ -281,4 +301,39 @@ class SvelteParser extends Parser {
281
301
  return expressions;
282
302
  }
283
303
  }
304
+ _SvelteParser_instances = new WeakSet(), _SvelteParser_traverseIfBlock = function _SvelteParser_traverseIfBlock(
305
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
306
+ originBlockNode, start, nodeName = 'if') {
307
+ const result = [];
308
+ start = start ?? originBlockNode.start;
309
+ const end = originBlockNode.children?.[0]?.start ?? originBlockNode.end;
310
+ const tag = this.sliceFragment(start, end);
311
+ const children = originBlockNode.children ?? [];
312
+ result.push({ ...tag, children, nodeName });
313
+ if (originBlockNode.else) {
314
+ if (originBlockNode.else.children[0].type === 'IfBlock') {
315
+ const elseif = __classPrivateFieldGet(this, _SvelteParser_instances, "m", _SvelteParser_traverseIfBlock).call(this, originBlockNode.else.children[0], children.at(-1)?.end, 'elseif');
316
+ result.push(...elseif);
317
+ }
318
+ else {
319
+ const start = children.at(-1)?.end ?? originBlockNode.end;
320
+ const end = originBlockNode.else.children[0].start;
321
+ const tag = this.sliceFragment(start, end);
322
+ result.push({
323
+ ...tag,
324
+ children: originBlockNode.else.children,
325
+ nodeName: 'else',
326
+ });
327
+ }
328
+ }
329
+ {
330
+ const start = result.at(-1)?.children.at(-1)?.end ?? originBlockNode.end;
331
+ const end = originBlockNode.end;
332
+ const tag = this.sliceFragment(start, end);
333
+ if (tag.raw) {
334
+ result.push({ ...tag, children: [], nodeName: '/if' });
335
+ }
336
+ }
337
+ return result;
338
+ };
284
339
  export const parser = new SvelteParser();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
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.1.1",
27
+ "@markuplint/html-parser": "4.2.0",
28
28
  "@markuplint/ml-ast": "4.0.1",
29
- "@markuplint/parser-utils": "4.1.1",
30
- "svelte": "^4.2.11"
29
+ "@markuplint/parser-utils": "4.2.0",
30
+ "svelte": "^4.2.12"
31
31
  },
32
- "gitHead": "10ce6c8374106f311eeaaffbae8f3fdcbb40f877"
32
+ "gitHead": "d5d99c5d84b676f8b2bb84684533ed74cf2f1da6"
33
33
  }