@markuplint/svelte-parser 4.0.1 → 4.1.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
@@ -47,6 +47,14 @@ declare class SvelteParser extends Parser<SvelteNode> {
47
47
  endCol: number;
48
48
  __rightText?: string | undefined;
49
49
  };
50
+ /**
51
+ * > A lowercase tag, like `<div>`, denotes a regular HTML element.
52
+ * A capitalised tag, such as `<Widget>` or `<Namespace.Widget>`, indicates a component.
53
+ *
54
+ * @see https://svelte.io/docs/basic-markup#tags
55
+ * @param nodeName
56
+ * @returns
57
+ */
50
58
  detectElementType(nodeName: string): import("@markuplint/ml-ast").ElementType;
51
59
  visitExpression(token: ChildToken, originBlockNode: SvelteNode): MLASTPreprocessorSpecificBlock[];
52
60
  }
package/lib/parser.js CHANGED
@@ -189,8 +189,16 @@ class SvelteParser extends Parser {
189
189
  potentialName,
190
190
  };
191
191
  }
192
+ /**
193
+ * > A lowercase tag, like `<div>`, denotes a regular HTML element.
194
+ * A capitalised tag, such as `<Widget>` or `<Namespace.Widget>`, indicates a component.
195
+ *
196
+ * @see https://svelte.io/docs/basic-markup#tags
197
+ * @param nodeName
198
+ * @returns
199
+ */
192
200
  detectElementType(nodeName) {
193
- return super.detectElementType(nodeName, /[.A-Z]/);
201
+ return super.detectElementType(nodeName, /^[A-Z]|\./);
194
202
  }
195
203
  visitExpression(token,
196
204
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
@@ -223,7 +231,8 @@ class SvelteParser extends Parser {
223
231
  nodeList.set(node, type);
224
232
  }
225
233
  let lastChild = null;
226
- for (const [node, type] of nodeList.entries()) {
234
+ for (const [node, _type] of nodeList.entries()) {
235
+ let type = _type;
227
236
  let start = node.start;
228
237
  let end = node.end;
229
238
  if (type === 'await') {
@@ -237,9 +246,15 @@ class SvelteParser extends Parser {
237
246
  start = lastChild?.end ?? start;
238
247
  }
239
248
  const tag = this.sliceFragment(start, end);
249
+ if (type === 'else' && node.type === 'ElseBlock' && node.children?.[0]?.type === 'IfBlock') {
250
+ type = 'elseif';
251
+ }
240
252
  if (node.children && Array.isArray(node.children)) {
241
253
  lastChild = node.children.at(-1) ?? null;
242
254
  }
255
+ if (tag.raw === '') {
256
+ continue;
257
+ }
243
258
  const expression = this.visitPsBlock({
244
259
  ...tag,
245
260
  depth: token.depth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "4.0.1",
3
+ "version": "4.1.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.0.0",
28
- "@markuplint/ml-ast": "4.0.0",
29
- "@markuplint/parser-utils": "4.0.0",
30
- "svelte": "^4.2.9"
27
+ "@markuplint/html-parser": "4.1.0",
28
+ "@markuplint/ml-ast": "4.0.1",
29
+ "@markuplint/parser-utils": "4.1.0",
30
+ "svelte": "^4.2.10"
31
31
  },
32
- "gitHead": "21cc70a0ea8456cd53de9aaf242aa8f0452f0490"
32
+ "gitHead": "b9817c30c2df71faa866e3b3fe286afa499deede"
33
33
  }