svelte2tsx 0.7.27 → 0.7.29

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 +17 -6
  2. package/index.mjs +17 -6
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -6178,15 +6178,20 @@ class HoistableInterfaces {
6178
6178
  if (hoistable.has(this.props_interface.name)) {
6179
6179
  for (const [name, node] of hoistable) {
6180
6180
  let pos = node.pos + astOffset;
6181
- // node.pos includes preceeding whitespace, which could mean we accidentally also move stuff appended to a previous node
6182
- if (name !== '$$ComponentProps') {
6181
+ if (name === '$$ComponentProps') {
6182
+ // So that organize imports doesn't mess with the types
6183
+ str.prependRight(pos, '\n');
6184
+ }
6185
+ else {
6186
+ // node.pos includes preceeding whitespace, which could mean we accidentally also move stuff appended to a previous node
6183
6187
  if (str.original[pos] === '\r') {
6184
6188
  pos++;
6185
6189
  }
6186
6190
  if (/\s/.test(str.original[pos])) {
6187
6191
  pos++;
6188
6192
  }
6189
- // jsdoc comments would be ignored if they are on the same line as the ;, so we add a newline, too
6193
+ // jsdoc comments would be ignored if they are on the same line as the ;, so we add a newline, too.
6194
+ // Also helps with organize imports not messing with the types
6190
6195
  str.prependRight(pos, ';\n');
6191
6196
  str.appendLeft(node.end + astOffset, ';');
6192
6197
  }
@@ -7265,9 +7270,8 @@ function handleImportDeclaration(node, str, astOffset, scriptStart, sourceFile)
7265
7270
  */
7266
7271
  function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
7267
7272
  var _a;
7268
- const firstImport = tsAst.statements
7269
- .filter(ts.isImportDeclaration)
7270
- .sort((a, b) => a.end - b.end)[0];
7273
+ const imports = tsAst.statements.filter(ts.isImportDeclaration).sort((a, b) => a.end - b.end);
7274
+ const firstImport = imports[0];
7271
7275
  if (!firstImport) {
7272
7276
  return;
7273
7277
  }
@@ -7276,6 +7280,13 @@ function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
7276
7280
  ? firstComment.pos + firstImport.getFullStart()
7277
7281
  : firstImport.getStart();
7278
7282
  str.appendRight(start + astOffset, '\n' + (hasModuleScript ? '\n' : ''));
7283
+ // Add a semi-colon to the last import if it doesn't have one, to prevent auto completion
7284
+ // and imports from being added at the wrong position
7285
+ const lastImport = imports[imports.length - 1];
7286
+ const end = lastImport.end + astOffset - 1;
7287
+ if (str.original[end] !== ';') {
7288
+ str.overwrite(end, lastImport.end + astOffset, str.original[end] + ';\n');
7289
+ }
7279
7290
  }
7280
7291
 
7281
7292
  function flatten(arr) {
package/index.mjs CHANGED
@@ -6158,15 +6158,20 @@ class HoistableInterfaces {
6158
6158
  if (hoistable.has(this.props_interface.name)) {
6159
6159
  for (const [name, node] of hoistable) {
6160
6160
  let pos = node.pos + astOffset;
6161
- // node.pos includes preceeding whitespace, which could mean we accidentally also move stuff appended to a previous node
6162
- if (name !== '$$ComponentProps') {
6161
+ if (name === '$$ComponentProps') {
6162
+ // So that organize imports doesn't mess with the types
6163
+ str.prependRight(pos, '\n');
6164
+ }
6165
+ else {
6166
+ // node.pos includes preceeding whitespace, which could mean we accidentally also move stuff appended to a previous node
6163
6167
  if (str.original[pos] === '\r') {
6164
6168
  pos++;
6165
6169
  }
6166
6170
  if (/\s/.test(str.original[pos])) {
6167
6171
  pos++;
6168
6172
  }
6169
- // jsdoc comments would be ignored if they are on the same line as the ;, so we add a newline, too
6173
+ // jsdoc comments would be ignored if they are on the same line as the ;, so we add a newline, too.
6174
+ // Also helps with organize imports not messing with the types
6170
6175
  str.prependRight(pos, ';\n');
6171
6176
  str.appendLeft(node.end + astOffset, ';');
6172
6177
  }
@@ -7245,9 +7250,8 @@ function handleImportDeclaration(node, str, astOffset, scriptStart, sourceFile)
7245
7250
  */
7246
7251
  function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
7247
7252
  var _a;
7248
- const firstImport = tsAst.statements
7249
- .filter(ts.isImportDeclaration)
7250
- .sort((a, b) => a.end - b.end)[0];
7253
+ const imports = tsAst.statements.filter(ts.isImportDeclaration).sort((a, b) => a.end - b.end);
7254
+ const firstImport = imports[0];
7251
7255
  if (!firstImport) {
7252
7256
  return;
7253
7257
  }
@@ -7256,6 +7260,13 @@ function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
7256
7260
  ? firstComment.pos + firstImport.getFullStart()
7257
7261
  : firstImport.getStart();
7258
7262
  str.appendRight(start + astOffset, '\n' + (hasModuleScript ? '\n' : ''));
7263
+ // Add a semi-colon to the last import if it doesn't have one, to prevent auto completion
7264
+ // and imports from being added at the wrong position
7265
+ const lastImport = imports[imports.length - 1];
7266
+ const end = lastImport.end + astOffset - 1;
7267
+ if (str.original[end] !== ';') {
7268
+ str.overwrite(end, lastImport.end + astOffset, str.original[end] + ';\n');
7269
+ }
7259
7270
  }
7260
7271
 
7261
7272
  function flatten(arr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.27",
3
+ "version": "0.7.29",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "svelte": "~4.2.19",
41
41
  "tiny-glob": "^0.2.6",
42
42
  "tslib": "^2.4.0",
43
- "typescript": "^5.6.3"
43
+ "typescript": "~5.6.3"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0",