svelte-origin 1.0.0-next.23 → 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.

package/dist/index.js CHANGED
@@ -3863,6 +3863,79 @@ function findMatchingBracket(source2, openIndex, openChar = "(", closeChar = ")"
3863
3863
  return -1;
3864
3864
  }
3865
3865
 
3866
+ // src/transform/reserved-keywords.ts
3867
+ var RESERVED_KEYWORDS = new Set([
3868
+ "break",
3869
+ "case",
3870
+ "catch",
3871
+ "continue",
3872
+ "debugger",
3873
+ "default",
3874
+ "delete",
3875
+ "do",
3876
+ "else",
3877
+ "finally",
3878
+ "for",
3879
+ "function",
3880
+ "if",
3881
+ "in",
3882
+ "instanceof",
3883
+ "new",
3884
+ "return",
3885
+ "switch",
3886
+ "this",
3887
+ "throw",
3888
+ "try",
3889
+ "typeof",
3890
+ "var",
3891
+ "void",
3892
+ "while",
3893
+ "with",
3894
+ "class",
3895
+ "const",
3896
+ "enum",
3897
+ "export",
3898
+ "extends",
3899
+ "import",
3900
+ "super",
3901
+ "implements",
3902
+ "interface",
3903
+ "let",
3904
+ "package",
3905
+ "private",
3906
+ "protected",
3907
+ "public",
3908
+ "static",
3909
+ "yield",
3910
+ "await",
3911
+ "async",
3912
+ "true",
3913
+ "false",
3914
+ "null",
3915
+ "undefined",
3916
+ "arguments",
3917
+ "eval"
3918
+ ]);
3919
+ function getInternalVarName(propName, forcePrefix = true) {
3920
+ return `___${propName}`;
3921
+ }
3922
+ function generatePropDestructure(propName, defaultValue) {
3923
+ const internalName = getInternalVarName(propName);
3924
+ return `${propName}: ${internalName} = ${defaultValue}`;
3925
+ }
3926
+ function generatePropDestructureNoDefault(propName) {
3927
+ const internalName = getInternalVarName(propName);
3928
+ return `${propName}: ${internalName}`;
3929
+ }
3930
+ function generateGetter(propName) {
3931
+ const internalName = getInternalVarName(propName);
3932
+ return `get ${propName}() { return ${internalName} }`;
3933
+ }
3934
+ function generateSetter(propName) {
3935
+ const internalName = getInternalVarName(propName);
3936
+ return `set ${propName}(v) { ${internalName} = v }`;
3937
+ }
3938
+
3866
3939
  // src/transform/schema.ts
