svelte-origin 1.0.0-next.20 → 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 +98 -1
- package/dist/index.js +98 -1
- package/dist/plugin.js +200 -1
- package/dist/post-process.js +98 -1
- package/dist/preprocess.js +200 -1
- 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
|
@@ -2238,7 +2238,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2238
2238
|
|
|
2239
2239
|
// src/transform/schema.ts
|
|
2240
2240
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2241
|
-
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");
|
|
2242
2251
|
const match = exportPattern.exec(source);
|
|
2243
2252
|
if (!match)
|
|
2244
2253
|
return null;
|
|
@@ -2274,6 +2283,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2274
2283
|
const attrs = parseAttrsContent(attrsContent);
|
|
2275
2284
|
return { attrs, parentNames };
|
|
2276
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
|
+
}
|
|
2277
2374
|
function parseAttrsContent(content) {
|
|
2278
2375
|
const result = [];
|
|
2279
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);
|
package/dist/plugin.js
CHANGED
|
@@ -2232,7 +2232,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2232
2232
|
|
|
2233
2233
|
// src/transform/schema.ts
|
|
2234
2234
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2235
|
-
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");
|
|
2236
2245
|
const match = exportPattern.exec(source);
|
|
2237
2246
|
if (!match)
|
|
2238
2247
|
return null;
|
|
@@ -2268,6 +2277,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2268
2277
|
const attrs = parseAttrsContent(attrsContent);
|
|
2269
2278
|
return { attrs, parentNames };
|
|
2270
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
|
+
}
|
|
2271
2368
|
function parseAttrsContent(content) {
|
|
2272
2369
|
const result = [];
|
|
2273
2370
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -3162,6 +3259,108 @@ function resolveImportPath(importPath, aliases, importerDir) {
|
|
|
3162
3259
|
return join(aliasPath, remainder);
|
|
3163
3260
|
}
|
|
3164
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
|
+
}
|
|
3165
3364
|
return null;
|
|
3166
3365
|
}
|
|
3167
3366
|
function resolveFilePath(basePath) {
|
package/dist/post-process.js
CHANGED
|
@@ -2236,7 +2236,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2236
2236
|
|
|
2237
2237
|
// src/transform/schema.ts
|
|
2238
2238
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2239
|
-
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");
|
|
2240
2249
|
const match = exportPattern.exec(source);
|
|
2241
2250
|
if (!match)
|
|
2242
2251
|
return null;
|
|
@@ -2272,6 +2281,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2272
2281
|
const attrs = parseAttrsContent(attrsContent);
|
|
2273
2282
|
return { attrs, parentNames };
|
|
2274
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
|
+
}
|
|
2275
2372
|
function parseAttrsContent(content) {
|
|
2276
2373
|
const result = [];
|
|
2277
2374
|
const parts = splitByTopLevelCommas(content);
|
package/dist/preprocess.js
CHANGED
|
@@ -2232,7 +2232,16 @@ function transformStandaloneAttrsDefinition(content) {
|
|
|
2232
2232
|
|
|
2233
2233
|
// src/transform/schema.ts
|
|
2234
2234
|
function parseOriginSchemaFromSource(source, exportName) {
|
|
2235
|
-
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");
|
|
2236
2245
|
const match = exportPattern.exec(source);
|
|
2237
2246
|
if (!match)
|
|
2238
2247
|
return null;
|
|
@@ -2268,6 +2277,94 @@ function parseOriginSchemaFromSource(source, exportName) {
|
|
|
2268
2277
|
const attrs = parseAttrsContent(attrsContent);
|
|
2269
2278
|
return { attrs, parentNames };
|
|
2270
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
|
+
}
|
|
2271
2368
|
function parseAttrsContent(content) {
|
|
2272
2369
|
const result = [];
|
|
2273
2370
|
const parts = splitByTopLevelCommas(content);
|
|
@@ -3162,6 +3259,108 @@ function resolveImportPath(importPath, aliases, importerDir) {
|
|
|
3162
3259
|
return join(aliasPath, remainder);
|
|
3163
3260
|
}
|
|
3164
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
|
+
}
|
|
3165
3364
|
return null;
|
|
3166
3365
|
}
|
|
3167
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);
|