svelte-origin 1.0.0-next.19 → 1.0.0-next.21
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 +103 -56
- package/dist/index.js +103 -56
- package/dist/plugin.js +205 -56
- package/dist/post-process.js +103 -56
- package/dist/preprocess.js +205 -56
- package/dist/vite-dts.js +98 -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
|
@@ -2032,65 +2032,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
|
|
|
2032
2032
|
const hasParents = parents.length > 0;
|
|
2033
2033
|
const propsLines = [];
|
|
2034
2034
|
if (attrDetails.length > 0) {
|
|
2035
|
-
const
|
|
2035
|
+
const propDefs = [];
|
|
2036
2036
|
for (const attr of attrDetails) {
|
|
2037
2037
|
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
|
|
2041
|
-
for (const attr of attrDetails) {
|
|
2042
|
-
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2043
|
-
const parentLast = `__last_parent_${attr.key}`;
|
|
2044
|
-
const localLast = `__last_local_${attr.key}`;
|
|
2045
|
-
propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
|
|
2046
|
-
` + ` const __parent = __inputAttrs.${attr.key}
|
|
2047
|
-
` + ` const __local = __props.${attr.key}
|
|
2048
|
-
|
|
2049
|
-
` + ` // Parent -> local
|
|
2050
|
-
` + ` if (__parent !== ${parentLast}) {
|
|
2051
|
-
` + ` ${parentLast} = __parent
|
|
2052
|
-
` + ` if (__local !== __parent) {
|
|
2053
|
-
` + ` __props.${attr.key} = __parent${defaultExpr}
|
|
2054
|
-
` + ` }
|
|
2055
|
-
` + ` ${localLast} = __props.${attr.key}
|
|
2056
|
-
` + ` return
|
|
2057
|
-
` + ` }
|
|
2058
|
-
|
|
2059
|
-
` + ` // Local -> parent
|
|
2060
|
-
` + ` if (__local !== ${localLast}) {
|
|
2061
|
-
` + ` ${localLast} = __local
|
|
2062
|
-
` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
|
|
2063
|
-
${parentLast} = __inputAttrs.${attr.key}
|
|
2064
|
-
` : "") + ` }
|
|
2065
|
-
` + `})`);
|
|
2038
|
+
propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
|
|
2039
|
+
propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
|
|
2066
2040
|
}
|
|
2041
|
+
propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
|
|
2067
2042
|
} else {
|
|
2068
|
-
propsLines.push("
|
|
2069
|
-
` + ` // Bidirectional sync between __inputAttrs and __props
|
|
2070
|
-
` + ` for (const key of Object.keys(__inputAttrs)) {
|
|
2071
|
-
` + ` const parentVal = __inputAttrs[key]
|
|
2072
|
-
` + ` const localVal = __props[key]
|
|
2073
|
-
` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
|
|
2074
|
-
` + ` __syncState.set(key, state)
|
|
2075
|
-
|
|
2076
|
-
` + ` // Parent changed -> update local
|
|
2077
|
-
` + ` if (parentVal !== state.parent) {
|
|
2078
|
-
` + ` state.parent = parentVal
|
|
2079
|
-
` + ` if (localVal !== parentVal) {
|
|
2080
|
-
` + ` __props[key] = parentVal
|
|
2081
|
-
` + ` state.local = parentVal
|
|
2082
|
-
` + ` }
|
|
2083
|
-
` + ` continue
|
|
2084
|
-
` + ` }
|
|
2085
|
-
|
|
2086
|
-
` + ` // Local changed -> update parent (for bindable props)
|
|
2087
|
-
` + ` if (localVal !== state.local) {
|
|
2088
|
-
` + ` state.local = localVal
|
|
2089
|
-
` + ` try { __inputAttrs[key] = localVal } catch {}
|
|
2090
|
-
` + ` state.parent = __inputAttrs[key]
|
|
2091
|
-
` + ` }
|
|
2092
|
-
` + ` }
|
|
2093
|
-
` + ` })`);
|
|
2043
|
+
propsLines.push("const __props = __inputAttrs");
|
|
2094
2044
|
}
|
|
2095
2045
|
const propsObjectCode = "\t\t" + propsLines.join(`
|
|
2096
2046
|
`);
|
|
@@ -2288,7 +2238,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2288
2238
|
|
|
2289
2239
|
// src/transform/schema.ts
|
|
2290
2240
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2291
|
-
const
|
|
2241
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
2242
|
+
if (sourceResult)
|
|
2243
|
+
return sourceResult;
|
|
2244
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
2245
|
+
if (compiledResult)
|
|
2246
|
+
return compiledResult;
|
|
2247
|
+
return null;
|
|
2248
|
+
}
|
|
2249
|
+
function parseSourceOrigin(source, exportName) {
|
|
2250
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2292
2251
|
const match = exportPattern.exec(source);
|
|
2293
2252
|
if (!match)
|
|
2294
2253
|
return null;
|
|
@@ -2324,6 +2283,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2324
2283
|
const attrs = parseAttrsContent(attrsContent);
|
|
2325
2284
|
return { attrs, parentNames };
|
|
2326
2285
|
}
|
|
2286
|
+
function parseCompiledOrigin(source, exportName) {
|
|
2287
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
2288
|
+
const match = exportPattern.exec(source);
|
|
2289
|
+
if (!match)
|
|
2290
|
+
return null;
|
|
2291
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2292
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2293
|
+
if (braceEnd === -1)
|
|
2294
|
+
return null;
|
|
2295
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2296
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2297
|
+
if (!schemaMatch)
|
|
2298
|
+
return { attrs: [], parentNames: [] };
|
|
2299
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2300
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2301
|
+
if (schemaEnd === -1)
|
|
2302
|
+
return { attrs: [], parentNames: [] };
|
|
2303
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2304
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2305
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2306
|
+
let parentNames = [];
|
|
2307
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2308
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2309
|
+
}
|
|
2310
|
+
return { attrs, parentNames };
|
|
2311
|
+
}
|
|
2312
|
+
function parseCompiledAttrSchema(content) {
|
|
2313
|
+
const result = [];
|
|
2314
|
+
let pos = 0;
|
|
2315
|
+
while (pos < content.length) {
|
|
2316
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
2317
|
+
pos++;
|
|
2318
|
+
if (pos >= content.length)
|
|
2319
|
+
break;
|
|
2320
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
2321
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
2322
|
+
if (endComment !== -1) {
|
|
2323
|
+
pos = endComment + 2;
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
2328
|
+
if (!keyMatch)
|
|
2329
|
+
break;
|
|
2330
|
+
const key = keyMatch[1];
|
|
2331
|
+
pos += keyMatch[0].length;
|
|
2332
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
2333
|
+
pos++;
|
|
2334
|
+
if (content[pos] !== "{")
|
|
2335
|
+
break;
|
|
2336
|
+
const valueStart = pos;
|
|
2337
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
2338
|
+
if (valueEnd === -1)
|
|
2339
|
+
break;
|
|
2340
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
2341
|
+
let defaultValue = "undefined";
|
|
2342
|
+
let bindable = false;
|
|
2343
|
+
let hasDefault = false;
|
|
2344
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
2345
|
+
if (defaultMatch) {
|
|
2346
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
2347
|
+
let depth = 0;
|
|
2348
|
+
let i = defaultStart;
|
|
2349
|
+
while (i < valueContent.length) {
|
|
2350
|
+
const char = valueContent[i];
|
|
2351
|
+
if (char === "{" || char === "(" || char === "[")
|
|
2352
|
+
depth++;
|
|
2353
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
2354
|
+
depth--;
|
|
2355
|
+
else if (char === "," && depth === 0)
|
|
2356
|
+
break;
|
|
2357
|
+
i++;
|
|
2358
|
+
}
|
|
2359
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
2360
|
+
}
|
|
2361
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
2362
|
+
if (bindableMatch) {
|
|
2363
|
+
bindable = bindableMatch[1] === "true";
|
|
2364
|
+
}
|
|
2365
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
2366
|
+
if (hasDefaultMatch) {
|
|
2367
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
2368
|
+
}
|
|
2369
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
2370
|
+
pos = valueEnd + 1;
|
|
2371
|
+
}
|
|
2372
|
+
return result;
|
|
2373
|
+
}
|
|
2327
2374
|
function parseAttrsContent(content) {
|
|
2328
2375
|
const result = [];
|
|
2329
2376
|
const parts = splitByTopLevelCommas(content);
|
package/dist/index.js
CHANGED
|
@@ -3891,7 +3891,16 @@ 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 parseSourceOrigin(source2, exportName) {
|
|
3903
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
3895
3904
|
const match = exportPattern.exec(source2);
|
|
3896
3905
|
if (!match)
|
|
3897
3906
|
return null;
|
|
@@ -3927,6 +3936,94 @@ function parseOriginSchemaFromSource(source2, exportName) {
|
|
|
3927
3936
|
const attrs = parseAttrsContent(attrsContent);
|
|
3928
3937
|
return { attrs, parentNames };
|
|
3929
3938
|
}
|
|
3939
|
+
function parseCompiledOrigin(source2, exportName) {
|
|
3940
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
3941
|
+
const match = exportPattern.exec(source2);
|
|
3942
|
+
if (!match)
|
|
3943
|
+
return null;
|
|
3944
|
+
const braceStart = match.index + match[0].length - 1;
|
|
3945
|
+
const braceEnd = findMatchingBracket(source2, braceStart, "{", "}");
|
|
3946
|
+
if (braceEnd === -1)
|
|
3947
|
+
return null;
|
|
3948
|
+
const configContent = source2.slice(braceStart + 1, braceEnd);
|
|
3949
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
3950
|
+
if (!schemaMatch)
|
|
3951
|
+
return { attrs: [], parentNames: [] };
|
|
3952
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
3953
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
3954
|
+
if (schemaEnd === -1)
|
|
3955
|
+
return { attrs: [], parentNames: [] };
|
|
3956
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
3957
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
3958
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
3959
|
+
let parentNames = [];
|
|
3960
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
3961
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
3962
|
+
}
|
|
3963
|
+
return { attrs, parentNames };
|
|
3964
|
+
}
|
|
3965
|
+
function parseCompiledAttrSchema(content) {
|
|
3966
|
+
const result = [];
|
|
3967
|
+
let pos = 0;
|
|
3968
|
+
while (pos < content.length) {
|
|
3969
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
3970
|
+
pos++;
|
|
3971
|
+
if (pos >= content.length)
|
|
3972
|
+
break;
|
|
3973
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
3974
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
3975
|
+
if (endComment !== -1) {
|
|
3976
|
+
pos = endComment + 2;
|
|
3977
|
+
continue;
|
|
3978
|
+
}
|
|
3979
|
+
}
|
|
3980
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
3981
|
+
if (!keyMatch)
|
|
3982
|
+
break;
|
|
3983
|
+
const key2 = keyMatch[1];
|
|
3984
|
+
pos += keyMatch[0].length;
|
|
3985
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
3986
|
+
pos++;
|
|
3987
|
+
if (content[pos] !== "{")
|
|
3988
|
+
break;
|
|
3989
|
+
const valueStart = pos;
|
|
3990
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
3991
|
+
if (valueEnd === -1)
|
|
3992
|
+
break;
|
|
3993
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
3994
|
+
let defaultValue = "undefined";
|
|
3995
|
+
let bindable2 = false;
|
|
3996
|
+
let hasDefault = false;
|
|
3997
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
3998
|
+
if (defaultMatch) {
|
|
3999
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
4000
|
+
let depth = 0;
|
|
4001
|
+
let i = defaultStart;
|
|
4002
|
+
while (i < valueContent.length) {
|
|
4003
|
+
const char = valueContent[i];
|
|
4004
|
+
if (char === "{" || char === "(" || char === "[")
|
|
4005
|
+
depth++;
|
|
4006
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
4007
|
+
depth--;
|
|
4008
|
+
else if (char === "," && depth === 0)
|
|
4009
|
+
break;
|
|
4010
|
+
i++;
|
|
4011
|
+
}
|
|
4012
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
4013
|
+
}
|
|
4014
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
4015
|
+
if (bindableMatch) {
|
|
4016
|
+
bindable2 = bindableMatch[1] === "true";
|
|
4017
|
+
}
|
|
4018
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
4019
|
+
if (hasDefaultMatch) {
|
|
4020
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
4021
|
+
}
|
|
4022
|
+
result.push({ key: key2, defaultValue, bindable: bindable2, hasDefault });
|
|
4023
|
+
pos = valueEnd + 1;
|
|
4024
|
+
}
|
|
4025
|
+
return result;
|
|
4026
|
+
}
|
|
3930
4027
|
function parseAttrsContent(content) {
|
|
3931
4028
|
const result = [];
|
|
3932
4029
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -6120,65 +6217,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
|
|
|
6120
6217
|
const hasParents = parents.length > 0;
|
|
6121
6218
|
const propsLines = [];
|
|
6122
6219
|
if (attrDetails.length > 0) {
|
|
6123
|
-
const
|
|
6220
|
+
const propDefs = [];
|
|
6124
6221
|
for (const attr2 of attrDetails) {
|
|
6125
6222
|
const defaultExpr = attr2.hasDefault ? ` ?? ${attr2.defaultValue}` : "";
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
|
|
6129
|
-
for (const attr2 of attrDetails) {
|
|
6130
|
-
const defaultExpr = attr2.hasDefault ? ` ?? ${attr2.defaultValue}` : "";
|
|
6131
|
-
const parentLast = `__last_parent_${attr2.key}`;
|
|
6132
|
-
const localLast = `__last_local_${attr2.key}`;
|
|
6133
|
-
propsLines.push(`let ${parentLast} = __inputAttrs.${attr2.key}`, `let ${localLast} = __props.${attr2.key}`, `$effect(() => {
|
|
6134
|
-
` + ` const __parent = __inputAttrs.${attr2.key}
|
|
6135
|
-
` + ` const __local = __props.${attr2.key}
|
|
6136
|
-
|
|
6137
|
-
` + ` // Parent -> local
|
|
6138
|
-
` + ` if (__parent !== ${parentLast}) {
|
|
6139
|
-
` + ` ${parentLast} = __parent
|
|
6140
|
-
` + ` if (__local !== __parent) {
|
|
6141
|
-
` + ` __props.${attr2.key} = __parent${defaultExpr}
|
|
6142
|
-
` + ` }
|
|
6143
|
-
` + ` ${localLast} = __props.${attr2.key}
|
|
6144
|
-
` + ` return
|
|
6145
|
-
` + ` }
|
|
6146
|
-
|
|
6147
|
-
` + ` // Local -> parent
|
|
6148
|
-
` + ` if (__local !== ${localLast}) {
|
|
6149
|
-
` + ` ${localLast} = __local
|
|
6150
|
-
` + (attr2.bindable ? ` try { __inputAttrs.${attr2.key} = __local } catch {}
|
|
6151
|
-
${parentLast} = __inputAttrs.${attr2.key}
|
|
6152
|
-
` : "") + ` }
|
|
6153
|
-
` + `})`);
|
|
6223
|
+
propDefs.push(`get ${attr2.key}() { return __inputAttrs.${attr2.key}${defaultExpr} }`);
|
|
6224
|
+
propDefs.push(`set ${attr2.key}(v) { __inputAttrs.${attr2.key} = v }`);
|
|
6154
6225
|
}
|
|
6226
|
+
propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
|
|
6155
6227
|
} else {
|
|
6156
|
-
propsLines.push("
|
|
6157
|
-
` + ` // Bidirectional sync between __inputAttrs and __props
|
|
6158
|
-
` + ` for (const key of Object.keys(__inputAttrs)) {
|
|
6159
|
-
` + ` const parentVal = __inputAttrs[key]
|
|
6160
|
-
` + ` const localVal = __props[key]
|
|
6161
|
-
` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
|
|
6162
|
-
` + ` __syncState.set(key, state)
|
|
6163
|
-
|
|
6164
|
-
` + ` // Parent changed -> update local
|
|
6165
|
-
` + ` if (parentVal !== state.parent) {
|
|
6166
|
-
` + ` state.parent = parentVal
|
|
6167
|
-
` + ` if (localVal !== parentVal) {
|
|
6168
|
-
` + ` __props[key] = parentVal
|
|
6169
|
-
` + ` state.local = parentVal
|
|
6170
|
-
` + ` }
|
|
6171
|
-
` + ` continue
|
|
6172
|
-
` + ` }
|
|
6173
|
-
|
|
6174
|
-
` + ` // Local changed -> update parent (for bindable props)
|
|
6175
|
-
` + ` if (localVal !== state.local) {
|
|
6176
|
-
` + ` state.local = localVal
|
|
6177
|
-
` + ` try { __inputAttrs[key] = localVal } catch {}
|
|
6178
|
-
` + ` state.parent = __inputAttrs[key]
|
|
6179
|
-
` + ` }
|
|
6180
|
-
` + ` }
|
|
6181
|
-
` + ` })`);
|
|
6228
|
+
propsLines.push("const __props = __inputAttrs");
|
|
6182
6229
|
}
|
|
6183
6230
|
const propsObjectCode = "\t\t" + propsLines.join(`
|
|
6184
6231
|
`);
|
package/dist/plugin.js
CHANGED
|
@@ -2026,65 +2026,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
|
|
|
2026
2026
|
const hasParents = parents.length > 0;
|
|
2027
2027
|
const propsLines = [];
|
|
2028
2028
|
if (attrDetails.length > 0) {
|
|
2029
|
-
const
|
|
2029
|
+
const propDefs = [];
|
|
2030
2030
|
for (const attr of attrDetails) {
|
|
2031
2031
|
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
|
|
2035
|
-
for (const attr of attrDetails) {
|
|
2036
|
-
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2037
|
-
const parentLast = `__last_parent_${attr.key}`;
|
|
2038
|
-
const localLast = `__last_local_${attr.key}`;
|
|
2039
|
-
propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
|
|
2040
|
-
` + ` const __parent = __inputAttrs.${attr.key}
|
|
2041
|
-
` + ` const __local = __props.${attr.key}
|
|
2042
|
-
|
|
2043
|
-
` + ` // Parent -> local
|
|
2044
|
-
` + ` if (__parent !== ${parentLast}) {
|
|
2045
|
-
` + ` ${parentLast} = __parent
|
|
2046
|
-
` + ` if (__local !== __parent) {
|
|
2047
|
-
` + ` __props.${attr.key} = __parent${defaultExpr}
|
|
2048
|
-
` + ` }
|
|
2049
|
-
` + ` ${localLast} = __props.${attr.key}
|
|
2050
|
-
` + ` return
|
|
2051
|
-
` + ` }
|
|
2052
|
-
|
|
2053
|
-
` + ` // Local -> parent
|
|
2054
|
-
` + ` if (__local !== ${localLast}) {
|
|
2055
|
-
` + ` ${localLast} = __local
|
|
2056
|
-
` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
|
|
2057
|
-
${parentLast} = __inputAttrs.${attr.key}
|
|
2058
|
-
` : "") + ` }
|
|
2059
|
-
` + `})`);
|
|
2032
|
+
propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
|
|
2033
|
+
propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
|
|
2060
2034
|
}
|
|
2035
|
+
propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
|
|
2061
2036
|
} else {
|
|
2062
|
-
propsLines.push("
|
|
2063
|
-
` + ` // Bidirectional sync between __inputAttrs and __props
|
|
2064
|
-
` + ` for (const key of Object.keys(__inputAttrs)) {
|
|
2065
|
-
` + ` const parentVal = __inputAttrs[key]
|
|
2066
|
-
` + ` const localVal = __props[key]
|
|
2067
|
-
` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
|
|
2068
|
-
` + ` __syncState.set(key, state)
|
|
2069
|
-
|
|
2070
|
-
` + ` // Parent changed -> update local
|
|
2071
|
-
` + ` if (parentVal !== state.parent) {
|
|
2072
|
-
` + ` state.parent = parentVal
|
|
2073
|
-
` + ` if (localVal !== parentVal) {
|
|
2074
|
-
` + ` __props[key] = parentVal
|
|
2075
|
-
` + ` state.local = parentVal
|
|
2076
|
-
` + ` }
|
|
2077
|
-
` + ` continue
|
|
2078
|
-
` + ` }
|
|
2079
|
-
|
|
2080
|
-
` + ` // Local changed -> update parent (for bindable props)
|
|
2081
|
-
` + ` if (localVal !== state.local) {
|
|
2082
|
-
` + ` state.local = localVal
|
|
2083
|
-
` + ` try { __inputAttrs[key] = localVal } catch {}
|
|
2084
|
-
` + ` state.parent = __inputAttrs[key]
|
|
2085
|
-
` + ` }
|
|
2086
|
-
` + ` }
|
|
2087
|
-
` + ` })`);
|
|
2037
|
+
propsLines.push("const __props = __inputAttrs");
|
|
2088
2038
|
}
|
|
2089
2039
|
const propsObjectCode = "\t\t" + propsLines.join(`
|
|
2090
2040
|
`);
|
|
@@ -2282,7 +2232,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2282
2232
|
|
|
2283
2233
|
// src/transform/schema.ts
|
|
2284
2234
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2285
|
-
const
|
|
2235
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
2236
|
+
if (sourceResult)
|
|
2237
|
+
return sourceResult;
|
|
2238
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
2239
|
+
if (compiledResult)
|
|
2240
|
+
return compiledResult;
|
|
2241
|
+
return null;
|
|
2242
|
+
}
|
|
2243
|
+
function parseSourceOrigin(source, exportName) {
|
|
2244
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2286
2245
|
const match = exportPattern.exec(source);
|
|
2287
2246
|
if (!match)
|
|
2288
2247
|
return null;
|
|
@@ -2318,6 +2277,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2318
2277
|
const attrs = parseAttrsContent(attrsContent);
|
|
2319
2278
|
return { attrs, parentNames };
|
|
2320
2279
|
}
|
|
2280
|
+
function parseCompiledOrigin(source, exportName) {
|
|
2281
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
2282
|
+
const match = exportPattern.exec(source);
|
|
2283
|
+
if (!match)
|
|
2284
|
+
return null;
|
|
2285
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2286
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2287
|
+
if (braceEnd === -1)
|
|
2288
|
+
return null;
|
|
2289
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2290
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2291
|
+
if (!schemaMatch)
|
|
2292
|
+
return { attrs: [], parentNames: [] };
|
|
2293
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2294
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2295
|
+
if (schemaEnd === -1)
|
|
2296
|
+
return { attrs: [], parentNames: [] };
|
|
2297
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2298
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2299
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2300
|
+
let parentNames = [];
|
|
2301
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2302
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2303
|
+
}
|
|
2304
|
+
return { attrs, parentNames };
|
|
2305
|
+
}
|
|
2306
|
+
function parseCompiledAttrSchema(content) {
|
|
2307
|
+
const result = [];
|
|
2308
|
+
let pos = 0;
|
|
2309
|
+
while (pos < content.length) {
|
|
2310
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
2311
|
+
pos++;
|
|
2312
|
+
if (pos >= content.length)
|
|
2313
|
+
break;
|
|
2314
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
2315
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
2316
|
+
if (endComment !== -1) {
|
|
2317
|
+
pos = endComment + 2;
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
2322
|
+
if (!keyMatch)
|
|
2323
|
+
break;
|
|
2324
|
+
const key = keyMatch[1];
|
|
2325
|
+
pos += keyMatch[0].length;
|
|
2326
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
2327
|
+
pos++;
|
|
2328
|
+
if (content[pos] !== "{")
|
|
2329
|
+
break;
|
|
2330
|
+
const valueStart = pos;
|
|
2331
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
2332
|
+
if (valueEnd === -1)
|
|
2333
|
+
break;
|
|
2334
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
2335
|
+
let defaultValue = "undefined";
|
|
2336
|
+
let bindable = false;
|
|
2337
|
+
let hasDefault = false;
|
|
2338
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
2339
|
+
if (defaultMatch) {
|
|
2340
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
2341
|
+
let depth = 0;
|
|
2342
|
+
let i = defaultStart;
|
|
2343
|
+
while (i < valueContent.length) {
|
|
2344
|
+
const char = valueContent[i];
|
|
2345
|
+
if (char === "{" || char === "(" || char === "[")
|
|
2346
|
+
depth++;
|
|
2347
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
2348
|
+
depth--;
|
|
2349
|
+
else if (char === "," && depth === 0)
|
|
2350
|
+
break;
|
|
2351
|
+
i++;
|
|
2352
|
+
}
|
|
2353
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
2354
|
+
}
|
|
2355
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
2356
|
+
if (bindableMatch) {
|
|
2357
|
+
bindable = bindableMatch[1] === "true";
|
|
2358
|
+
}
|
|
2359
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
2360
|
+
if (hasDefaultMatch) {
|
|
2361
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
2362
|
+
}
|
|
2363
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
2364
|
+
pos = valueEnd + 1;
|
|
2365
|
+
}
|
|
2366
|
+
return result;
|
|
2367
|
+
}
|
|
2321
2368
|
function parseAttrsContent(content) {
|
|
2322
2369
|
const result = [];
|
|
2323
2370
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -3212,6 +3259,108 @@ function resolveImportPath(importPath, aliases, importerDir) {
|
|
|
3212
3259
|
return join(aliasPath, remainder);
|
|
3213
3260
|
}
|
|
3214
3261
|
}
|
|
3262
|
+
const npmResolved = resolveNpmPackageImport(importPath, importerDir);
|
|
3263
|
+
if (npmResolved) {
|
|
3264
|
+
return npmResolved;
|
|
3265
|
+
}
|
|
3266
|
+
return null;
|
|
3267
|
+
}
|
|
3268
|
+
function resolveNpmPackageImport(importPath, importerDir) {
|
|
3269
|
+
if (importPath.startsWith(".") || importPath.startsWith("/") || /^[a-zA-Z]:/.test(importPath)) {
|
|
3270
|
+
return null;
|
|
3271
|
+
}
|
|
3272
|
+
let packageName;
|
|
3273
|
+
let subpath;
|
|
3274
|
+
if (importPath.startsWith("@")) {
|
|
3275
|
+
const parts = importPath.split("/");
|
|
3276
|
+
if (parts.length < 2)
|
|
3277
|
+
return null;
|
|
3278
|
+
packageName = `${parts[0]}/${parts[1]}`;
|
|
3279
|
+
subpath = parts.slice(2).join("/");
|
|
3280
|
+
} else {
|
|
3281
|
+
const slashIndex = importPath.indexOf("/");
|
|
3282
|
+
if (slashIndex === -1) {
|
|
3283
|
+
packageName = importPath;
|
|
3284
|
+
subpath = "";
|
|
3285
|
+
} else {
|
|
3286
|
+
packageName = importPath.slice(0, slashIndex);
|
|
3287
|
+
subpath = importPath.slice(slashIndex + 1);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
let currentDir = importerDir;
|
|
3291
|
+
const root = isAbsolute(importerDir) ? (importerDir.match(/^[a-zA-Z]:[/\\]/) || ["/"])[0] : "/";
|
|
3292
|
+
while (currentDir !== root && currentDir !== dirname(currentDir)) {
|
|
3293
|
+
const nodeModulesDir = join(currentDir, "node_modules");
|
|
3294
|
+
const packageDir = join(nodeModulesDir, packageName);
|
|
3295
|
+
if (existsSync(packageDir)) {
|
|
3296
|
+
const packageJsonPath = join(packageDir, "package.json");
|
|
3297
|
+
const exportKey = subpath ? `./${subpath}` : ".";
|
|
3298
|
+
if (existsSync(packageJsonPath)) {
|
|
3299
|
+
try {
|
|
3300
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
3301
|
+
if (packageJson.exports) {
|
|
3302
|
+
const resolvedExport = resolvePackageExports(packageJson.exports, exportKey);
|
|
3303
|
+
if (resolvedExport) {
|
|
3304
|
+
return join(packageDir, resolvedExport);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
if (!subpath) {
|
|
3308
|
+
const mainEntry = packageJson.module || packageJson.main || "index.js";
|
|
3309
|
+
return join(packageDir, mainEntry);
|
|
3310
|
+
}
|
|
3311
|
+
} catch {}
|
|
3312
|
+
}
|
|
3313
|
+
if (subpath) {
|
|
3314
|
+
const resolvedSubpath = join(packageDir, subpath);
|
|
3315
|
+
return resolvedSubpath;
|
|
3316
|
+
}
|
|
3317
|
+
return join(packageDir, "index.js");
|
|
3318
|
+
}
|
|
3319
|
+
currentDir = dirname(currentDir);
|
|
3320
|
+
}
|
|
3321
|
+
return null;
|
|
3322
|
+
}
|
|
3323
|
+
function resolvePackageExports(exports, subpath) {
|
|
3324
|
+
if (typeof exports === "string") {
|
|
3325
|
+
return subpath === "." ? exports : null;
|
|
3326
|
+
}
|
|
3327
|
+
if (typeof exports !== "object" || exports === null) {
|
|
3328
|
+
return null;
|
|
3329
|
+
}
|
|
3330
|
+
const exportEntry = exports[subpath];
|
|
3331
|
+
if (exportEntry) {
|
|
3332
|
+
return resolveExportCondition(exportEntry);
|
|
3333
|
+
}
|
|
3334
|
+
if (subpath === "." && exports["."]) {
|
|
3335
|
+
return resolveExportCondition(exports["."]);
|
|
3336
|
+
}
|
|
3337
|
+
if (subpath === ".") {
|
|
3338
|
+
const resolved = resolveExportCondition(exports);
|
|
3339
|
+
if (resolved)
|
|
3340
|
+
return resolved;
|
|
3341
|
+
}
|
|
3342
|
+
return null;
|
|
3343
|
+
}
|
|
3344
|
+
function resolveExportCondition(condition) {
|
|
3345
|
+
if (typeof condition === "string") {
|
|
3346
|
+
return condition;
|
|
3347
|
+
}
|
|
3348
|
+
if (typeof condition !== "object" || condition === null) {
|
|
3349
|
+
return null;
|
|
3350
|
+
}
|
|
3351
|
+
const condObj = condition;
|
|
3352
|
+
const preferredConditions = ["svelte", "import", "module", "default", "require"];
|
|
3353
|
+
for (const cond of preferredConditions) {
|
|
3354
|
+
if (cond in condObj) {
|
|
3355
|
+
const value = condObj[cond];
|
|
3356
|
+
if (typeof value === "string") {
|
|
3357
|
+
return value;
|
|
3358
|
+
}
|
|
3359
|
+
const resolved = resolveExportCondition(value);
|
|
3360
|
+
if (resolved)
|
|
3361
|
+
return resolved;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3215
3364
|
return null;
|
|
3216
3365
|
}
|
|
3217
3366
|
function resolveFilePath(basePath) {
|
package/dist/post-process.js
CHANGED
|
@@ -2030,65 +2030,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
|
|
|
2030
2030
|
const hasParents = parents.length > 0;
|
|
2031
2031
|
const propsLines = [];
|
|
2032
2032
|
if (attrDetails.length > 0) {
|
|
2033
|
-
const
|
|
2033
|
+
const propDefs = [];
|
|
2034
2034
|
for (const attr of attrDetails) {
|
|
2035
2035
|
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
|
|
2039
|
-
for (const attr of attrDetails) {
|
|
2040
|
-
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2041
|
-
const parentLast = `__last_parent_${attr.key}`;
|
|
2042
|
-
const localLast = `__last_local_${attr.key}`;
|
|
2043
|
-
propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
|
|
2044
|
-
` + ` const __parent = __inputAttrs.${attr.key}
|
|
2045
|
-
` + ` const __local = __props.${attr.key}
|
|
2046
|
-
|
|
2047
|
-
` + ` // Parent -> local
|
|
2048
|
-
` + ` if (__parent !== ${parentLast}) {
|
|
2049
|
-
` + ` ${parentLast} = __parent
|
|
2050
|
-
` + ` if (__local !== __parent) {
|
|
2051
|
-
` + ` __props.${attr.key} = __parent${defaultExpr}
|
|
2052
|
-
` + ` }
|
|
2053
|
-
` + ` ${localLast} = __props.${attr.key}
|
|
2054
|
-
` + ` return
|
|
2055
|
-
` + ` }
|
|
2056
|
-
|
|
2057
|
-
` + ` // Local -> parent
|
|
2058
|
-
` + ` if (__local !== ${localLast}) {
|
|
2059
|
-
` + ` ${localLast} = __local
|
|
2060
|
-
` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
|
|
2061
|
-
${parentLast} = __inputAttrs.${attr.key}
|
|
2062
|
-
` : "") + ` }
|
|
2063
|
-
` + `})`);
|
|
2036
|
+
propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
|
|
2037
|
+
propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
|
|
2064
2038
|
}
|
|
2039
|
+
propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
|
|
2065
2040
|
} else {
|
|
2066
|
-
propsLines.push("
|
|
2067
|
-
` + ` // Bidirectional sync between __inputAttrs and __props
|
|
2068
|
-
` + ` for (const key of Object.keys(__inputAttrs)) {
|
|
2069
|
-
` + ` const parentVal = __inputAttrs[key]
|
|
2070
|
-
` + ` const localVal = __props[key]
|
|
2071
|
-
` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
|
|
2072
|
-
` + ` __syncState.set(key, state)
|
|
2073
|
-
|
|
2074
|
-
` + ` // Parent changed -> update local
|
|
2075
|
-
` + ` if (parentVal !== state.parent) {
|
|
2076
|
-
` + ` state.parent = parentVal
|
|
2077
|
-
` + ` if (localVal !== parentVal) {
|
|
2078
|
-
` + ` __props[key] = parentVal
|
|
2079
|
-
` + ` state.local = parentVal
|
|
2080
|
-
` + ` }
|
|
2081
|
-
` + ` continue
|
|
2082
|
-
` + ` }
|
|
2083
|
-
|
|
2084
|
-
` + ` // Local changed -> update parent (for bindable props)
|
|
2085
|
-
` + ` if (localVal !== state.local) {
|
|
2086
|
-
` + ` state.local = localVal
|
|
2087
|
-
` + ` try { __inputAttrs[key] = localVal } catch {}
|
|
2088
|
-
` + ` state.parent = __inputAttrs[key]
|
|
2089
|
-
` + ` }
|
|
2090
|
-
` + ` }
|
|
2091
|
-
` + ` })`);
|
|
2041
|
+
propsLines.push("const __props = __inputAttrs");
|
|
2092
2042
|
}
|
|
2093
2043
|
const propsObjectCode = "\t\t" + propsLines.join(`
|
|
2094
2044
|
`);
|
|
@@ -2286,7 +2236,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2286
2236
|
|
|
2287
2237
|
// src/transform/schema.ts
|
|
2288
2238
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2289
|
-
const
|
|
2239
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
2240
|
+
if (sourceResult)
|
|
2241
|
+
return sourceResult;
|
|
2242
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
2243
|
+
if (compiledResult)
|
|
2244
|
+
return compiledResult;
|
|
2245
|
+
return null;
|
|
2246
|
+
}
|
|
2247
|
+
function parseSourceOrigin(source, exportName) {
|
|
2248
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2290
2249
|
const match = exportPattern.exec(source);
|
|
2291
2250
|
if (!match)
|
|
2292
2251
|
return null;
|
|
@@ -2322,6 +2281,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2322
2281
|
const attrs = parseAttrsContent(attrsContent);
|
|
2323
2282
|
return { attrs, parentNames };
|
|
2324
2283
|
}
|
|
2284
|
+
function parseCompiledOrigin(source, exportName) {
|
|
2285
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
2286
|
+
const match = exportPattern.exec(source);
|
|
2287
|
+
if (!match)
|
|
2288
|
+
return null;
|
|
2289
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2290
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2291
|
+
if (braceEnd === -1)
|
|
2292
|
+
return null;
|
|
2293
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2294
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2295
|
+
if (!schemaMatch)
|
|
2296
|
+
return { attrs: [], parentNames: [] };
|
|
2297
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2298
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2299
|
+
if (schemaEnd === -1)
|
|
2300
|
+
return { attrs: [], parentNames: [] };
|
|
2301
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2302
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2303
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2304
|
+
let parentNames = [];
|
|
2305
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2306
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2307
|
+
}
|
|
2308
|
+
return { attrs, parentNames };
|
|
2309
|
+
}
|
|
2310
|
+
function parseCompiledAttrSchema(content) {
|
|
2311
|
+
const result = [];
|
|
2312
|
+
let pos = 0;
|
|
2313
|
+
while (pos < content.length) {
|
|
2314
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
2315
|
+
pos++;
|
|
2316
|
+
if (pos >= content.length)
|
|
2317
|
+
break;
|
|
2318
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
2319
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
2320
|
+
if (endComment !== -1) {
|
|
2321
|
+
pos = endComment + 2;
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
2326
|
+
if (!keyMatch)
|
|
2327
|
+
break;
|
|
2328
|
+
const key = keyMatch[1];
|
|
2329
|
+
pos += keyMatch[0].length;
|
|
2330
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
2331
|
+
pos++;
|
|
2332
|
+
if (content[pos] !== "{")
|
|
2333
|
+
break;
|
|
2334
|
+
const valueStart = pos;
|
|
2335
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
2336
|
+
if (valueEnd === -1)
|
|
2337
|
+
break;
|
|
2338
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
2339
|
+
let defaultValue = "undefined";
|
|
2340
|
+
let bindable = false;
|
|
2341
|
+
let hasDefault = false;
|
|
2342
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
2343
|
+
if (defaultMatch) {
|
|
2344
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
2345
|
+
let depth = 0;
|
|
2346
|
+
let i = defaultStart;
|
|
2347
|
+
while (i < valueContent.length) {
|
|
2348
|
+
const char = valueContent[i];
|
|
2349
|
+
if (char === "{" || char === "(" || char === "[")
|
|
2350
|
+
depth++;
|
|
2351
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
2352
|
+
depth--;
|
|
2353
|
+
else if (char === "," && depth === 0)
|
|
2354
|
+
break;
|
|
2355
|
+
i++;
|
|
2356
|
+
}
|
|
2357
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
2358
|
+
}
|
|
2359
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
2360
|
+
if (bindableMatch) {
|
|
2361
|
+
bindable = bindableMatch[1] === "true";
|
|
2362
|
+
}
|
|
2363
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
2364
|
+
if (hasDefaultMatch) {
|
|
2365
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
2366
|
+
}
|
|
2367
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
2368
|
+
pos = valueEnd + 1;
|
|
2369
|
+
}
|
|
2370
|
+
return result;
|
|
2371
|
+
}
|
|
2325
2372
|
function parseAttrsContent(content) {
|
|
2326
2373
|
const result = [];
|
|
2327
2374
|
const parts = splitByTopLevelCommas(content);
|
package/dist/preprocess.js
CHANGED
|
@@ -2026,65 +2026,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
|
|
|
2026
2026
|
const hasParents = parents.length > 0;
|
|
2027
2027
|
const propsLines = [];
|
|
2028
2028
|
if (attrDetails.length > 0) {
|
|
2029
|
-
const
|
|
2029
|
+
const propDefs = [];
|
|
2030
2030
|
for (const attr of attrDetails) {
|
|
2031
2031
|
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
|
|
2035
|
-
for (const attr of attrDetails) {
|
|
2036
|
-
const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
|
|
2037
|
-
const parentLast = `__last_parent_${attr.key}`;
|
|
2038
|
-
const localLast = `__last_local_${attr.key}`;
|
|
2039
|
-
propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
|
|
2040
|
-
` + ` const __parent = __inputAttrs.${attr.key}
|
|
2041
|
-
` + ` const __local = __props.${attr.key}
|
|
2042
|
-
|
|
2043
|
-
` + ` // Parent -> local
|
|
2044
|
-
` + ` if (__parent !== ${parentLast}) {
|
|
2045
|
-
` + ` ${parentLast} = __parent
|
|
2046
|
-
` + ` if (__local !== __parent) {
|
|
2047
|
-
` + ` __props.${attr.key} = __parent${defaultExpr}
|
|
2048
|
-
` + ` }
|
|
2049
|
-
` + ` ${localLast} = __props.${attr.key}
|
|
2050
|
-
` + ` return
|
|
2051
|
-
` + ` }
|
|
2052
|
-
|
|
2053
|
-
` + ` // Local -> parent
|
|
2054
|
-
` + ` if (__local !== ${localLast}) {
|
|
2055
|
-
` + ` ${localLast} = __local
|
|
2056
|
-
` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
|
|
2057
|
-
${parentLast} = __inputAttrs.${attr.key}
|
|
2058
|
-
` : "") + ` }
|
|
2059
|
-
` + `})`);
|
|
2032
|
+
propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
|
|
2033
|
+
propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
|
|
2060
2034
|
}
|
|
2035
|
+
propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
|
|
2061
2036
|
} else {
|
|
2062
|
-
propsLines.push("
|
|
2063
|
-
` + ` // Bidirectional sync between __inputAttrs and __props
|
|
2064
|
-
` + ` for (const key of Object.keys(__inputAttrs)) {
|
|
2065
|
-
` + ` const parentVal = __inputAttrs[key]
|
|
2066
|
-
` + ` const localVal = __props[key]
|
|
2067
|
-
` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
|
|
2068
|
-
` + ` __syncState.set(key, state)
|
|
2069
|
-
|
|
2070
|
-
` + ` // Parent changed -> update local
|
|
2071
|
-
` + ` if (parentVal !== state.parent) {
|
|
2072
|
-
` + ` state.parent = parentVal
|
|
2073
|
-
` + ` if (localVal !== parentVal) {
|
|
2074
|
-
` + ` __props[key] = parentVal
|
|
2075
|
-
` + ` state.local = parentVal
|
|
2076
|
-
` + ` }
|
|
2077
|
-
` + ` continue
|
|
2078
|
-
` + ` }
|
|
2079
|
-
|
|
2080
|
-
` + ` // Local changed -> update parent (for bindable props)
|
|
2081
|
-
` + ` if (localVal !== state.local) {
|
|
2082
|
-
` + ` state.local = localVal
|
|
2083
|
-
` + ` try { __inputAttrs[key] = localVal } catch {}
|
|
2084
|
-
` + ` state.parent = __inputAttrs[key]
|
|
2085
|
-
` + ` }
|
|
2086
|
-
` + ` }
|
|
2087
|
-
` + ` })`);
|
|
2037
|
+
propsLines.push("const __props = __inputAttrs");
|
|
2088
2038
|
}
|
|
2089
2039
|
const propsObjectCode = "\t\t" + propsLines.join(`
|
|
2090
2040
|
`);
|
|
@@ -2282,7 +2232,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2282
2232
|
|
|
2283
2233
|
// src/transform/schema.ts
|
|
2284
2234
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2285
|
-
const
|
|
2235
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
2236
|
+
if (sourceResult)
|
|
2237
|
+
return sourceResult;
|
|
2238
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
2239
|
+
if (compiledResult)
|
|
2240
|
+
return compiledResult;
|
|
2241
|
+
return null;
|
|
2242
|
+
}
|
|
2243
|
+
function parseSourceOrigin(source, exportName) {
|
|
2244
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
2286
2245
|
const match = exportPattern.exec(source);
|
|
2287
2246
|
if (!match)
|
|
2288
2247
|
return null;
|
|
@@ -2318,6 +2277,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2318
2277
|
const attrs = parseAttrsContent(attrsContent);
|
|
2319
2278
|
return { attrs, parentNames };
|
|
2320
2279
|
}
|
|
2280
|
+
function parseCompiledOrigin(source, exportName) {
|
|
2281
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
2282
|
+
const match = exportPattern.exec(source);
|
|
2283
|
+
if (!match)
|
|
2284
|
+
return null;
|
|
2285
|
+
const braceStart = match.index + match[0].length - 1;
|
|
2286
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
2287
|
+
if (braceEnd === -1)
|
|
2288
|
+
return null;
|
|
2289
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
2290
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
2291
|
+
if (!schemaMatch)
|
|
2292
|
+
return { attrs: [], parentNames: [] };
|
|
2293
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
2294
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
2295
|
+
if (schemaEnd === -1)
|
|
2296
|
+
return { attrs: [], parentNames: [] };
|
|
2297
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
2298
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
2299
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
2300
|
+
let parentNames = [];
|
|
2301
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
2302
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
2303
|
+
}
|
|
2304
|
+
return { attrs, parentNames };
|
|
2305
|
+
}
|
|
2306
|
+
function parseCompiledAttrSchema(content) {
|
|
2307
|
+
const result = [];
|
|
2308
|
+
let pos = 0;
|
|
2309
|
+
while (pos < content.length) {
|
|
2310
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
2311
|
+
pos++;
|
|
2312
|
+
if (pos >= content.length)
|
|
2313
|
+
break;
|
|
2314
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
2315
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
2316
|
+
if (endComment !== -1) {
|
|
2317
|
+
pos = endComment + 2;
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
2322
|
+
if (!keyMatch)
|
|
2323
|
+
break;
|
|
2324
|
+
const key = keyMatch[1];
|
|
2325
|
+
pos += keyMatch[0].length;
|
|
2326
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
2327
|
+
pos++;
|
|
2328
|
+
if (content[pos] !== "{")
|
|
2329
|
+
break;
|
|
2330
|
+
const valueStart = pos;
|
|
2331
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
2332
|
+
if (valueEnd === -1)
|
|
2333
|
+
break;
|
|
2334
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
2335
|
+
let defaultValue = "undefined";
|
|
2336
|
+
let bindable = false;
|
|
2337
|
+
let hasDefault = false;
|
|
2338
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
2339
|
+
if (defaultMatch) {
|
|
2340
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
2341
|
+
let depth = 0;
|
|
2342
|
+
let i = defaultStart;
|
|
2343
|
+
while (i < valueContent.length) {
|
|
2344
|
+
const char = valueContent[i];
|
|
2345
|
+
if (char === "{" || char === "(" || char === "[")
|
|
2346
|
+
depth++;
|
|
2347
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
2348
|
+
depth--;
|
|
2349
|
+
else if (char === "," && depth === 0)
|
|
2350
|
+
break;
|
|
2351
|
+
i++;
|
|
2352
|
+
}
|
|
2353
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
2354
|
+
}
|
|
2355
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
2356
|
+
if (bindableMatch) {
|
|
2357
|
+
bindable = bindableMatch[1] === "true";
|
|
2358
|
+
}
|
|
2359
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
2360
|
+
if (hasDefaultMatch) {
|
|
2361
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
2362
|
+
}
|
|
2363
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
2364
|
+
pos = valueEnd + 1;
|
|
2365
|
+
}
|
|
2366
|
+
return result;
|
|
2367
|
+
}
|
|
2321
2368
|
function parseAttrsContent(content) {
|
|
2322
2369
|
const result = [];
|
|
2323
2370
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -3212,6 +3259,108 @@ function resolveImportPath(importPath, aliases, importerDir) {
|
|
|
3212
3259
|
return join(aliasPath, remainder);
|
|
3213
3260
|
}
|
|
3214
3261
|
}
|
|
3262
|
+
const npmResolved = resolveNpmPackageImport(importPath, importerDir);
|
|
3263
|
+
if (npmResolved) {
|
|
3264
|
+
return npmResolved;
|
|
3265
|
+
}
|
|
3266
|
+
return null;
|
|
3267
|
+
}
|
|
3268
|
+
function resolveNpmPackageImport(importPath, importerDir) {
|
|
3269
|
+
if (importPath.startsWith(".") || importPath.startsWith("/") || /^[a-zA-Z]:/.test(importPath)) {
|
|
3270
|
+
return null;
|
|
3271
|
+
}
|
|
3272
|
+
let packageName;
|
|
3273
|
+
let subpath;
|
|
3274
|
+
if (importPath.startsWith("@")) {
|
|
3275
|
+
const parts = importPath.split("/");
|
|
3276
|
+
if (parts.length < 2)
|
|
3277
|
+
return null;
|
|
3278
|
+
packageName = `${parts[0]}/${parts[1]}`;
|
|
3279
|
+
subpath = parts.slice(2).join("/");
|
|
3280
|
+
} else {
|
|
3281
|
+
const slashIndex = importPath.indexOf("/");
|
|
3282
|
+
if (slashIndex === -1) {
|
|
3283
|
+
packageName = importPath;
|
|
3284
|
+
subpath = "";
|
|
3285
|
+
} else {
|
|
3286
|
+
packageName = importPath.slice(0, slashIndex);
|
|
3287
|
+
subpath = importPath.slice(slashIndex + 1);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
let currentDir = importerDir;
|
|
3291
|
+
const root = isAbsolute(importerDir) ? (importerDir.match(/^[a-zA-Z]:[/\\]/) || ["/"])[0] : "/";
|
|
3292
|
+
while (currentDir !== root && currentDir !== dirname(currentDir)) {
|
|
3293
|
+
const nodeModulesDir = join(currentDir, "node_modules");
|
|
3294
|
+
const packageDir = join(nodeModulesDir, packageName);
|
|
3295
|
+
if (existsSync(packageDir)) {
|
|
3296
|
+
const packageJsonPath = join(packageDir, "package.json");
|
|
3297
|
+
const exportKey = subpath ? `./${subpath}` : ".";
|
|
3298
|
+
if (existsSync(packageJsonPath)) {
|
|
3299
|
+
try {
|
|
3300
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
3301
|
+
if (packageJson.exports) {
|
|
3302
|
+
const resolvedExport = resolvePackageExports(packageJson.exports, exportKey);
|
|
3303
|
+
if (resolvedExport) {
|
|
3304
|
+
return join(packageDir, resolvedExport);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
if (!subpath) {
|
|
3308
|
+
const mainEntry = packageJson.module || packageJson.main || "index.js";
|
|
3309
|
+
return join(packageDir, mainEntry);
|
|
3310
|
+
}
|
|
3311
|
+
} catch {}
|
|
3312
|
+
}
|
|
3313
|
+
if (subpath) {
|
|
3314
|
+
const resolvedSubpath = join(packageDir, subpath);
|
|
3315
|
+
return resolvedSubpath;
|
|
3316
|
+
}
|
|
3317
|
+
return join(packageDir, "index.js");
|
|
3318
|
+
}
|
|
3319
|
+
currentDir = dirname(currentDir);
|
|
3320
|
+
}
|
|
3321
|
+
return null;
|
|
3322
|
+
}
|
|
3323
|
+
function resolvePackageExports(exports, subpath) {
|
|
3324
|
+
if (typeof exports === "string") {
|
|
3325
|
+
return subpath === "." ? exports : null;
|
|
3326
|
+
}
|
|
3327
|
+
if (typeof exports !== "object" || exports === null) {
|
|
3328
|
+
return null;
|
|
3329
|
+
}
|
|
3330
|
+
const exportEntry = exports[subpath];
|
|
3331
|
+
if (exportEntry) {
|
|
3332
|
+
return resolveExportCondition(exportEntry);
|
|
3333
|
+
}
|
|
3334
|
+
if (subpath === "." && exports["."]) {
|
|
3335
|
+
return resolveExportCondition(exports["."]);
|
|
3336
|
+
}
|
|
3337
|
+
if (subpath === ".") {
|
|
3338
|
+
const resolved = resolveExportCondition(exports);
|
|
3339
|
+
if (resolved)
|
|
3340
|
+
return resolved;
|
|
3341
|
+
}
|
|
3342
|
+
return null;
|
|
3343
|
+
}
|
|
3344
|
+
function resolveExportCondition(condition) {
|
|
3345
|
+
if (typeof condition === "string") {
|
|
3346
|
+
return condition;
|
|
3347
|
+
}
|
|
3348
|
+
if (typeof condition !== "object" || condition === null) {
|
|
3349
|
+
return null;
|
|
3350
|
+
}
|
|
3351
|
+
const condObj = condition;
|
|
3352
|
+
const preferredConditions = ["svelte", "import", "module", "default", "require"];
|
|
3353
|
+
for (const cond of preferredConditions) {
|
|
3354
|
+
if (cond in condObj) {
|
|
3355
|
+
const value = condObj[cond];
|
|
3356
|
+
if (typeof value === "string") {
|
|
3357
|
+
return value;
|
|
3358
|
+
}
|
|
3359
|
+
const resolved = resolveExportCondition(value);
|
|
3360
|
+
if (resolved)
|
|
3361
|
+
return resolved;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3215
3364
|
return null;
|
|
3216
3365
|
}
|
|
3217
3366
|
function resolveFilePath(basePath) {
|
package/dist/vite-dts.js
CHANGED
|
@@ -202,7 +202,16 @@ function findMatchingBracket(source, openIndex, openChar = "(", closeChar = ")")
|
|
|
202
202
|
|
|
203
203
|
// src/transform/schema.ts
|
|
204
204
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
205
|
-
const
|
|
205
|
+
const sourceResult = parseSourceOrigin(source, exportName);
|
|
206
|
+
if (sourceResult)
|
|
207
|
+
return sourceResult;
|
|
208
|
+
const compiledResult = parseCompiledOrigin(source, exportName);
|
|
209
|
+
if (compiledResult)
|
|
210
|
+
return compiledResult;
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
function parseSourceOrigin(source, exportName) {
|
|
214
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
|
|
206
215
|
const match = exportPattern.exec(source);
|
|
207
216
|
if (!match)
|
|
208
217
|
return null;
|
|
@@ -238,6 +247,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
238
247
|
const attrs = parseAttrsContent(attrsContent);
|
|
239
248
|
return { attrs, parentNames };
|
|
240
249
|
}
|
|
250
|
+
function parseCompiledOrigin(source, exportName) {
|
|
251
|
+
const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createOrigin\\s*\\(\\s*\\{`, "s");
|
|
252
|
+
const match = exportPattern.exec(source);
|
|
253
|
+
if (!match)
|
|
254
|
+
return null;
|
|
255
|
+
const braceStart = match.index + match[0].length - 1;
|
|
256
|
+
const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
|
|
257
|
+
if (braceEnd === -1)
|
|
258
|
+
return null;
|
|
259
|
+
const configContent = source.slice(braceStart + 1, braceEnd);
|
|
260
|
+
const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
|
|
261
|
+
if (!schemaMatch)
|
|
262
|
+
return { attrs: [], parentNames: [] };
|
|
263
|
+
const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
|
|
264
|
+
const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
|
|
265
|
+
if (schemaEnd === -1)
|
|
266
|
+
return { attrs: [], parentNames: [] };
|
|
267
|
+
const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
|
|
268
|
+
const attrs = parseCompiledAttrSchema(schemaContent);
|
|
269
|
+
const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
|
|
270
|
+
let parentNames = [];
|
|
271
|
+
if (parentsMatch && parentsMatch[1].trim()) {
|
|
272
|
+
parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
|
|
273
|
+
}
|
|
274
|
+
return { attrs, parentNames };
|
|
275
|
+
}
|
|
276
|
+
function parseCompiledAttrSchema(content) {
|
|
277
|
+
const result = [];
|
|
278
|
+
let pos = 0;
|
|
279
|
+
while (pos < content.length) {
|
|
280
|
+
while (pos < content.length && /[\s,]/.test(content[pos]))
|
|
281
|
+
pos++;
|
|
282
|
+
if (pos >= content.length)
|
|
283
|
+
break;
|
|
284
|
+
if (content.slice(pos, pos + 2) === "/*") {
|
|
285
|
+
const endComment = content.indexOf("*/", pos + 2);
|
|
286
|
+
if (endComment !== -1) {
|
|
287
|
+
pos = endComment + 2;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const keyMatch = content.slice(pos).match(/^(\w+)\s*:/);
|
|
292
|
+
if (!keyMatch)
|
|
293
|
+
break;
|
|
294
|
+
const key = keyMatch[1];
|
|
295
|
+
pos += keyMatch[0].length;
|
|
296
|
+
while (pos < content.length && /\s/.test(content[pos]))
|
|
297
|
+
pos++;
|
|
298
|
+
if (content[pos] !== "{")
|
|
299
|
+
break;
|
|
300
|
+
const valueStart = pos;
|
|
301
|
+
const valueEnd = findMatchingBracket(content, valueStart, "{", "}");
|
|
302
|
+
if (valueEnd === -1)
|
|
303
|
+
break;
|
|
304
|
+
const valueContent = content.slice(valueStart + 1, valueEnd);
|
|
305
|
+
let defaultValue = "undefined";
|
|
306
|
+
let bindable = false;
|
|
307
|
+
let hasDefault = false;
|
|
308
|
+
const defaultMatch = valueContent.match(/\bdefault\s*:\s*/);
|
|
309
|
+
if (defaultMatch) {
|
|
310
|
+
const defaultStart = defaultMatch.index + defaultMatch[0].length;
|
|
311
|
+
let depth = 0;
|
|
312
|
+
let i = defaultStart;
|
|
313
|
+
while (i < valueContent.length) {
|
|
314
|
+
const char = valueContent[i];
|
|
315
|
+
if (char === "{" || char === "(" || char === "[")
|
|
316
|
+
depth++;
|
|
317
|
+
else if (char === "}" || char === ")" || char === "]")
|
|
318
|
+
depth--;
|
|
319
|
+
else if (char === "," && depth === 0)
|
|
320
|
+
break;
|
|
321
|
+
i++;
|
|
322
|
+
}
|
|
323
|
+
defaultValue = valueContent.slice(defaultStart, i).trim();
|
|
324
|
+
}
|
|
325
|
+
const bindableMatch = valueContent.match(/\bbindable\s*:\s*(true|false)/);
|
|
326
|
+
if (bindableMatch) {
|
|
327
|
+
bindable = bindableMatch[1] === "true";
|
|
328
|
+
}
|
|
329
|
+
const hasDefaultMatch = valueContent.match(/\bhasDefault\s*:\s*(true|false)/);
|
|
330
|
+
if (hasDefaultMatch) {
|
|
331
|
+
hasDefault = hasDefaultMatch[1] === "true";
|
|
332
|
+
}
|
|
333
|
+
result.push({ key, defaultValue, bindable, hasDefault });
|
|
334
|
+
pos = valueEnd + 1;
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
241
338
|
function parseAttrsContent(content) {
|
|
242
339
|
const result = [];
|
|
243
340
|
const parts = splitByTopLevelCommas(content);
|