3867
3940
  function parseOriginSchemaFromSource(source2, exportName) {
3868
3941
  const sourceResult = parseSourceOrigin(source2, exportName);
@@ -4201,14 +4274,14 @@ function generatePropsDestructuring(attrs, factoryName) {
4201
4274
  for (const attr2 of attrs) {
4202
4275
  if (attr2.bindable) {
4203
4276
  if (attr2.hasDefault) {
4204
- parts.push(`${attr2.key} = $bindable(${attr2.defaultValue})`);
4277
+ parts.push(generatePropDestructure(attr2.key, `$bindable(${attr2.defaultValue})`));
4205
4278
  } else {
4206
- parts.push(`${attr2.key} = $bindable()`);
4279
+ parts.push(generatePropDestructure(attr2.key, "$bindable()"));
4207
4280
  }
4208
4281
  } else if (attr2.hasDefault) {
4209
- parts.push(`${attr2.key} = ${attr2.defaultValue}`);
4282
+ parts.push(generatePropDestructure(attr2.key, attr2.defaultValue));
4210
4283
  } else {
4211
- parts.push(attr2.key);
4284
+ parts.push(generatePropDestructureNoDefault(attr2.key));
4212
4285
  }
4213
4286
  }
4214
4287
  return `let { ${parts.join(", ")} }: $attrs.Of<typeof ${factoryName}> = $props()`;
@@ -4216,9 +4289,9 @@ function generatePropsDestructuring(attrs, factoryName) {
4216
4289
  function generateFactoryCallFromAttrs(factoryName, attrs) {
4217
4290
  const parts = [];
4218
4291
  for (const attr2 of attrs) {
4219
- parts.push(`get ${attr2.key}() { return ${attr2.key} }`);
4292
+ parts.push(generateGetter(attr2.key));
4220
4293
  if (attr2.bindable) {
4221
- parts.push(`set ${attr2.key}(v) { ${attr2.key} = v }`);
4294
+ parts.push(generateSetter(attr2.key));
4222
4295
  }
4223
4296
  }
4224
4297
  return `${factoryName}({ ${parts.join(", ")} })`;
@@ -6537,7 +6610,10 @@ function transformAttrsOriginCallsSync(s, source2, neededImports) {
6537
6610
  let firstFactoryExpr = null;
6538
6611
  let propsTypeDeclaration = null;
6539
6612
  let isFirstDeclaration = true;
6540
- const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source2);
6613
+ const originInstances = new Map;
6614
+ const existingPropsMatch = source2.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
6615
+ const hasExistingProps = !!existingPropsMatch;
6616
+ const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source2) && !hasExistingProps;
6541
6617
  for (const decl of declarations) {
6542
6618
  const { varName, startIndex, macroOpenParen } = decl;
6543
6619
  const closeParenIndex = findMatchingBracket(source2, macroOpenParen);
@@ -6558,20 +6634,47 @@ function transformAttrsOriginCallsSync(s, source2, neededImports) {
6558
6634
  expansionLines.push(`type $$Props = $attrs.Of<${typeExpr}>`);
6559
6635
  propsTypeDeclaration = "";
6560
6636
  }
6561
- expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
6637
+ if (hasExistingProps) {
6638
+ const existingContent = existingPropsMatch[1];
6639
+ const hasRestSpread = /\.\.\.\s*(\w+)\s*$/.test(existingContent);
6640
+ if (!hasRestSpread && isFirstDeclaration) {
6641
+ const restVarName = "___originAttrs";
6642
+ const newContent = existingContent.trimEnd() ? `${existingContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
6643
+ const braceEnd = source2.indexOf("}", existingPropsMatch.index + 5);
6644
+ if (braceEnd !== -1) {
6645
+ s.overwrite(existingPropsMatch.index + 5, braceEnd, ` ${newContent} `);
6646
+ }
6647
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVarName}))`);
6648
+ } else {
6649
+ const restMatch = existingContent.match(/\.\.\.\s*(\w+)\s*$/);
6650
+ const restVar = restMatch ? restMatch[1] : "___originAttrs";
6651
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVar}))`);
6652
+ }
6653
+ } else {
6654
+ expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
6655
+ }
6562
6656
  s.overwrite(startIndex, endIndex, expansionLines.join(`
6563
6657
  `));
6658
+ originInstances.set(varName, {
6659
+ varName,
6660
+ factoryExpr,
6661
+ startPos: startIndex,
6662
+ endPos: endIndex
6663
+ });
6564
6664
  neededImports.add("__attrsFor");
6565
6665
  changed = true;
6566
6666
  isFirstDeclaration = false;
6567
6667
  }
6568
- return { changed, propsTypeDeclaration };
6668
+ return { changed, propsTypeDeclaration, originInstances };
6569
6669
  }
6570
6670
  async function transformAttrsOriginCalls(s, source2, neededImports, schemaResolver) {
6571
6671
  const declarations = findVariableDeclarationsWithMacro(source2, "$attrs.origin");
6572
6672
  let changed = false;
6573
6673
  let propsTypeDeclaration = null;
6574
- const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source2);
6674
+ const originInstances = new Map;
6675
+ const existingPropsMatch = source2.match(/let\s*\{([^}]*)\}\s*(?::\s*[^=]+)?\s*=\s*\$props\s*\(\s*\)/);
6676
+ const hasExistingProps = !!existingPropsMatch;
6677
+ const needsPropsInjection = declarations.length > 0 && !hasExistingPropsDeclaration(source2) && !hasExistingProps;
6575
6678
  const matches = [];
6576
6679
  for (const decl of declarations) {
6577
6680
  const { varName, startIndex, macroOpenParen } = decl;
@@ -6591,6 +6694,7 @@ async function transformAttrsOriginCalls(s, source2, neededImports, schemaResolv
6591
6694
  }
6592
6695
  let firstFactoryExpr = null;
6593
6696
  let isFirstDeclaration = true;
6697
+ let restVarInjected = false;
6594
6698
  for (const { varName, factoryExpr, startIndex, endIndex, isGeneric } of matches) {
6595
6699
  const expansionLines = [];
6596
6700
  let usesFallback = true;
@@ -6618,15 +6722,40 @@ async function transformAttrsOriginCalls(s, source2, neededImports, schemaResolv
6618
6722
  }
6619
6723
  if (usesFallback) {
6620
6724
  const normalizedFactoryCall = normalizeFactoryCall(factoryExpr);
6621
- expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
6725
+ if (hasExistingProps) {
6726
+ const existingContent = existingPropsMatch[1];
6727
+ const hasRestSpread = /\.\.\.\s*(\w+)\s*$/.test(existingContent);
6728
+ if (!hasRestSpread && !restVarInjected) {
6729
+ const restVarName = "___originAttrs";
6730
+ const newContent = existingContent.trimEnd() ? `${existingContent.trimEnd()}, ...${restVarName}` : `...${restVarName}`;
6731
+ const braceEnd = source2.indexOf("}", existingPropsMatch.index + 5);
6732
+ if (braceEnd !== -1) {
6733
+ s.overwrite(existingPropsMatch.index + 5, braceEnd, ` ${newContent} `);
6734
+ restVarInjected = true;
6735
+ }
6736
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVarName}))`);
6737
+ } else {
6738
+ const restMatch = existingContent.match(/\.\.\.\s*(\w+)\s*$/);
6739
+ const restVar = restMatch ? restMatch[1] : "___originAttrs";
6740
+ expansionLines.push(`let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ${restVar}))`);
6741
+ }
6742
+ } else {
6743
+ expansionLines.push(`let ___attrs: $$Props = $props()`, `let ${varName} = ${normalizedFactoryCall}(__attrsFor(${normalizedFactoryCall}, ___attrs))`);
6744
+ }
6622
6745
  neededImports.add("__attrsFor");
