svelte-origin 1.0.0-next.21 → 1.0.0-next.23

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.

Potentially problematic release.


This version of svelte-origin might be problematic. Click here for more details.

package/dist/vite-dts.js CHANGED
@@ -210,6 +210,73 @@ function parseOriginSchemaFromSource(source, exportName) {
210
210
  return compiledResult;
211
211
  return null;
212
212
  }
213
+ function parseAttrsSchemaFromSource(source, exportName) {
214
+ const sourceResult = parseSourceAttrs(source, exportName);
215
+ if (sourceResult)
216
+ return sourceResult;
217
+ const compiledResult = parseCompiledAttrs(source, exportName);
218
+ if (compiledResult)
219
+ return compiledResult;
220
+ return null;
221
+ }
222
+ function parseSourceAttrs(source, exportName) {
223
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
224
+ const match = exportPattern.exec(source);
225
+ if (!match)
226
+ return null;
227
+ const attrsStart = match.index + match[0].length - 1;
228
+ const attrsEnd = findMatchingBracket(source, attrsStart);
229
+ if (attrsEnd === -1)
230
+ return null;
231
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
232
+ let parentNames = [];
233
+ if (attrsContent.startsWith("[")) {
234
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
235
+ if (closeBracket !== -1) {
236
+ const parentsContent = attrsContent.slice(1, closeBracket);
237
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
238
+ let i = closeBracket + 1;
239
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
240
+ i++;
241
+ attrsContent = attrsContent.slice(i);
242
+ }
243
+ }
244
+ if (!attrsContent.startsWith("{")) {
245
+ return { attrs: [], parentNames };
246
+ }
247
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
248
+ if (objEnd === -1)
249
+ return { attrs: [], parentNames };
250
+ const objContent = attrsContent.slice(1, objEnd);
251
+ const attrs = parseAttrsContent(objContent);
252
+ return { attrs, parentNames };
253
+ }
254
+ function parseCompiledAttrs(source, exportName) {
255
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
256
+ const match = exportPattern.exec(source);
257
+ if (!match)
258
+ return null;
259
+ const braceStart = match.index + match[0].length - 1;
260
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
261
+ if (braceEnd === -1)
262
+ return null;
263
+ const configContent = source.slice(braceStart + 1, braceEnd);
264
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
265
+ if (!schemaMatch)
266
+ return { attrs: [], parentNames: [] };
267
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
268
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
269
+ if (schemaEnd === -1)
270
+ return { attrs: [], parentNames: [] };
271
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
272
+ const attrs = parseCompiledAttrSchema(schemaContent);
273
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
274
+ let parentNames = [];
275
+ if (parentsMatch && parentsMatch[1].trim()) {
276
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
277
+ }
278
+ return { attrs, parentNames };
279
+ }
213
280
  function parseSourceOrigin(source, exportName) {
214
281
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
215
282
  const match = exportPattern.exec(source);
@@ -235,6 +302,13 @@ function parseSourceOrigin(source, exportName) {
235
302
  }
236
303
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
237
304
  if (!attrsMatch) {
305
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
306
+ if (externalRefMatch) {
307
+ const propsRef = externalRefMatch[1];
308
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
309
+ return { attrs: [], parentNames, propsRef };
310
+ }
311
+ }
238
312
  return { attrs: [], parentNames };
239
313
  }
240
314
  const attrsStart = attrsMatch.index;
@@ -271,7 +345,9 @@ function parseCompiledOrigin(source, exportName) {
271
345
  if (parentsMatch && parentsMatch[1].trim()) {
272
346
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
273
347
  }
274
- return { attrs, parentNames };
348
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
349
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
350
+ return { attrs, parentNames, propsRef };
275
351
  }
276
352
  function parseCompiledAttrSchema(content) {
277
353
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-origin",
3
- "version": "1.0.0-next.21",
3
+ "version": "1.0.0-next.23",
4
4
  "description": "Compiler-assisted state and prop ergonomics for Svelte 5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",