svelte-origin 1.0.0-next.20 → 1.0.0-next.22
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/dist/aliases.d.ts +1 -0
- package/dist/cli.js +194 -2
- package/dist/index.js +194 -2
- package/dist/plugin.js +379 -2
- package/dist/post-process.js +194 -2
- package/dist/preprocess.js +384 -2
- package/dist/transform/schema.d.ts +17 -0
- package/dist/vite-dts.js +174 -1
- package/package.json +1 -1
package/dist/aliases.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare function resolveAliases(config?: AliasConfig): ResolvedAliases;
|
|
|
36
36
|
* - Exact matches: "$lib" -> "src/lib"
|
|
37
37
|
* - Prefix matches: "$lib/utils" -> "src/lib/utils"
|
|
38
38
|
* - Longest match wins: "$lib/components" before "$lib"
|
|
39
|
+
* - npm package imports via node_modules resolution
|
|
39
40
|
*/
|
|
40
41
|
export declare function resolveImportPath(importPath: string, aliases: Record<string, string>, importerDir: string): string | null;
|
|
41
42
|
/**
|
package/dist/cli.js
CHANGED
|
@@ -1975,6 +1975,7 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
1975
1975
|
let attrsContent = "";
|
|
1976
1976
|
let contentWithoutAttrs = bodyContent;
|
|
1977
1977
|
let attrPropertyName = "props";
|
|
1978
|
+
let propsRef = null;
|
|
1978
1979
|
if (attrsMatch) {
|
|
1979
1980
|
attrPropertyName = attrsMatch[1];
|
|
1980
1981
|
const attrsStart = attrsMatch.index;
|
|
@@ -2005,13 +2006,31 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
2005
2006
|
}
|
|
2006
2007
|
contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
|
|
2007
2008
|
}
|
|
2009
|
+
} else {
|
|
2010
|
+
const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
|
|
2011
|
+
if (externalRefMatch) {
|
|
2012
|
+
const propName = externalRefMatch[1];
|
|
2013
|
+
const refName = externalRefMatch[2];
|
|
2014
|
+
if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
|
|
2015
|
+
attrPropertyName = propName;
|
|
2016
|
+
propsRef = refName;
|
|
2017
|
+
const refStart = externalRefMatch.index;
|
|
2018
|
+
const refEnd = refStart + externalRefMatch[0].length;
|
|
2019
|
+
contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2008
2022
|
}
|
|
2009
2023
|
const attrDetails = parseAttrsSource(attrsContent);
|
|
2010
2024
|
const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
|
|
2011
2025
|
const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
|
|
2012
2026
|
let configCode = `{
|
|
2013
2027
|
__attrSchema: ${attrSchemaCode},
|
|
2014
|
-
__parents: ${parentsCode}
|
|
2028
|
+
__parents: ${parentsCode},`;
|
|
2029
|
+
if (propsRef) {
|
|
2030
|
+
configCode += `
|
|
2031
|
+
__propsRef: ${propsRef},`;
|
|
2032
|
+
}
|
|
2033
|
+
configCode += `
|
|
2015
2034
|
__create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
|
|
2016
2035
|
${createFnBody}
|
|
2017
2036
|
}`;
|
|
@@ -2238,7 +2257,83 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2238
2257
|
|
|
2239
2258
|
// src/transform/schema.ts
|
|
2240
2259
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2241
|
-
const
|
|
2260
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
2261
|
+
if (sourceResult)
|
|
2262
|
+
return sourceResult;
|
|
2263
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
2264
|
+
if (compiledResult)
|
|
2265
|
+
return compiledResult;
|
|
2266
|
+
return null;
|
|
2267
|
+
}
|
|
2268
|
+
function parseAttrsSchemaFromSource(source, exportName) {
|
|
2269
|
+
const sourceResult = parseSourceAttrs(source, exportName);
|
|
2270
|
+
if (sourceResult)
|
|
2271
|
+
return sourceResult;
|
|
2272
|
+
const compiledResult = parseCompiledAttrs(source, exportName);
|
|
2273
|
+
if (compiledResult)
|
|
2274
|
+
return compiledResult;
|
|
2275
|
+
return null;
|
|
2276
|
+
}
|
|
2277
|
+
function parseSourceAttrs(source, exportName) {
|
|
2278
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
|
|
2279
|
+
const match = exportPattern.exec(source);
|
|
2280
|
+
if (!match)
|
|
2281
|
+
return null;
|
|
2282
|
+
const attrsStart = match.index + match[0].length - 1;
|
|
2283
|
+
const attrsEnd = findMatchingBracket(source, attrsStart);
|
|
2284
|
+
if (attrsEnd === -1)
|
|
2285
|
+
return null;
|
|
2286
|
+
let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
|
|
2287
|
+
let parentNames = [];
|
|
2288
|
+
if (attrsContent.startsWith("[")) {
|
|
2289
|
+
const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
|
|
2290
|
+
if (closeBracket !== -1) {
|
|
2291
|
+
const parentsContent = attrsContent.slice(1, closeBracket);
|
|
2292
|
+
parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2293
|
+
let i = closeBracket + 1;
|
|
2294
|
+
while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
|
|
2295
|
+
i++;
|
|
2296
|
+
attrsContent = attrsContent.slice(i);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
if (!attrsContent.startsWith("{")) {
|
|
2300
|
+
return { attrs: [], parentNames };
|
|
2301
|
+
}
|
|
2302
|
+
const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
|
|
2303
|
+
if (objEnd === -1)
|
|
2304
|
+
return { attrs: [], parentNames };
|
|
2305
|
+
const objContent = attrsContent.slice(1, objEnd);
|
|
2306
|
+
const attrs = parseAttrsContent(objContent);
|
|
2307
|
+
return { attrs, parentNames };
|
|
2308
|
+
}
|
|
2309
|
+
function parseCompiledAttrs(source, exportName) {
|
|
2310
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
|
|
2311
|
+
const match = exportPattern.exec(source);
|
|
2312
|
+
if (!match)
|
|
2313
|
+
return null;
|
|
2314
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2315
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2316
|
+
if (braceEnd === -1)
|
|
2317
|
+
return null;
|
|
2318
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2319
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2320
|
+
if (!schemaMatch)
|
|
2321
|
+
return { attrs: [], parentNames: [] };
|
|
2322
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2323
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2324
|
+
if (schemaEnd === -1)
|
|
2325
|
+
return { attrs: [], parentNames: [] };
|
|
2326
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2327
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2328
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2329
|
+
let parentNames = [];
|
|
2330
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2331
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2332
|
+
}
|
|
2333
|
+
return { attrs, parentNames };
|
|
2334
|
+
}
|
|
2335
|
+
function parseSourceOrigin(source, exportName) {
|
|
2336
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2242
2337
|
const match = exportPattern.exec(source);
|
|
2243
2338
|
if (!match)
|
|
2244
2339
|
return null;
|
|
@@ -2262,6 +2357,13 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2262
2357
|
}
|
|
2263
2358
|
const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
|
|
2264
2359
|
if (!attrsMatch) {
|
|
2360
|
+
const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
|
|
2361
|
+
if (externalRefMatch) {
|
|
2362
|
+
const propsRef = externalRefMatch[1];
|
|
2363
|
+
if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
|
|
2364
|
+
return { attrs: [], parentNames, propsRef };
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2265
2367
|
return { attrs: [], parentNames };
|
|
2266
2368
|
}
|
|
2267
2369
|
const attrsStart = attrsMatch.index;
|
|
@@ -2274,6 +2376,96 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2274
2376
|
const attrs = parseAttrsContent(attrsContent);
|
|
2275
2377
|
return { attrs, parentNames };
|
|
2276
2378
|
}
|
|
2379
|
+
function parseCompiledOrigin(source, exportName) {
|
|
2380
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
2381
|
+
const match = exportPattern.exec(source);
|
|
2382
|
+
if (!match)
|
|
2383
|
+
return null;
|
|
2384
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2385
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2386
|
+
if (braceEnd === -1)
|
|
2387
|
+
return null;
|
|
2388
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2389
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2390
|
+
if (!schemaMatch)
|
|
2391
|
+
return { attrs: [], parentNames: [] };
|
|
2392
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2393
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2394
|
+
if (schemaEnd === -1)
|
|
2395
|
+
return { attrs: [], parentNames: [] };
|
|
2396
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2397
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2398
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2399
|
+
let parentNames = [];
|
|
2400
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2401
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2402
|
+
}
|
|
2403
|
+
const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
|
|
2404
|
+
const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
|
|
2405
|
+
return { attrs, parentNames, propsRef };
|
|
2406
|
+
}
|
|
2407
|
+
function parseCompiledAttrSchema(content) {
|
|
2408
|
+
const result = [];
|
|
2409
|
+
let pos = 0;
|
|
2410
|
+
while (pos < content.length) {
|
|
2411
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
2412
|
+
pos++;
|
|
2413
|
+
if (pos >= content.length)
|
|
2414
|
+
break;
|
|
2415
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
2416
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
2417
|
+
if (endComment !== -1) {
|
|
2418
|
+
pos = endComment + 2;
|
|
2419
|
+
continue;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
2423
|
+
if (!keyMatch)
|
|
2424
|
+
break;
|
|
2425
|
+
const key = keyMatch[1];
|
|
2426
|
+
pos += keyMatch[0].length;
|
|
2427
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
2428
|
+
pos++;
|
|
2429
|
+
if (content[pos] !== "{")
|
|
2430
|
+
break;
|
|
2431
|
+
const valueStart = pos;
|
|
2432
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
2433
|
+
if (valueEnd === -1)
|
|
2434
|
+
break;
|
|
2435
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
2436
|
+
let defaultValue = "undefined";
|
|
2437
|
+
let bindable = false;
|
|
2438
|
+
let hasDefault = false;
|
|
2439
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
2440
|
+
if (defaultMatch) {
|
|
2441
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
2442
|
+
let depth = 0;
|
|
2443
|
+
let i = defaultStart;
|
|
2444
|
+
while (i < valueContent.length) {
|
|
2445
|
+
const char = valueContent[i];
|
|
2446
|
+
if (char === "{" || char === "(" || char === "[")
|
|
2447
|
+
depth++;
|
|
2448
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
2449
|
+
depth--;
|
|
2450
|
+
else if (char === "," && depth === 0)
|
|
2451
|
+
break;
|
|
2452
|
+
i++;
|
|
2453
|
+
}
|
|
2454
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
2455
|
+
}
|
|
2456
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
2457
|
+
if (bindableMatch) {
|
|
2458
|
+
bindable = bindableMatch[1] === "true";
|
|
2459
|
+
}
|
|
2460
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
2461
|
+
if (hasDefaultMatch) {
|
|
2462
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
2463
|
+
}
|
|
2464
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
2465
|
+
pos = valueEnd + 1;
|
|
2466
|
+
}
|
|
2467
|
+
return result;
|
|
2468
|
+
}
|
|
2277
2469
|
function parseAttrsContent(content) {
|
|
2278
2470
|
const result = [];
|
|
2279
2471
|
const parts = splitByTopLevelCommas(content);
|
package/dist/index.js
CHANGED
|
@@ -3891,7 +3891,83 @@ function findMatchingBracket(source2, openIndex, openChar = "(", closeChar = ")"
|
|
|
3891
3891
|
|
|
3892
3892
|
// src/transform/schema.ts
|
|
3893
3893
|
function parseOriginSchemaFromSource(source2, exportName) {
|
|
3894
|
-
const
|
|
3894
|
+
const sourceResult = parseSourceOrigin(source2, exportName);
|
|
3895
|
+
if (sourceResult)
|
|
3896
|
+
return sourceResult;
|
|
3897
|
+
const compiledResult = parseCompiledOrigin(source2, exportName);
|
|
3898
|
+
if (compiledResult)
|
|
3899
|
+
return compiledResult;
|
|
3900
|
+
return null;
|
|
3901
|
+
}
|
|
3902
|
+
function parseAttrsSchemaFromSource(source2, exportName) {
|
|
3903
|
+
const sourceResult = parseSourceAttrs(source2, exportName);
|
|
3904
|
+
if (sourceResult)
|
|
3905
|
+
return sourceResult;
|
|
3906
|
+
const compiledResult = parseCompiledAttrs(source2, exportName);
|
|
3907
|
+
if (compiledResult)
|
|
3908
|
+
return compiledResult;
|
|
3909
|
+
return null;
|
|
3910
|
+
}
|
|
3911
|
+
function parseSourceAttrs(source2, exportName) {
|
|
3912
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
|
|
3913
|
+
const match = exportPattern.exec(source2);
|
|
3914
|
+
if (!match)
|
|
3915
|
+
return null;
|
|
3916
|
+
const attrsStart = match.index + match[0].length - 1;
|
|
3917
|
+
const attrsEnd = findMatchingBracket(source2, attrsStart);
|
|
3918
|
+
if (attrsEnd === -1)
|
|
3919
|
+
return null;
|
|
3920
|
+
let attrsContent = source2.slice(attrsStart + 1, attrsEnd).trim();
|
|
3921
|
+
let parentNames = [];
|
|
3922
|
+
if (attrsContent.startsWith("[")) {
|
|
3923
|
+
const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
|
|
3924
|
+
if (closeBracket !== -1) {
|
|
3925
|
+
const parentsContent = attrsContent.slice(1, closeBracket);
|
|
3926
|
+
parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
3927
|
+
let i = closeBracket + 1;
|
|
3928
|
+
while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
|
|
3929
|
+
i++;
|
|
3930
|
+
attrsContent = attrsContent.slice(i);
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
if (!attrsContent.startsWith("{")) {
|
|
3934
|
+
return { attrs: [], parentNames };
|
|
3935
|
+
}
|
|
3936
|
+
const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
|
|
3937
|
+
if (objEnd === -1)
|
|
3938
|
+
return { attrs: [], parentNames };
|
|
3939
|
+
const objContent = attrsContent.slice(1, objEnd);
|
|
3940
|
+
const attrs = parseAttrsContent(objContent);
|
|
3941
|
+
return { attrs, parentNames };
|
|
3942
|
+
}
|
|
3943
|
+
function parseCompiledAttrs(source2, exportName) {
|
|
3944
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
|
|
3945
|
+
const match = exportPattern.exec(source2);
|
|
3946
|
+
if (!match)
|
|
3947
|
+
return null;
|
|
3948
|
+
const braceStart = match.index + match[0].length - 1;
|
|
3949
|
+
const braceEnd = findMatchingBracket(source2, braceStart, "{", "}");
|
|
3950
|
+
if (braceEnd === -1)
|
|
3951
|
+
return null;
|
|
3952
|
+
const configContent = source2.slice(braceStart + 1, braceEnd);
|
|
3953
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
3954
|
+
if (!schemaMatch)
|
|
3955
|
+
return { attrs: [], parentNames: [] };
|
|
3956
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
3957
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
3958
|
+
if (schemaEnd === -1)
|
|
3959
|
+
return { attrs: [], parentNames: [] };
|
|
3960
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
3961
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
3962
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
3963
|
+
let parentNames = [];
|
|
3964
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
3965
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
3966
|
+
}
|
|
3967
|
+
return { attrs, parentNames };
|
|
3968
|
+
}
|
|
3969
|
+
function parseSourceOrigin(source2, exportName) {
|
|
3970
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
3895
3971
|
const match = exportPattern.exec(source2);
|
|
3896
3972
|
if (!match)
|
|
3897
3973
|
return null;
|
|
@@ -3915,6 +3991,13 @@ function parseOriginSchemaFromSource(source2, exportName) {
|
|
|
3915
3991
|
}
|
|
3916
3992
|
const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
|
|
3917
3993
|
if (!attrsMatch) {
|
|
3994
|
+
const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
|
|
3995
|
+
if (externalRefMatch) {
|
|
3996
|
+
const propsRef = externalRefMatch[1];
|
|
3997
|
+
if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
|
|
3998
|
+
return { attrs: [], parentNames, propsRef };
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
3918
4001
|
return { attrs: [], parentNames };
|
|
3919
4002
|
}
|
|
3920
4003
|
const attrsStart = attrsMatch.index;
|
|
@@ -3927,6 +4010,96 @@ function parseOriginSchemaFromSource(source2, exportName) {
|
|
|
3927
4010
|
const attrs = parseAttrsContent(attrsContent);
|
|
3928
4011
|
return { attrs, parentNames };
|
|
3929
4012
|
}
|
|
4013
|
+
function parseCompiledOrigin(source2, exportName) {
|
|
4014
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
4015
|
+
const match = exportPattern.exec(source2);
|
|
4016
|
+
if (!match)
|
|
4017
|
+
return null;
|
|
4018
|
+
const braceStart = match.index + match[0].length - 1;
|
|
4019
|
+
const braceEnd = findMatchingBracket(source2, braceStart, "{", "}");
|
|
4020
|
+
if (braceEnd === -1)
|
|
4021
|
+
return null;
|
|
4022
|
+
const configContent = source2.slice(braceStart + 1, braceEnd);
|
|
4023
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
4024
|
+
if (!schemaMatch)
|
|
4025
|
+
return { attrs: [], parentNames: [] };
|
|
4026
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
4027
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
4028
|
+
if (schemaEnd === -1)
|
|
4029
|
+
return { attrs: [], parentNames: [] };
|
|
4030
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
4031
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
4032
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
4033
|
+
let parentNames = [];
|
|
4034
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
4035
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
4036
|
+
}
|
|
4037
|
+
const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
|
|
4038
|
+
const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
|
|
4039
|
+
return { attrs, parentNames, propsRef };
|
|
4040
|
+
}
|
|
4041
|
+
function parseCompiledAttrSchema(content) {
|
|
4042
|
+
const result = [];
|
|
4043
|
+
let pos = 0;
|
|
4044
|
+
while (pos < content.length) {
|
|
4045
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
4046
|
+
pos++;
|
|
4047
|
+
if (pos >= content.length)
|
|
4048
|
+
break;
|
|
4049
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
4050
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
4051
|
+
if (endComment !== -1) {
|
|
4052
|
+
pos = endComment + 2;
|
|
4053
|
+
continue;
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
4057
|
+
if (!keyMatch)
|
|
4058
|
+
break;
|
|
4059
|
+
const key2 = keyMatch[1];
|
|
4060
|
+
pos += keyMatch[0].length;
|
|
4061
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
4062
|
+
pos++;
|
|
4063
|
+
if (content[pos] !== "{")
|
|
4064
|
+
break;
|
|
4065
|
+
const valueStart = pos;
|
|
4066
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
4067
|
+
if (valueEnd === -1)
|
|
4068
|
+
break;
|
|
4069
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
4070
|
+
let defaultValue = "undefined";
|
|
4071
|
+
let bindable2 = false;
|
|
4072
|
+
let hasDefault = false;
|
|
4073
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
4074
|
+
if (defaultMatch) {
|
|
4075
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
4076
|
+
let depth = 0;
|
|
4077
|
+
let i = defaultStart;
|
|
4078
|
+
while (i < valueContent.length) {
|
|
4079
|
+
const char = valueContent[i];
|
|
4080
|
+
if (char === "{" || char === "(" || char === "[")
|
|
4081
|
+
depth++;
|
|
4082
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
4083
|
+
depth--;
|
|
4084
|
+
else if (char === "," && depth === 0)
|
|
4085
|
+
break;
|
|
4086
|
+
i++;
|
|
4087
|
+
}
|
|
4088
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
4089
|
+
}
|
|
4090
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
4091
|
+
if (bindableMatch) {
|
|
4092
|
+
bindable2 = bindableMatch[1] === "true";
|
|
4093
|
+
}
|
|
4094
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
4095
|
+
if (hasDefaultMatch) {
|
|
4096
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
4097
|
+
}
|
|
4098
|
+
result.push({ key: key2, defaultValue, bindable: bindable2, hasDefault });
|
|
4099
|
+
pos = valueEnd + 1;
|
|
4100
|
+
}
|
|
4101
|
+
return result;
|
|
4102
|
+
}
|
|
3930
4103
|
function parseAttrsContent(content) {
|
|
3931
4104
|
const result = [];
|
|
3932
4105
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -6063,6 +6236,7 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
6063
6236
|
let attrsContent = "";
|
|
6064
6237
|
let contentWithoutAttrs = bodyContent;
|
|
6065
6238
|
let attrPropertyName = "props";
|
|
6239
|
+
let propsRef = null;
|
|
6066
6240
|
if (attrsMatch) {
|
|
6067
6241
|
attrPropertyName = attrsMatch[1];
|
|
6068
6242
|
const attrsStart = attrsMatch.index;
|
|
@@ -6093,13 +6267,31 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
6093
6267
|
}
|
|
6094
6268
|
contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
|
|
6095
6269
|
}
|
|
6270
|
+
} else {
|
|
6271
|
+
const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
|
|
6272
|
+
if (externalRefMatch) {
|
|
6273
|
+
const propName = externalRefMatch[1];
|
|
6274
|
+
const refName = externalRefMatch[2];
|
|
6275
|
+
if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
|
|
6276
|
+
attrPropertyName = propName;
|
|
6277
|
+
propsRef = refName;
|
|
6278
|
+
const refStart = externalRefMatch.index;
|
|
6279
|
+
const refEnd = refStart + externalRefMatch[0].length;
|
|
6280
|
+
contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6096
6283
|
}
|
|
6097
6284
|
const attrDetails = parseAttrsSource(attrsContent);
|
|
6098
6285
|
const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
|
|
6099
6286
|
const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
|
|
6100
6287
|
let configCode = `{
|
|
6101
6288
|
__attrSchema: ${attrSchemaCode},
|
|
6102
|
-
__parents: ${parentsCode}
|
|
6289
|
+
__parents: ${parentsCode},`;
|
|
6290
|
+
if (propsRef) {
|
|
6291
|
+
configCode += `
|
|
6292
|
+
__propsRef: ${propsRef},`;
|
|
6293
|
+
}
|
|
6294
|
+
configCode += `
|
|
6103
6295
|
__create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
|
|
6104
6296
|
${createFnBody}
|
|
6105
6297
|
}`;
|