6623
6746
  }
6624
6747
  s.overwrite(startIndex, endIndex, expansionLines.join(`
6625
6748
  `));
6749
+ originInstances.set(varName, {
6750
+ varName,
6751
+ factoryExpr,
6752
+ startPos: startIndex,
6753
+ endPos: endIndex
6754
+ });
6626
6755
  changed = true;
6627
6756
  isFirstDeclaration = false;
6628
6757
  }
6629
- return { changed, propsTypeDeclaration };
6758
+ return { changed, propsTypeDeclaration, originInstances };
6630
6759
  }
6631
6760
 
6632
6761
  // src/transform/element-types.ts
@@ -6638,9 +6767,9 @@ function getElementTypeImport(element2) {
6638
6767
  function generateReactiveAttrsWrapper(attrs) {
6639
6768
  const parts = [];
6640
6769
  for (const attr2 of attrs) {
6641
- parts.push(`get ${attr2.key}() { return ${attr2.key} }`);
6770
+ parts.push(generateGetter(attr2.key));
6642
6771
  if (attr2.bindable) {
6643
- parts.push(`set ${attr2.key}(v) { ${attr2.key} = v }`);
6772
+ parts.push(generateSetter(attr2.key));
6644
6773
  }
6645
6774
  }
6646
6775
  return `{ ${parts.join(", ")} }`;
@@ -6650,14 +6779,14 @@ function generateAttrsForMerge(attrs) {
6650
6779
  for (const attr2 of attrs) {
6651
6780
  if (attr2.bindable) {
6652
6781
  if (attr2.hasDefault) {
6653
- parts.push(`${attr2.key} = $bindable(${attr2.defaultValue})`);
6782
+ parts.push(generatePropDestructure(attr2.key, `$bindable(${attr2.defaultValue})`));
6654
6783
  } else {
6655
- parts.push(`${attr2.key} = $bindable()`);
6784
+ parts.push(generatePropDestructure(attr2.key, "$bindable()"));
6656
6785
  }
6657
6786
  } else if (attr2.hasDefault) {
6658
- parts.push(`${attr2.key} = ${attr2.defaultValue}`);
6787
+ parts.push(generatePropDestructure(attr2.key, attr2.defaultValue));
6659
6788
  } else {
6660
- parts.push(attr2.key);
6789
+ parts.push(generatePropDestructureNoDefault(attr2.key));
6661
6790
  }
6662
6791
  }
6663
6792
  return parts.join(", ");
@@ -6834,6 +6963,291 @@ async function transformAttrsForCalls(s, source2, neededImports, schemaResolver)
6834
6963
  return changed;
6835
6964
  }
6836
6965
 
6966
+ // src/transform/origin-destructure-transform.ts
6967
+ function transformOriginDestructuring(s, source2, originInstances) {
6968
+ let changed = false;
6969
+ const destructures = findOriginDestructures(source2, originInstances);
6970
+ for (const d of destructures.reverse()) {
6971
+ const replacement = generateDestructureReplacement(d, originInstances);
6972
+ if (replacement) {
6973
+ s.overwrite(d.startPos, d.endPos, replacement);
6974
+ changed = true;
6975
+ }
6976
+ }
6977
+ return changed;
6978
+ }
6979
+ function findOriginDestructures(source2, originInstances) {
6980
+ const results = [];
6981
+ const destructurePattern = /\b(let|const|var)\s*\{/g;
6982
+ let match;
6983
+ while ((match = destructurePattern.exec(source2)) !== null) {
6984
+ if (isInsideStringOrComment(source2, match.index))
6985
+ continue;
6986
+ const declKeyword = match[1];
6987
+ const braceStart = match.index + match[0].length - 1;
6988
+ const braceEnd = findMatchingBracket(source2, braceStart, "{", "}");
6989
+ if (braceEnd === -1)
6990
+ continue;
6991
+ let i = braceEnd + 1;
6992
+ while (i < source2.length && /\s/.test(source2[i]))
6993
+ i++;
6994
+ if (source2[i] !== "=")
6995
+ continue;
6996
+ i++;
6997
+ while (i < source2.length && /\s/.test(source2[i]))
6998
+ i++;
6999
+ const exprStart = i;
7000
+ let sourceVar = "";
7001
+ while (i < source2.length && /[\w$]/.test(source2[i])) {
7002
+ sourceVar += source2[i];
7003
+ i++;
7004
+ }
7005
+ if (!sourceVar)
7006
+ continue;
7007
+ if (!originInstances.has(sourceVar))
7008
+ continue;
7009
+ let isPropsAccess = false;
7010
+ const afterVarPos = i;
7011
+ while (i < source2.length && /\s/.test(source2[i]))
7012
+ i++;
7013
+ if (source2[i] === ".") {
7014
+ i++;
7015
+ while (i < source2.length && /\s/.test(source2[i]))
7016
+ i++;
7017
+ const propName = readIdentifier(source2, i);
7018
+ if (propName === "props") {
7019
+ isPropsAccess = true;
7020
+ i += propName.length;
7021
+ } else {
7022
+ continue;
7023
+ }
7024
+ }
7025
+ let endPos = i;
7026
+ while (endPos < source2.length && /\s/.test(source2[endPos]) && source2[endPos] !== `
7027
+ `)
7028
+ endPos++;
7029
+ if (source2[endPos] === ";")
7030
+ endPos++;
7031
+ if (source2[endPos] === `
7032
+ `)
7033
+ endPos++;
7034
+ const patternContent = source2.slice(braceStart + 1, braceEnd);
7035
+ const parsed = parseDestructurePattern(patternContent, isPropsAccess);
7036
+ results.push({
7037
+ startPos: match.index,
7038
+ endPos,
7039
+ sourceVar,
7040
+ isPropsAccess,
7041
+ methods: parsed.methods,
7042
+ props: parsed.props,
7043
+ nestedPropsPattern: parsed.nestedProps
7044
+ });
7045
+ }
7046
+ return results;
7047
+ }
7048
+ function parseDestructurePattern(content, isPropsAccess) {
7049
+ const methods = [];
7050
+ const props = [];
7051
+ let nestedProps = null;
7052
+ const parts = splitByTopLevelCommas2(content);
7053
+ for (const part of parts) {
7054
+ const trimmed = part.trim();
7055
+ if (!trimmed)
7056
+ continue;
7057
+ const propsMatch = trimmed.match(/^props\s*:\s*\{/);
7058
+ if (propsMatch) {
7059
+ const braceStart = trimmed.indexOf("{");
7060
+ const braceEnd = findMatchingBracket(trimmed, braceStart, "{", "}");
7061
+ if (braceEnd !== -1) {
7062
+ const nestedContent = trimmed.slice(braceStart + 1, braceEnd);
7063
+ const nestedParts = splitByTopLevelCommas2(nestedContent);
7064
+ const nestedPropsList = [];
7065
+ for (const np of nestedParts) {
7066
+ const parsed = parseDestructuredProp(np.trim());
7067
+ if (parsed)
7068
+ nestedPropsList.push(parsed);
7069
+ }
7070
+ nestedProps = {
7071
+ startPos: 0,
7072
+ endPos: 0,
7073
+ props: nestedPropsList
7074
+ };
7075
+ }
7076
+ continue;
7077
+ }
7078
+ if (isPropsAccess) {
7079
+ const parsed = parseDestructuredProp(trimmed);
7080
+ if (parsed)
7081
+ props.push(parsed);
7082
+ } else {
7083
+ const parsed = parseDestructuredItem(trimmed);
7084
+ if (parsed)
7085
+ methods.push(parsed);
7086
+ }
7087
+ }
7088
+ return { methods, props, nestedProps };
7089
+ }
7090
+ function parseDestructuredItem(part) {
7091
+ const trimmed = part.trim();
7092
+ if (!trimmed)
7093
+ return null;
7094
+ const colonIdx = findTopLevelColon(trimmed);
7095
+ let key2;
7096
+ let alias = null;
7097
+ let rest = trimmed;
7098
+ if (colonIdx !== -1) {
7099
+ key2 = trimmed.slice(0, colonIdx).trim();
7100
+ rest = trimmed.slice(colonIdx + 1).trim();
7101
+ const eqIdx2 = findTopLevelEquals(rest);
7102
+ if (eqIdx2 !== -1) {
7103
+ alias = rest.slice(0, eqIdx2).trim();
7104
+ return {
7105
+ key: key2,
7106
+ alias,
7107
+ defaultValue: rest.slice(eqIdx2 + 1).trim()
7108
+ };
7109
+ } else {
7110
+ alias = rest;
7111
+ return { key: key2, alias, defaultValue: null };
7112
+ }
7113
+ }
7114
+ const eqIdx = findTopLevelEquals(trimmed);
7115
+ if (eqIdx !== -1) {
7116
+ key2 = trimmed.slice(0, eqIdx).trim();
7117
+ return {
7118
+ key: key2,
7119
+ alias: null,
7120
+ defaultValue: trimmed.slice(eqIdx + 1).trim()
7121
+ };
7122
+ }
7123
+ return { key: trimmed, alias: null, defaultValue: null };
7124
+ }
7125
+ function parseDestructuredProp(part) {
7126
+ const item = parseDestructuredItem(part);
7127
+ if (!item)
7128
+ return null;
7129
+ let isBindable2 = false;
7130
+ let bindableDefault = null;
7131
+ if (item.defaultValue) {
7132
+ const bindableMatch = item.defaultValue.match(/^\$bindable\s*\(/);
7133
+ if (bindableMatch) {
7134
+ isBindable2 = true;
7135
+ const parenStart = item.defaultValue.indexOf("(");
7136
+ const parenEnd = findMatchingBracket(item.defaultValue, parenStart, "(", ")");
7137
+ if (parenEnd !== -1) {
7138
+ bindableDefault = item.defaultValue.slice(parenStart + 1, parenEnd).trim() || null;
7139
+ }
7140
+ }
7141
+ }
7142
+ return {
7143
+ ...item,
7144
+ isBindable: isBindable2,
7145
+ bindableDefault
7146
+ };
7147
+ }
7148
+ function generateDestructureReplacement(d, originInstances) {
7149
+ const lines = [];
7150
+ const instance = originInstances.get(d.sourceVar);
7151
+ if (!instance)
7152
+ return null;
7153
+ for (const m of d.methods) {
7154
+ const varName = m.alias || m.key;
7155
+ if (m.defaultValue) {
7156
+ lines.push(`let ${varName} = ${d.sourceVar}.${m.key}?.bind(${d.sourceVar}) ?? ${m.defaultValue}`);
7157
+ } else {
7158
+ lines.push(`let ${varName} = ${d.sourceVar}.${m.key}.bind(${d.sourceVar})`);
7159
+ }
7160
+ }
7161
+ if (d.nestedPropsPattern) {
7162
+ for (const p of d.nestedPropsPattern.props) {
7163
+ lines.push(...generatePropAccessors(p, d.sourceVar));
7164
+ }
7165
+ }
7166
+ if (d.isPropsAccess) {
7167
+ for (const p of d.props) {
7168
+ lines.push(...generatePropAccessors(p, d.sourceVar));
7169
+ }
7170
+ }
7171
+ return lines.join(`
7172
+ `) + `
7173
+ `;
7174
+ }
7175
+ function generatePropAccessors(p, sourceVar) {
7176
+ const lines = [];
7177
+ const varName = p.alias || p.key;
7178
+ if (p.isBindable) {
7179
+ const defaultVal = p.bindableDefault || "undefined";
7180
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key} ?? ${defaultVal})`);
7181
+ } else if (p.defaultValue) {
7182
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key} ?? ${p.defaultValue})`);
7183
+ } else {
7184
+ lines.push(`let ${varName} = $derived(${sourceVar}.props.${p.key})`);
7185
+ }
7186
+ return lines;
7187
+ }
7188
+ function splitByTopLevelCommas2(content) {
7189
+ const parts = [];
7190
+ let current = "";
7191
+ let depth = 0;
7192
+ for (let i = 0;i < content.length; i++) {
7193
+ const char = content[i];
7194
+ if (char === "{" || char === "(" || char === "[" || char === "<") {
7195
+ depth++;
7196
+ current += char;
7197
+ } else if (char === "}" || char === ")" || char === "]" || char === ">") {
7198
+ depth--;
7199
+ current += char;
7200
+ } else if (char === "," && depth === 0) {
7201
+ parts.push(current);
7202
+ current = "";
7203
+ } else {
7204
+ current += char;
7205
+ }
7206
+ }
7207
+ if (current.trim()) {
7208
+ parts.push(current);
7209
+ }
7210
+ return parts;
7211
+ }
7212
+ function findTopLevelColon(str) {
7213
+ let depth = 0;
7214
+ for (let i = 0;i < str.length; i++) {
7215
+ const char = str[i];
7216
+ if (char === "{" || char === "(" || char === "[" || char === "<")
7217
+ depth++;
7218
+ else if (char === "}" || char === ")" || char === "]" || char === ">")
7219
+ depth--;
7220
+ else if (char === ":" && depth === 0)
7221
+ return i;
7222
+ }
7223
+ return -1;
7224
+ }
7225
+ function findTopLevelEquals(str) {
7226
+ let depth = 0;
7227
+ for (let i = 0;i < str.length; i++) {
7228
+ const char = str[i];
7229
+ if (char === "{" || char === "(" || char === "[" || char === "<")
7230
+ depth++;
7231
+ else if (char === "}" || char === ")" || char === "]" || char === ">")
7232
+ depth--;
7233
+ else if (char === "=" && depth === 0) {
7234
+ if (str[i + 1] !== "=" && str[i + 1] !== ">") {
7235
+ return i;
7236
+ }
7237
+ }
7238
+ }
7239
+ return -1;
7240
+ }
7241
+ function readIdentifier(str, start) {
7242
+ let result = "";
7243
+ let i = start;
7244
+ while (i < str.length && /[\w$]/.test(str[i])) {
7245
+ result += str[i];
7246
+ i++;
7247
+ }
7248
+ return result;
7249
+ }
7250
+
6837
7251
  // src/transform/core.ts
6838
7252
  function transformScript(source2, options = {}) {
6839
7253
  if (options.schemaResolver) {
@@ -6856,6 +7270,9 @@ function transformScript(source2, options = {}) {
6856
7270
  const result = transformAttrsOriginCallsSync(s, source2, neededImports);
6857
7271
  changed = result.changed || changed;
6858
7272
  propsTypeDeclaration = result.propsTypeDeclaration;
7273
+ if (result.originInstances.size > 0) {
7274
+ changed = transformOriginDestructuring(s, source2, result.originInstances) || changed;
7275
+ }
6859
7276
  }
6860
7277
  if (isComponent) {
6861
7278
  changed = transformAttrsForCallsSync(s, source2, neededImports) || changed;
@@ -6927,6 +7344,9 @@ async function transformScriptAsync(source2, options) {
6927
7344
  const result = await transformAttrsOriginCalls(s, source2, neededImports, schemaResolver);
6928
7345
  changed = result.changed || changed;
6929
7346
  propsTypeDeclaration = result.propsTypeDeclaration;
7347
+ if (result.originInstances.size > 0) {
7348
+ changed = transformOriginDestructuring(s, source2, result.originInstances) || changed;
7349
+ }
6930
7350
  }
6931
7351
  if (isComponent) {
6932
7352
  changed = await transformAttrsForCalls(s, source2, neededImports, schemaResolver) || changed;
@@ -6997,6 +7417,9 @@ async function transformScriptContent(source2, options) {
6997
7417
  const result = await transformAttrsOriginCalls(s, source2, neededImports, schemaResolver);
6998
7418
  changed = result.changed || changed;
6999
7419
  propsTypeDeclaration = result.propsTypeDeclaration;
7420
+ if (result.originInstances.size > 0) {
7421
+ changed = transformOriginDestructuring(s, source2, result.originInstances) || changed;
7422
+ }
7000
7423
  }
7001
7424
  if (isComponent) {
7002
7425
  changed = await transformAttrsForCalls(s, source2, neededImports, schemaResolver) || changed;