svelte2tsx 0.6.14 → 0.6.16

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/index.js CHANGED
@@ -1252,17 +1252,16 @@ class MagicString {
1252
1252
  }
1253
1253
  }
1254
1254
 
1255
- function parseAttributeValue(value) {
1256
- return /^['"]/.test(value) ? value.slice(1, -1) : value;
1257
- }
1258
1255
  function parseAttributes(str, start) {
1259
1256
  const attrs = [];
1260
- str.split(/\s+/)
1261
- .filter(Boolean)
1262
- .forEach((attr) => {
1257
+ const pattern = /([\w-$]+\b)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
1258
+ let match;
1259
+ while ((match = pattern.exec(str)) !== null) {
1260
+ const attr = match[0];
1261
+ const name = match[1];
1262
+ const value = match[2] || match[3] || match[4];
1263
1263
  const attrStart = start + str.indexOf(attr);
1264
- const [name, value] = attr.split('=');
1265
- attrs[name] = value ? parseAttributeValue(value) : name;
1264
+ attrs[name] = value !== null && value !== void 0 ? value : name;
1266
1265
  attrs.push({
1267
1266
  type: 'Attribute',
1268
1267
  name,
@@ -1271,13 +1270,13 @@ function parseAttributes(str, start) {
1271
1270
  type: 'Text',
1272
1271
  start: attrStart + attr.indexOf('=') + 1,
1273
1272
  end: attrStart + attr.length,
1274
- raw: parseAttributeValue(value)
1273
+ raw: value
1275
1274
  }
1276
1275
  ],
1277
1276
  start: attrStart,
1278
1277
  end: attrStart + attr.length
1279
1278
  });
1280
- });
1279
+ }
1281
1280
  return attrs;
1282
1281
  }
