svelte2tsx 0.7.21 → 0.7.22

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.
Files changed (3) hide show
  1. package/index.js +22 -14
  2. package/index.mjs +22 -14
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -4549,12 +4549,13 @@ function is$$PropsDeclaration(node) {
4549
4549
  return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
4550
4550
  }
4551
4551
  class ExportedNames {
4552
- constructor(str, astOffset, basename, isTsFile, isSvelte5Plus) {
4552
+ constructor(str, astOffset, basename, isTsFile, isSvelte5Plus, isRunes) {
4553
4553
  this.str = str;
4554
4554
  this.astOffset = astOffset;
4555
4555
  this.basename = basename;
4556
4556
  this.isTsFile = isTsFile;
4557
4557
  this.isSvelte5Plus = isSvelte5Plus;
4558
+ this.isRunes = isRunes;
4558
4559
  this.usesAccessors = false;
4559
4560
  /**
4560
4561
  * Uses the `$$Props` type
@@ -4636,10 +4637,10 @@ class ExportedNames {
4636
4637
  if (ts.isNamedExports(exportClause)) {
4637
4638
  for (const ne of exportClause.elements) {
4638
4639
  if (ne.propertyName) {
4639
- this.addExport(ne.propertyName, false, ne.name);
4640
+ this.addExport(ne.propertyName, false, ne.name, undefined, undefined, true);
4640
4641
  }
4641
4642
  else {
4642
- this.addExport(ne.name, false);
4643
+ this.addExport(ne.name, false, undefined, undefined, undefined, true);
4643
4644
  }
4644
4645
  }
4645
4646
  //we can remove entire statement
@@ -4976,7 +4977,7 @@ class ExportedNames {
4976
4977
  /**
4977
4978
  * Adds export to map
4978
4979
  */
4979
- addExport(name, isLet, target = null, type = null, required = false) {
4980
+ addExport(name, isLet, target = null, type = null, required = false, isNamedExport = false) {
4980
4981
  const existingDeclaration = this.possibleExports.get(name.text);
4981
4982
  if (target) {
4982
4983
  this.exports.set(name.text, {
@@ -4984,7 +4985,8 @@ class ExportedNames {
4984
4985
  type: (type === null || type === void 0 ? void 0 : type.getText()) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.type),
4985
4986
  identifierText: target.text,
4986
4987
  required: required || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.required),
4987
- doc: this.getDoc(target) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc)
4988
+ doc: this.getDoc(target) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc),
4989
+ isNamedExport
4988
4990
  });
4989
4991
  }
4990
4992
  else {
@@ -4992,7 +4994,8 @@ class ExportedNames {
4992
4994
  isLet: isLet || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.isLet),
4993
4995
  type: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.type,
4994
4996
  required: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.required,
4995
- doc: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc
4997
+ doc: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc,
4998
+ isNamedExport
4996
4999
  });
4997
5000
  }
4998
5001
  if (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.isLet) {
@@ -5103,7 +5106,7 @@ class ExportedNames {
5103
5106
  */
5104
5107
  createExportsStr() {
5105
5108
  const names = Array.from(this.exports.entries());
5106
- const others = names.filter(([, { isLet }]) => !isLet);
5109
+ const others = names.filter(([, { isLet, isNamedExport }]) => !isLet || (this.usesRunes() && isNamedExport));
5107
5110
  const needsAccessors = this.usesAccessors && names.length > 0 && !this.usesRunes(); // runes mode doesn't support accessors
5108
5111
  if (this.isSvelte5Plus) {
5109
5112
  let str = '';
@@ -5175,7 +5178,7 @@ class ExportedNames {
5175
5178
  this.isSvelte5Plus && globals.some((global) => runes.includes(global));
5176
5179
  }
5177
5180
  usesRunes() {
5178
- return this.hasRunesGlobals || this.hasPropsRune();
5181
+ return this.hasRunesGlobals || this.hasPropsRune() || this.isRunes;
5179
5182
  }
5180
5183
  }
5181
5184
 
@@ -6135,12 +6138,12 @@ class InterfacesAndTypes {
6135
6138
  }
6136
6139
  }
6137
6140
 
6138
- function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, isTSFile, basename, isSvelte5Plus) {
6141
+ function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, isTSFile, basename, isSvelte5Plus, isRunes) {
6139
6142
  const htmlx = str.original;
6140
6143
  const scriptContent = htmlx.substring(script.content.start, script.content.end);
6141
6144
  const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
6142
6145
  const astOffset = script.content.start;
6143
- const exportedNames = new ExportedNames(str, astOffset, basename, isTSFile, isSvelte5Plus);
6146
+ const exportedNames = new ExportedNames(str, astOffset, basename, isTSFile, isSvelte5Plus, isRunes);
6144
6147
  const generics = new Generics(str, astOffset, script);
6145
6148
  const interfacesAndTypes = new InterfacesAndTypes();
6146
6149
  const implicitTopLevelNames = new ImplicitTopLevelNames(str, astOffset);
@@ -6781,6 +6784,7 @@ function processSvelteTemplate(str, parse, options) {
6781
6784
  let uses$$restProps = false;
6782
6785
  let uses$$slots = false;
6783
6786
  let usesAccessors = !!options.accessors;
6787
+ let isRunes = false;
6784
6788
  const componentDocumentation = new ComponentDocumentation();
6785
6789
  //track if we are in a declaration scope
6786
6790
  const isDeclaration = { value: false };
@@ -6804,6 +6808,9 @@ function processSvelteTemplate(str, parse, options) {
6804
6808
  usesAccessors = true;
6805
6809
  }
6806
6810
  break;
6811
+ case 'runes':
6812
+ isRunes = true;
6813
+ break;
6807
6814
  }
6808
6815
  }
6809
6816
  };
