svelte2tsx 0.7.15 → 0.7.17

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.d.ts CHANGED
@@ -108,6 +108,10 @@ export interface EmitDtsConfig {
108
108
  * set to `src/lib` by default.
109
109
  */
110
110
  libRoot?: string;
111
+ /**
112
+ * Name of your tsconfig file, if it's not the standard `tsconfig.json` or `jsconfig.json`
113
+ */
114
+ tsconfig?: string;
111
115
  }
112
116
 
113
117
  // to make typo fix non-breaking, continue to export the old name but mark it as deprecated
package/index.js CHANGED
@@ -35,6 +35,20 @@ for (let i = 0; i < chars.length; i++) {
35
35
  intToChar[i] = c;
36
36
  charToInt[c] = i;
37
37
  }
38
+ function encodeInteger(builder, num, relative) {
39
+ let delta = num - relative;
40
+ delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
41
+ do {
42
+ let clamped = delta & 0b011111;
43
+ delta >>>= 5;
44
+ if (delta > 0)
45
+ clamped |= 0b100000;
46
+ builder.write(intToChar[clamped]);
47
+ } while (delta > 0);
48
+ return num;
49
+ }
50
+
51
+ const bufLength = 1024 * 16;
38
52
  // Provide a fallback for older environments.
39
53
  const td = typeof TextDecoder !== 'undefined'
40
54
  ? /* #__PURE__ */ new TextDecoder()
@@ -54,63 +68,54 @@ const td = typeof TextDecoder !== 'undefined'
54
68
  return out;
55
69
  },
56
70
  };
71
+ class StringWriter {
72
+ constructor() {
73
+ this.pos = 0;
74
+ this.out = '';
75
+ this.buffer = new Uint8Array(bufLength);
76
+ }
77
+ write(v) {
78
+ const { buffer } = this;
79
+ buffer[this.pos++] = v;
80
+ if (this.pos === bufLength) {
81
+ this.out += td.decode(buffer);
82
+ this.pos = 0;
83
+ }
84
+ }
85
+ flush() {
86
+ const { buffer, out, pos } = this;
87
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
88
+ }
89
+ }
57
90
  function encode(decoded) {
58
- const state = new Int32Array(5);
59
- const bufLength = 1024 * 16;
60
- const subLength = bufLength - 36;
61
- const buf = new Uint8Array(bufLength);
62
- const sub = buf.subarray(0, subLength);
63
- let pos = 0;
64
- let out = '';
91
+ const writer = new StringWriter();
92
+ let sourcesIndex = 0;
93
+ let sourceLine = 0;
94
+ let sourceColumn = 0;
95
+ let namesIndex = 0;
65
96
  for (let i = 0; i < decoded.length; i++) {
66
97
  const line = decoded[i];
67
- if (i > 0) {
68
- if (pos === bufLength) {
69
- out += td.decode(buf);
70
- pos = 0;
71
- }
72
- buf[pos++] = semicolon;
73
- }
98
+ if (i > 0)
99
+ writer.write(semicolon);
74
100
  if (line.length === 0)
75
101
  continue;
76
- state[0] = 0;
102
+ let genColumn = 0;
77
103
  for (let j = 0; j < line.length; j++) {
78
104
  const segment = line[j];
79
- // We can push up to 5 ints, each int can take at most 7 chars, and we
80
- // may push a comma.
81
- if (pos > subLength) {
82
- out += td.decode(sub);
83
- buf.copyWithin(0, subLength, pos);
84
- pos -= subLength;
85
- }
86
105
  if (j > 0)
87
- buf[pos++] = comma;
88
- pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
106
+ writer.write(comma);
107
+ genColumn = encodeInteger(writer, segment[0], genColumn);
89
108
  if (segment.length === 1)
90
109
  continue;
91
- pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
92
- pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
93
- pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
110
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
111
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
112
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
94
113
  if (segment.length === 4)
95
114
  continue;
96
- pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
115
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
97
116
  }
98
117
  }
99
- return out + td.decode(buf.subarray(0, pos));
100
- }
101
- function encodeInteger(buf, pos, state, segment, j) {
102
- const next = segment[j];
103
- let num = next - state[j];
104
- state[j] = next;
105
- num = num < 0 ? (-num << 1) | 1 : num << 1;
106
- do {
107
- let clamped = num & 0b011111;
108
- num >>>= 5;
109
- if (num > 0)
110
- clamped |= 0b100000;
111
- buf[pos++] = intToChar[clamped];
112
- } while (num > 0);
113
- return pos;
118
+ return writer.flush();
114
119
  }
115
120
 
