@markuplint/svelte-parser 5.1.0 → 5.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.
@@ -1,3 +1,4 @@
1
+ import type { NamespaceURI } from '@markuplint/ml-ast';
1
2
  /**
2
3
  * Result of scanning a single component file for its root element information.
3
4
  */
@@ -47,6 +48,8 @@ export interface ComponentScanSlotWrapper {
47
48
  readonly isRoot: boolean;
48
49
  readonly attrs: readonly ComponentScanAttr[];
49
50
  readonly contents: readonly ComponentScanContent[];
51
+ /** The namespace of the element when the elements between it and the root element decide it. */
52
+ readonly namespace?: NamespaceURI;
50
53
  }
51
54
  /**
52
55
  * A script/ESM source block extracted from a component file.
@@ -1,3 +1,4 @@
1
+ import { getNamespaceBelow } from '@markuplint/parser-utils';
1
2
  import { parser } from './parser.js';
2
3
  function extractComponentInfo(doc) {
3
4
  const root = findRoot(doc);
@@ -151,6 +152,24 @@ function findWrapper(n, nodes) {
151
152
  }
152
153
  return null;
153
154
  }
155
+ /**
156
+ * The names of the elements from the child of `root` down to `el`, for the namespace of `el`
157
+ * (`getNamespaceBelow`). A component is `null`, as it does not enter a namespace by its name.
158
+ */
159
+ function getNamesBelow(el, root, nodes) {
160
+ const names = [];
161
+ let current = el;
162
+ while (current && current.uuid !== root.uuid) {
163
+ if (isElement(current) && !current.isFragment && current.nodeName !== 'template') {
164
+ names.unshift(getNamespaceSubject(current));
165
+ }
166
+ current = current.parentNodeUuid ? nodes.get(current.parentNodeUuid) : undefined;
167
+ }
168
+ return names;
169
+ }
170
+ function getNamespaceSubject(el) {
171
+ return el.elementType === 'authored' ? null : el.nodeName;
172
+ }
154
173
  function isWithin(n, root, nodes) {
155
174
  let current = n;
156
175
  while (current) {
@@ -230,11 +249,15 @@ function scanSlotContent(doc) {
230
249
  return {
231
250
  slotWrappers: [...wrappers.values()].map(wrapper => {
232
251
  const isNative = wrapper.elementType === 'html';
252
+ const namespace = isNative
253
+ ? getNamespaceBelow(getNamespaceSubject(root), getNamesBelow(wrapper, root, nodes))
254
+ : null;
233
255
  return {
234
256
  element: wrapper.nodeName,
235
257
  isRoot: wrapper.uuid === root.uuid,
236
258
  attrs: isNative ? extractAttrs(wrapper) : [],
237
259
  contents: isNative ? extractContents(wrapper) : [],
260
+ ...(namespace ? { namespace } : {}),
238
261
  };
239
262
  }),
240
263
  rootContents: extractContents(root),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "Svelte parser for markuplint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,10 +40,10 @@
40
40
  "clean": "tsc --build --clean tsconfig.build.json"
41
41
  },
42
42
  "dependencies": {
43
- "@markuplint/html-parser": "5.1.0",
44
- "@markuplint/ml-ast": "5.1.0",
45
- "@markuplint/parser-utils": "5.1.0",
46
- "svelte": "5.55.7"
43
+ "@markuplint/html-parser": "5.2.0",
44
+ "@markuplint/ml-ast": "5.1.1",
45
+ "@markuplint/parser-utils": "5.2.0",
46
+ "svelte": "^5.57.1"
47
47
  },
48
- "gitHead": "3a061784a8211034ad0c1cbd64798c0213414f65"
48
+ "gitHead": "d8b2feab77c9c862513615bea6b80d2817431878"
49
49
  }