svelte2tsx 0.5.5 → 0.5.6

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 +70 -72
  2. package/index.mjs +70 -72
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -119,7 +119,7 @@ var Chunk = function Chunk(start, end, content) {
119
119
  // we make these non-enumerable, for sanity while debugging
120
120
  Object.defineProperties(this, {
121
121
  previous: { writable: true, value: null },
122
- next: { writable: true, value: null }
122
+ next: { writable: true, value: null },
123
123
  });
124
124
  };
125
125
 
@@ -229,7 +229,6 @@ Chunk.prototype.trimEnd = function trimEnd (rx) {
229
229
  this.split(this.start + trimmed.length).edit('', undefined, true);
230
230
  }
231
231
  return true;
232
-
233
232
  } else {
234
233
  this.edit('', undefined, true);
235
234
 
@@ -250,7 +249,6 @@ Chunk.prototype.trimStart = function trimStart (rx) {
250
249
  this.edit('', undefined, true);
251
250
  }
252
251
  return true;
253
-
254
252
  } else {
255
253
  this.edit('', undefined, true);
256
254
 
@@ -435,7 +433,7 @@ var n = '\n';
435
433
  var warned = {
436
434
  insertLeft: false,
437
435
  insertRight: false,
438
- storeName: false
436
+ storeName: false,
439
437
  };
440
438
 
441
439
  var MagicString = function MagicString(string, options) {
@@ -444,19 +442,19 @@ var MagicString = function MagicString(string, options) {
444
442
  var chunk = new Chunk(0, string.length, string);
445
443
 
446
444
  Object.defineProperties(this, {
447
- original: { writable: true, value: string },
448
- outro: { writable: true, value: '' },
449
- intro: { writable: true, value: '' },
450
- firstChunk: { writable: true, value: chunk },
451
- lastChunk: { writable: true, value: chunk },
452
- lastSearchedChunk: { writable: true, value: chunk },
453
- byStart: { writable: true, value: {} },
454
- byEnd: { writable: true, value: {} },
455
- filename: { writable: true, value: options.filename },
445
+ original: { writable: true, value: string },
446
+ outro: { writable: true, value: '' },
447
+ intro: { writable: true, value: '' },
448
+ firstChunk: { writable: true, value: chunk },
449
+ lastChunk: { writable: true, value: chunk },
450
+ lastSearchedChunk: { writable: true, value: chunk },
451
+ byStart: { writable: true, value: {} },
452
+ byEnd: { writable: true, value: {} },
453
+ filename: { writable: true, value: options.filename },
456
454
  indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
457
- sourcemapLocations: { writable: true, value: new BitSet() },
458
- storedNames: { writable: true, value: {} },
459
- indentStr: { writable: true, value: guessIndent(string) }
455
+ sourcemapLocations: { writable: true, value: new BitSet() },
456
+ storedNames: { writable: true, value: {} },
457
+ indentStr: { writable: true, value: guessIndent(string) },
460
458
  });
461
459
 
462
460
  this.byStart[0] = chunk;
@@ -580,7 +578,7 @@ MagicString.prototype.generateDecodedMap = function generateDecodedMap (options)
580
578
  sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
581
579
  sourcesContent: options.includeContent ? [this.original] : [null],
582
580
  names: names,
583
- mappings: mappings.raw
581
+ mappings: mappings.raw,
584
582
  };
585
583
  };
586
584
 
@@ -678,12 +676,16 @@ MagicString.prototype.indent = function indent (indentStr, options) {
678
676
  };
679
677
 
680
678
  MagicString.prototype.insert = function insert () {
681
- throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
679
+ throw new Error(
680
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
681
+ );
682
682
  };
683
683
 
684
684
  MagicString.prototype.insertLeft = function insertLeft (index, content) {
685
685
  if (!warned.insertLeft) {
686
- console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
686
+ console.warn(
687
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
688
+ ); // eslint-disable-line no-console
687
689
  warned.insertLeft = true;
688
690
  }
689
691
 
@@ -692,7 +694,9 @@ MagicString.prototype.insertLeft = function insertLeft (index, content) {
692
694
 
693
695
  MagicString.prototype.insertRight = function insertRight (index, content) {
694
696
  if (!warned.insertRight) {
695
- console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
697
+ console.warn(
698
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
699
+ ); // eslint-disable-line no-console
696
700
  warned.insertRight = true;
697
701
  }
698
702
 
@@ -744,14 +748,18 @@ MagicString.prototype.overwrite = function overwrite (start, end, content, optio
744
748
 
745
749
  if (end > this.original.length) { throw new Error('end is out of bounds'); }
746
750
  if (start === end)
747
- { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
751
+ { throw new Error(
752
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
753
+ ); }
748
754
 
749
755
  this._split(start);
750
756
  this._split(end);
751
757
 
752
758
  if (options === true) {
753
759
  if (!warned.storeName) {
754
- console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
760
+ console.warn(
761
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
762
+ ); // eslint-disable-line no-console
755
763
  warned.storeName = true;
756
764
  }
757
765
 
@@ -762,28 +770,23 @@ MagicString.prototype.overwrite = function overwrite (start, end, content, optio
762
770
 
763
771
  if (storeName) {
764
772
  var original = this.original.slice(start, end);
765
- this.storedNames[original] = true;
773
+ Object.defineProperty(this.storedNames, original, { writable: true, value: true, enumerable: true });
766
774
  }
767
775
 
768
776
  var first = this.byStart[start];
769
777
  var last = this.byEnd[end];
770
778
 
771
779
  if (first) {
772
- if (end > first.end && first.next !== this.byStart[first.end]) {
773
- throw new Error('Cannot overwrite across a split point');
774
- }
775
-
776
- first.edit(content, storeName, contentOnly);
777
-
778
- if (first !== last) {
779
- var chunk = first.next;
780
- while (chunk !== last) {
781
- chunk.edit('', false);
782
- chunk = chunk.next;
780
+ var chunk = first;
781
+ while (chunk !== last) {
782
+ if (chunk.next !== this.byStart[chunk.end]) {
783
+ throw new Error('Cannot overwrite across a split point');
783
784
  }
784
-
785
+ chunk = chunk.next;
785
786
  chunk.edit('', false);
786
787
  }
788
+
789
+ first.edit(content, storeName, contentOnly);
787
790
  } else {
788
791
  // must be inserting at the end
789
792
  var newChunk = new Chunk(start, end, '').edit(content, storeName);
@@ -857,53 +860,43 @@ MagicString.prototype.remove = function remove (start, end) {
857
860
  };
858
861
 
859
862
  MagicString.prototype.lastChar = function lastChar () {
860
- if (this.outro.length)
861
- { return this.outro[this.outro.length - 1]; }
863
+ if (this.outro.length) { return this.outro[this.outro.length - 1]; }
862
864
  var chunk = this.lastChunk;
863
865
  do {
864
- if (chunk.outro.length)
865
- { return chunk.outro[chunk.outro.length - 1]; }
866
- if (chunk.content.length)
867
- { return chunk.content[chunk.content.length - 1]; }
868
- if (chunk.intro.length)
869
- { return chunk.intro[chunk.intro.length - 1]; }
870
- } while (chunk = chunk.previous);
871
- if (this.intro.length)
872
- { return this.intro[this.intro.length - 1]; }
866
+ if (chunk.outro.length) { return chunk.outro[chunk.outro.length - 1]; }
867
+ if (chunk.content.length) { return chunk.content[chunk.content.length - 1]; }
868
+ if (chunk.intro.length) { return chunk.intro[chunk.intro.length - 1]; }
869
+ } while ((chunk = chunk.previous));
870
+ if (this.intro.length) { return this.intro[this.intro.length - 1]; }
873
871
  return '';
874
872
  };
875
873
 
876
874
  MagicString.prototype.lastLine = function lastLine () {
877
875
  var lineIndex = this.outro.lastIndexOf(n);
878
- if (lineIndex !== -1)
879
- { return this.outro.substr(lineIndex + 1); }
876
+ if (lineIndex !== -1) { return this.outro.substr(lineIndex + 1); }
880
877
  var lineStr = this.outro;
881
878
  var chunk = this.lastChunk;
882
879
  do {
883
880
  if (chunk.outro.length > 0) {
884
881
  lineIndex = chunk.outro.lastIndexOf(n);
885
- if (lineIndex !== -1)
886
- { return chunk.outro.substr(lineIndex + 1) + lineStr; }
882
+ if (lineIndex !== -1) { return chunk.outro.substr(lineIndex + 1) + lineStr; }
887
883
  lineStr = chunk.outro + lineStr;
888
884
  }
889
885
 
890
886
  if (chunk.content.length > 0) {
891
887
  lineIndex = chunk.content.lastIndexOf(n);
892
- if (lineIndex !== -1)
893
- { return chunk.content.substr(lineIndex + 1) + lineStr; }
888
+ if (lineIndex !== -1) { return chunk.content.substr(lineIndex + 1) + lineStr; }
894
889
  lineStr = chunk.content + lineStr;
895
890
  }
896
891
 
897
892
  if (chunk.intro.length > 0) {
898
893
  lineIndex = chunk.intro.lastIndexOf(n);
899
- if (lineIndex !== -1)
900
- { return chunk.intro.substr(lineIndex + 1) + lineStr; }
894
+ if (lineIndex !== -1) { return chunk.intro.substr(lineIndex + 1) + lineStr; }
901
895
  lineStr = chunk.intro + lineStr;
902
896
  }
903
- } while (chunk = chunk.previous);
897
+ } while ((chunk = chunk.previous));
904
898
  lineIndex = this.intro.lastIndexOf(n);
905
- if (lineIndex !== -1)
906
- { return this.intro.substr(lineIndex + 1) + lineStr; }
899
+ if (lineIndex !== -1) { return this.intro.substr(lineIndex + 1) + lineStr; }
907
900
  return this.intro + lineStr;
908
901
  };
909
902
 
@@ -1017,11 +1010,13 @@ MagicString.prototype.toString = function toString () {
1017
1010
  MagicString.prototype.isEmpty = function isEmpty () {
1018
1011
  var chunk = this.firstChunk;
1019
1012
  do {
1020
- if (chunk.intro.length && chunk.intro.trim() ||
1021
- chunk.content.length && chunk.content.trim() ||
1022
- chunk.outro.length && chunk.outro.trim())
1013
+ if (
1014
+ (chunk.intro.length && chunk.intro.trim()) ||
1015
+ (chunk.content.length && chunk.content.trim()) ||
1016
+ (chunk.outro.length && chunk.outro.trim())
1017
+ )
1023
1018
  { return false; }
1024
- } while (chunk = chunk.next);
1019
+ } while ((chunk = chunk.next));
1025
1020
  return true;
1026
1021
  };
1027
1022
 
@@ -1030,7 +1025,7 @@ MagicString.prototype.length = function length () {
1030
1025
  var length = 0;
1031
1026
  do {
1032
1027
  length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1033
- } while (chunk = chunk.next);
1028
+ } while ((chunk = chunk.next));
1034
1029
  return length;
1035
1030
  };
1036
1031
 
@@ -5321,21 +5316,24 @@ class ExportedNames {
5321
5316
  return;
5322
5317
  }
5323
5318
  const handleTypeAssertion = (declaration) => {
5324
- var _a;
5325
5319
  const identifier = declaration.name;
5326
5320
  const tsType = declaration.type;
5327
5321
  const jsDocType = ts__default['default'].getJSDocType(declaration);
5328
5322
  const type = tsType || jsDocType;
5329
- if (!ts__default['default'].isIdentifier(identifier) ||
5330
- (!type &&
5323
+ if (ts__default['default'].isIdentifier(identifier) &&
5324
+ // Ensure initialization for proper control flow and to avoid "possibly undefined" type errors.
5325
+ // Also ensure prop is typed as any with a type annotation in TS strict mode
5326
+ (!declaration.initializer ||
5327
+ // Widen the type, else it's narrowed to the initializer
5328
+ type ||
5331
5329
  // Edge case: TS infers `export let bla = false` to type `false`.
5332
5330
  // prevent that by adding the any-wrap in this case, too.
5333
- ![ts__default['default'].SyntaxKind.FalseKeyword, ts__default['default'].SyntaxKind.TrueKeyword].includes((_a = declaration.initializer) === null || _a === void 0 ? void 0 : _a.kind))) {
5334
- return;
5331
+ (!type &&
5332
+ [ts__default['default'].SyntaxKind.FalseKeyword, ts__default['default'].SyntaxKind.TrueKeyword].includes(declaration.initializer.kind)))) {
5333
+ const name = identifier.getText();
5334
+ const end = declaration.end + this.astOffset;
5335
+ preprendStr(this.str, end, surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`));
5335
5336
  }
5336
- const name = identifier.getText();
5337
- const end = declaration.end + this.astOffset;
5338
- preprendStr(this.str, end, surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`));
5339
5337
  };
5340
5338
  const findComma = (target) => target.getChildren().filter((child) => child.kind === ts__default['default'].SyntaxKind.CommaToken);
5341
5339
  const splitDeclaration = () => {
@@ -5962,7 +5960,7 @@ function handleStore(node, parent, str) {
5962
5960
  }
5963
5961
  if (simpleOperator) {
5964
5962
  const storename = node.name.slice(1); // drop the $
5965
- str.overwrite(parent.start, parent.end, `${storename}.set( $${storename} ${simpleOperator} 1)`);
5963
+ str.overwrite(parent.start, parent.end, `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})`);
5966
5964
  }
5967
5965
  else {
5968
5966
  console.warn(`Warning - unrecognized UpdateExpression operator ${parent.operator}!
@@ -6426,7 +6424,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
6426
6424
  simpleOperator = '-';
6427
6425
  }
6428
6426
  if (simpleOperator) {
6429
- str.overwrite(parent.getStart() + astOffset, parent.end + astOffset, `${storename}.set( $${storename} ${simpleOperator} 1)`);
6427
+ str.overwrite(parent.getStart() + astOffset, parent.end + astOffset, `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})`);
6430
6428
  return;
6431
6429
  }
6432
6430
  else {
package/index.mjs CHANGED
@@ -89,7 +89,7 @@ var Chunk = function Chunk(start, end, content) {
89
89
  // we make these non-enumerable, for sanity while debugging
90
90
  Object.defineProperties(this, {
91
91
  previous: { writable: true, value: null },
92
- next: { writable: true, value: null }
92
+ next: { writable: true, value: null },
93
93
  });
94
94
  };
95
95
 
@@ -199,7 +199,6 @@ Chunk.prototype.trimEnd = function trimEnd (rx) {
199
199
  this.split(this.start + trimmed.length).edit('', undefined, true);
200
200
  }
201
201
  return true;
202
-
203
202
  } else {
204
203
  this.edit('', undefined, true);
205
204
 
@@ -220,7 +219,6 @@ Chunk.prototype.trimStart = function trimStart (rx) {
220
219
  this.edit('', undefined, true);
221
220
  }
222
221
  return true;
223
-
224
222
  } else {
225
223
  this.edit('', undefined, true);
226
224
 
@@ -405,7 +403,7 @@ var n = '\n';
405
403
  var warned = {
406
404
  insertLeft: false,
407
405
  insertRight: false,
408
- storeName: false
406
+ storeName: false,
409
407
  };
410
408
 
411
409
  var MagicString = function MagicString(string, options) {
@@ -414,19 +412,19 @@ var MagicString = function MagicString(string, options) {
414
412
  var chunk = new Chunk(0, string.length, string);
415
413
 
416
414
  Object.defineProperties(this, {
417
- original: { writable: true, value: string },
418
- outro: { writable: true, value: '' },
419
- intro: { writable: true, value: '' },
420
- firstChunk: { writable: true, value: chunk },
421
- lastChunk: { writable: true, value: chunk },
422
- lastSearchedChunk: { writable: true, value: chunk },
423
- byStart: { writable: true, value: {} },
424
- byEnd: { writable: true, value: {} },
425
- filename: { writable: true, value: options.filename },
415
+ original: { writable: true, value: string },
416
+ outro: { writable: true, value: '' },
417
+ intro: { writable: true, value: '' },
418
+ firstChunk: { writable: true, value: chunk },
419
+ lastChunk: { writable: true, value: chunk },
420
+ lastSearchedChunk: { writable: true, value: chunk },
421
+ byStart: { writable: true, value: {} },
422
+ byEnd: { writable: true, value: {} },
423
+ filename: { writable: true, value: options.filename },
426
424
  indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
427
- sourcemapLocations: { writable: true, value: new BitSet() },
428
- storedNames: { writable: true, value: {} },
429
- indentStr: { writable: true, value: guessIndent(string) }
425
+ sourcemapLocations: { writable: true, value: new BitSet() },
426
+ storedNames: { writable: true, value: {} },
427
+ indentStr: { writable: true, value: guessIndent(string) },
430
428
  });
431
429
 
432
430
  this.byStart[0] = chunk;
@@ -550,7 +548,7 @@ MagicString.prototype.generateDecodedMap = function generateDecodedMap (options)
550
548
  sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
551
549
  sourcesContent: options.includeContent ? [this.original] : [null],
552
550
  names: names,
553
- mappings: mappings.raw
551
+ mappings: mappings.raw,
554
552
  };
555
553
  };
556
554
 
@@ -648,12 +646,16 @@ MagicString.prototype.indent = function indent (indentStr, options) {
648
646
  };
649
647
 
650
648
  MagicString.prototype.insert = function insert () {
651
- throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
649
+ throw new Error(
650
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
651
+ );
652
652
  };
653
653
 
654
654
  MagicString.prototype.insertLeft = function insertLeft (index, content) {
655
655
  if (!warned.insertLeft) {
656
- console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
656
+ console.warn(
657
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
658
+ ); // eslint-disable-line no-console
657
659
  warned.insertLeft = true;
658
660
  }
659
661
 
@@ -662,7 +664,9 @@ MagicString.prototype.insertLeft = function insertLeft (index, content) {
662
664
 
663
665
  MagicString.prototype.insertRight = function insertRight (index, content) {
664
666
  if (!warned.insertRight) {
665
- console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
667
+ console.warn(
668
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
669
+ ); // eslint-disable-line no-console
666
670
  warned.insertRight = true;
667
671
  }
668
672
 
@@ -714,14 +718,18 @@ MagicString.prototype.overwrite = function overwrite (start, end, content, optio
714
718
 
715
719
  if (end > this.original.length) { throw new Error('end is out of bounds'); }
716
720
  if (start === end)
717
- { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
721
+ { throw new Error(
722
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
723
+ ); }
718
724
 
719
725
  this._split(start);
720
726
  this._split(end);
721
727
 
722
728
  if (options === true) {
723
729
  if (!warned.storeName) {
724
- console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
730
+ console.warn(
731
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
732
+ ); // eslint-disable-line no-console
725
733
  warned.storeName = true;
726
734
  }
727
735
 
@@ -732,28 +740,23 @@ MagicString.prototype.overwrite = function overwrite (start, end, content, optio
732
740
 
733
741
  if (storeName) {
734
742
  var original = this.original.slice(start, end);
735
- this.storedNames[original] = true;
743
+ Object.defineProperty(this.storedNames, original, { writable: true, value: true, enumerable: true });
736
744
  }
737
745
 
738
746
  var first = this.byStart[start];
739
747
  var last = this.byEnd[end];
740
748
 
741
749
  if (first) {
742
- if (end > first.end && first.next !== this.byStart[first.end]) {
743
- throw new Error('Cannot overwrite across a split point');
744
- }
745
-
746
- first.edit(content, storeName, contentOnly);
747
-
748
- if (first !== last) {
749
- var chunk = first.next;
750
- while (chunk !== last) {
751
- chunk.edit('', false);
752
- chunk = chunk.next;
750
+ var chunk = first;
751
+ while (chunk !== last) {
752
+ if (chunk.next !== this.byStart[chunk.end]) {
753
+ throw new Error('Cannot overwrite across a split point');
753
754
  }
754
-
755
+ chunk = chunk.next;
755
756
  chunk.edit('', false);
756
757
  }
758
+
759
+ first.edit(content, storeName, contentOnly);
757
760
  } else {
758
761
  // must be inserting at the end
759
762
  var newChunk = new Chunk(start, end, '').edit(content, storeName);
@@ -827,53 +830,43 @@ MagicString.prototype.remove = function remove (start, end) {
827
830
  };
828
831
 
829
832
  MagicString.prototype.lastChar = function lastChar () {
830
- if (this.outro.length)
831
- { return this.outro[this.outro.length - 1]; }
833
+ if (this.outro.length) { return this.outro[this.outro.length - 1]; }
832
834
  var chunk = this.lastChunk;
833
835
  do {
834
- if (chunk.outro.length)
835
- { return chunk.outro[chunk.outro.length - 1]; }
836
- if (chunk.content.length)
837
- { return chunk.content[chunk.content.length - 1]; }
838
- if (chunk.intro.length)
839
- { return chunk.intro[chunk.intro.length - 1]; }
840
- } while (chunk = chunk.previous);
841
- if (this.intro.length)
842
- { return this.intro[this.intro.length - 1]; }
836
+ if (chunk.outro.length) { return chunk.outro[chunk.outro.length - 1]; }
837
+ if (chunk.content.length) { return chunk.content[chunk.content.length - 1]; }
838
+ if (chunk.intro.length) { return chunk.intro[chunk.intro.length - 1]; }
839
+ } while ((chunk = chunk.previous));
840
+ if (this.intro.length) { return this.intro[this.intro.length - 1]; }
843
841
  return '';
844
842
  };
845
843
 
846
844
  MagicString.prototype.lastLine = function lastLine () {
847
845
  var lineIndex = this.outro.lastIndexOf(n);
848
- if (lineIndex !== -1)
849
- { return this.outro.substr(lineIndex + 1); }
846
+ if (lineIndex !== -1) { return this.outro.substr(lineIndex + 1); }
850
847
  var lineStr = this.outro;
851
848
  var chunk = this.lastChunk;
852
849
  do {
853
850
  if (chunk.outro.length > 0) {
854
851
  lineIndex = chunk.outro.lastIndexOf(n);
855
- if (lineIndex !== -1)
856
- { return chunk.outro.substr(lineIndex + 1) + lineStr; }
852
+ if (lineIndex !== -1) { return chunk.outro.substr(lineIndex + 1) + lineStr; }
857
853
  lineStr = chunk.outro + lineStr;
858
854
  }
859
855
 
860
856
  if (chunk.content.length > 0) {
861
857
  lineIndex = chunk.content.lastIndexOf(n);
862
- if (lineIndex !== -1)
863
- { return chunk.content.substr(lineIndex + 1) + lineStr; }
858
+ if (lineIndex !== -1) { return chunk.content.substr(lineIndex + 1) + lineStr; }
864
859
  lineStr = chunk.content + lineStr;
865
860
  }
866
861
 
867
862
  if (chunk.intro.length > 0) {
868
863
  lineIndex = chunk.intro.lastIndexOf(n);
869
- if (lineIndex !== -1)
870
- { return chunk.intro.substr(lineIndex + 1) + lineStr; }
864
+ if (lineIndex !== -1) { return chunk.intro.substr(lineIndex + 1) + lineStr; }
871
865
  lineStr = chunk.intro + lineStr;
872
866
  }
873
- } while (chunk = chunk.previous);
867
+ } while ((chunk = chunk.previous));
874
868
  lineIndex = this.intro.lastIndexOf(n);
875
- if (lineIndex !== -1)
876
- { return this.intro.substr(lineIndex + 1) + lineStr; }
869
+ if (lineIndex !== -1) { return this.intro.substr(lineIndex + 1) + lineStr; }
877
870
  return this.intro + lineStr;
878
871
  };
879
872
 
@@ -987,11 +980,13 @@ MagicString.prototype.toString = function toString () {
987
980
  MagicString.prototype.isEmpty = function isEmpty () {
988
981
  var chunk = this.firstChunk;
989
982
  do {
990
- if (chunk.intro.length && chunk.intro.trim() ||
991
- chunk.content.length && chunk.content.trim() ||
992
- chunk.outro.length && chunk.outro.trim())
983
+ if (
984
+ (chunk.intro.length && chunk.intro.trim()) ||
985
+ (chunk.content.length && chunk.content.trim()) ||
986
+ (chunk.outro.length && chunk.outro.trim())
987
+ )
993
988
  { return false; }
994
- } while (chunk = chunk.next);
989
+ } while ((chunk = chunk.next));
995
990
  return true;
996
991
  };
997
992
 
@@ -1000,7 +995,7 @@ MagicString.prototype.length = function length () {
1000
995
  var length = 0;
1001
996
  do {
1002
997
  length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1003
- } while (chunk = chunk.next);
998
+ } while ((chunk = chunk.next));
1004
999
  return length;
1005
1000
  };
1006
1001
 
@@ -5291,21 +5286,24 @@ class ExportedNames {
5291
5286
  return;
5292
5287
  }
5293
5288
  const handleTypeAssertion = (declaration) => {
5294
- var _a;
5295
5289
  const identifier = declaration.name;
5296
5290
  const tsType = declaration.type;
5297
5291
  const jsDocType = ts__default.getJSDocType(declaration);
5298
5292
  const type = tsType || jsDocType;
5299
- if (!ts__default.isIdentifier(identifier) ||
5300
- (!type &&
5293
+ if (ts__default.isIdentifier(identifier) &&
5294
+ // Ensure initialization for proper control flow and to avoid "possibly undefined" type errors.
5295
+ // Also ensure prop is typed as any with a type annotation in TS strict mode
5296
+ (!declaration.initializer ||
5297
+ // Widen the type, else it's narrowed to the initializer
5298
+ type ||
5301
5299
  // Edge case: TS infers `export let bla = false` to type `false`.
5302
5300
  // prevent that by adding the any-wrap in this case, too.
5303
- ![ts__default.SyntaxKind.FalseKeyword, ts__default.SyntaxKind.TrueKeyword].includes((_a = declaration.initializer) === null || _a === void 0 ? void 0 : _a.kind))) {
5304
- return;
5301
+ (!type &&
5302
+ [ts__default.SyntaxKind.FalseKeyword, ts__default.SyntaxKind.TrueKeyword].includes(declaration.initializer.kind)))) {
5303
+ const name = identifier.getText();
5304
+ const end = declaration.end + this.astOffset;
5305
+ preprendStr(this.str, end, surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`));
5305
5306
  }
5306
- const name = identifier.getText();
5307
- const end = declaration.end + this.astOffset;
5308
- preprendStr(this.str, end, surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`));
5309
5307
  };
5310
5308
  const findComma = (target) => target.getChildren().filter((child) => child.kind === ts__default.SyntaxKind.CommaToken);
5311
5309
  const splitDeclaration = () => {
@@ -5932,7 +5930,7 @@ function handleStore(node, parent, str) {
5932
5930
  }
5933
5931
  if (simpleOperator) {
5934
5932
  const storename = node.name.slice(1); // drop the $
5935
- str.overwrite(parent.start, parent.end, `${storename}.set( $${storename} ${simpleOperator} 1)`);
5933
+ str.overwrite(parent.start, parent.end, `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})`);
5936
5934
  }
5937
5935
  else {
5938
5936
  console.warn(`Warning - unrecognized UpdateExpression operator ${parent.operator}!
@@ -6396,7 +6394,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
6396
6394
  simpleOperator = '-';
6397
6395
  }
6398
6396
  if (simpleOperator) {
6399
- str.overwrite(parent.getStart() + astOffset, parent.end + astOffset, `${storename}.set( $${storename} ${simpleOperator} 1)`);
6397
+ str.overwrite(parent.getStart() + astOffset, parent.end + astOffset, `(${storename}.set( $${storename} ${simpleOperator} 1), $${storename})`);
6400
6398
  return;
6401
6399
  }
6402
6400
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "svelte": "~3.46.1",
38
38
  "tiny-glob": "^0.2.6",
39
39
  "tslib": "^1.10.0",
40
- "typescript": "^4.5.3"
40
+ "typescript": "^4.6.2"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "svelte": "^3.24",