116
121
  class BitSet {
@@ -207,6 +212,16 @@ class Chunk {
207
212
  this.intro = content + this.intro;
208
213
  }
209
214
 
215
+ reset() {
216
+ this.intro = '';
217
+ this.outro = '';
218
+ if (this.edited) {
219
+ this.content = this.original;
220
+ this.storeName = false;
221
+ this.edited = false;
222
+ }
223
+ }
224
+
210
225
  split(index) {
211
226
  const sliceIndex = index - this.start;
212
227
 
@@ -222,6 +237,13 @@ class Chunk {
222
237
  this.end = index;
223
238
 
224
239
  if (this.edited) {
240
+ // after split we should save the edit content record into the correct chunk
241
+ // to make sure sourcemap correct
242
+ // For example:
243
+ // ' test'.trim()
244
+ // split -> ' ' + 'test'
245
+ // ✔️ edit -> '' + 'test'
246
+ // ✖️ edit -> 'test' + ''
225
247
  // TODO is this block necessary?...
226
248
  newChunk.edit('', false);
227
249
  this.content = '';
@@ -250,6 +272,10 @@ class Chunk {
250
272
  if (trimmed.length) {
251
273
  if (trimmed !== this.content) {
252
274
  this.split(this.start + trimmed.length).edit('', undefined, true);
275
+ if (this.edited) {
276
+ // save the change, if it has been edited
277
+ this.edit(trimmed, this.storeName, true);
278
+ }
253
279
  }
254
280
  return true;
255
281
  } else {
@@ -268,7 +294,11 @@ class Chunk {
268
294
 
269
295
  if (trimmed.length) {
270
296
  if (trimmed !== this.content) {
271
- this.split(this.end - trimmed.length);
297
+ const newChunk = this.split(this.end - trimmed.length);
298
+ if (this.edited) {
299
+ // save the change, if it has been edited
300
+ newChunk.edit(trimmed, this.storeName, true);
301
+ }
272
302
  this.edit('', undefined, true);
273
303
  }
274
304
  return true;
@@ -281,9 +311,9 @@ class Chunk {
281
311
  }
282
312
  }
283
313
 
284
- function getBtoa () {
285
- if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
286
- return (str) => window.btoa(unescape(encodeURIComponent(str)));
314
+ function getBtoa() {
315
+ if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
316
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
287
317
  } else if (typeof Buffer === 'function') {
288
318
  return (str) => Buffer.from(str, 'utf-8').toString('base64');
289
319
  } else {
@@ -303,6 +333,9 @@ class SourceMap {
303
333
  this.sourcesContent = properties.sourcesContent;
304
334
  this.names = properties.names;
305
335
  this.mappings = encode(properties.mappings);
336
+ if (typeof properties.x_google_ignoreList !== 'undefined') {
337
+ this.x_google_ignoreList = properties.x_google_ignoreList;
338
+ }
306
339
  }
307
340
 
308
341
  toString() {
@@ -391,6 +424,8 @@ function getLocator(source) {
391
424
  };
392
425
  }
393
426
 
427
+ const wordRegex = /\w/;
428
+
394
429
  class Mappings {
395
430
  constructor(hires) {
396
431
  this.hires = hires;
@@ -403,26 +438,67 @@ class Mappings {
403
438
 
404
439
  addEdit(sourceIndex, content, loc, nameIndex) {
405
440
  if (content.length) {
441
+ const contentLengthMinusOne = content.length - 1;
442
+ let contentLineEnd = content.indexOf('\n', 0);
443
+ let previousContentLineEnd = -1;
444
+ // Loop through each line in the content and add a segment, but stop if the last line is empty,
445
+ // else code afterwards would fill one line too many
446
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
447
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
448
+ if (nameIndex >= 0) {
449
+ segment.push(nameIndex);
450
+ }
451
+ this.rawSegments.push(segment);
452
+
453
+ this.generatedCodeLine += 1;
454
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
455
+ this.generatedCodeColumn = 0;
456
+
457
+ previousContentLineEnd = contentLineEnd;
458
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
459
+ }
460
+
406
461
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
407
462
  if (nameIndex >= 0) {
408
463
  segment.push(nameIndex);
409
464
  }
410
465
  this.rawSegments.push(segment);
466
+
467
+ this.advance(content.slice(previousContentLineEnd + 1));
411
468
  } else if (this.pending) {
412
469
  this.rawSegments.push(this.pending);
470
+ this.advance(content);
413
471
  }
414
472
 
415
- this.advance(content);
416
473
  this.pending = null;
417
474
  }
418
475
 
419
476
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
420
477
  let originalCharIndex = chunk.start;
421
478
  let first = true;
479
+ // when iterating each char, check if it's in a word boundary
480
+ let charInHiresBoundary = false;
422
481
 
423
482
  while (originalCharIndex < chunk.end) {
424
483
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
425
- this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
484
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
485
+
486
+ if (this.hires === 'boundary') {
487
+ // in hires "boundary", group segments per word boundary than per char
488
+ if (wordRegex.test(original[originalCharIndex])) {
489
+ // for first char in the boundary found, start the boundary by pushing a segment
490
+ if (!charInHiresBoundary) {
491
+ this.rawSegments.push(segment);
492
+ charInHiresBoundary = true;
493
+ }
494
+ } else {
495
+ // for non-word char, end the boundary by pushing a segment
496
+ this.rawSegments.push(segment);
497
+ charInHiresBoundary = false;
498
+ }
499
+ } else {
500
+ this.rawSegments.push(segment);
501
+ }
426
502
  }
427
503
 
428
504
  if (original[originalCharIndex] === '\n') {
@@ -487,6 +563,7 @@ class MagicString {
487
563
  sourcemapLocations: { writable: true, value: new BitSet() },
488
564
  storedNames: { writable: true, value: {} },
489
565
  indentStr: { writable: true, value: undefined },
566
+ ignoreList: { writable: true, value: options.ignoreList },
490
567
  });
491
568
 
492
569
  this.byStart[0] = chunk;
@@ -594,7 +671,7 @@ class MagicString {
594
671
  sourceIndex,
595
672
  chunk.content,
596
673
  loc,
597
- chunk.storeName ? names.indexOf(chunk.original) : -1
674
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
598
675
  );
599
676
  } else {
600
677
  mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
@@ -604,11 +681,14 @@ class MagicString {
604
681
  });
605
682
 
606
683
  return {
607
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
608
- sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
609
- sourcesContent: options.includeContent ? [this.original] : [null],
684
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
685
+ sources: [
686
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
687
+ ],
688
+ sourcesContent: options.includeContent ? [this.original] : undefined,
610
689
  names,
611
690
  mappings: mappings.raw,
691
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
612
692
  };
613
693
  }
614
694
 
@@ -722,14 +802,14 @@ class MagicString {
722
802
 
723
803
  insert() {
724
804
  throw new Error(
725
- 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
805
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
726
806
  );
727
807
  }
728
808
 
729
809
  insertLeft(index, content) {
730
810
  if (!warned.insertLeft) {
731
811
  console.warn(
732
- 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
812
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
733
813
  ); // eslint-disable-line no-console
734
814
  warned.insertLeft = true;
735
815
  }
@@ -740,7 +820,7 @@ class MagicString {
740
820
  insertRight(index, content) {
741
821
  if (!warned.insertRight) {
742
822
  console.warn(
743
- 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
823
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
744
824
  ); // eslint-disable-line no-console
745
825
  warned.insertRight = true;
746
826
  }
@@ -793,13 +873,15 @@ class MagicString {
793
873
  update(start, end, content, options) {
794
874
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
795
875
 
796
- while (start < 0) start += this.original.length;
797
- while (end < 0) end += this.original.length;
876
+ if (this.original.length !== 0) {
877
+ while (start < 0) start += this.original.length;
878
+ while (end < 0) end += this.original.length;
879
+ }
798
880
 
799
881
  if (end > this.original.length) throw new Error('end is out of bounds');
800
882
  if (start === end)
801
883
  throw new Error(
802
- 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
884
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
803
885
  );
804
886
 
805
887
  this._split(start);
@@ -808,7 +890,7 @@ class MagicString {
808
890
  if (options === true) {
809
891
  if (!warned.storeName) {
810
892
  console.warn(
811
- 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
893
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
812
894
  ); // eslint-disable-line no-console
813
895
  warned.storeName = true;
814
896
  }
@@ -890,8 +972,10 @@ class MagicString {
890
972
  }
891
973
 
892
974
  remove(start, end) {
893
- while (start < 0) start += this.original.length;
894
- while (end < 0) end += this.original.length;
975
+ if (this.original.length !== 0) {
976
+ while (start < 0) start += this.original.length;
977
+ while (end < 0) end += this.original.length;
978
+ }
895
979
 
896
980
  if (start === end) return this;
897
981
 
@@ -913,6 +997,30 @@ class MagicString {
913
997
  return this;
914
998
  }
915
999
 
1000
+ reset(start, end) {
1001
+ if (this.original.length !== 0) {
1002
+ while (start < 0) start += this.original.length;
1003
+ while (end < 0) end += this.original.length;
1004
+ }
1005
+
1006
+ if (start === end) return this;
1007
+
1008
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
1009
+ if (start > end) throw new Error('end must be greater than start');
1010
+
1011
+ this._split(start);
1012
+ this._split(end);
1013
+
1014
+ let chunk = this.byStart[start];
1015
+
1016
+ while (chunk) {
1017
+ chunk.reset();
1018
+
1019
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
1020
+ }
1021
+ return this;
1022
+ }
1023
+
916
1024
  lastChar() {
917
1025
  if (this.outro.length) return this.outro[this.outro.length - 1];
918
1026
  let chunk = this.lastChunk;
@@ -955,8 +1063,10 @@ class MagicString {
955
1063
  }
956
1064
 
957
1065
  slice(start = 0, end = this.original.length) {
958
- while (start < 0) start += this.original.length;
959
- while (end < 0) end += this.original.length;
1066
+ if (this.original.length !== 0) {
1067
+ while (start < 0) start += this.original.length;
1068
+ while (end < 0) end += this.original.length;
1069
+ }
960
1070
 
961
1071
  let result = '';
962
1072
 
@@ -1030,7 +1140,7 @@ class MagicString {
1030
1140
  // zero-length edited chunks are a special case (overlapping replacements)
1031
1141
  const loc = getLocator(this.original)(index);
1032
1142
  throw new Error(
1033
- `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
1143
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1034
1144
  );
1035
1145
  }
1036
1146
 
@@ -1185,21 +1295,29 @@ class MagicString {
1185
1295
  if (searchValue.global) {
1186
1296
  const matches = matchAll(searchValue, this.original);
1187
1297
  matches.forEach((match) => {
1188
- if (match.index != null)
1298
+ if (match.index != null) {
1299
+ const replacement = getReplacement(match, this.original);
1300
+ if (replacement !== match[0]) {
1301
+ this.overwrite(
1302
+ match.index,
1303
+ match.index + match[0].length,
1304
+ replacement
1305
+ );
1306
+ }
1307
+ }
1308
+ });
1309
+ } else {
1310
+ const match = this.original.match(searchValue);
1311
+ if (match && match.index != null) {
1312
+ const replacement = getReplacement(match, this.original);
1313
+ if (replacement !== match[0]) {
1189
1314
  this.overwrite(
1190
1315
  match.index,
1191
1316
  match.index + match[0].length,
1192
- getReplacement(match, this.original)
1317
+ replacement
1193
1318
  );
1194
- });
1195
- } else {
1196
- const match = this.original.match(searchValue);
1197
- if (match && match.index != null)
1198
- this.overwrite(
1199
- match.index,
1200
- match.index + match[0].length,
1201
- getReplacement(match, this.original)
1202
- );
1319
+ }
1320
+ }
1203
1321
  }
1204
1322
  return this;
1205
1323
  }
@@ -1231,7 +1349,9 @@ class MagicString {
1231
1349
  index !== -1;
1232
1350
  index = original.indexOf(string, index + stringLength)
1233
1351
  ) {
1234
- this.overwrite(index, index + stringLength, replacement);
1352
+ const previous = original.slice(index, index + stringLength);
1353
+ if (previous !== replacement)
1354
+ this.overwrite(index, index + stringLength, replacement);
1235
1355
  }
1236
1356
 
1237
1357
  return this;
@@ -1244,7 +1364,7 @@ class MagicString {
1244
1364
 
1245
1365
  if (!searchValue.global) {
1246
1366
  throw new TypeError(
1247
- 'MagicString.prototype.replaceAll called with a non-global RegExp argument'
1367
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
1248
1368
  );
1249
1369
  }
1250
1370
 
@@ -1809,7 +1929,7 @@ function rangeWithTrailingPropertyAccess(originalText, node) {
1809
1929
  */
1810
1930
  function getEnd(node) {
1811
1931
  var _a, _b;
1812
- return isTypescriptNode(node) ? node.expression.end : (_b = (_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : node.end;
1932
+ return isTypescriptNode(node) ? node.expression.end : ((_b = (_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : node.end);
1813
1933
  }
1814
1934
  function isTypescriptNode(node) {
1815
1935
  return (node.type === 'TSAsExpression' ||
@@ -2166,6 +2286,7 @@ class InlineComponent {
2166
2286
  this.eventsTransformation = [];
2167
2287
  this.snippetPropsTransformation = [];
2168
2288
  this.endTransformation = [];
2289
+ this.originalName = this.node.name;
2169
2290
  if (parent) {
2170
2291
  parent.child = this;
2171
2292
  }
@@ -2707,6 +2828,12 @@ function handleBinding(str, attr, parent, element, preserveBind, isSvelte5Plus)
2707
2828
  if (isSvelte5Plus && element instanceof InlineComponent) {
2708
2829
  // To check if property is actually bindable
2709
2830
  element.appendToStartEnd([`${element.name}.$$bindings = '${attr.name}';`]);
2831
+ // To check if the binding is also assigned to the variable (only works when there's no assertion, we can't transform that)
2832
+ if (!isTypescriptNode(attr.expression)) {
2833
+ element.appendToStartEnd([
2834
+ `${expressionStr} = __sveltets_binding_value(${element.originalName}, '${attr.name}');`
2835
+ ]);
2836
+ }
2710
2837
  }
2711
2838
  if (element instanceof Element) {
2712
2839
  element.addAttribute(name, value);
@@ -5310,7 +5437,10 @@ class Scripts {
5310
5437
  // should be 2 at most, one each, so using forEach is safe
5311
5438
  this.topLevelScripts.forEach((tag) => {
5312
5439
  if (tag.attributes &&
5313
- tag.attributes.find((a) => a.name == 'context' && a.value.length == 1 && a.value[0].raw == 'module')) {
5440
+ tag.attributes.find((a) => (a.name == 'context' &&
5441
+ a.value.length == 1 &&
5442
+ a.value[0].raw == 'module') ||
5443
+ a.name === 'module')) {
5314
5444
  moduleScriptTag = tag;
5315
5445
  }
5316
5446
  else {
@@ -6968,7 +7098,11 @@ async function emitDts(config) {
6968
7098
  const likely_failed_files = result.diagnostics.filter((diagnostic) => {
6969
7099
  // List of errors which hint at a failed d.ts generation
6970
7100
  // https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
6971
- return diagnostic.code === 2527 || (diagnostic.code >= 4000 && diagnostic.code <= 4108);
7101
+ return (diagnostic.code === 2527 ||
7102
+ diagnostic.code === 5088 ||
7103
+ diagnostic.code === 2742 ||
7104
+ (diagnostic.code >= 9005 && diagnostic.code <= 9039) ||
7105
+ (diagnostic.code >= 4000 && diagnostic.code <= 4108));
6972
7106
  });
6973
7107
  if (likely_failed_files.length > 0) {
6974
7108
  const failed_by_file = new Map();
@@ -6993,7 +7127,7 @@ function loadTsconfig(config, svelteMap) {
6993
7127
  var _a;
6994
7128
  const libRoot = config.libRoot || process.cwd();
6995
7129
  const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
6996
- let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
7130
+ let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, config.tsconfig);
6997
7131
  if (!tsconfigFile && !jsconfigFile) {
6998
7132
  throw new Error('Failed to locate tsconfig or jsconfig');
6999
7133
  }
package/index.mjs CHANGED
@@ -15,6 +15,20 @@ for (let i = 0; i < chars.length; i++) {
15
15
  intToChar[i] = c;
16
16
  charToInt[c] = i;
17
17
  }
18
+ function encodeInteger(builder, num, relative) {
19
+ let delta = num - relative;
20
+ delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
21
+ do {
22
+ let clamped = delta & 0b011111;
23
+ delta >>>= 5;
24
+ if (delta > 0)
25
+ clamped |= 0b100000;
26
+ builder.write(intToChar[clamped]);
27
+ } while (delta > 0);
28
+ return num;
29
+ }
30
+
31
+ const bufLength = 1024 * 16;
18
32
  // Provide a fallback for older environments.
19
33
  const td = typeof TextDecoder !== 'undefined'
20
34
  ? /* #__PURE__ */ new TextDecoder()
@@ -34,63 +48,54 @@ const td = typeof TextDecoder !== 'undefined'
34
48
  return out;
35
49
  },
36
50
  };
51
+ class StringWriter {
52
+ constructor() {
53
+ this.pos = 0;
54
+ this.out = '';
55
+ this.buffer = new Uint8Array(bufLength);
56
+ }
57
+ write(v) {
58
+ const { buffer } = this;
59
+ buffer[this.pos++] = v;
60
+ if (this.pos === bufLength) {
61
+ this.out += td.decode(buffer);
62
+ this.pos = 0;
63
+ }
64
+ }
65
+ flush() {
66
+ const { buffer, out, pos } = this;
67
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
68
+ }
69
+ }
37
70
  function encode(decoded) {
38
- const state = new Int32Array(5);
39
- const bufLength = 1024 * 16;
40
- const subLength = bufLength - 36;
41
- const buf = new Uint8Array(bufLength);
42
- const sub = buf.subarray(0, subLength);
43
- let pos = 0;
44
- let out = '';
71
+ const writer = new StringWriter();
72
+ let sourcesIndex = 0;
73
+ let sourceLine = 0;
74
+ let sourceColumn = 0;
75
+ let namesIndex = 0;
45
76
  for (let i = 0; i < decoded.length; i++) {
46
77
  const line = decoded[i];
47
- if (i > 0) {
48
- if (pos === bufLength) {
49
- out += td.decode(buf);
50
- pos = 0;
51
- }
52
- buf[pos++] = semicolon;
53
- }
78
+ if (i > 0)
79
+ writer.write(semicolon);
54
80
  if (line.length === 0)
55
81
  continue;
56
- state[0] = 0;
82
+ let genColumn = 0;
57
83
  for (let j = 0; j < line.length; j++) {
58
84
  const segment = line[j];
59
- // We can push up to 5 ints, each int can take at most 7 chars, and we
60
- // may push a comma.
61
- if (pos > subLength) {
62
- out += td.decode(sub);
63
- buf.copyWithin(0, subLength, pos);
64
- pos -= subLength;
65
- }
66
85
  if (j > 0)
67
- buf[pos++] = comma;
68
- pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
86
+ writer.write(comma);
87
+ genColumn = encodeInteger(writer, segment[0], genColumn);
69
88
  if (segment.length === 1)
70
89
  continue;
71
- pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
72
- pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
73
- pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
90
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
91
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
92
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
74
93
  if (segment.length === 4)
75
94
  continue;
76
- pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
95
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
77
96
  }
78
97
  }
79
- return out + td.decode(buf.subarray(0, pos));
80
- }
81
- function encodeInteger(buf, pos, state, segment, j) {
82
- const next = segment[j];
83
- let num = next - state[j];
84
- state[j] = next;
85
- num = num < 0 ? (-num << 1) | 1 : num << 1;
86
- do {
87
- let clamped = num & 0b011111;
88
- num >>>= 5;
89
- if (num > 0)
90
- clamped |= 0b100000;
91
- buf[pos++] = intToChar[clamped];
92
- } while (num > 0);
93
- return pos;
98
+ return writer.flush();
94
99
  }
95
100
 
96
101
  class BitSet {
@@ -187,6 +192,16 @@ class Chunk {
187
192
  this.intro = content + this.intro;
188
193
  }
189
194
 
195
+ reset() {
196
+ this.intro = '';
197
+ this.outro = '';
198
+ if (this.edited) {
199
+ this.content = this.original;
200
+ this.storeName = false;
201
+ this.edited = false;
202
+ }
203
+ }
204
+
190
205
  split(index) {
191
206
  const sliceIndex = index - this.start;
192
207
 
@@ -202,6 +217,13 @@ class Chunk {
202
217
  this.end = index;
203
218
 
204
219
  if (this.edited) {
220
+ // after split we should save the edit content record into the correct chunk
221
+ // to make sure sourcemap correct
222
+ // For example:
223
+ // ' test'.trim()
224
+ // split -> ' ' + 'test'
225
+ // ✔️ edit -> '' + 'test'
226
+ // ✖️ edit -> 'test' + ''
205
227
  // TODO is this block necessary?...
206
228
  newChunk.edit('', false);
207
229
  this.content = '';
@@ -230,6 +252,10 @@ class Chunk {
230
252
  if (trimmed.length) {
231
253
  if (trimmed !== this.content) {
232
254
  this.split(this.start + trimmed.length).edit('', undefined, true);
255
+ if (this.edited) {
256
+ // save the change, if it has been edited
257
+ this.edit(trimmed, this.storeName, true);
258
+ }
233
259
  }
234
260
  return true;
235
261
  } else {
@@ -248,7 +274,11 @@ class Chunk {
248
274
 
249
275
  if (trimmed.length) {
250
276
  if (trimmed !== this.content) {
251
- this.split(this.end - trimmed.length);
277
+ const newChunk = this.split(this.end - trimmed.length);
278
+ if (this.edited) {
279
+ // save the change, if it has been edited
280
+ newChunk.edit(trimmed, this.storeName, true);
281
+ }
252
282
  this.edit('', undefined, true);
253
283
  }
254
284
  return true;
@@ -261,9 +291,9 @@ class Chunk {
261
291
  }
262
292
  }
263
293
 
264
- function getBtoa () {
265
- if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
266
- return (str) => window.btoa(unescape(encodeURIComponent(str)));
294
+ function getBtoa() {
295
+ if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
296
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
267
297
  } else if (typeof Buffer === 'function') {
268
298
  return (str) => Buffer.from(str, 'utf-8').toString('base64');
269
299
  } else {
@@ -283,6 +313,9 @@ class SourceMap {
283
313
  this.sourcesContent = properties.sourcesContent;
284
314
  this.names = properties.names;
285
315
  this.mappings = encode(properties.mappings);
316
+ if (typeof properties.x_google_ignoreList !== 'undefined') {
317
+ this.x_google_ignoreList = properties.x_google_ignoreList;
318
+ }
286
319
  }
287
320
 
288
321
  toString() {
@@ -371,6 +404,8 @@ function getLocator(source) {
371
404
  };
372
405
  }
373
406
 
407
+ const wordRegex = /\w/;
408
+
374
409
  class Mappings {
375
410
  constructor(hires) {
376
411
  this.hires = hires;
@@ -383,26 +418,67 @@ class Mappings {
383
418
 
384
419
  addEdit(sourceIndex, content, loc, nameIndex) {
385
420
  if (content.length) {
421
+ const contentLengthMinusOne = content.length - 1;
422
+ let contentLineEnd = content.indexOf('\n', 0);
423
+ let previousContentLineEnd = -1;
424
+ // Loop through each line in the content and add a segment, but stop if the last line is empty,
425
+ // else code afterwards would fill one line too many
426
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
427
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
428
+ if (nameIndex >= 0) {
429
+ segment.push(nameIndex);
430
+ }
431
+ this.rawSegments.push(segment);
432
+
433
+ this.generatedCodeLine += 1;
434
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
435
+ this.generatedCodeColumn = 0;
436
+
437
+ previousContentLineEnd = contentLineEnd;
438
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
439
+ }
440
+
386
441
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
387
442
  if (nameIndex >= 0) {
388
443
  segment.push(nameIndex);
389
444
  }
390
445
  this.rawSegments.push(segment);
446
+
447
+ this.advance(content.slice(previousContentLineEnd + 1));
391
448
  } else if (this.pending) {
392
449
  this.rawSegments.push(this.pending);
450
+ this.advance(content);
393
451
  }
394
452
 
395
- this.advance(content);
396
453
  this.pending = null;
397
454
  }
398
455
 
399
456
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
400
457
  let originalCharIndex = chunk.start;
401
458
  let first = true;
459
+ // when iterating each char, check if it's in a word boundary
460
+ let charInHiresBoundary = false;
402
461
 
403
462
  while (originalCharIndex < chunk.end) {
404
463
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
405
- this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
464
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
465
+
466
+ if (this.hires === 'boundary') {
467
+ // in hires "boundary", group segments per word boundary than per char
468
+ if (wordRegex.test(original[originalCharIndex])) {
469
+ // for first char in the boundary found, start the boundary by pushing a segment
470
+ if (!charInHiresBoundary) {
471
+ this.rawSegments.push(segment);
472
+ charInHiresBoundary = true;
473
+ }
474
+ } else {
475
+ // for non-word char, end the boundary by pushing a segment
476
+ this.rawSegments.push(segment);
477
+ charInHiresBoundary = false;
478
+ }
479
+ } else {
480
+ this.rawSegments.push(segment);
481
+ }
406
482
  }
407
483
 
408
484
  if (original[originalCharIndex] === '\n') {
@@ -467,6 +543,7 @@ class MagicString {
467
543
  sourcemapLocations: { writable: true, value: new BitSet() },
468
544
  storedNames: { writable: true, value: {} },
469
545
  indentStr: { writable: true, value: undefined },
546
+ ignoreList: { writable: true, value: options.ignoreList },
470
547
  });
471
548
 
472
549
  this.byStart[0] = chunk;
@@ -574,7 +651,7 @@ class MagicString {
574
651
  sourceIndex,
575
652
  chunk.content,
576
653
  loc,
577
- chunk.storeName ? names.indexOf(chunk.original) : -1
654
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
578
655
  );
579
656
  } else {
580
657
  mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
@@ -584,11 +661,14 @@ class MagicString {
584
661
  });
585
662
 
586
663
  return {
587
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
588
- sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
589
- sourcesContent: options.includeContent ? [this.original] : [null],
664
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
665
+ sources: [
666
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
667
+ ],
668
+ sourcesContent: options.includeContent ? [this.original] : undefined,
590
669
  names,
591
670
  mappings: mappings.raw,
671
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
592
672
  };
593
673
  }
594
674
 
@@ -702,14 +782,14 @@ class MagicString {
702
782
 
703
783
  insert() {
704
784
  throw new Error(
705
- 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
785
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
706
786
  );
707
787
  }
708
788
 
709
789
  insertLeft(index, content) {
710
790
  if (!warned.insertLeft) {
711
791
  console.warn(
712
- 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
792
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
713
793
  ); // eslint-disable-line no-console
714
794
  warned.insertLeft = true;
715
795
  }
@@ -720,7 +800,7 @@ class MagicString {
720
800
  insertRight(index, content) {
721
801
  if (!warned.insertRight) {
722
802
  console.warn(
723
- 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
803
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
724
804
  ); // eslint-disable-line no-console
725
805
  warned.insertRight = true;
726
806
  }
@@ -773,13 +853,15 @@ class MagicString {
773
853
  update(start, end, content, options) {
774
854
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
775
855
 
776
- while (start < 0) start += this.original.length;
777
- while (end < 0) end += this.original.length;
856
+ if (this.original.length !== 0) {
857
+ while (start < 0) start += this.original.length;
858
+ while (end < 0) end += this.original.length;
859
+ }
778
860
 
779
861
  if (end > this.original.length) throw new Error('end is out of bounds');
780
862
  if (start === end)
781
863
  throw new Error(
782
- 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
864
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
783
865
  );
784
866
 
785
867
  this._split(start);
@@ -788,7 +870,7 @@ class MagicString {
788
870
  if (options === true) {
789
871
  if (!warned.storeName) {
790
872
  console.warn(
791
- 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
873
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
792
874
  ); // eslint-disable-line no-console
793
875
  warned.storeName = true;
794
876
  }
@@ -870,8 +952,10 @@ class MagicString {
870
952
  }
871
953
 
872
954
  remove(start, end) {
873
- while (start < 0) start += this.original.length;
874
- while (end < 0) end += this.original.length;
955
+ if (this.original.length !== 0) {
956
+ while (start < 0) start += this.original.length;
957
+ while (end < 0) end += this.original.length;
958
+ }
875
959
 
876
960
  if (start === end) return this;
877
961
 
@@ -893,6 +977,30 @@ class MagicString {
893
977
  return this;
894
978
  }
895
979
 
980
+ reset(start, end) {
981
+ if (this.original.length !== 0) {
982
+ while (start < 0) start += this.original.length;
983
+ while (end < 0) end += this.original.length;
984
+ }
985
+
986
+ if (start === end) return this;
987
+
988
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
989
+ if (start > end) throw new Error('end must be greater than start');
990
+
991
+ this._split(start);
992
+ this._split(end);
993
+
994
+ let chunk = this.byStart[start];
995
+
996
+ while (chunk) {
997
+ chunk.reset();
998
+
999
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
1000
+ }
1001
+ return this;
1002
+ }
1003
+
896
1004
  lastChar() {
897
1005
  if (this.outro.length) return this.outro[this.outro.length - 1];
898
1006
  let chunk = this.lastChunk;
@@ -935,8 +1043,10 @@ class MagicString {
935
1043
  }
936
1044
 
937
1045
  slice(start = 0, end = this.original.length) {
938
- while (start < 0) start += this.original.length;
939
- while (end < 0) end += this.original.length;
1046
+ if (this.original.length !== 0) {
1047
+ while (start < 0) start += this.original.length;
1048
+ while (end < 0) end += this.original.length;
1049
+ }
940
1050
 
941
1051
  let result = '';
942
1052
 
@@ -1010,7 +1120,7 @@ class MagicString {
1010
1120
  // zero-length edited chunks are a special case (overlapping replacements)
1011
1121
  const loc = getLocator(this.original)(index);
1012
1122
  throw new Error(
1013
- `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
1123
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
1014
1124
  );
1015
1125
  }
1016
1126
 
@@ -1165,21 +1275,29 @@ class MagicString {
1165
1275
  if (searchValue.global) {
1166
1276
  const matches = matchAll(searchValue, this.original);
1167
1277
  matches.forEach((match) => {
1168
- if (match.index != null)
1278
+ if (match.index != null) {
1279
+ const replacement = getReplacement(match, this.original);
1280
+ if (replacement !== match[0]) {
1281
+ this.overwrite(
1282
+ match.index,
1283
+ match.index + match[0].length,
1284
+ replacement
1285
+ );
1286
+ }
1287
+ }
1288
+ });
1289
+ } else {
1290
+ const match = this.original.match(searchValue);
1291
+ if (match && match.index != null) {
1292
+ const replacement = getReplacement(match, this.original);
1293
+ if (replacement !== match[0]) {
1169
1294
  this.overwrite(
1170
1295
  match.index,
1171
1296
  match.index + match[0].length,
1172
- getReplacement(match, this.original)
1297
+ replacement
1173
1298
  );
1174
- });
1175
- } else {
1176
- const match = this.original.match(searchValue);
1177
- if (match && match.index != null)
1178
- this.overwrite(
1179
- match.index,
1180
- match.index + match[0].length,
1181
- getReplacement(match, this.original)
1182
- );
1299
+ }
1300
+ }
1183
1301
  }
1184
1302
  return this;
1185
1303
  }
@@ -1211,7 +1329,9 @@ class MagicString {
1211
1329
  index !== -1;
1212
1330
  index = original.indexOf(string, index + stringLength)
1213
1331
  ) {
1214
- this.overwrite(index, index + stringLength, replacement);
1332
+ const previous = original.slice(index, index + stringLength);
1333
+ if (previous !== replacement)
1334
+ this.overwrite(index, index + stringLength, replacement);
1215
1335
  }
1216
1336
 
1217
1337
  return this;
@@ -1224,7 +1344,7 @@ class MagicString {
1224
1344
 
1225
1345
  if (!searchValue.global) {
1226
1346
  throw new TypeError(
1227
- 'MagicString.prototype.replaceAll called with a non-global RegExp argument'
1347
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
1228
1348
  );
1229
1349
  }
1230
1350
 
@@ -1789,7 +1909,7 @@ function rangeWithTrailingPropertyAccess(originalText, node) {
1789
1909
  */
1790
1910
  function getEnd(node) {
1791
1911
  var _a, _b;
1792
- return isTypescriptNode(node) ? node.expression.end : (_b = (_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : node.end;
1912
+ return isTypescriptNode(node) ? node.expression.end : ((_b = (_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : node.end);
1793
1913
  }
1794
1914
  function isTypescriptNode(node) {
1795
1915
  return (node.type === 'TSAsExpression' ||
@@ -2146,6 +2266,7 @@ class InlineComponent {
2146
2266
  this.eventsTransformation = [];
2147
2267
  this.snippetPropsTransformation = [];
2148
2268
  this.endTransformation = [];
2269
+ this.originalName = this.node.name;
2149
2270
  if (parent) {
2150
2271
  parent.child = this;
2151
2272
  }
@@ -2687,6 +2808,12 @@ function handleBinding(str, attr, parent, element, preserveBind, isSvelte5Plus)
2687
2808
  if (isSvelte5Plus && element instanceof InlineComponent) {
2688
2809
  // To check if property is actually bindable
2689
2810
  element.appendToStartEnd([`${element.name}.$$bindings = '${attr.name}';`]);
2811
+ // To check if the binding is also assigned to the variable (only works when there's no assertion, we can't transform that)
2812
+ if (!isTypescriptNode(attr.expression)) {
2813
+ element.appendToStartEnd([
2814
+ `${expressionStr} = __sveltets_binding_value(${element.originalName}, '${attr.name}');`
2815
+ ]);
2816
+ }
2690
2817
  }
2691
2818
  if (element instanceof Element) {
2692
2819
  element.addAttribute(name, value);
@@ -5290,7 +5417,10 @@ class Scripts {
5290
5417
  // should be 2 at most, one each, so using forEach is safe
5291
5418
  this.topLevelScripts.forEach((tag) => {
5292
5419
  if (tag.attributes &&
5293
- tag.attributes.find((a) => a.name == 'context' && a.value.length == 1 && a.value[0].raw == 'module')) {
5420
+ tag.attributes.find((a) => (a.name == 'context' &&
5421
+ a.value.length == 1 &&
5422
+ a.value[0].raw == 'module') ||
5423
+ a.name === 'module')) {
5294
5424
  moduleScriptTag = tag;
5295
5425
  }
5296
5426
  else {
@@ -6948,7 +7078,11 @@ async function emitDts(config) {
6948
7078
  const likely_failed_files = result.diagnostics.filter((diagnostic) => {
6949
7079
  // List of errors which hint at a failed d.ts generation
6950
7080
  // https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
6951
- return diagnostic.code === 2527 || (diagnostic.code >= 4000 && diagnostic.code <= 4108);
7081
+ return (diagnostic.code === 2527 ||
7082
+ diagnostic.code === 5088 ||
7083
+ diagnostic.code === 2742 ||
7084
+ (diagnostic.code >= 9005 && diagnostic.code <= 9039) ||
7085
+ (diagnostic.code >= 4000 && diagnostic.code <= 4108));
6952
7086
  });
6953
7087
  if (likely_failed_files.length > 0) {
6954
7088
  const failed_by_file = new Map();
@@ -6973,7 +7107,7 @@ function loadTsconfig(config, svelteMap) {
6973
7107
  var _a;
6974
7108
  const libRoot = config.libRoot || process.cwd();
6975
7109
  const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
6976
- let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
7110
+ let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, config.tsconfig);
6977
7111
  if (!tsconfigFile && !jsconfigFile) {
6978
7112
  throw new Error('Failed to locate tsconfig or jsconfig');
6979
7113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.15",
3
+ "version": "0.7.17",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",
@@ -18,26 +18,26 @@
18
18
  "module": "index.mjs",
19
19
  "types": "index.d.ts",
20
20
  "devDependencies": {
21
- "@jridgewell/sourcemap-codec": "^1.4.14",
22
- "@jridgewell/trace-mapping": "^0.3.17",
21
+ "@jridgewell/sourcemap-codec": "^1.5.0",
22
+ "@jridgewell/trace-mapping": "^0.3.25",
23
23
  "@rollup/plugin-commonjs": "^24.0.0",
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
27
  "@types/estree": "^0.0.42",
28
28
  "@types/mocha": "^9.1.0",
29
- "@types/node": "^16.0.0",
29
+ "@types/node": "^18.0.0",
30
30
  "@types/unist": "^2.0.3",
31
31
  "@types/vfile": "^3.0.2",
32
32
  "builtin-modules": "^3.3.0",
33
33
  "estree-walker": "^2.0.1",
34
- "magic-string": "^0.27.0",
34
+ "magic-string": "^0.30.11",
35
35
  "mocha": "^9.2.0",
36
36
  "periscopic": "^2.0.2",
37
37
  "rollup": "3.7.5",
38
38
  "rollup-plugin-delete": "^2.0.0",
39
39
  "source-map-support": "^0.5.16",
40
- "svelte": "~3.57.0",
40
+ "svelte": "~4.2.19",
41
41
  "tiny-glob": "^0.2.6",
42
42
  "tslib": "^2.4.0",
43
43
  "typescript": "^5.5.2"
@@ -223,9 +223,9 @@ declare type ATypedSvelteComponent = {
223
223
  declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
224
224
  declare function __sveltets_2_ensureComponent<
225
225
  // @ts-ignore svelte.Component doesn't exist in Svelte 4
226
- T extends ConstructorOfATypedSvelteComponent | (0 extends (1 & import('svelte').Component) ? never : import('svelte').Component<any, any, any>) | null | undefined
226
+ T extends ConstructorOfATypedSvelteComponent | (typeof import('svelte') extends { mount: any } ? import('svelte').Component<any, any, any> : never) | null | undefined
227
227
  // @ts-ignore svelte.Component doesn't exist in Svelte 4
228
- >(type: T): NonNullable<T extends ConstructorOfATypedSvelteComponent ? T : 0 extends (1 & import('svelte').Component) ? T : T extends import('svelte').Component<infer Props> ? typeof import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> : T>;
228
+ >(type: T): NonNullable<T extends ConstructorOfATypedSvelteComponent ? T : typeof import('svelte') extends { mount: any } ? T extends import('svelte').Component<infer Props> ? typeof import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> : T : T>;
229
229
  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[];
230
230
 
231
231
  type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
@@ -254,3 +254,16 @@ declare function __sveltets_2_isomorphic_component<
254
254
  declare function __sveltets_2_isomorphic_component_slots<
255
255
  Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
256
256
  >(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;
257
+
258
+ type __sveltets_NonUndefined<T> = T extends undefined ? never : T;
259
+
260
+ declare function __sveltets_binding_value<
261
+ // @ts-ignore this is only used for Svelte 5, which knows about the Component type
262
+ Comp extends typeof import('svelte').Component<any>,
263
+ Key extends string
264
+ >(comp: Comp, key: Key): Key extends keyof import('svelte').ComponentProps<Comp> ?
265
+ // bail on unknown because it hints at a generic type which we can't properly resolve here
266
+ // remove undefined because optional properties have it, and would result in false positives
267
+ unknown extends import('svelte').ComponentProps<Comp>[Key] ? any : __sveltets_NonUndefined<import('svelte').ComponentProps<Comp>[Key]> : any;
268
+ // Overload to ensure typings that only use old SvelteComponent class or something invalid are gracefully handled
269
+ declare function __sveltets_binding_value(comp: any, key: string): any