svelte-origin 1.0.0-next.22 → 1.0.0-next.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

@@ -2253,6 +2253,79 @@ function transformStandaloneAttrsDefinition(content) {
2253
2253
  }`;
2254
2254
  }
2255
2255
 
2256
+ // src/transform/reserved-keywords.ts
2257
+ var RESERVED_KEYWORDS = new Set([
2258
+ "break",
2259
+ "case",
2260
+ "catch",
2261
+ "continue",
2262
+ "debugger",
2263
+ "default",
2264
+ "delete",
2265
+ "do",
2266
+ "else",
2267
+ "finally",
2268
+ "for",
2269
+ "function",
2270
+ "if",
2271
+ "in",
2272
+ "instanceof",
2273
+ "new",
2274
+ "return",
2275
+ "switch",
2276
+ "this",
2277
+ "throw",
2278
+ "try",
2279
+ "typeof",
2280
+ "var",
2281
+ "void",
2282
+ "while",
2283
+ "with",
2284
+ "class",
2285
+ "const",
2286
+ "enum",
2287
+ "export",
2288
+ "extends",
2289
+ "import",
2290
+ "super",
2291
+ "implements",
2292
+ "interface",
2293
+ "let",
2294
+ "package",
2295
+ "private",
2296
+ "protected",
2297
+ "public",
2298
+ "static",
2299
+ "yield",
2300
+ "await",
2301
+ "async",
2302
+ "true",
2303
+ "false",
2304
+ "null",
2305
+ "undefined",
2306
+ "arguments",
2307
+ "eval"
2308
+ ]);
2309
+ function getInternalVarName(propName, forcePrefix = true) {
2310
+ return `___${propName}`;
2311
+ }
2312
+ function generatePropDestructure(propName, defaultValue) {
2313
+ const internalName = getInternalVarName(propName);
2314
+ return `${propName}: ${internalName} = ${defaultValue}`;
2315
+ }
2316
+ function generatePropDestructureNoDefault(propName) {
2317
+ const internalName = getInternalVarName(propName);
2318
+ return `${propName}: ${internalName}`;
2319
+ }
2320
+ function generateGetter(propName) {
2321
+ const internalName = getInternalVarName(propName);
2322
+ return `get ${propName}() { return ${internalName} }`;
2323
+ }
2324
+ function generateSetter(propName) {
2325
+ const internalName = getInternalVarName(propName);
2326
+ return `set ${propName}(v) { ${internalName} = v }`;
2327
+ }
2328
+
2256
2329
  // src/transform/schema.ts
2257
2330
  function parseOriginSchemaFromSource(source, exportName) {
2258
2331
  const sourceResult = parseSourceOrigin(source, exportName);
@@ -2591,14 +2664,14 @@ function generatePropsDestructuring(attrs, factoryName) {
2591
2664
  for (const attr of attrs) {
2592
2665
  if (attr.bindable) {
2593
2666
  if (attr.hasDefault) {
2594
- parts.push(`${attr.key} = $bindable(${attr.defaultValue})`);
2667
+ parts.push(generatePropDestructure(attr.key, `$bindable(${attr.defaultValue})`));
2595
2668
  } else {
2596
- parts.push(`${attr.key} = $bindable()`);
2669
+ parts.push(generatePropDestructure(attr.key, "$bindable()"));
2597
2670
  }
2598
2671
  } else if (attr.hasDefault) {
2599
- parts.push(`${attr.key} = ${attr.defaultValue}`);
2672
+ parts.push(generatePropDestructure(attr.key, attr.defaultValue));
2600
2673
  } else {
2601
- parts.push(attr.key);
2674
+ parts.push(generatePropDestructureNoDefault(attr.key));
2602
2675
  }
2603
2676
  }
2604
2677
  return `let { ${parts.join(", ")} }: $attrs.Of<typeof ${factoryName}> = $props()`;
@@ -2606,9 +2679,9 @@ function generatePropsDestructuring(attrs, factoryName) {
2606
2679
  function generateFactoryCallFromAttrs(factoryName, attrs) {
2607
2680
  const parts = [];
2608
2681
  for (const attr of attrs) {
2609
- parts.push(`get ${attr.key}() { return ${attr.key} }`);
2682
+ parts.push(generateGetter(attr.key));
2610
2683
  if (attr.bindable) {
2611
- parts.push(`set ${attr.key}(v) { ${attr.key} = v }`);
2684
+ parts.push(generateSetter(attr.key));
2612
2685
  }
2613
2686
  }
2614
2687
  return `${factoryName}({ ${parts.join(", ")} })`;
@@ -2742,7 +2815,10 @@ function transformAttrsOriginCallsSync(s, source, neededImports) {
2742
2815
  let firstFactoryExpr = null;
2743
2816
  let propsTypeDeclaration = null;
2744
2817
  let isFirstDeclaration = true;
2745
- const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source);
2818
+ const originInstances = new Map;
2819
+ const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
2820
+ const hasExistingProps = !!existingPropsMatch;
2821
+ const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source) && !hasExistingProps;
2746
2822
  for (const decl of declarations) {
2747
2823
  const { varName, startIndex, macroOpenParen } = decl;
2748
2824
  const closeParenIndex = findMatchingBracket(source, macroOpenParen);
@@ -2763,20 +2839,47 @@ function transformAttrsOriginCallsSync(s, source, neededImports) {
2763
2839
  expansionLines.push(`type $$Props = $attrs.Of<${typeExpr}>`);
2764
2840
  propsTypeDeclaration = "";
2765
2841
  }
2766
- expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
2842
+ if (hasExistingProps) {
2843
+ const existingContent = existingPropsMatch[1];
2844
+ const hasRestSpread = /\.\.\.\s*(\w+)\s*$/.test(existingContent);
2845
+ if (!hasRestSpread && isFirstDeclaration) {
2846
+ const restVarName = "___originAttrs";
2847
+ const newContent = existingContent.trimEnd() ? `${existingContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
2848
+ const braceEnd = source.indexOf("}", existingPropsMatch.index + 5);
2849
+ if (braceEnd !== -1) {
2850
+ s.overwrite(existingPropsMatch.index + 5, braceEnd, ` ${newContent} `);
2851
+ }
2852
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVarName}))`);
2853
+ } else {
2854
+ const restMatch = existingContent.match(/\.\.\.\s*(\w+)\s*$/);
2855
+ const restVar = restMatch ? restMatch[1] : "___originAttrs";
2856
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVar}))`);
2857
+ }
2858
+ } else {
2859
+ expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
2860
+ }
2767
2861
  s.overwrite(startIndex, endIndex, expansionLines.join(`
2768
2862
  `));
