svelte2tsx 0.7.41 → 0.7.43

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 +23 -6
  2. package/index.mjs +23 -6
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -2183,6 +2183,16 @@ class Element {
2183
2183
  transform(this.str, endStart, this.node.end, this.endTransformation);
2184
2184
  }
2185
2185
  }
2186
+ isCustomElement() {
2187
+ var _a, _b, _c;
2188
+ if (this.tagName.includes('-')) {
2189
+ return true;
2190
+ }
2191
+ if ((_c = (_b = (_a = this.node.attributes) === null || _a === void 0 ? void 0 : _a.find((a) => a.name === 'is')) === null || _b === void 0 ? void 0 : _b.value[0]) === null || _c === void 0 ? void 0 : _c.data.includes('-')) {
2192
+ return true;
2193
+ }
2194
+ return false;
2195
+ }
2186
2196
  getStartTransformation() {
2187
2197
  var _a, _b;
2188
2198
  const createElement = `${this.typingsNamespace}.createElement`;
@@ -2603,7 +2613,7 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
2603
2613
  const transformAttributeCase = (name) => {
2604
2614
  if (!preserveCase &&
2605
2615
  !svgAttributes.find((x) => x == name) &&
2606
- !(element instanceof Element && element.tagName.includes('-')) &&
2616
+ !(element instanceof Element && element.isCustomElement()) &&
2607
2617
  !(svelte5Plus && name.startsWith('on'))) {
2608
2618
  return name.toLowerCase();
2609
2619
  }
@@ -3187,6 +3197,13 @@ function handleMustacheTag(str, node, parent) {
3187
3197
  // handled inside Attribute.ts / StyleDirective.ts
3188
3198
  return;
3189
3199
  }
3200
+ const text = str.original.slice(node.start + 1, node.end - 1);
3201
+ if (text.trimStart().startsWith('{')) {
3202
+ // possibly an object literal, wrapping it in parentheses so it's treated as an expression
3203
+ str.overwrite(node.start, node.start + 1, ';(', { contentOnly: true });
3204
+ str.overwrite(node.end - 1, node.end, ');', { contentOnly: true });
3205
+ return;
3206
+ }
3190
3207
  str.overwrite(node.start, node.start + 1, '', { contentOnly: true });
3191
3208
  str.overwrite(node.end - 1, node.end, ';', { contentOnly: true });
3192
3209
  }
@@ -5072,7 +5089,6 @@ function convertHtmlxToJsx(str, ast, tags, options = { svelte5Plus: false }) {
5072
5089
  case 'Title':
5073
5090
  case 'Document':
5074
5091
  case 'Body':
5075
- case 'SvelteHTML':
5076
5092
  case 'SvelteBoundary':
5077
5093
  case 'Slot':
5078
5094
  case 'SlotTemplate':
@@ -5201,7 +5217,6 @@ function convertHtmlxToJsx(str, ast, tags, options = { svelte5Plus: false }) {
5201
5217
  case 'Head':
5202
5218
  case 'Title':
5203
5219
  case 'Body':
5204
- case 'SvelteHTML':
5205
5220
  case 'SvelteBoundary':
5206
5221
  case 'Document':
5207
5222
  case 'Slot':
@@ -8162,9 +8177,11 @@ function loadTsconfig(config, svelteMap) {
8162
8177
  options: {
8163
8178
  ...options,
8164
8179
  noEmit: false, // Set to true in case of jsconfig, force false, else nothing is emitted
8165
- moduleResolution:
8166
- // NodeJS: up to 4.9, Node10: since 5.0
8167
- (_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10, // Classic if not set, which gives wrong results
8180
+ moduleResolution: options.moduleResolution &&
8181
+ options.moduleResolution !== ts.ModuleResolutionKind.Classic
8182
+ ? options.moduleResolution
8183
+ : // NodeJS: up to 4.9, Node10: since 5.0
8184
+ ((_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10), // Classic if not set, which gives wrong results
8168
8185
  declaration: true, // Needed for d.ts file generation
8169
8186
  emitDeclarationOnly: true, // We only want d.ts file generation
8170
8187
  declarationDir: config.declarationDir, // Where to put the declarations
package/index.mjs CHANGED
@@ -2163,6 +2163,16 @@ class Element {
2163
2163
  transform(this.str, endStart, this.node.end, this.endTransformation);
2164
2164
  }
2165
2165
  }
2166
+ isCustomElement() {
2167
+ var _a, _b, _c;
2168
+ if (this.tagName.includes('-')) {
2169
+ return true;
2170
+ }
2171
+ if ((_c = (_b = (_a = this.node.attributes) === null || _a === void 0 ? void 0 : _a.find((a) => a.name === 'is')) === null || _b === void 0 ? void 0 : _b.value[0]) === null || _c === void 0 ? void 0 : _c.data.includes('-')) {
2172
+ return true;
2173
+ }
2174
+ return false;
2175
+ }
2166
2176
  getStartTransformation() {
2167
2177
  var _a, _b;
2168
2178
  const createElement = `${this.typingsNamespace}.createElement`;
@@ -2583,7 +2593,7 @@ function handleAttribute(str, attr, parent, preserveCase, svelte5Plus, element)
2583
2593
  const transformAttributeCase = (name) => {
2584
2594
  if (!preserveCase &&
2585
2595
  !svgAttributes.find((x) => x == name) &&
2586
- !(element instanceof Element && element.tagName.includes('-')) &&
2596
+ !(element instanceof Element && element.isCustomElement()) &&
2587
2597
  !(svelte5Plus && name.startsWith('on'))) {
2588
2598
  return name.toLowerCase();
2589
2599
  }
@@ -3167,6 +3177,13 @@ function handleMustacheTag(str, node, parent) {
3167
3177
  // handled inside Attribute.ts / StyleDirective.ts
3168
3178
  return;
3169
3179
  }
3180
+ const text = str.original.slice(node.start + 1, node.end - 1);
3181
+ if (text.trimStart().startsWith('{')) {
3182
+ // possibly an object literal, wrapping it in parentheses so it's treated as an expression
3183
+ str.overwrite(node.start, node.start + 1, ';(', { contentOnly: true });
3184
+ str.overwrite(node.end - 1, node.end, ');', { contentOnly: true });
3185
+ return;
3186
+ }
3170
3187
  str.overwrite(node.start, node.start + 1, '', { contentOnly: true });
3171
3188
  str.overwrite(node.end - 1, node.end, ';', { contentOnly: true });
3172
3189
  }
@@ -5052,7 +5069,6 @@ function convertHtmlxToJsx(str, ast, tags, options = { svelte5Plus: false }) {
5052
5069
  case 'Title':
5053
5070
  case 'Document':
5054
5071
  case 'Body':
5055
- case 'SvelteHTML':
5056
5072
  case 'SvelteBoundary':
5057
5073
  case 'Slot':
5058
5074
  case 'SlotTemplate':
@@ -5181,7 +5197,6 @@ function convertHtmlxToJsx(str, ast, tags, options = { svelte5Plus: false }) {
5181
5197
  case 'Head':
5182
5198
  case 'Title':
5183
5199
  case 'Body':
5184
- case 'SvelteHTML':
5185
5200
  case 'SvelteBoundary':
5186
5201
  case 'Document':
5187
5202
  case 'Slot':
@@ -8142,9 +8157,11 @@ function loadTsconfig(config, svelteMap) {
8142
8157
  options: {
8143
8158
  ...options,
8144
8159
  noEmit: false, // Set to true in case of jsconfig, force false, else nothing is emitted
8145
- moduleResolution:
8146
- // NodeJS: up to 4.9, Node10: since 5.0
8147
- (_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10, // Classic if not set, which gives wrong results
8160
+ moduleResolution: options.moduleResolution &&
8161
+ options.moduleResolution !== ts.ModuleResolutionKind.Classic
8162
+ ? options.moduleResolution
8163
+ : // NodeJS: up to 4.9, Node10: since 5.0
8164
+ ((_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10), // Classic if not set, which gives wrong results
8148
8165
  declaration: true, // Needed for d.ts file generation
8149
8166
  emitDeclarationOnly: true, // We only want d.ts file generation
8150
8167
  declarationDir: config.declarationDir, // Where to put the declarations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.41",
3
+ "version": "0.7.43",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "The Svelte Community",
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.8.2"
43
+ "typescript": "^5.9.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0",