svelte2tsx 0.7.29 → 0.7.30

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 +9 -8
  2. package/index.mjs +9 -8
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -2919,17 +2919,18 @@ function handleDebug(str, debugBlock) {
2919
2919
  * `ensureArray` will error that there are more args than expected
2920
2920
  */
2921
2921
  function handleEach(str, eachBlock) {
2922
- var _a;
2923
- const startEnd = str.original.indexOf('}', ((_a = eachBlock.key) === null || _a === void 0 ? void 0 : _a.end) || eachBlock.context.end) + 1;
2922
+ var _a, _b, _c;
2923
+ const startEnd = str.original.indexOf('}', ((_a = eachBlock.key) === null || _a === void 0 ? void 0 : _a.end) || ((_b = eachBlock.context) === null || _b === void 0 ? void 0 : _b.end) || eachBlock.expression.end) + 1;
2924
2924
  let transforms;
2925
2925
  // {#each true, [1,2]} is valid but for (const x of true, [1,2]) is not if not wrapped with braces
2926
2926
  const containsComma = str.original
2927
2927
  .substring(eachBlock.expression.start, eachBlock.expression.end)
2928
2928
  .includes(',');
2929
2929
  const expressionEnd = getEnd(eachBlock.expression);
2930
- const contextEnd = getEnd(eachBlock.context);
2931
- const arrayAndItemVarTheSame = str.original.substring(eachBlock.expression.start, expressionEnd) ===
2932
- str.original.substring(eachBlock.context.start, contextEnd);
2930
+ const contextEnd = eachBlock.context && getEnd(eachBlock.context);
2931
+ const arrayAndItemVarTheSame = !!eachBlock.context &&
2932
+ str.original.substring(eachBlock.expression.start, expressionEnd) ===
2933
+ str.original.substring(eachBlock.context.start, contextEnd);
2933
2934
  if (arrayAndItemVarTheSame) {
2934
2935
  transforms = [
2935
2936
  `{ const $$_each = __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
@@ -2942,14 +2943,14 @@ function handleEach(str, eachBlock) {
2942
2943
  else {
2943
2944
  transforms = [
2944
2945
  'for(let ',
2945
- [eachBlock.context.start, contextEnd],
2946
+ eachBlock.context ? [eachBlock.context.start, contextEnd] : '$$each_item',
2946
2947
  ` of __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
2947
2948
  [eachBlock.expression.start, eachBlock.expression.end],
2948
- `${containsComma ? ')' : ''})){`
2949
+ `${containsComma ? ')' : ''})){${eachBlock.context ? '' : '$$each_item;'}`
2949
2950
  ];
2950
2951
  }
2951
2952
  if (eachBlock.index) {
2952
- const indexStart = str.original.indexOf(eachBlock.index, eachBlock.context.end);
2953
+ const indexStart = str.original.indexOf(eachBlock.index, ((_c = eachBlock.context) === null || _c === void 0 ? void 0 : _c.end) || eachBlock.expression.end);
2953
2954
  const indexEnd = indexStart + eachBlock.index.length;
2954
2955
  transforms.push('let ', [indexStart, indexEnd], ' = 1;');
2955
2956
  }
package/index.mjs CHANGED
@@ -2899,17 +2899,18 @@ function handleDebug(str, debugBlock) {
2899
2899
  * `ensureArray` will error that there are more args than expected
2900
2900
  */
2901
2901
  function handleEach(str, eachBlock) {
2902
- var _a;
2903
- const startEnd = str.original.indexOf('}', ((_a = eachBlock.key) === null || _a === void 0 ? void 0 : _a.end) || eachBlock.context.end) + 1;
2902
+ var _a, _b, _c;
2903
+ const startEnd = str.original.indexOf('}', ((_a = eachBlock.key) === null || _a === void 0 ? void 0 : _a.end) || ((_b = eachBlock.context) === null || _b === void 0 ? void 0 : _b.end) || eachBlock.expression.end) + 1;
2904
2904
  let transforms;
2905
2905
  // {#each true, [1,2]} is valid but for (const x of true, [1,2]) is not if not wrapped with braces
2906
2906
  const containsComma = str.original
2907
2907
  .substring(eachBlock.expression.start, eachBlock.expression.end)
2908
2908
  .includes(',');
2909
2909
  const expressionEnd = getEnd(eachBlock.expression);
2910
- const contextEnd = getEnd(eachBlock.context);
2911
- const arrayAndItemVarTheSame = str.original.substring(eachBlock.expression.start, expressionEnd) ===
2912
- str.original.substring(eachBlock.context.start, contextEnd);
2910
+ const contextEnd = eachBlock.context && getEnd(eachBlock.context);
2911
+ const arrayAndItemVarTheSame = !!eachBlock.context &&
2912
+ str.original.substring(eachBlock.expression.start, expressionEnd) ===
2913
+ str.original.substring(eachBlock.context.start, contextEnd);
2913
2914
  if (arrayAndItemVarTheSame) {
2914
2915
  transforms = [
2915
2916
  `{ const $$_each = __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
@@ -2922,14 +2923,14 @@ function handleEach(str, eachBlock) {
2922
2923
  else {
2923
2924
  transforms = [
2924
2925
  'for(let ',
2925
- [eachBlock.context.start, contextEnd],
2926
+ eachBlock.context ? [eachBlock.context.start, contextEnd] : '$$each_item',
2926
2927
  ` of __sveltets_2_ensureArray(${containsComma ? '(' : ''}`,
2927
2928
  [eachBlock.expression.start, eachBlock.expression.end],
2928
- `${containsComma ? ')' : ''})){`
2929
+ `${containsComma ? ')' : ''})){${eachBlock.context ? '' : '$$each_item;'}`
2929
2930
  ];
2930
2931
  }
2931
2932
  if (eachBlock.index) {
2932
- const indexStart = str.original.indexOf(eachBlock.index, eachBlock.context.end);
2933
+ const indexStart = str.original.indexOf(eachBlock.index, ((_c = eachBlock.context) === null || _c === void 0 ? void 0 : _c.end) || eachBlock.expression.end);
2933
2934
  const indexEnd = indexStart + eachBlock.index.length;
2934
2935
  transforms.push('let ', [indexStart, indexEnd], ' = 1;');
2935
2936
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.29",
3
+ "version": "0.7.30",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",