2863
+ originInstances.set(varName, {
2864
+ varName,
2865
+ factoryExpr,
2866
+ startPos: startIndex,
2867
+ endPos: endIndex
2868
+ });
2769
2869
  neededImports.add("__attrsFor");
2770
2870
  changed = true;
2771
2871
  isFirstDeclaration = false;
2772
2872
  }
2773
- return { changed, propsTypeDeclaration };
2873
+ return { changed, propsTypeDeclaration, originInstances };
2774
2874
  }
2775
2875
  async function transformAttrsOriginCalls(s, source, neededImports, schemaResolver) {
2776
2876
  const declarations = findVariableDeclarationsWithMacro(source, "$attrs.origin");
2777
2877
  let changed = false;
2778
2878
  let propsTypeDeclaration = null;
2779
- const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source);
2879
+ const originInstances = new Map;
2880
+ const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
2881
+ const hasExistingProps = !!existingPropsMatch;
2882
+ const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source) && !hasExistingProps;
2780
2883
  const matches = [];
2781
2884
  for (const decl of declarations) {
2782
2885
  const { varName, startIndex, macroOpenParen } = decl;
@@ -2796,6 +2899,7 @@ async function transformAttrsOriginCalls(s, source, neededImports, schemaResolve
2796
2899
  }
2797
2900
  let firstFactoryExpr = null;
2798
2901
  let isFirstDeclaration = true;
2902
+ let restVarInjected = false;
2799
2903
  for (const { varName, factoryExpr, startIndex, endIndex, isGeneric } of matches) {
2800
2904
  const expansionLines = [];
2801
2905
  let usesFallback = true;
@@ -2823,15 +2927,40 @@ async function transformAttrsOriginCalls(s, source, neededImports, schemaResolve
2823
2927
  }
2824
2928
  if (usesFallback) {
2825
2929
  const normalizedFactoryCall = normalizeFactoryCall(factoryExpr);
2826
- expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
2930
+ if (hasExistingProps) {
2931
+ const existingContent = existingPropsMatch[1];
2932
+ const hasRestSpread = /\.\.\.\s*(\w+)\s*$/.test(existingContent);
2933
+ if (!hasRestSpread && !restVarInjected) {
2934
+ const restVarName = "___originAttrs";
2935
+ const newContent = existingContent.trimEnd() ? `${existingContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
2936
+ const braceEnd = source.indexOf("}", existingPropsMatch.index + 5);
2937
+ if (braceEnd !== -1) {
2938
+ s.overwrite(existingPropsMatch.index + 5, braceEnd, ` ${newContent} `);
2939
+ restVarInjected = true;
2940
+ }
2941
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVarName}))`);
2942
+ } else {
2943
+ const restMatch = existingContent.match(/\.\.\.\s*(\w+)\s*$/);
2944
+ const restVar = restMatch ? restMatch[1] : "___originAttrs";
2945
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVar}))`);
2946
+ }
2947
+ } else {
2948
+ expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
2949
+ }
2827
2950
  neededImports.add("__attrsFor");
2828
2951
  }
2829
2952
  s.overwrite(startIndex, endIndex, expansionLines.join(`
2830
2953
  `));
2954
+ originInstances.set(varName, {
2955
+ varName,
2956
+ factoryExpr,
2957
+ startPos: startIndex,
2958
+ endPos: endIndex
2959
+ });
2831
2960
  changed = true;
2832
2961
  isFirstDeclaration = false;
2833
2962
  }
2834
- return { changed, propsTypeDeclaration };
2963
+ return { changed, propsTypeDeclaration, originInstances };
2835
2964
  }
2836
2965
 
2837
2966
  // src/transform/element-types.ts
@@ -2840,7 +2969,34 @@ function getElementTypeImport(element) {
2840
2969
  }
2841
2970
 
2842
2971
  // src/transform/attrs-for-transform.ts
2843
- function transformAttrsForCalls(s, source, neededImports) {
2972
+ function generateReactiveAttrsWrapper(attrs) {
2973
+ const parts = [];
2974
+ for (const attr of attrs) {
2975
+ parts.push(generateGetter(attr.key));
2976
+ if (attr.bindable) {
2977
+ parts.push(generateSetter(attr.key));
2978
+ }
2979
+ }
2980
+ return `{ ${parts.join(", ")} }`;
2981
+ }
2982
+ function generateAttrsForMerge(attrs) {
2983
+ const parts = [];
2984
+ for (const attr of attrs) {
2985
+ if (attr.bindable) {
2986
+ if (attr.hasDefault) {
2987
+ parts.push(generatePropDestructure(attr.key, `$bindable(${attr.defaultValue})`));
2988
+ } else {
2989
+ parts.push(generatePropDestructure(attr.key, "$bindable()"));
2990
+ }
2991
+ } else if (attr.hasDefault) {
2992
+ parts.push(generatePropDestructure(attr.key, attr.defaultValue));
2993
+ } else {
2994
+ parts.push(generatePropDestructureNoDefault(attr.key));
2995
+ }
2996
+ }
2997
+ return parts.join(", ");
2998
+ }
2999
+ function transformAttrsForCallsSync(s, source, neededImports) {
2844
3000
  let changed = false;
2845
3001
  const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
2846
3002
  let restVarName = null;
@@ -2906,6 +3062,396 @@ function transformAttrsForCalls(s, source, neededImports) {
2906
3062
  }
2907
3063
  return changed;
2908
3064
  }
3065
+ async function transformAttrsForCalls(s, source, neededImports, schemaResolver) {
3066
+ let changed = false;
3067
+ const existingPropsMatch = source.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
3068
+ let restVarName = null;
3069
+ let existingPropsStart = -1;
3070
+ let existingDestructureContent = "";
3071
+ if (existingPropsMatch) {
3072
+ existingPropsStart = existingPropsMatch.index;
3073
+ existingDestructureContent = existingPropsMatch[1];
3074
+ const restMatch = existingDestructureContent.match(/\.\.\.\s*(\w+)\s*$/);
3075
+ if (restMatch) {
3076
+ restVarName = restMatch[1];
3077
+ }
3078
+ }
3079
+ const declarations = findVariableDeclarationsWithMacro(source, "$attrs.for");
3080
+ for (const decl of declarations) {
3081
+ const { varName, startIndex, macroOpenParen } = decl;
3082
+ const closeParenIndex = findMatchingBracket(source, macroOpenParen);
3083
+ if (closeParenIndex === -1)
3084
+ continue;
3085
+ const arg = source.slice(macroOpenParen + 1, closeParenIndex).trim();
3086
+ const endIndex = closeParenIndex + 1;
3087
+ const stringMatch = arg.match(/^['"](\w+)['"]$/);
3088
+ if (stringMatch) {
3089
+ const element = stringMatch[1];
3090
+ const typeImport = getElementTypeImport(element);
3091
+ if (existingPropsMatch && existingPropsStart !== -1) {
3092
+ if (!restVarName) {
3093
+ restVarName = "___restAttrs";
3094
+ const newDestructure = existingDestructureContent.trimEnd() ? `${existingDestructureContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
3095
+ const braceEnd = source.indexOf("}", existingPropsStart + 5);
3096
+ if (braceEnd !== -1) {
3097
+ s.overwrite(existingPropsStart + 5, braceEnd, ` ${newDestructure} `);
3098
+ }
3099
+ }
3100
+ s.overwrite(startIndex, endIndex, `let ${varName} = ${restVarName} as ${typeImport}`);
3101
+ } else {
3102
+ const expansion = `let { ...${varName} } = $props<${typeImport}>()`;
3103
+ s.overwrite(startIndex, endIndex, expansion);
3104
+ }
3105
+ } else {
3106
+ const factoryName = arg;
3107
+ let transformed = false;
3108
+ if (schemaResolver) {
3109
+ const importPath = findImportPath(source, factoryName);
3110
+ if (importPath) {
3111
+ const schema = await schemaResolver.resolve(importPath, factoryName);
3112
+ if (schema && schema.attrs.length > 0) {
3113
+ if (existingPropsMatch && existingPropsStart !== -1) {
3114
+ const additionalAttrs = generateAttrsForMerge(schema.attrs);
3115
+ const restMatch = existingDestructureContent.match(/,?\s*\.\.\.\s*(\w+)\s*$/);
3116
+ let baseContent = existingDestructureContent;
3117
+ let restPart = "";
3118
+ if (restMatch) {
3119
+ restPart = restMatch[0];
3120
+ baseContent = existingDestructureContent.slice(0, restMatch.index);
3121
+ }
3122
+ const mergedDestructure = baseContent.trimEnd() ? `${baseContent.trimEnd()}, ${additionalAttrs}${restPart}` : `${additionalAttrs}${restPart}`;
3123
+ const braceEnd = source.indexOf("}", existingPropsStart + 5);
3124
+ if (braceEnd !== -1) {
3125
+ s.overwrite(existingPropsStart + 5, braceEnd, ` ${mergedDestructure} `);
3126
+ }
3127
+ const wrapper = generateReactiveAttrsWrapper(schema.attrs);
3128
+ s.overwrite(startIndex, endIndex, `let ${varName} = __attrsFor(${factoryName}, ${wrapper})`);
3129
+ transformed = true;
3130
+ } else {
3131
+ const propsDestructure = generatePropsDestructuring(schema.attrs, factoryName);
3132
+ const wrapper = generateReactiveAttrsWrapper(schema.attrs);
3133
+ const expansion = [
3134
+ propsDestructure,
3135
+ `let ${varName} = __attrsFor(${factoryName}, ${wrapper})`
3136
+ ].join(`
3137
+ `);
3138
+ s.overwrite(startIndex, endIndex, expansion);
3139
+ transformed = true;
3140
+ }
3141
+ }
3142
+ }
3143
+ }
3144
+ if (!transformed) {
3145
+ if (existingPropsMatch && existingPropsStart !== -1) {
3146
+ if (!restVarName) {
3147
+ restVarName = "___restAttrs";
3148
+ const newDestructure = existingDestructureContent.trimEnd() ? `${existingDestructureContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
3149
+ const braceEnd = source.indexOf("}", existingPropsStart + 5);
3150
+ if (braceEnd !== -1) {
3151
+ s.overwrite(existingPropsStart + 5, braceEnd, ` ${newDestructure} `);
3152
+ }
3153
+ }
3154
+ s.overwrite(startIndex, endIndex, `let ${varName} = __attrsFor(${factoryName}, ${restVarName})`);
3155
+ } else {
3156
+ const expansion = [
3157
+ `let ___attrs: $attrs.Of<typeof ${factoryName}> = $props()`,
3158
+ `let ${varName} = __attrsFor(${factoryName}, ___attrs)`
3159
+ ].join(`
3160
+ `);
3161
+ s.overwrite(startIndex, endIndex, expansion);
3162
+ }
3163
+ }
3164
+ neededImports.add("__attrsFor");
3165
+ }
3166
+ changed = true;
3167
+ }
3168
+ return changed;
3169
+ }
3170
+
3171
+ // src/transform/origin-destructure-transform.ts
3172
+ function transformOriginDestructuring(s, source, originInstances) {
3173
+ let changed = false;
3174
+ const destructures = findOriginDestructures(source, originInstances);
3175
+ for (const d of destructures.reverse()) {
3176
+ const replacement = generateDestructureReplacement(d, originInstances);
3177
+ if (replacement) {
3178
+ s.overwrite(d.startPos, d.endPos, replacement);
3179
+ changed = true;
3180
+ }
3181
+ }
3182
+ return changed;
3183
+ }
3184
+ function findOriginDestructures(source, originInstances) {
3185
+ const results = [];
3186
+ const destructurePattern = /\b(let|const|var)\s*\{/g;
3187
+ let match;
3188
+ while ((match = destructurePattern.exec(source)) !== null) {
3189
+ if (isInsideStringOrComment(source, match.index))
3190
+ continue;
3191
+ const declKeyword = match[1];
3192
+ const braceStart = match.index + match[0].length - 1;
3193
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
3194
+ if (braceEnd === -1)
3195
+ continue;
3196
+ let i = braceEnd + 1;
3197
+ while (i < source.length && /\s/.test(source[i]))
3198
+ i++;
3199
+ if (source[i] !== "=")
3200
+ continue;
3201
+ i++;
3202
+ while (i < source.length && /\s/.test(source[i]))
3203
+ i++;
3204
+ const exprStart = i;
3205
+ let sourceVar = "";
3206
+ while (i < source.length && /[\w$]/.test(source[i])) {
3207
+ sourceVar += source[i];
3208
+ i++;
3209
+ }
3210
+ if (!sourceVar)
3211
+ continue;
3212
+ if (!originInstances.has(sourceVar))
3213
+ continue;
3214
+ let isPropsAccess = false;
3215
+ const afterVarPos = i;
3216
+ while (i < source.length && /\s/.test(source[i]))
3217
+ i++;
3218
+ if (source[i] === ".") {
3219
+ i++;
3220
+ while (i < source.length && /\s/.test(source[i]))
3221
+ i++;
3222
+ const propName = readIdentifier(source, i);
3223
+ if (propName === "props") {
3224
+ isPropsAccess = true;
3225
+ i += propName.length;
3226
+ } else {
3227
+ continue;
3228
+ }
3229
+ }
3230
+ let endPos = i;
3231
+ while (endPos < source.length && /\s/.test(source[endPos]) && source[endPos] !== `
3232
+ `)
3233
+ endPos++;
3234
+ if (source[endPos] === ";")
3235
+ endPos++;
3236
+ if (source[endPos] === `
3237
+ `)
3238
+ endPos++;
3239
+ const patternContent = source.slice(braceStart + 1, braceEnd);
3240
+ const parsed = parseDestructurePattern(patternContent, isPropsAccess);
3241
+ results.push({
3242
+ startPos: match.index,
3243
+ endPos,
3244
+ sourceVar,
3245
+ isPropsAccess,
3246
+ methods: parsed.methods,
3247
+ props: parsed.props,
3248
+ nestedPropsPattern: parsed.nestedProps
3249
+ });
3250
+ }
3251
+ return results;
3252
+ }
3253
+ function parseDestructurePattern(content, isPropsAccess) {
3254
+ const methods = [];
3255
+ const props = [];
3256
+ let nestedProps = null;
3257
+ const parts = splitByTopLevelCommas2(content);
3258
+ for (const part of parts) {
3259
+ const trimmed = part.trim();
3260
+ if (!trimmed)
3261
+ continue;
3262
+ const propsMatch = trimmed.match(/^props\s*:\s*\{/);
3263
+ if (propsMatch) {
3264
+ const braceStart = trimmed.indexOf("{");
3265
+ const braceEnd = findMatchingBracket(trimmed, braceStart, "{", "}");
3266
+ if (braceEnd !== -1) {
3267
+ const nestedContent = trimmed.slice(braceStart + 1, braceEnd);
3268
+ const nestedParts = splitByTopLevelCommas2(nestedContent);
3269
+ const nestedPropsList = [];
3270
+ for (const np of nestedParts) {
3271
+ const parsed = parseDestructuredProp(np.trim());
3272
+ if (parsed)
3273
+ nestedPropsList.push(parsed);
3274
+ }
3275
+ nestedProps = {
3276
+ startPos: 0,
3277
+ endPos: 0,
3278
+ props: nestedPropsList
3279
+ };
3280
+ }
3281
+ continue;
3282
+ }
3283
+ if (isPropsAccess) {
3284
+ const parsed = parseDestructuredProp(trimmed);
3285
+ if (parsed)
3286
+ props.push(parsed);
3287
+ } else {
3288
+ const parsed = parseDestructuredItem(trimmed);
3289
+ if (parsed)
3290
+ methods.push(parsed);
3291
+ }
3292
+ }
3293
+ return { methods, props, nestedProps };
3294
+ }
3295
+ function parseDestructuredItem(part) {
3296
+ const trimmed = part.trim();
3297
+ if (!trimmed)
3298
+ return null;
3299
+ const colonIdx = findTopLevelColon(trimmed);
3300
+ let key;
3301
+ let alias = null;
3302
+ let rest = trimmed;
3303
+ if (colonIdx !== -1) {
3304
+ key = trimmed.slice(0, colonIdx).trim();
3305
+ rest = trimmed.slice(colonIdx + 1).trim();
3306
+ const eqIdx2 = findTopLevelEquals(rest);
3307
+ if (eqIdx2 !== -1) {
3308
+ alias = rest.slice(0, eqIdx2).trim();
3309
+ return {
3310
+ key,
3311
+ alias,
3312
+ defaultValue: rest.slice(eqIdx2 + 1).trim()
3313
+ };
3314
+ } else {
3315
+ alias = rest;
3316
+ return { key, alias, defaultValue: null };
3317
+ }
3318
+ }
3319
+ const eqIdx = findTopLevelEquals(trimmed);
3320
+ if (eqIdx !== -1) {
3321
+ key = trimmed.slice(0, eqIdx).trim();
3322
+ return {
3323
+ key,
3324
+ alias: null,
3325
+ defaultValue: trimmed.slice(eqIdx + 1).trim()
3326
+ };
3327
+ }
3328
+ return { key: trimmed, alias: null, defaultValue: null };
3329
+ }
3330
+ function parseDestructuredProp(part) {
3331
+ const item = parseDestructuredItem(part);
3332
+ if (!item)
3333
+ return null;
3334
+ let isBindable = false;
3335
+ let bindableDefault = null;
3336
+ if (item.defaultValue) {
3337
+ const bindableMatch = item.defaultValue.match(/^\$bindable\s*\(/);
3338
+ if (bindableMatch) {
3339
+ isBindable = true;
3340
+ const parenStart = item.defaultValue.indexOf("(");
3341
+ const parenEnd = findMatchingBracket(item.defaultValue, parenStart, "(", ")");
3342
+ if (parenEnd !== -1) {
3343
+ bindableDefault = item.defaultValue.slice(parenStart + 1, parenEnd).trim() || null;
3344
+ }
3345
+ }
3346
+ }
3347
+ return {
3348
+ ...item,
3349
+ isBindable,
3350
+ bindableDefault
3351
+ };
3352
+ }
3353
+ function generateDestructureReplacement(d, originInstances) {
3354
+ const lines = [];
3355
+ const instance = originInstances.get(d.sourceVar);
3356
+ if (!instance)
3357
+ return null;
3358
+ for (const m of d.methods) {
3359
+ const varName = m.alias || m.key;
3360
+ if (m.defaultValue) {
3361
+ lines.push(`let ${varName} = ${d.sourceVar}.${m.key}?.bind(${d.sourceVar}) ?? ${m.defaultValue}`);
3362
+ } else {
3363
+ lines.push(`let ${varName} = ${d.sourceVar}.${m.key}.bind(${d.sourceVar})`);
3364
+ }
3365
+ }
3366
+ if (d.nestedPropsPattern) {
3367
+ for (const p of d.nestedPropsPattern.props) {
3368
+ lines.push(...generatePropAccessors(p, d.sourceVar));
3369
+ }
3370
+ }
3371
+ if (d.isPropsAccess) {
3372
+ for (const p of d.props) {
3373
+ lines.push(...generatePropAccessors(p, d.sourceVar));
3374
+ }
3375
+ }
3376
+ return lines.join(`
3377
+ `) + `
3378
+ `;
3379
+ }
3380
+ function generatePropAccessors(p, sourceVar) {
3381
+ const lines = [];
3382
+ const varName = p.alias || p.key;
3383
+ if (p.isBindable) {
3384
+ const defaultVal = p.bindableDefault || "undefined";
3385
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key} ?? ${defaultVal})`);
3386
+ } else if (p.defaultValue) {
3387
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key} ?? ${p.defaultValue})`);
3388
+ } else {
3389
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key})`);
3390
+ }
3391
+ return lines;
3392
+ }
3393
+ function splitByTopLevelCommas2(content) {
3394
+ const parts = [];
3395
+ let current = "";
3396
+ let depth = 0;
3397
+ for (let i = 0;i < content.length; i++) {
3398
+ const char = content[i];
3399
+ if (char === "{" || char === "(" || char === "[" || char === "<") {
3400
+ depth++;
3401
+ current += char;
3402
+ } else if (char === "}" || char === ")" || char === "]" || char === ">") {
3403
+ depth--;
3404
+ current += char;
3405
+ } else if (char === "," && depth === 0) {
3406
+ parts.push(current);
3407
+ current = "";
3408
+ } else {
3409
+ current += char;
3410
+ }
3411
+ }
3412
+ if (current.trim()) {
3413
+ parts.push(current);
3414
+ }
3415
+ return parts;
3416
+ }
3417
+ function findTopLevelColon(str) {
3418
+ let depth = 0;
3419
+ for (let i = 0;i < str.length; i++) {
3420
+ const char = str[i];
3421
+ if (char === "{" || char === "(" || char === "[" || char === "<")
3422
+ depth++;
3423
+ else if (char === "}" || char === ")" || char === "]" || char === ">")
3424
+ depth--;
3425
+ else if (char === ":" && depth === 0)
3426
+ return i;
3427
+ }
3428
+ return -1;
3429
+ }
3430
+ function findTopLevelEquals(str) {
3431
+ let depth = 0;
3432
+ for (let i = 0;i < str.length; i++) {
3433
+ const char = str[i];
3434
+ if (char === "{" || char === "(" || char === "[" || char === "<")
3435
+ depth++;
3436
+ else if (char === "}" || char === ")" || char === "]" || char === ">")
3437
+ depth--;
3438
+ else if (char === "=" && depth === 0) {
3439
+ if (str[i + 1] !== "=" && str[i + 1] !== ">") {
3440
+ return i;
3441
+ }
3442
+ }
3443
+ }
3444
+ return -1;
3445
+ }
3446
+ function readIdentifier(str, start) {
3447
+ let result = "";
3448
+ let i = start;
3449
+ while (i < str.length && /[\w$]/.test(str[i])) {
3450
+ result += str[i];
3451
+ i++;
3452
+ }
3453
+ return result;
3454
+ }
2909
3455
 
