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/cli.js +233 -6
- package/dist/index.js +240 -39
- package/dist/plugin.js +354 -6
- package/dist/post-process.js +233 -6
- package/dist/preprocess.js +356 -6
- package/dist/runtime/index.js +7 -33
- package/dist/transform/attrs-for-transform.d.ts +36 -5
- package/dist/transform/schema.d.ts +17 -0
- package/dist/vite-dts.js +77 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -1969,6 +1969,7 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
1969
1969
|
let attrsContent = "";
|
|
1970
1970
|
let contentWithoutAttrs = bodyContent;
|
|
1971
1971
|
let attrPropertyName = "props";
|
|
1972
|
+
let propsRef = null;
|
|
1972
1973
|
if (attrsMatch) {
|
|
1973
1974
|
attrPropertyName = attrsMatch[1];
|
|
1974
1975
|
const attrsStart = attrsMatch.index;
|
|
@@ -1999,13 +2000,31 @@ function transformOriginDefinition(content, svelteImports) {
|
|
|
1999
2000
|
}
|
|
2000
2001
|
contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
|
|
2001
2002
|
}
|
|
2003
|
+
} else {
|
|
2004
|
+
const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
|
|
2005
|
+
if (externalRefMatch) {
|
|
2006
|
+
const propName = externalRefMatch[1];
|
|
2007
|
+
const refName = externalRefMatch[2];
|
|
2008
|
+
if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
|
|
2009
|
+
attrPropertyName = propName;
|
|
2010
|
+
propsRef = refName;
|
|
2011
|
+
const refStart = externalRefMatch.index;
|
|
2012
|
+
const refEnd = refStart + externalRefMatch[0].length;
|
|
2013
|
+
contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2002
2016
|
}
|
|
2003
2017
|
const attrDetails = parseAttrsSource(attrsContent);
|
|
2004
2018
|
const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
|
|
2005
2019
|
const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
|
|
2006
2020
|
let configCode = `{
|
|
2007
2021
|
__attrSchema: ${attrSchemaCode},
|
|
2008
|
-
__parents: ${parentsCode}
|
|
2022
|
+
__parents: ${parentsCode},`;
|
|
2023
|
+
if (propsRef) {
|
|
2024
|
+
configCode += `
|
|
2025
|
+
__propsRef: ${propsRef},`;
|
|
2026
|
+
}
|
|
2027
|
+
configCode += `
|
|
2009
2028
|
__create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
|
|
2010
2029
|
${createFnBody}
|
|
2011
2030
|
}`;
|
|
@@ -2240,6 +2259,73 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2240
2259
|
return compiledResult;
|
|
2241
2260
|
return null;
|
|
2242
2261
|
}
|
|
2262
|
+
function parseAttrsSchemaFromSource(source, exportName) {
|
|
2263
|
+
const sourceResult = parseSourceAttrs(source, exportName);
|
|
2264
|
+
if (sourceResult)
|
|
2265
|
+
return sourceResult;
|
|
2266
|
+
const compiledResult = parseCompiledAttrs(source, exportName);
|
|
2267
|
+
if (compiledResult)
|
|
2268
|
+
return compiledResult;
|
|
2269
|
+
return null;
|
|
2270
|
+
}
|
|
2271
|
+
function parseSourceAttrs(source, exportName) {
|
|
2272
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
|
|
2273
|
+
const match = exportPattern.exec(source);
|
|
2274
|
+
if (!match)
|
|
2275
|
+
return null;
|
|
2276
|
+
const attrsStart = match.index + match[0].length - 1;
|
|
2277
|
+
const attrsEnd = findMatchingBracket(source, attrsStart);
|
|
2278
|
+
if (attrsEnd === -1)
|
|
2279
|
+
return null;
|
|
2280
|
+
let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
|
|
2281
|
+
let parentNames = [];
|
|
2282
|
+
if (attrsContent.startsWith("[")) {
|
|
2283
|
+
const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
|
|
2284
|
+
if (closeBracket !== -1) {
|
|
2285
|
+
const parentsContent = attrsContent.slice(1, closeBracket);
|
|
2286
|
+
parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2287
|
+
let i = closeBracket + 1;
|
|
2288
|
+
while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
|
|
2289
|
+
i++;
|
|
2290
|
+
attrsContent = attrsContent.slice(i);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
if (!attrsContent.startsWith("{")) {
|
|
2294
|
+
return { attrs: [], parentNames };
|
|
2295
|
+
}
|
|
2296
|
+
const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
|
|
2297
|
+
if (objEnd === -1)
|
|
2298
|
+
return { attrs: [], parentNames };
|
|
2299
|
+
const objContent = attrsContent.slice(1, objEnd);
|
|
2300
|
+
const attrs = parseAttrsContent(objContent);
|
|
2301
|
+
return { attrs, parentNames };
|
|
2302
|
+
}
|
|
2303
|
+
function parseCompiledAttrs(source, exportName) {
|
|
2304
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
|
|
2305
|
+
const match = exportPattern.exec(source);
|
|
2306
|
+
if (!match)
|
|
2307
|
+
return null;
|
|
2308
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2309
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2310
|
+
if (braceEnd === -1)
|
|
2311
|
+
return null;
|
|
2312
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2313
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2314
|
+
if (!schemaMatch)
|
|
2315
|
+
return { attrs: [], parentNames: [] };
|
|
2316
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2317
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2318
|
+
if (schemaEnd === -1)
|
|
2319
|
+
return { attrs: [], parentNames: [] };
|
|
2320
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2321
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2322
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2323
|
+
let parentNames = [];
|
|
2324
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2325
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2326
|
+
}
|
|
2327
|
+
return { attrs, parentNames };
|
|
2328
|
+
}
|
|
2243
2329
|
function parseSourceOrigin(source, exportName) {
|
|
2244
2330
|
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2245
2331
|
const match = exportPattern.exec(source);
|
|
@@ -2265,6 +2351,13 @@ function parseSourceOrigin(source, exportName) {
|
|
|
2265
2351
|
}
|
|
2266
2352
|
const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
|
|
2267
2353
|
if (!attrsMatch) {
|
|
2354
|
+
const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
|
|
2355
|
+
if (externalRefMatch) {
|
|
2356
|
+
const propsRef = externalRefMatch[1];
|
|
2357
|
+
if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
|
|
2358
|
+
return { attrs: [], parentNames, propsRef };
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2268
2361
|
return { attrs: [], parentNames };
|
|
2269
2362
|
}
|
|
2270
2363
|
const attrsStart = attrsMatch.index;
|
|
@@ -2301,7 +2394,9 @@ function parseCompiledOrigin(source, exportName) {
|
|
|
2301
2394
|
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2302
2395
|
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2303
2396
|
}
|
|
2304
|
-
|
|
2397
|
+
const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
|
|
2398
|
+
const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
|
|
2399
|
+
return { attrs, parentNames, propsRef };
|
|
2305
2400
|
}
|
|
2306
2401
|
function parseCompiledAttrSchema(content) {
|
|
2307
2402
|
const result = [];
|
|
@@ -2741,7 +2836,34 @@ function getElementTypeImport(element) {
|
|
|
2741
2836
|
}
|
|
2742
2837
|
|
|
2743
2838
|
// src/transform/attrs-for-transform.ts
|
|
2744
|
-
function
|
|
2839
|
+
function generateReactiveAttrsWrapper(attrs) {
|
|
2840
|
+
const parts = [];
|
|
2841
|
+
for (const attr of attrs) {
|
|
2842
|
+
parts.push(`get ${attr.key}() { return ${attr.key} }`);
|
|
2843
|
+
if (attr.bindable) {
|
|
2844
|
+
parts.push(`set ${attr.key}(v) { ${attr.key} = v }`);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
return `{ ${parts.join(", ")} }`;
|
|
2848
|
+
}
|
|
2849
|
+
function generateAttrsForMerge(attrs) {
|
|
2850
|
+
const parts = [];
|
|
2851
|
+
for (const attr of attrs) {
|
|
2852
|
+
if (attr.bindable) {
|
|
2853
|
+
if (attr.hasDefault) {
|
|
2854
|
+
parts.push(`${attr.key} = $bindable(${attr.defaultValue})`);
|
|
2855
|
+
} else {
|
|
2856
|
+
parts.push(`${attr.key} = $bindable()`);
|
|
2857
|
+
}
|
|
2858
|
+
} else if (attr.hasDefault) {
|
|
2859
|
+
parts.push(`${attr.key} = ${attr.defaultValue}`);
|
|
2860
|
+
} else {
|
|
2861
|
+
parts.push(attr.key);
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
return parts.join(", ");
|
|
2865
|
+
}
|
|
2866
|
+
function transformAttrsForCallsSync(s, source, neededImports) {
|
|
2745
2867
|
let changed = false;
|
|
2746
2868
|
const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
|
|
2747
2869
|
let restVarName = null;
|
|
@@ -2807,6 +2929,111 @@ function transformAttrsForCalls(s, source, neededImports) {
|
|
|
2807
2929
|
}
|
|
2808
2930
|
return changed;
|
|
2809
2931
|
}
|
|
2932
|
+
async function transformAttrsForCalls(s, source, neededImports, schemaResolver) {
|
|
2933
|
+
let changed = false;
|
|
2934
|
+
const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
|
|
2935
|
+
let restVarName = null;
|
|
2936
|
+
let existingPropsStart = -1;
|
|
2937
|
+
let existingDestructureContent = "";
|
|
2938
|
+
if (existingPropsMatch) {
|
|
2939
|
+
existingPropsStart = existingPropsMatch.index;
|
|
2940
|
+
existingDestructureContent = existingPropsMatch[1];
|
|
2941
|
+
const restMatch = existingDestructureContent.match(/\.\.\.\s*(\w+)\s*$/);
|
|
2942
|
+
if (restMatch) {
|
|
2943
|
+
restVarName = restMatch[1];
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
const declarations = findVariableDeclarationsWithMacro(source, "$attrs.for");
|
|
2947
|
+
for (const decl of declarations) {
|
|
2948
|
+
const { varName, startIndex, macroOpenParen } = decl;
|
|
2949
|
+
const closeParenIndex = findMatchingBracket(source, macroOpenParen);
|
|
2950
|
+
if (closeParenIndex === -1)
|
|
2951
|
+
continue;
|
|
2952
|
+
const arg = source.slice(macroOpenParen + 1, closeParenIndex).trim();
|
|
2953
|
+
const endIndex = closeParenIndex + 1;
|
|
2954
|
+
const stringMatch = arg.match(/^['"](\w+)['"]$/);
|
|
2955
|
+
if (stringMatch) {
|
|
2956
|
+
const element = stringMatch[1];
|
|
2957
|
+
const typeImport = getElementTypeImport(element);
|
|
2958
|
+
if (existingPropsMatch && existingPropsStart !== -1) {
|
|
2959
|
+
if (!restVarName) {
|
|
2960
|
+
restVarName = "___restAttrs";
|
|
2961
|
+
const newDestructure = existingDestructureContent.trimEnd() ? `${existingDestructureContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
|
|
2962
|
+
const braceEnd = source.indexOf("}", existingPropsStart + 5);
|
|
2963
|
+
if (braceEnd !== -1) {
|
|
2964
|
+
s.overwrite(existingPropsStart + 5, braceEnd, ` ${newDestructure} `);
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
s.overwrite(startIndex, endIndex, `let ${varName} = ${restVarName} as ${typeImport}`);
|
|
2968
|
+
} else {
|
|
2969
|
+
const expansion = `let { ...${varName} } = $props<${typeImport}>()`;
|
|
2970
|
+
s.overwrite(startIndex, endIndex, expansion);
|
|
2971
|
+
}
|
|
2972
|
+
} else {
|
|
2973
|
+
const factoryName = arg;
|
|
2974
|
+
let transformed = false;
|
|
2975
|
+
if (schemaResolver) {
|
|
2976
|
+
const importPath = findImportPath(source, factoryName);
|
|
2977
|
+
if (importPath) {
|
|
2978
|
+
const schema = await schemaResolver.resolve(importPath, factoryName);
|
|
2979
|
+
if (schema && schema.attrs.length > 0) {
|
|
2980
|
+
if (existingPropsMatch && existingPropsStart !== -1) {
|
|
2981
|
+
const additionalAttrs = generateAttrsForMerge(schema.attrs);
|
|
2982
|
+
const restMatch = existingDestructureContent.match(/,?\s*\.\.\.\s*(\w+)\s*$/);
|
|
2983
|
+
let baseContent = existingDestructureContent;
|
|
2984
|
+
let restPart = "";
|
|
2985
|
+
if (restMatch) {
|
|
2986
|
+
restPart = restMatch[0];
|
|
2987
|
+
baseContent = existingDestructureContent.slice(0, restMatch.index);
|
|
2988
|
+
}
|
|
2989
|
+
const mergedDestructure = baseContent.trimEnd() ? `${baseContent.trimEnd()}, ${additionalAttrs}${restPart}` : `${additionalAttrs}${restPart}`;
|
|
2990
|
+
const braceEnd = source.indexOf("}", existingPropsStart + 5);
|
|
2991
|
+
if (braceEnd !== -1) {
|
|
2992
|
+
s.overwrite(existingPropsStart + 5, braceEnd, ` ${mergedDestructure} `);
|
|
2993
|
+
}
|
|
2994
|
+
const wrapper = generateReactiveAttrsWrapper(schema.attrs);
|
|
2995
|
+
s.overwrite(startIndex, endIndex, `let ${varName} = __attrsFor(${factoryName}, ${wrapper})`);
|
|
2996
|
+
transformed = true;
|
|
2997
|
+
} else {
|
|
2998
|
+
const propsDestructure = generatePropsDestructuring(schema.attrs, factoryName);
|
|
2999
|
+
const wrapper = generateReactiveAttrsWrapper(schema.attrs);
|
|
3000
|
+
const expansion = [
|
|
3001
|
+
propsDestructure,
|
|
3002
|
+
`let ${varName} = __attrsFor(${factoryName}, ${wrapper})`
|
|
3003
|
+
].join(`
|
|
3004
|
+
`);
|
|
3005
|
+
s.overwrite(startIndex, endIndex, expansion);
|
|
3006
|
+
transformed = true;
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
if (!transformed) {
|
|
3012
|
+
if (existingPropsMatch && existingPropsStart !== -1) {
|
|
3013
|
+
if (!restVarName) {
|
|
3014
|
+
restVarName = "___restAttrs";
|
|
3015
|
+
const newDestructure = existingDestructureContent.trimEnd() ? `${existingDestructureContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
|
|
3016
|
+
const braceEnd = source.indexOf("}", existingPropsStart + 5);
|
|
3017
|
+
if (braceEnd !== -1) {
|
|
3018
|
+
s.overwrite(existingPropsStart + 5, braceEnd, ` ${newDestructure} `);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
s.overwrite(startIndex, endIndex, `let ${varName} = __attrsFor(${factoryName}, ${restVarName})`);
|
|
3022
|
+
} else {
|
|
3023
|
+
const expansion = [
|
|
3024
|
+
`let ___attrs: $attrs.Of<typeof ${factoryName}> = $props()`,
|
|
3025
|
+
`let ${varName} = __attrsFor(${factoryName}, ___attrs)`
|
|
3026
|
+
].join(`
|
|
3027
|
+
`);
|
|
3028
|
+
s.overwrite(startIndex, endIndex, expansion);
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
neededImports.add("__attrsFor");
|
|
3032
|
+
}
|
|
3033
|
+
changed = true;
|
|
3034
|
+
}
|
|
3035
|
+
return changed;
|
|
3036
|
+
}
|
|
2810
3037
|
|
|
2811
3038
|
// src/transform/core.ts
|
|
2812
3039
|
function transformScript(source, options = {}) {
|
|
@@ -2832,7 +3059,7 @@ function transformScript(source, options = {}) {
|
|
|
2832
3059
|
propsTypeDeclaration = result.propsTypeDeclaration;
|
|
2833
3060
|
}
|
|
2834
3061
|
if (isComponent) {
|
|
2835
|
-
changed =
|
|
3062
|
+
changed = transformAttrsForCallsSync(s, source, neededImports) || changed;
|
|
2836
3063
|
}
|
|
2837
3064
|
const needsPropsInjection = propsTypeDeclaration && propsTypeDeclaration.length > 0;
|
|
2838
3065
|
if (isComponent && (neededImports.size > 0 || needsPropsInjection)) {
|
|
@@ -2903,7 +3130,7 @@ async function transformScriptAsync(source, options) {
|
|
|
2903
3130
|
propsTypeDeclaration = result.propsTypeDeclaration;
|
|
2904
3131
|
}
|
|
2905
3132
|
if (isComponent) {
|
|
2906
|
-
changed = transformAttrsForCalls(s, source, neededImports) || changed;
|
|
3133
|
+
changed = await transformAttrsForCalls(s, source, neededImports, schemaResolver) || changed;
|
|
2907
3134
|
}
|
|
2908
3135
|
const needsPropsInjectionAsync = propsTypeDeclaration && propsTypeDeclaration.length > 0;
|
|
2909
3136
|
if (isComponent && (neededImports.size > 0 || needsPropsInjectionAsync)) {
|
|
@@ -2973,7 +3200,7 @@ async function transformScriptContent(source, options) {
|
|
|
2973
3200
|
propsTypeDeclaration = result.propsTypeDeclaration;
|
|
2974
3201
|
}
|
|
2975
3202
|
if (isComponent) {
|
|
2976
|
-
changed = transformAttrsForCalls(s, source, neededImports) || changed;
|
|
3203
|
+
changed = await transformAttrsForCalls(s, source, neededImports, schemaResolver) || changed;
|
|
2977
3204
|
}
|
|
2978
3205
|
if (neededImports.size > 0) {
|
|
2979
3206
|
const importStatement = generateRuntimeImport([...neededImports]);
|
|
@@ -3669,6 +3896,58 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
|
|
|
3669
3896
|
mergedAttrs.push(attr);
|
|
3670
3897
|
}
|
|
3671
3898
|
}
|
|
3899
|
+
if (schema.propsRef) {
|
|
3900
|
+
const propsRefImportPath = findImportPath(source, schema.propsRef);
|
|
3901
|
+
let propsRefSchema = null;
|
|
3902
|
+
if (propsRefImportPath) {
|
|
3903
|
+
if (debug) {
|
|
3904
|
+
console.log(`[svelte-origin] Resolving propsRef: ${schema.propsRef} from import ${propsRefImportPath}`);
|
|
3905
|
+
}
|
|
3906
|
+
propsRefSchema = await resolveAttrsSchema(propsRefImportPath, schema.propsRef, filePath, cache, debug, aliases);
|
|
3907
|
+
} else {
|
|
3908
|
+
if (debug) {
|
|
3909
|
+
console.log(`[svelte-origin] Resolving propsRef: ${schema.propsRef} from same file`);
|
|
3910
|
+
}
|
|
3911
|
+
propsRefSchema = parseAttrsSchemaFromSource(source, schema.propsRef);
|
|
3912
|
+
if (propsRefSchema && propsRefSchema.parentNames.length > 0) {
|
|
3913
|
+
const resolvedParentAttrs = [];
|
|
3914
|
+
for (const parentName of propsRefSchema.parentNames) {
|
|
3915
|
+
const parentImportPath = findImportPath(source, parentName);
|
|
3916
|
+
let parentSchema = null;
|
|
3917
|
+
if (parentImportPath) {
|
|
3918
|
+
parentSchema = await resolveAttrsSchema(parentImportPath, parentName, filePath, cache, debug, aliases);
|
|
3919
|
+
} else {
|
|
3920
|
+
parentSchema = parseAttrsSchemaFromSource(source, parentName);
|
|
3921
|
+
}
|
|
3922
|
+
if (parentSchema) {
|
|
3923
|
+
for (const attr of parentSchema.attrs) {
|
|
3924
|
+
const existingIndex = resolvedParentAttrs.findIndex((a) => a.key === attr.key);
|
|
3925
|
+
if (existingIndex === -1) {
|
|
3926
|
+
resolvedParentAttrs.push(attr);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
for (const attr of propsRefSchema.attrs) {
|
|
3932
|
+
const existingIndex = resolvedParentAttrs.findIndex((a) => a.key === attr.key);
|
|
3933
|
+
if (existingIndex !== -1) {
|
|
3934
|
+
resolvedParentAttrs[existingIndex] = attr;
|
|
3935
|
+
} else {
|
|
3936
|
+
resolvedParentAttrs.push(attr);
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
propsRefSchema = { attrs: resolvedParentAttrs, parentNames: propsRefSchema.parentNames };
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
if (propsRefSchema) {
|
|
3943
|
+
for (const attr of propsRefSchema.attrs) {
|
|
3944
|
+
const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
|
|
3945
|
+
if (existingIndex === -1) {
|
|
3946
|
+
mergedAttrs.push(attr);
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3672
3951
|
const mergedSchema = {
|
|
3673
3952
|
attrs: mergedAttrs,
|
|
3674
3953
|
parentNames: schema.parentNames
|
|
@@ -3686,6 +3965,75 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
|
|
|
3686
3965
|
return null;
|
|
3687
3966
|
}
|
|
3688
3967
|
}
|
|
3968
|
+
async function resolveAttrsSchema(importPath, exportName, importerId, cache, debug, aliases) {
|
|
3969
|
+
const cacheKey = `attrs::${importPath}::${exportName}`;
|
|
3970
|
+
if (cache.has(cacheKey)) {
|
|
3971
|
+
if (debug) {
|
|
3972
|
+
console.log(`[svelte-origin] Cache hit for ${cacheKey}`);
|
|
3973
|
+
}
|
|
3974
|
+
return cache.get(cacheKey) || null;
|
|
3975
|
+
}
|
|
3976
|
+
try {
|
|
3977
|
+
const importerDir = dirname2(importerId);
|
|
3978
|
+
if (debug) {
|
|
3979
|
+
console.log(`[svelte-origin] Resolving attrs: ${exportName} from ${importPath}`);
|
|
3980
|
+
}
|
|
3981
|
+
const resolvedPath = resolveImportPath(importPath, aliases, importerDir);
|
|
3982
|
+
if (!resolvedPath) {
|
|
3983
|
+
cache.set(cacheKey, null);
|
|
3984
|
+
return null;
|
|
3985
|
+
}
|
|
3986
|
+
const filePath = resolveFilePath(resolvedPath);
|
|
3987
|
+
if (!filePath) {
|
|
3988
|
+
cache.set(cacheKey, null);
|
|
3989
|
+
return null;
|
|
3990
|
+
}
|
|
3991
|
+
const source = readFileSync2(filePath, "utf-8");
|
|
3992
|
+
const schema = parseAttrsSchemaFromSource(source, exportName);
|
|
3993
|
+
if (!schema) {
|
|
3994
|
+
cache.set(cacheKey, null);
|
|
3995
|
+
return null;
|
|
3996
|
+
}
|
|
3997
|
+
const mergedAttrs = [];
|
|
3998
|
+
for (const parentName of schema.parentNames) {
|
|
3999
|
+
const parentImportPath = findImportPath(source, parentName);
|
|
4000
|
+
if (parentImportPath) {
|
|
4001
|
+
const parentSchema = await resolveAttrsSchema(parentImportPath, parentName, filePath, cache, debug, aliases);
|
|
4002
|
+
if (parentSchema) {
|
|
4003
|
+
for (const attr of parentSchema.attrs) {
|
|
4004
|
+
const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
|
|
4005
|
+
if (existingIndex === -1) {
|
|
4006
|
+
mergedAttrs.push(attr);
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
for (const attr of schema.attrs) {
|
|
4013
|
+
const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
|
|
4014
|
+
if (existingIndex !== -1) {
|
|
4015
|
+
mergedAttrs[existingIndex] = attr;
|
|
4016
|
+
} else {
|
|
4017
|
+
mergedAttrs.push(attr);
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
const mergedSchema = {
|
|
4021
|
+
attrs: mergedAttrs,
|
|
4022
|
+
parentNames: schema.parentNames
|
|
4023
|
+
};
|
|
4024
|
+
if (debug) {
|
|
4025
|
+
console.log(`[svelte-origin] Resolved attrs schema for ${exportName}:`, mergedSchema.attrs.map((a) => a.key));
|
|
4026
|
+
}
|
|
4027
|
+
cache.set(cacheKey, mergedSchema);
|
|
4028
|
+
return mergedSchema;
|
|
4029
|
+
} catch (error) {
|
|
4030
|
+
if (debug) {
|
|
4031
|
+
console.error(`[svelte-origin] Error resolving attrs schema for ${importPath}:`, error);
|
|
4032
|
+
}
|
|
4033
|
+
cache.set(cacheKey, null);
|
|
4034
|
+
return null;
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
3689
4037
|
var plugin_default = svelteOrigin;
|
|
3690
4038
|
export {
|
|
3691
4039
|
svelteOrigin,
|