@@ -6983,7 +6990,8 @@ function processSvelteTemplate(str, parse, options) {
6983
6990
  uses$$slots,
6984
6991
  componentDocumentation,
6985
6992
  resolvedStores,
6986
- usesAccessors
6993
+ usesAccessors,
6994
+ isRunes
6987
6995
  };
6988
6996
  }
6989
6997
  function svelte2tsx(svelte, options = { parse: compiler.parse }) {
@@ -6993,7 +7001,7 @@ function svelte2tsx(svelte, options = { parse: compiler.parse }) {
6993
7001
  const basename = path.basename(options.filename || '');
6994
7002
  const svelte5Plus = Number(options.version[0]) > 4;
6995
7003
  // process the htmlx as a svelte template
6996
- let { htmlAst, moduleScriptTag, scriptTag, rootSnippets, slots, uses$$props, uses$$slots, uses$$restProps, events, componentDocumentation, resolvedStores, usesAccessors } = processSvelteTemplate(str, options.parse || compiler.parse, {
7004
+ let { htmlAst, moduleScriptTag, scriptTag, rootSnippets, slots, uses$$props, uses$$slots, uses$$restProps, events, componentDocumentation, resolvedStores, usesAccessors, isRunes } = processSvelteTemplate(str, options.parse || compiler.parse, {
6997
7005
  ...options,
6998
7006
  svelte5Plus
6999
7007
  });
@@ -7018,7 +7026,7 @@ function svelte2tsx(svelte, options = { parse: compiler.parse }) {
7018
7026
  : instanceScriptTarget;
7019
7027
  const implicitStoreValues = new ImplicitStoreValues(resolvedStores, renderFunctionStart);
7020
7028
  //move the instance script and process the content
7021
- let exportedNames = new ExportedNames(str, 0, basename, options === null || options === void 0 ? void 0 : options.isTsFile, svelte5Plus);
7029
+ let exportedNames = new ExportedNames(str, 0, basename, options === null || options === void 0 ? void 0 : options.isTsFile, svelte5Plus, isRunes);
7022
7030
  let generics = new Generics(str, 0, { attributes: [] });
7023
7031
  let uses$$SlotsInterface = false;
7024
7032
  if (scriptTag) {
@@ -7027,7 +7035,7 @@ function svelte2tsx(svelte, options = { parse: compiler.parse }) {
7027
7035
  str.move(scriptTag.start, scriptTag.end, instanceScriptTarget);
7028
7036
  }
7029
7037
  const res = processInstanceScriptContent(str, scriptTag, events, implicitStoreValues, options.mode,
7030
- /**hasModuleScripts */ !!moduleScriptTag, options === null || options === void 0 ? void 0 : options.isTsFile, basename, svelte5Plus);
7038
+ /**hasModuleScripts */ !!moduleScriptTag, options === null || options === void 0 ? void 0 : options.isTsFile, basename, svelte5Plus, isRunes);
7031
7039
  uses$$props = uses$$props || res.uses$$props;
7032
7040
  uses$$restProps = uses$$restProps || res.uses$$restProps;
7033
7041
  uses$$slots = uses$$slots || res.uses$$slots;
package/index.mjs CHANGED
@@ -4529,12 +4529,13 @@ function is$$PropsDeclaration(node) {
4529
4529
  return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
4530
4530
  }
4531
4531
  class ExportedNames {
4532
- constructor(str, astOffset, basename, isTsFile, isSvelte5Plus) {
4532
+ constructor(str, astOffset, basename, isTsFile, isSvelte5Plus, isRunes) {
4533
4533
  this.str = str;
4534
4534
  this.astOffset = astOffset;
4535
4535
  this.basename = basename;
4536
4536
  this.isTsFile = isTsFile;
4537
4537
  this.isSvelte5Plus = isSvelte5Plus;
4538
+ this.isRunes = isRunes;
4538
4539
  this.usesAccessors = false;
4539
4540
  /**
4540
4541
  * Uses the `$$Props` type
@@ -4616,10 +4617,10 @@ class ExportedNames {
4616
4617
  if (ts.isNamedExports(exportClause)) {
4617
4618
  for (const ne of exportClause.elements) {
4618
4619
  if (ne.propertyName) {
4619
- this.addExport(ne.propertyName, false, ne.name);
4620
+ this.addExport(ne.propertyName, false, ne.name, undefined, undefined, true);
4620
4621
  }
4621
4622
  else {
4622
- this.addExport(ne.name, false);
4623
+ this.addExport(ne.name, false, undefined, undefined, undefined, true);
4623
4624
  }
4624
4625
  }
4625
4626
  //we can remove entire statement
@@ -4956,7 +4957,7 @@ class ExportedNames {
4956
4957
  /**
4957
4958
  * Adds export to map
4958
4959
  */
4959
- addExport(name, isLet, target = null, type = null, required = false) {
4960
+ addExport(name, isLet, target = null, type = null, required = false, isNamedExport = false) {
4960
4961
  const existingDeclaration = this.possibleExports.get(name.text);
4961
4962
  if (target) {
4962
4963
  this.exports.set(name.text, {
@@ -4964,7 +4965,8 @@ class ExportedNames {
4964
4965
  type: (type === null || type === void 0 ? void 0 : type.getText()) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.type),
4965
4966
  identifierText: target.text,
4966
4967
  required: required || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.required),
4967
- doc: this.getDoc(target) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc)
4968
+ doc: this.getDoc(target) || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc),
4969
+ isNamedExport
4968
4970
  });
4969
4971
  }
4970
4972
  else {
@@ -4972,7 +4974,8 @@ class ExportedNames {
4972
4974
  isLet: isLet || (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.isLet),
4973
4975
  type: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.type,
4974
4976
  required: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.required,
4975
- doc: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc
4977
+ doc: existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.doc,
4978
+ isNamedExport
4976
4979
  });
4977
4980
  }
4978
4981
  if (existingDeclaration === null || existingDeclaration === void 0 ? void 0 : existingDeclaration.isLet) {
@@ -5083,7 +5086,7 @@ class ExportedNames {
5083
5086
  */
5084
5087
  createExportsStr() {
5085
5088
  const names = Array.from(this.exports.entries());
5086
- const others = names.filter(([, { isLet }]) => !isLet);
5089
+ const others = names.filter(([, { isLet, isNamedExport }]) => !isLet || (this.usesRunes() && isNamedExport));
5087
5090
  const needsAccessors = this.usesAccessors && names.length > 0 && !this.usesRunes(); // runes mode doesn't support accessors
5088
5091
  if (this.isSvelte5Plus) {
5089
5092
  let str = '';
@@ -5155,7 +5158,7 @@ class ExportedNames {
5155
5158
  this.isSvelte5Plus && globals.some((global) => runes.includes(global));
5156
5159
  }
5157
5160
  usesRunes() {
5158
- return this.hasRunesGlobals || this.hasPropsRune();
5161
+ return this.hasRunesGlobals || this.hasPropsRune() || this.isRunes;
5159
5162
  }
5160
5163
  }
5161
5164
 
@@ -6115,12 +6118,12 @@ class InterfacesAndTypes {
6115
6118
  }
6116
6119
  }
6117
6120
 
6118
- function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, isTSFile, basename, isSvelte5Plus) {
6121
+ function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, isTSFile, basename, isSvelte5Plus, isRunes) {
6119
6122
  const htmlx = str.original;
6120
6123
  const scriptContent = htmlx.substring(script.content.start, script.content.end);
6121
6124
  const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
6122
6125
  const astOffset = script.content.start;
6123
- const exportedNames = new ExportedNames(str, astOffset, basename, isTSFile, isSvelte5Plus);
6126
+ const exportedNames = new ExportedNames(str, astOffset, basename, isTSFile, isSvelte5Plus, isRunes);
6124
6127
  const generics = new Generics(str, astOffset, script);
6125
6128
  const interfacesAndTypes = new InterfacesAndTypes();
6126
6129
  const implicitTopLevelNames = new ImplicitTopLevelNames(str, astOffset);
@@ -6761,6 +6764,7 @@ function processSvelteTemplate(str, parse, options) {
6761
6764
  let uses$$restProps = false;
6762
6765
  let uses$$slots = false;
6763
6766
  let usesAccessors = !!options.accessors;
6767
+ let isRunes = false;
6764
6768
  const componentDocumentation = new ComponentDocumentation();
6765
6769
  //track if we are in a declaration scope
6766
6770
  const isDeclaration = { value: false };
@@ -6784,6 +6788,9 @@ function processSvelteTemplate(str, parse, options) {
6784
6788
  usesAccessors = true;
6785
6789
  }
6786
6790
  break;
6791
+ case 'runes':
6792
+ isRunes = true;
6793
+ break;
6787
6794
  }
6788
6795
  }
6789
6796
  };
@@ -6963,7 +6970,8 @@ function processSvelteTemplate(str, parse, options) {
6963
6970
  uses$$slots,
6964
6971
  componentDocumentation,
6965
6972
  resolvedStores,
6966
- usesAccessors
6973
+ usesAccessors,
6974
+ isRunes
6967
6975
  };
6968
6976
  }
6969
6977
  function svelte2tsx(svelte, options = { parse }) {
@@ -6973,7 +6981,7 @@ function svelte2tsx(svelte, options = { parse }) {
6973
6981
  const basename = path__default.basename(options.filename || '');
6974
6982
  const svelte5Plus = Number(options.version[0]) > 4;
6975
6983
  // process the htmlx as a svelte template
6976
- let { htmlAst, moduleScriptTag, scriptTag, rootSnippets, slots, uses$$props, uses$$slots, uses$$restProps, events, componentDocumentation, resolvedStores, usesAccessors } = processSvelteTemplate(str, options.parse || parse, {
6984
+ let { htmlAst, moduleScriptTag, scriptTag, rootSnippets, slots, uses$$props, uses$$slots, uses$$restProps, events, componentDocumentation, resolvedStores, usesAccessors, isRunes } = processSvelteTemplate(str, options.parse || parse, {
6977
6985
  ...options,
6978
6986
  svelte5Plus
6979
6987
  });
@@ -6998,7 +7006,7 @@ function svelte2tsx(svelte, options = { parse }) {
6998
7006
  : instanceScriptTarget;
6999
7007
  const implicitStoreValues = new ImplicitStoreValues(resolvedStores, renderFunctionStart);
7000
7008
  //move the instance script and process the content
7001
- let exportedNames = new ExportedNames(str, 0, basename, options === null || options === void 0 ? void 0 : options.isTsFile, svelte5Plus);
7009
+ let exportedNames = new ExportedNames(str, 0, basename, options === null || options === void 0 ? void 0 : options.isTsFile, svelte5Plus, isRunes);
7002
7010
  let generics = new Generics(str, 0, { attributes: [] });
7003
7011
  let uses$$SlotsInterface = false;
7004
7012
  if (scriptTag) {
@@ -7007,7 +7015,7 @@ function svelte2tsx(svelte, options = { parse }) {
7007
7015
  str.move(scriptTag.start, scriptTag.end, instanceScriptTarget);
7008
7016
  }
7009
7017
  const res = processInstanceScriptContent(str, scriptTag, events, implicitStoreValues, options.mode,
7010
- /**hasModuleScripts */ !!moduleScriptTag, options === null || options === void 0 ? void 0 : options.isTsFile, basename, svelte5Plus);
7018
+ /**hasModuleScripts */ !!moduleScriptTag, options === null || options === void 0 ? void 0 : options.isTsFile, basename, svelte5Plus, isRunes);
7011
7019
  uses$$props = uses$$props || res.uses$$props;
7012
7020
  uses$$restProps = uses$$restProps || res.uses$$restProps;
7013
7021
  uses$$slots = uses$$slots || res.uses$$slots;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.21",
3
+ "version": "0.7.22",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",