2910
3456
  // src/transform/core.ts
2911
3457
  function transformScript(source, options = {}) {
@@ -2929,9 +3475,12 @@ function transformScript(source, options = {}) {
2929
3475
  const result = transformAttrsOriginCallsSync(s, source, neededImports);
2930
3476
  changed = result.changed || changed;
2931
3477
  propsTypeDeclaration = result.propsTypeDeclaration;
3478
+ if (result.originInstances.size > 0) {
3479
+ changed = transformOriginDestructuring(s, source, result.originInstances) || changed;
3480
+ }
2932
3481
  }
2933
3482
  if (isComponent) {
2934
- changed = transformAttrsForCalls(s, source, neededImports) || changed;
3483
+ changed = transformAttrsForCallsSync(s, source, neededImports) || changed;
2935
3484
  }
2936
3485
  const needsPropsInjection = propsTypeDeclaration && propsTypeDeclaration.length > 0;
2937
3486
  if (isComponent && (neededImports.size > 0 || needsPropsInjection)) {
@@ -3000,9 +3549,12 @@ async function transformScriptAsync(source, options) {
3000
3549
  const result = await transformAttrsOriginCalls(s, source, neededImports, schemaResolver);
3001
3550
  changed = result.changed || changed;
3002
3551
  propsTypeDeclaration = result.propsTypeDeclaration;
3552
+ if (result.originInstances.size > 0) {
3553
+ changed = transformOriginDestructuring(s, source, result.originInstances) || changed;
3554
+ }
3003
3555
  }
3004
3556
  if (isComponent) {
3005
- changed = transformAttrsForCalls(s, source, neededImports) || changed;
3557
+ changed = await transformAttrsForCalls(s, source, neededImports, schemaResolver) || changed;
3006
3558
  }
3007
3559
  const needsPropsInjectionAsync = propsTypeDeclaration && propsTypeDeclaration.length > 0;
3008
3560
  if (isComponent && (neededImports.size > 0 || needsPropsInjectionAsync)) {
@@ -3070,9 +3622,12 @@ async function transformScriptContent(source, options) {
3070
3622
  const result = await transformAttrsOriginCalls(s, source, neededImports, schemaResolver);
3071
3623
  changed = result.changed || changed;
3072
3624
  propsTypeDeclaration = result.propsTypeDeclaration;
3625
+ if (result.originInstances.size > 0) {
3626
+ changed = transformOriginDestructuring(s, source, result.originInstances) || changed;
3627
+ }
3073
3628
  }
3074
3629
  if (isComponent) {
3075
- changed = transformAttrsForCalls(s, source, neededImports) || changed;
3630
+ changed = await transformAttrsForCalls(s, source, neededImports, schemaResolver) || changed;
3076
3631
  }
3077
3632
  if (neededImports.size > 0) {
3078
3633
  const importStatement = generateRuntimeImport([...neededImports]);