1283
1282
  function extractTag(htmlx, tag) {
@@ -2343,7 +2342,11 @@ const oneWayBindingAttributes = new Set([
2343
2342
  'ended',
2344
2343
  'readyState',
2345
2344
  'naturalWidth',
2346
- 'naturalHeight'
2345
+ 'naturalHeight',
2346
+ 'contentRect',
2347
+ 'contentBoxSize',
2348
+ 'borderBoxSize',
2349
+ 'devicePixelContentBoxSize'
2347
2350
  ]);
2348
2351
  /**
2349
2352
  * List of all binding names that are transformed to sth like `binding = variable`.
@@ -2788,7 +2791,9 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
2788
2791
  stripDoctype(str);
2789
2792
  let element;
2790
2793
  compiler.walk(ast, {
2791
- enter: (node, parent, prop, index) => {
2794
+ enter: (estreeTypedNode, estreeTypedParent, prop, index) => {
2795
+ const node = estreeTypedNode;
2796
+ const parent = estreeTypedParent;
2792
2797
  try {
2793
2798
  switch (node.type) {
2794
2799
  case 'IfBlock':
@@ -2889,7 +2894,9 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
2889
2894
  throw e;
2890
2895
  }
2891
2896
  },
2892
- leave: (node, parent, prop, index) => {
2897
+ leave: (estreeTypedNode, estreeTypedParent, prop, index) => {
2898
+ const node = estreeTypedNode;
2899
+ const parent = estreeTypedParent;
2893
2900
  try {
2894
2901
  switch (node.type) {
2895
2902
  case 'IfBlock':
@@ -3943,7 +3950,7 @@ class ExportedNames {
3943
3950
  if (exportModifier) {
3944
3951
  const isLet = node.declarationList.flags === ts.NodeFlags.Let;
3945
3952
  const isConst = node.declarationList.flags === ts.NodeFlags.Const;
3946
- this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExport(...args));
3953
+ this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExportForBindingPattern(...args));
3947
3954
  if (isLet) {
3948
3955
  this.propTypeAssertToUserDefined(node.declarationList);
3949
3956
  }
@@ -4150,12 +4157,6 @@ class ExportedNames {
4150
4157
  * Adds export to map
4151
4158
  */
4152
4159
  addExport(name, isLet, target = null, type = null, required = false) {
4153
- if (name.kind != ts.SyntaxKind.Identifier) {
4154
- throw Error('export source kind not supported ' + name);
4155
- }
4156
- if (target && target.kind != ts.SyntaxKind.Identifier) {
4157
- throw Error('export target kind not supported ' + target);
4158
- }
4159
4160
  const existingDeclaration = this.possibleExports.get(name.text);
4160
4161
  if (target) {
4161
4162
  this.exports.set(name.text, {
@@ -4178,6 +4179,17 @@ class ExportedNames {
4178
4179
  this.propTypeAssertToUserDefined(existingDeclaration.declaration);
4179
4180
  }
4180
4181
  }
4182
+ addExportForBindingPattern(name, isLet, target = null, type = null, required = false) {
4183
+ if (ts.isIdentifier(name)) {
4184
+ if (!target || ts.isIdentifier(target)) {
4185
+ this.addExport(name, isLet, target, type, required);
4186
+ }
4187
+ return;
4188
+ }
4189
+ name.elements.forEach((child) => {
4190
+ this.addExportForBindingPattern(child.name, isLet, undefined, type, required);
4191
+ });
4192
+ }
4181
4193
  getDoc(target) {
4182
4194
  var _a, _b;
4183
4195
  let doc = undefined;
@@ -5255,16 +5267,29 @@ function getLineOffsets(text) {
5255
5267
  }
5256
5268
 
5257
5269
  class Generics {
5258
- constructor(str, astOffset) {
5270
+ constructor(str, astOffset, script) {
5271
+ var _a, _b;
5259
5272
  this.str = str;
5260
5273
  this.astOffset = astOffset;
5261
5274
  this.definitions = [];
5262
5275
  this.typeReferences = [];
5263
5276
  this.references = [];
5277
+ this.genericsAttr = script.attributes.find((attr) => attr.name === 'generics');
5278
+ const generics = (_b = (_a = this.genericsAttr) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.raw;
5279
+ if (generics) {
5280
+ this.definitions = generics.split(',').map((g) => g.trim());
5281
+ this.references = this.definitions.map((def) => def.split(/\s/)[0]);
5282
+ }
5283
+ else {
5284
+ this.genericsAttr = undefined;
5285
+ }
5264
5286
  }
5265
5287
  addIfIsGeneric(node) {
5266
5288
  var _a, _b;
5267
5289
  if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
5290
+ if (this.genericsAttr) {
5291
+ throw new Error('Invalid $$Generic declaration: $$Generic definitions are not allowed when the generics attribute is present on the script tag');
5292
+ }
5268
5293
  if (((_a = node.type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) > 1) {
5269
5294
  throw new Error('Invalid $$Generic declaration: Only one type argument allowed');
5270
5295
  }
@@ -5386,7 +5411,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
5386
5411
  const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
5387
5412
  const astOffset = script.content.start;
5388
5413
  const exportedNames = new ExportedNames(str, astOffset, basename);
5389
- const generics = new Generics(str, astOffset);
5414
+ const generics = new Generics(str, astOffset, script);
5390
5415
  const interfacesAndTypes = new InterfacesAndTypes();
5391
5416
  const implicitTopLevelNames = new ImplicitTopLevelNames(str, astOffset);
5392
5417
  let uses$$props = false;
@@ -5613,7 +5638,11 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
5613
5638
  const scriptContent = htmlx.substring(script.content.start, script.content.end);
5614
5639
  const tsAst = ts.createSourceFile('component.module.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
5615
5640
  const astOffset = script.content.start;
5616
- const generics = new Generics(str, astOffset);
5641
+ const generics = new Generics(str, astOffset, script);
5642
+ if (generics.genericsAttr) {
5643
+ const start = htmlx.indexOf('generics', script.start);
5644
+ throwError(start, start + 8, 'The generics attribute is only allowed on the instance script', str.original);
5645
+ }
5617
5646
  const walk = (node) => {
5618
5647
  resolveImplicitStoreValue(node, implicitStoreValues, str, astOffset);
5619
5648
  generics.throwIfIsGeneric(node);
@@ -5832,7 +5861,25 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
5832
5861
  //I couldn't get magicstring to let me put the script before the <> we prepend during conversion of the template to jsx, so we just close it instead
5833
5862
  const scriptTagEnd = htmlx.lastIndexOf('>', scriptTag.content.start) + 1;
5834
5863
  str.overwrite(scriptTag.start, scriptTag.start + 1, ';');
5835
- str.overwrite(scriptTag.start + 1, scriptTagEnd, `function render${generics.toDefinitionString(true)}() {${propsDecl}\n`);
5864
+ if (generics.genericsAttr) {
5865
+ let start = generics.genericsAttr.value[0].start;
5866
+ let end = generics.genericsAttr.value[0].end;
5867
+ if (htmlx.charAt(start) === '"' || htmlx.charAt(start) === "'") {
5868
+ start++;
5869
+ end--;
5870
+ }
5871
+ str.overwrite(scriptTag.start + 1, start - 1, `function render`);
5872
+ str.overwrite(start - 1, start, `<`); // if the generics are unused, only this char is colored opaque
5873
+ if (end < scriptTagEnd) {
5874
+ str.overwrite(end, scriptTagEnd, `>() {${propsDecl}\n`);
5875
+ }
5876
+ else {
5877
+ str.prependRight(end, `>() {${propsDecl}\n`);
5878
+ }
5879
+ }
5880
+ else {
5881
+ str.overwrite(scriptTag.start + 1, scriptTagEnd, `function render${generics.toDefinitionString(true)}() {${propsDecl}\n`);
5882
+ }
5836
5883
  const scriptEndTagStart = htmlx.lastIndexOf('<', scriptTag.end - 1);
5837
5884
  // wrap template with callback
5838
5885
  str.overwrite(scriptEndTagStart, scriptTag.end, `${slotsDeclaration};\nasync () => {`, {
@@ -5840,8 +5887,7 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
5840
5887
  });
5841
5888
  }
5842
5889
  else {
5843
- str.prependRight(scriptDestination, `;function render${generics.toDefinitionString(true)}() {` +
5844
- `${propsDecl}${slotsDeclaration}\nasync () => {`);
5890
+ str.prependRight(scriptDestination, `;function render() {` + `${propsDecl}${slotsDeclaration}\nasync () => {`);
5845
5891
  }
5846
5892
  const slotsAsDef = uses$$SlotsInterface
5847
5893
  ? '{} as unknown as $$Slots'
@@ -6104,7 +6150,7 @@ function svelte2tsx(svelte, options = {}) {
6104
6150
  const implicitStoreValues = new ImplicitStoreValues(resolvedStores, renderFunctionStart);
6105
6151
  //move the instance script and process the content
6106
6152
  let exportedNames = new ExportedNames(str, 0, basename);
6107
- let generics = new Generics(str, 0);
6153
+ let generics = new Generics(str, 0, { attributes: [] });
6108
6154
  let uses$$SlotsInterface = false;
6109
6155
  if (scriptTag) {
6110
6156
  //ensure it is between the module script and the rest of the template (the variables need to be declared before the jsx template)
@@ -6154,6 +6200,7 @@ function svelte2tsx(svelte, options = {}) {
6154
6200
  // Prepend the import which is used for TS files
6155
6201
  // The other shims need to be provided by the user ambient-style,
6156
6202
  // for example through filenames.push(require.resolve('svelte2tsx/svelte-shims.d.ts'))
6203
+ // TODO replace with SvelteComponent for Svelte 5, keep old for backwards compatibility with Svelte 3
6157
6204
  str.prepend('import { SvelteComponentTyped } from "svelte"\n' + '\n');
6158
6205
  let code = str.toString();
6159
6206
  // Remove all tsx occurences and the template part from the output
package/index.mjs CHANGED
@@ -1232,17 +1232,16 @@ class MagicString {
1232
1232
  }
1233
1233
  }
1234
1234
 
1235
- function parseAttributeValue(value) {
1236
- return /^['"]/.test(value) ? value.slice(1, -1) : value;
1237
- }
1238
1235
  function parseAttributes(str, start) {
1239
1236
  const attrs = [];
1240
- str.split(/\s+/)
1241
- .filter(Boolean)
1242
- .forEach((attr) => {
1237
+ const pattern = /([\w-$]+\b)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
1238
+ let match;
1239
+ while ((match = pattern.exec(str)) !== null) {
1240
+ const attr = match[0];
1241
+ const name = match[1];
1242
+ const value = match[2] || match[3] || match[4];
1243
1243
  const attrStart = start + str.indexOf(attr);
1244
- const [name, value] = attr.split('=');
1245
- attrs[name] = value ? parseAttributeValue(value) : name;
1244
+ attrs[name] = value !== null && value !== void 0 ? value : name;
1246
1245
  attrs.push({
1247
1246
  type: 'Attribute',
1248
1247
  name,
@@ -1251,13 +1250,13 @@ function parseAttributes(str, start) {
1251
1250
  type: 'Text',
1252
1251
  start: attrStart + attr.indexOf('=') + 1,
1253
1252
  end: attrStart + attr.length,
1254
- raw: parseAttributeValue(value)
1253
+ raw: value
1255
1254
  }
1256
1255
  ],
1257
1256
  start: attrStart,
1258
1257
  end: attrStart + attr.length
1259
1258
  });
1260
- });
1259
+ }
1261
1260
  return attrs;
1262
1261
  }
1263
1262
  function extractTag(htmlx, tag) {
@@ -2323,7 +2322,11 @@ const oneWayBindingAttributes = new Set([
2323
2322
  'ended',
2324
2323
  'readyState',
2325
2324
  'naturalWidth',
2326
- 'naturalHeight'
2325
+ 'naturalHeight',
2326
+ 'contentRect',
2327
+ 'contentBoxSize',
2328
+ 'borderBoxSize',
2329
+ 'devicePixelContentBoxSize'
2327
2330
  ]);
2328
2331
  /**
2329
2332
  * List of all binding names that are transformed to sth like `binding = variable`.
@@ -2768,7 +2771,9 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
2768
2771
  stripDoctype(str);
2769
2772
  let element;
2770
2773
  walk$1(ast, {
2771
- enter: (node, parent, prop, index) => {
2774
+ enter: (estreeTypedNode, estreeTypedParent, prop, index) => {
2775
+ const node = estreeTypedNode;
2776
+ const parent = estreeTypedParent;
2772
2777
  try {
2773
2778
  switch (node.type) {
2774
2779
  case 'IfBlock':
@@ -2869,7 +2874,9 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
2869
2874
  throw e;
2870
2875
  }
2871
2876
  },
2872
- leave: (node, parent, prop, index) => {
2877
+ leave: (estreeTypedNode, estreeTypedParent, prop, index) => {
2878
+ const node = estreeTypedNode;
2879
+ const parent = estreeTypedParent;
2873
2880
  try {
2874
2881
  switch (node.type) {
2875
2882
  case 'IfBlock':
@@ -3923,7 +3930,7 @@ class ExportedNames {
3923
3930
  if (exportModifier) {
3924
3931
  const isLet = node.declarationList.flags === ts.NodeFlags.Let;
3925
3932
  const isConst = node.declarationList.flags === ts.NodeFlags.Const;
3926
- this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExport(...args));
3933
+ this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExportForBindingPattern(...args));
3927
3934
  if (isLet) {
3928
3935
  this.propTypeAssertToUserDefined(node.declarationList);
3929
3936
  }
@@ -4130,12 +4137,6 @@ class ExportedNames {
4130
4137
  * Adds export to map
4131
4138
  */
4132
4139
  addExport(name, isLet, target = null, type = null, required = false) {
4133
- if (name.kind != ts.SyntaxKind.Identifier) {
4134
- throw Error('export source kind not supported ' + name);
4135
- }
4136
- if (target && target.kind != ts.SyntaxKind.Identifier) {
4137
- throw Error('export target kind not supported ' + target);
4138
- }
4139
4140
  const existingDeclaration = this.possibleExports.get(name.text);
4140
4141
  if (target) {
4141
4142
  this.exports.set(name.text, {
@@ -4158,6 +4159,17 @@ class ExportedNames {
4158
4159
  this.propTypeAssertToUserDefined(existingDeclaration.declaration);
4159
4160
  }
4160
4161
  }
4162
+ addExportForBindingPattern(name, isLet, target = null, type = null, required = false) {
4163
+ if (ts.isIdentifier(name)) {
4164
+ if (!target || ts.isIdentifier(target)) {
4165
+ this.addExport(name, isLet, target, type, required);
4166
+ }
4167
+ return;
4168
+ }
4169
+ name.elements.forEach((child) => {
4170
+ this.addExportForBindingPattern(child.name, isLet, undefined, type, required);
4171
+ });
4172
+ }
4161
4173
  getDoc(target) {
4162
4174
  var _a, _b;
4163
4175
  let doc = undefined;
@@ -5235,16 +5247,29 @@ function getLineOffsets(text) {
5235
5247
  }
5236
5248
 
5237
5249
  class Generics {
5238
- constructor(str, astOffset) {
5250
+ constructor(str, astOffset, script) {
5251
+ var _a, _b;
5239
5252
  this.str = str;
5240
5253
  this.astOffset = astOffset;
5241
5254
  this.definitions = [];
5242
5255
  this.typeReferences = [];
5243
5256
  this.references = [];
5257
+ this.genericsAttr = script.attributes.find((attr) => attr.name === 'generics');
5258
+ const generics = (_b = (_a = this.genericsAttr) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.raw;
5259
+ if (generics) {
5260
+ this.definitions = generics.split(',').map((g) => g.trim());
5261
+ this.references = this.definitions.map((def) => def.split(/\s/)[0]);
5262
+ }
5263
+ else {
5264
+ this.genericsAttr = undefined;
5265
+ }
5244
5266
  }
5245
5267
  addIfIsGeneric(node) {
5246
5268
  var _a, _b;
5247
5269
  if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
5270
+ if (this.genericsAttr) {
5271
+ throw new Error('Invalid $$Generic declaration: $$Generic definitions are not allowed when the generics attribute is present on the script tag');
5272
+ }
5248
5273
  if (((_a = node.type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) > 1) {
5249
5274
  throw new Error('Invalid $$Generic declaration: Only one type argument allowed');
5250
5275
  }
@@ -5366,7 +5391,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
5366
5391
  const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
5367
5392
  const astOffset = script.content.start;
5368
5393
  const exportedNames = new ExportedNames(str, astOffset, basename);
5369
- const generics = new Generics(str, astOffset);
5394
+ const generics = new Generics(str, astOffset, script);
5370
5395
  const interfacesAndTypes = new InterfacesAndTypes();
5371
5396
  const implicitTopLevelNames = new ImplicitTopLevelNames(str, astOffset);
5372
5397
  let uses$$props = false;
@@ -5593,7 +5618,11 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
5593
5618
  const scriptContent = htmlx.substring(script.content.start, script.content.end);
5594
5619
  const tsAst = ts.createSourceFile('component.module.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
5595
5620
  const astOffset = script.content.start;
5596
- const generics = new Generics(str, astOffset);
5621
+ const generics = new Generics(str, astOffset, script);
5622
+ if (generics.genericsAttr) {
5623
+ const start = htmlx.indexOf('generics', script.start);
5624
+ throwError(start, start + 8, 'The generics attribute is only allowed on the instance script', str.original);
5625
+ }
5597
5626
  const walk = (node) => {
5598
5627
  resolveImplicitStoreValue(node, implicitStoreValues, str, astOffset);
5599
5628
  generics.throwIfIsGeneric(node);
@@ -5812,7 +5841,25 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
5812
5841
  //I couldn't get magicstring to let me put the script before the <> we prepend during conversion of the template to jsx, so we just close it instead
5813
5842
  const scriptTagEnd = htmlx.lastIndexOf('>', scriptTag.content.start) + 1;
5814
5843
  str.overwrite(scriptTag.start, scriptTag.start + 1, ';');
5815
- str.overwrite(scriptTag.start + 1, scriptTagEnd, `function render${generics.toDefinitionString(true)}() {${propsDecl}\n`);
5844
+ if (generics.genericsAttr) {
5845
+ let start = generics.genericsAttr.value[0].start;
5846
+ let end = generics.genericsAttr.value[0].end;
5847
+ if (htmlx.charAt(start) === '"' || htmlx.charAt(start) === "'") {
5848
+ start++;
5849
+ end--;
5850
+ }
5851
+ str.overwrite(scriptTag.start + 1, start - 1, `function render`);
5852
+ str.overwrite(start - 1, start, `<`); // if the generics are unused, only this char is colored opaque
5853
+ if (end < scriptTagEnd) {
5854
+ str.overwrite(end, scriptTagEnd, `>() {${propsDecl}\n`);
5855
+ }
5856
+ else {
5857
+ str.prependRight(end, `>() {${propsDecl}\n`);
5858
+ }
5859
+ }
5860
+ else {
5861
+ str.overwrite(scriptTag.start + 1, scriptTagEnd, `function render${generics.toDefinitionString(true)}() {${propsDecl}\n`);
5862
+ }
5816
5863
  const scriptEndTagStart = htmlx.lastIndexOf('<', scriptTag.end - 1);
5817
5864
  // wrap template with callback
5818
5865
  str.overwrite(scriptEndTagStart, scriptTag.end, `${slotsDeclaration};\nasync () => {`, {
@@ -5820,8 +5867,7 @@ function createRenderFunction({ str, scriptTag, scriptDestination, slots, events
5820
5867
  });
5821
5868
  }
5822
5869
  else {
5823
- str.prependRight(scriptDestination, `;function render${generics.toDefinitionString(true)}() {` +
5824
- `${propsDecl}${slotsDeclaration}\nasync () => {`);
5870
+ str.prependRight(scriptDestination, `;function render() {` + `${propsDecl}${slotsDeclaration}\nasync () => {`);
5825
5871
  }
5826
5872
  const slotsAsDef = uses$$SlotsInterface
5827
5873
  ? '{} as unknown as $$Slots'
@@ -6084,7 +6130,7 @@ function svelte2tsx(svelte, options = {}) {
6084
6130
  const implicitStoreValues = new ImplicitStoreValues(resolvedStores, renderFunctionStart);
6085
6131
  //move the instance script and process the content
6086
6132
  let exportedNames = new ExportedNames(str, 0, basename);
6087
- let generics = new Generics(str, 0);
6133
+ let generics = new Generics(str, 0, { attributes: [] });
6088
6134
  let uses$$SlotsInterface = false;
6089
6135
  if (scriptTag) {
6090
6136
  //ensure it is between the module script and the rest of the template (the variables need to be declared before the jsx template)
@@ -6134,6 +6180,7 @@ function svelte2tsx(svelte, options = {}) {
6134
6180
  // Prepend the import which is used for TS files
6135
6181
  // The other shims need to be provided by the user ambient-style,
6136
6182
  // for example through filenames.push(require.resolve('svelte2tsx/svelte-shims.d.ts'))
6183
+ // TODO replace with SvelteComponent for Svelte 5, keep old for backwards compatibility with Svelte 3
6137
6184
  str.prepend('import { SvelteComponentTyped } from "svelte"\n' + '\n');
6138
6185
  let code = str.toString();
6139
6186
  // Remove all tsx occurences and the template part from the output
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",
@@ -24,10 +24,13 @@
24
24
  "@rollup/plugin-json": "^6.0.0",
25
25
  "@rollup/plugin-node-resolve": "^15.0.0",
26
26
  "@rollup/plugin-typescript": "^10.0.0",
27
+ "@types/estree": "^0.0.42",
27
28
  "@types/mocha": "^9.1.0",
28
29
  "@types/node": "^16.0.0",
29
30
  "@types/unist": "^2.0.3",
30
31
  "@types/vfile": "^3.0.2",
32
+ "builtin-modules": "^3.3.0",
33
+ "estree-walker": "^2.0.1",
31
34
  "magic-string": "^0.27.0",
32
35
  "mocha": "^9.2.0",
33
36
  "periscopic": "^2.0.2",
@@ -37,18 +40,12 @@
37
40
  "svelte": "~3.57.0",
38
41
  "tiny-glob": "^0.2.6",
39
42
  "tslib": "^2.4.0",
40
- "typescript": "^5.0.3"
43
+ "typescript": "^5.1.3"
41
44
  },
42
45
  "peerDependencies": {
43
- "svelte": "^3.55",
46
+ "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0",
44
47
  "typescript": "^4.9.4 || ^5.0.0"
45
48
  },
46
- "scripts": {
47
- "build": "rollup -c",
48
- "prepublishOnly": "npm run build",
49
- "dev": "rollup -c -w",
50
- "test": "mocha test/test.ts"
51
- },
52
49
  "files": [
53
50
  "index.mjs",
54
51
  "index.js",
@@ -56,12 +53,18 @@
56
53
  "README.md",
57
54
  "LICENSE",
58
55
  "svelte-jsx.d.ts",
56
+ "svelte-jsx-v4.d.ts",
59
57
  "svelte-native-jsx.d.ts",
60
58
  "svelte-shims.d.ts",
61
- "svelte-html-do-not-use.d.ts"
59
+ "svelte-shims-v4.d.ts"
62
60
  ],
63
61
  "dependencies": {
64
62
  "dedent-js": "^1.0.1",
65
63
  "pascal-case": "^3.1.1"
64
+ },
65
+ "scripts": {
66
+ "build": "rollup -c",
67
+ "dev": "rollup -c -w",
68
+ "test": "mocha test/test.ts"
66
69
  }
67
- }
70
+ }
@@ -0,0 +1,229 @@
1
+ /// <reference lib="dom" />
2
+
3
+ declare namespace svelteHTML {
4
+
5
+ // Every namespace eligible for use needs to implement the following two functions
6
+ /**
7
+ * @internal do not use
8
+ */
9
+ function mapElementTag<K extends keyof ElementTagNameMap>(
10
+ tag: K
11
+ ): ElementTagNameMap[K];
12
+ function mapElementTag<K extends keyof SVGElementTagNameMap>(
13
+ tag: K
14
+ ): SVGElementTagNameMap[K];
15
+ function mapElementTag(
16
+ tag: any
17
+ ): any; // needs to be any because used in context of <svelte:element>
18
+
19
+ /**
20
+ * @internal do not use
21
+ */
22
+ function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
23
+ // "undefined | null" because of <svelte:element>
24
+ element: Key | undefined | null, attrs: string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]
25
+ ): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
26
+ function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
27
+ // "undefined | null" because of <svelte:element>
28
+ element: Key | undefined | null, attrsEnhancers: T, attrs: (string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]) & T
29
+ ): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
30
+
31
+ // For backwards-compatibility and ease-of-use, in case someone enhanced the typings from import('svelte/elements').HTMLAttributes/SVGAttributes
32
+ interface HTMLAttributes<T extends EventTarget = any> {}
33
+ interface SVGAttributes<T extends EventTarget = any> {}
34
+
35
+ /**
36
+ * @internal do not use
37
+ */
38
+ type HTMLProps<Property extends string, Override> =
39
+ Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof Override> & Override;
40
+
41
+ interface IntrinsicElements {
42
+ a: HTMLProps<'a', HTMLAttributes>;
43
+ abbr: HTMLProps<'abbr', HTMLAttributes>;
44
+ address: HTMLProps<'address', HTMLAttributes>;
45
+ area: HTMLProps<'area', HTMLAttributes>;
46
+ article: HTMLProps<'article', HTMLAttributes>;
47
+ aside: HTMLProps<'aside', HTMLAttributes>;
48
+ audio: HTMLProps<'audio', HTMLAttributes>;
49
+ b: HTMLProps<'b', HTMLAttributes>;
50
+ base: HTMLProps<'base', HTMLAttributes>;
51
+ bdi: HTMLProps<'bdi', HTMLAttributes>;
52
+ bdo: HTMLProps<'bdo', HTMLAttributes>;
53
+ big: HTMLProps<'big', HTMLAttributes>;
54
+ blockquote: HTMLProps<'blockquote', HTMLAttributes>;
55
+ body: HTMLProps<'body', HTMLAttributes>;
56
+ br: HTMLProps<'br', HTMLAttributes>;
57
+ button: HTMLProps<'button', HTMLAttributes>;
58
+ canvas: HTMLProps<'canvas', HTMLAttributes>;
59
+ caption: HTMLProps<'caption', HTMLAttributes>;
60
+ cite: HTMLProps<'cite', HTMLAttributes>;
61
+ code: HTMLProps<'code', HTMLAttributes>;
62
+ col: HTMLProps<'col', HTMLAttributes>;
63
+ colgroup: HTMLProps<'colgroup', HTMLAttributes>;
64
+ data: HTMLProps<'data', HTMLAttributes>;
65
+ datalist: HTMLProps<'datalist', HTMLAttributes>;
66
+ dd: HTMLProps<'dd', HTMLAttributes>;
67
+ del: HTMLProps<'del', HTMLAttributes>;
68
+ details: HTMLProps<'details', HTMLAttributes>;
69
+ dfn: HTMLProps<'dfn', HTMLAttributes>;
70
+ dialog: HTMLProps<'dialog', HTMLAttributes>;
71
+ div: HTMLProps<'div', HTMLAttributes>;
72
+ dl: HTMLProps<'dl', HTMLAttributes>;
73
+ dt: HTMLProps<'dt', HTMLAttributes>;
74
+ em: HTMLProps<'em', HTMLAttributes>;
75
+ embed: HTMLProps<'embed', HTMLAttributes>;
76
+ fieldset: HTMLProps<'fieldset', HTMLAttributes>;
77
+ figcaption: HTMLProps<'figcaption', HTMLAttributes>;
78
+ figure: HTMLProps<'figure', HTMLAttributes>;
79
+ footer: HTMLProps<'footer', HTMLAttributes>;
80
+ form: HTMLProps<'form', HTMLAttributes>;
81
+ h1: HTMLProps<'h1', HTMLAttributes>;
82
+ h2: HTMLProps<'h2', HTMLAttributes>;
83
+ h3: HTMLProps<'h3', HTMLAttributes>;
84
+ h4: HTMLProps<'h4', HTMLAttributes>;
85
+ h5: HTMLProps<'h5', HTMLAttributes>;
86
+ h6: HTMLProps<'h6', HTMLAttributes>;
87
+ head: HTMLProps<'head', HTMLAttributes>;
88
+ header: HTMLProps<'header', HTMLAttributes>;
89
+ hgroup: HTMLProps<'hgroup', HTMLAttributes>;
90
+ hr: HTMLProps<'hr', HTMLAttributes>;
91
+ html: HTMLProps<'html', HTMLAttributes>;
92
+ i: HTMLProps<'i', HTMLAttributes>;
93
+ iframe: HTMLProps<'iframe', HTMLAttributes>;
94
+ img: HTMLProps<'img', HTMLAttributes>;
95
+ input: HTMLProps<'input', HTMLAttributes>;
96
+ ins: HTMLProps<'ins', HTMLAttributes>;
97
+ kbd: HTMLProps<'kbd', HTMLAttributes>;
98
+ keygen: HTMLProps<'keygen', HTMLAttributes>;
99
+ label: HTMLProps<'label', HTMLAttributes>;
100
+ legend: HTMLProps<'legend', HTMLAttributes>;
101
+ li: HTMLProps<'li', HTMLAttributes>;
102
+ link: HTMLProps<'link', HTMLAttributes>;
103
+ main: HTMLProps<'main', HTMLAttributes>;
104
+ map: HTMLProps<'map', HTMLAttributes>;
105
+ mark: HTMLProps<'mark', HTMLAttributes>;
106
+ menu: HTMLProps<'menu', HTMLAttributes>;
107
+ menuitem: HTMLProps<'menuitem', HTMLAttributes>;
108
+ meta: HTMLProps<'meta', HTMLAttributes>;
109
+ meter: HTMLProps<'meter', HTMLAttributes>;
110
+ nav: HTMLProps<'nav', HTMLAttributes>;
111
+ noscript: HTMLProps<'noscript', HTMLAttributes>;
112
+ object: HTMLProps<'object', HTMLAttributes>;
113
+ ol: HTMLProps<'ol', HTMLAttributes>;
114
+ optgroup: HTMLProps<'optgroup', HTMLAttributes>;
115
+ option: HTMLProps<'option', HTMLAttributes>;
116
+ output: HTMLProps<'output', HTMLAttributes>;
117
+ p: HTMLProps<'p', HTMLAttributes>;
118
+ param: HTMLProps<'param', HTMLAttributes>;
119
+ picture: HTMLProps<'picture', HTMLAttributes>;
120
+ pre: HTMLProps<'pre', HTMLAttributes>;
121
+ progress: HTMLProps<'progress', HTMLAttributes>;
122
+ q: HTMLProps<'q', HTMLAttributes>;
123
+ rp: HTMLProps<'rp', HTMLAttributes>;
124
+ rt: HTMLProps<'rt', HTMLAttributes>;
125
+ ruby: HTMLProps<'ruby', HTMLAttributes>;
126
+ s: HTMLProps<'s', HTMLAttributes>;
127
+ samp: HTMLProps<'samp', HTMLAttributes>;
128
+ slot: HTMLProps<'slot', HTMLAttributes>;
129
+ script: HTMLProps<'script', HTMLAttributes>;
130
+ section: HTMLProps<'section', HTMLAttributes>;
131
+ select: HTMLProps<'select', HTMLAttributes>;
132
+ small: HTMLProps<'small', HTMLAttributes>;
133
+ source: HTMLProps<'source', HTMLAttributes>;
134
+ span: HTMLProps<'span', HTMLAttributes>;
135
+ strong: HTMLProps<'strong', HTMLAttributes>;
136
+ style: HTMLProps<'style', HTMLAttributes>;
137
+ sub: HTMLProps<'sub', HTMLAttributes>;
138
+ summary: HTMLProps<'summary', HTMLAttributes>;
139
+ sup: HTMLProps<'sup', HTMLAttributes>;
140
+ table: HTMLProps<'table', HTMLAttributes>;
141
+ template: HTMLProps<'template', HTMLAttributes>;
142
+ tbody: HTMLProps<'tbody', HTMLAttributes>;
143
+ td: HTMLProps<'td', HTMLAttributes>;
144
+ textarea: HTMLProps<'textarea', HTMLAttributes>;
145
+ tfoot: HTMLProps<'tfoot', HTMLAttributes>;
146
+ th: HTMLProps<'th', HTMLAttributes>;
147
+ thead: HTMLProps<'thead', HTMLAttributes>;
148
+ time: HTMLProps<'time', HTMLAttributes>;
149
+ title: HTMLProps<'title', HTMLAttributes>;
150
+ tr: HTMLProps<'tr', HTMLAttributes>;
151
+ track: HTMLProps<'track', HTMLAttributes>;
152
+ u: HTMLProps<'u', HTMLAttributes>;
153
+ ul: HTMLProps<'ul', HTMLAttributes>;
154
+ var: HTMLProps<'var', HTMLAttributes>;
155
+ video: HTMLProps<'video', HTMLAttributes>;
156
+ wbr: HTMLProps<'wbr', HTMLAttributes>;
157
+ webview: HTMLProps<'webview', HTMLAttributes>;
158
+ // SVG
159
+ svg: HTMLProps<'svg', SVGAttributes>;
160
+
161
+ animate: HTMLProps<'animate', SVGAttributes>;
162
+ animateMotion: HTMLProps<'animateMotion', SVGAttributes>;
163
+ animateTransform: HTMLProps<'animateTransform', SVGAttributes>;
164
+ circle: HTMLProps<'circle', SVGAttributes>;
165
+ clipPath: HTMLProps<'clipPath', SVGAttributes>;
166
+ defs: HTMLProps<'defs', SVGAttributes>;
167
+ desc: HTMLProps<'desc', SVGAttributes>;
168
+ ellipse: HTMLProps<'ellipse', SVGAttributes>;
169
+ feBlend: HTMLProps<'feBlend', SVGAttributes>;
170
+ feColorMatrix: HTMLProps<'feColorMatrix', SVGAttributes>;
171
+ feComponentTransfer: HTMLProps<'feComponentTransfer', SVGAttributes>;
172
+ feComposite: HTMLProps<'feComposite', SVGAttributes>;
173
+ feConvolveMatrix: HTMLProps<'feConvolveMatrix', SVGAttributes>;
174
+ feDiffuseLighting: HTMLProps<'feDiffuseLighting', SVGAttributes>;
175
+ feDisplacementMap: HTMLProps<'feDisplacementMap', SVGAttributes>;
176
+ feDistantLight: HTMLProps<'feDistantLight', SVGAttributes>;
177
+ feDropShadow: HTMLProps<'feDropShadow', SVGAttributes>;
178
+ feFlood: HTMLProps<'feFlood', SVGAttributes>;
179
+ feFuncA: HTMLProps<'feFuncA', SVGAttributes>;
180
+ feFuncB: HTMLProps<'feFuncB', SVGAttributes>;
181
+ feFuncG: HTMLProps<'feFuncG', SVGAttributes>;
182
+ feFuncR: HTMLProps<'feFuncR', SVGAttributes>;
183
+ feGaussianBlur: HTMLProps<'feGaussianBlur', SVGAttributes>;
184
+ feImage: HTMLProps<'feImage', SVGAttributes>;
185
+ feMerge: HTMLProps<'feMerge', SVGAttributes>;
186
+ feMergeNode: HTMLProps<'feMergeNode', SVGAttributes>;
187
+ feMorphology: HTMLProps<'feMorphology', SVGAttributes>;
188
+ feOffset: HTMLProps<'feOffset', SVGAttributes>;
189
+ fePointLight: HTMLProps<'fePointLight', SVGAttributes>;
190
+ feSpecularLighting: HTMLProps<'feSpecularLighting', SVGAttributes>;
191
+ feSpotLight: HTMLProps<'feSpotLight', SVGAttributes>;
192
+ feTile: HTMLProps<'feTile', SVGAttributes>;
193
+ feTurbulence: HTMLProps<'feTurbulence', SVGAttributes>;
194
+ filter: HTMLProps<'filter', SVGAttributes>;
195
+ foreignObject: HTMLProps<'foreignObject', SVGAttributes>;
196
+ g: HTMLProps<'g', SVGAttributes>;
197
+ image: HTMLProps<'image', SVGAttributes>;
198
+ line: HTMLProps<'line', SVGAttributes>;
199
+ linearGradient: HTMLProps<'linearGradient', SVGAttributes>;
200
+ marker: HTMLProps<'marker', SVGAttributes>;
201
+ mask: HTMLProps<'mask', SVGAttributes>;
202
+ metadata: HTMLProps<'metadata', SVGAttributes>;
203
+ mpath: HTMLProps<'mpath', SVGAttributes>;
204
+ path: HTMLProps<'path', SVGAttributes>;
205
+ pattern: HTMLProps<'pattern', SVGAttributes>;
206
+ polygon: HTMLProps<'polygon', SVGAttributes>;
207
+ polyline: HTMLProps<'polyline', SVGAttributes>;
208
+ radialGradient: HTMLProps<'radialGradient', SVGAttributes>;
209
+ rect: HTMLProps<'rect', SVGAttributes>;
210
+ stop: HTMLProps<'stop', SVGAttributes>;
211
+ switch: HTMLProps<'switch', SVGAttributes>;
212
+ symbol: HTMLProps<'symbol', SVGAttributes>;
213
+ text: HTMLProps<'text', SVGAttributes>;
214
+ textPath: HTMLProps<'textPath', SVGAttributes>;
215
+ tspan: HTMLProps<'tspan', SVGAttributes>;
216
+ use: HTMLProps<'use', SVGAttributes>;
217
+ view: HTMLProps<'view', SVGAttributes>;
218
+
219
+ // Svelte specific
220
+ 'svelte:window': HTMLProps<'svelte:window', HTMLAttributes>;
221
+ 'svelte:body': HTMLProps<'svelte:body', HTMLAttributes>;
222
+ 'svelte:fragment': { slot?: string };
223
+ 'svelte:options': { [name: string]: any };
224
+ 'svelte:head': { [name: string]: any };
225
+
226
+ [name: string]: { [name: string]: any };
227
+ }
228
+
229
+ }
@@ -0,0 +1,227 @@
1
+ // Whenever a ambient declaration changes, its number should be increased
2
+ // This way, we avoid the situation where multiple ambient versions of svelte2tsx
3
+ // are loaded and their declarations conflict each other
4
+ // See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
5
+ // If you change anything in this file, think about whether or not it should be backported to svelte-shims.d.ts
6
+
7
+ type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
8
+ /** @internal PRIVATE API, DO NOT USE */
9
+ type SvelteComponentConstructor<T, U extends import('svelte').ComponentConstructorOptions<any>> = new (options: U) => T;
10
+
11
+ /** @internal PRIVATE API, DO NOT USE */
12
+ type SvelteActionReturnType = {
13
+ update?: (args: any) => void,
14
+ destroy?: () => void
15
+ } | void
16
+
17
+ /** @internal PRIVATE API, DO NOT USE */
18
+ type SvelteTransitionConfig = {
19
+ delay?: number,
20
+ duration?: number,
21
+ easing?: (t: number) => number,
22
+ css?: (t: number, u: number) => string,
23
+ tick?: (t: number, u: number) => void
24
+ }
25
+
26
+ /** @internal PRIVATE API, DO NOT USE */
27
+ type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
28
+
29
+ /** @internal PRIVATE API, DO NOT USE */
30
+ type SvelteAnimationReturnType = {
31
+ delay?: number,
32
+ duration?: number,
33
+ easing?: (t: number) => number,
34
+ css?: (t: number, u: number) => string,
35
+ tick?: (t: number, u: number) => void
36
+ }
37
+
38
+ /** @internal PRIVATE API, DO NOT USE */
39
+ type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
40
+ /** @internal PRIVATE API, DO NOT USE */
41
+ type SvelteAllProps = { [index: string]: any }
42
+ /** @internal PRIVATE API, DO NOT USE */
43
+ type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
44
+ /** @internal PRIVATE API, DO NOT USE */
45
+ type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
46
+ /** @internal PRIVATE API, DO NOT USE */
47
+ type SvelteRestProps = { [index: string]: any }
48
+ /** @internal PRIVATE API, DO NOT USE */
49
+ type SvelteSlots = { [index: string]: any }
50
+ /** @internal PRIVATE API, DO NOT USE */
51
+ type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
52
+
53
+ // Forces TypeScript to look into the type which results in a better representation of it
54
+ // which helps for error messages and is necessary for d.ts file transformation so that
55
+ // no ambient type references are left in the output
56
+ /** @internal PRIVATE API, DO NOT USE */
57
+ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
58
+
59
+ /** @internal PRIVATE API, DO NOT USE */
60
+ type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
61
+ /** @internal PRIVATE API, DO NOT USE */
62
+ declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
63
+
64
+ declare var process: NodeJS.Process & { browser: boolean }
65
+ declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
66
+ declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
67
+ declare function __sveltets_2_allPropsType(): SvelteAllProps
68
+ declare function __sveltets_2_restPropsType(): SvelteRestProps
69
+ declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
70
+
71
+ // Overload of the following two functions is necessary.
72
+ // An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
73
+ // optionalProps need to be first or its type cannot be infered correctly.
74
+
75
+ declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}>(
76
+ render: {props: Props, events: Events, slots: Slots }
77
+ ): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
78
+ declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
79
+ optionalProps: OptionalProps[],
80
+ render: {props: Props, events: Events, slots: Slots }
81
+ ): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
82
+
83
+ declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}>(
84
+ render: {props: Props, events: Events, slots: Slots }
85
+ ): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
86
+ declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
87
+ optionalProps: OptionalProps[],
88
+ render: {props: Props, events: Events, slots: Slots }
89
+ ): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
90
+
91
+
92
+ declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}>(
93
+ render: {props: Props, events: Events, slots: Slots }
94
+ ): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots }
95
+
96
+ declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}>(
97
+ render: {props: Props, events: Events, slots: Slots }
98
+ ): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots }
99
+
100
+ declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
101
+ declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
102
+ declare function __sveltets_2_any(dummy: any): any;
103
+ // declare function __sveltets_1_empty(...dummy: any[]): {};
104
+ // declare function __sveltets_1_componentType(): AConstructorTypeOf<import("svelte").SvelteComponentTyped<any, any, any>>
105
+ declare function __sveltets_2_invalidate<T>(getValue: () => T): T
106
+
107
+ declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
108
+ event: K
109
+ ): HTMLBodyElementEventMap[K];
110
+ declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
111
+ event: K
112
+ ): WindowEventMap[K];
113
+ declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
114
+ event: K
115
+ ): HTMLElementEventMap[K];
116
+
117
+ declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
118
+ events: Events, eventKey: K
119
+ ): Events[K];
120
+ declare function __sveltets_2_bubbleEventDef(
121
+ events: any, eventKey: string
122
+ ): any;
123
+
124
+ declare const __sveltets_2_customEvent: CustomEvent<any>;
125
+ declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
126
+
127
+ declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
128
+ declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
129
+ declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
130
+ declare function __sveltets_2_unionType(...types: any[]): any;
131
+
132
+ declare function __sveltets_2_createSvelte2TsxComponent<Props, Events, Slots>(
133
+ render: {props: Props, events: Events, slots: Slots }
134
+ ): SvelteComponentConstructor<import("svelte").SvelteComponentTyped<Props, Events, Slots>,import('svelte').ComponentConstructorOptions<Props>>;
135
+
136
+ declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
137
+ declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
138
+
139
+ // v2
140
+ declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
141
+ declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponentTyped<any, any, any>;
142
+
143
+ declare function __sveltets_2_any(...dummy: any[]): any;
144
+ declare function __sveltets_2_empty(...dummy: any[]): {};
145
+ declare function __sveltets_2_union<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(t1:T1,t2?:T2,t3?:T3,t4?:T4,t5?:T5,t6?:T6,t7?:T7,t8?:T8,t9?:T9,t10?:T10): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;
146
+ declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
147
+
148
+ declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
149
+
150
+ /** @internal PRIVATE API, DO NOT USE */
151
+ type __sveltets_2_SvelteAnimationReturnType = {
152
+ delay?: number,
153
+ duration?: number,
154
+ easing?: (t: number) => number,
155
+ css?: (t: number, u: number) => string,
156
+ tick?: (t: number, u: number) => void
157
+ }
158
+ declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
159
+ declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
160
+
161
+ /** @internal PRIVATE API, DO NOT USE */
162
+ type __sveltets_2_SvelteActionReturnType = {
163
+ update?: (args: any) => void,
164
+ destroy?: () => void,
165
+ $$_attributes?: Record<string, any>,
166
+ } | void
167
+ declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
168
+
169
+ /** @internal PRIVATE API, DO NOT USE */
170
+ type __sveltets_2_SvelteTransitionConfig = {
171
+ delay?: number,
172
+ duration?: number,
173
+ easing?: (t: number) => number,
174
+ css?: (t: number, u: number) => string,
175
+ tick?: (t: number, u: number) => void
176
+ }
177
+ /** @internal PRIVATE API, DO NOT USE */
178
+ type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
179
+ declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
180
+
181
+ // Includes undefined and null for all types as all usages also allow these
182
+ declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
183
+ declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
184
+
185
+ // The following is necessary because there are two clashing errors that can't be solved at the same time
186
+ // when using Svelte2TsxComponent, more precisely the event typings in
187
+ // __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
188
+ // If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
189
+ // If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
190
+ // If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
191
+ // Therefore introduce two more base classes just for this case.
192
+ /**
193
+ * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
194
+ */
195
+ declare type ATypedSvelteComponent = {
196
+ /**
197
+ * @internal This is for type checking capabilities only
198
+ * and does not exist at runtime. Don't use this property.
199
+ */
200
+ $$prop_def: any;
201
+ /**
202
+ * @internal This is for type checking capabilities only
203
+ * and does not exist at runtime. Don't use this property.
204
+ */
205
+ $$events_def: any;
206
+ /**
207
+ * @internal This is for type checking capabilities only
208
+ * and does not exist at runtime. Don't use this property.
209
+ */
210
+ $$slot_def: any;
211
+
212
+ $on(event: string, handler: ((e: any) => any) | null | undefined): () => void;
213
+ }
214
+ /**
215
+ * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
216
+ *
217
+ * If you're looking for the type of a Svelte Component, use `SvelteComponentTyped` and `ComponentType` instead:
218
+ *
219
+ * ```ts
220
+ * import type { ComponentType, SvelteComponentTyped } from "svelte";
221
+ * let myComponentConstructor: ComponentType<SvelteComponentTyped> = ..;
222
+ * ```
223
+ */
224
+ declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
225
+ declare function __sveltets_2_ensureComponent<T extends ConstructorOfATypedSvelteComponent | null | undefined>(type: T): NonNullable<T>;
226
+
227
+ declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(array: T): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];
package/svelte-shims.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // This way, we avoid the situation where multiple ambient versions of svelte2tsx
3
3
  // are loaded and their declarations conflict each other
4
4
  // See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
5
+ // If you change anything in this file, think about whether or not it should also be added to svelte-shims-v4.d.ts
5
6
 
6
7
  // -- start svelte-ls-remove --
7
8
  declare module '*.svelte' {