svelte2tsx 0.7.9 → 0.7.11

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 +28 -17
  2. package/index.mjs +28 -17
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -1480,8 +1480,8 @@ function parseAttributes(str, start) {
1480
1480
  return attrs;
1481
1481
  }
1482
1482
  // Regex ensures that attributes with > characters in them still result in the content being matched correctly
1483
- const scriptRegex = /(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/script>/g;
1484
- const styleRegex = /(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/style>/g;
1483
+ const scriptRegex = /(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/script>/g;
1484
+ const styleRegex = /(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/style>/g;
1485
1485
  function extractTag(htmlx, tag) {
1486
1486
  const exp = tag === 'script' ? scriptRegex : styleRegex;
1487
1487
  const matches = [];
@@ -3092,22 +3092,21 @@ function handleTransitionDirective(str, attr, element) {
3092
3092
  * ```
3093
3093
  */
3094
3094
  function handleSnippet(str, snippetBlock, component) {
3095
- var _a, _b, _c, _d, _e, _f;
3095
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
3096
3096
  const isImplicitProp = component !== undefined;
3097
3097
  const endSnippet = str.original.lastIndexOf('{', snippetBlock.end - 1);
3098
3098
  // Return something to silence the "snippet type not assignable to return type void" error
3099
3099
  str.overwrite(endSnippet, snippetBlock.end, `};return __sveltets_2_any(0)}${isImplicitProp ? '' : ';'}`, {
3100
3100
  contentOnly: true
3101
3101
  });
3102
- const startEnd = str.original.indexOf('}',
3103
- // context was the first iteration in a .next release, remove at some point
3104
- ((_b = (_a = snippetBlock.parameters) === null || _a === void 0 ? void 0 : _a.at(-1)) === null || _b === void 0 ? void 0 : _b.end) || snippetBlock.expression.end) + 1;
3102
+ const lastParameter = (_a = snippetBlock.parameters) === null || _a === void 0 ? void 0 : _a.at(-1);
3103
+ const startEnd = str.original.indexOf('}', (_d = (_c = (_b = lastParameter === null || lastParameter === void 0 ? void 0 : lastParameter.typeAnnotation) === null || _b === void 0 ? void 0 : _b.end) !== null && _c !== void 0 ? _c : lastParameter === null || lastParameter === void 0 ? void 0 : lastParameter.end) !== null && _d !== void 0 ? _d : snippetBlock.expression.end) + 1;
3105
3104
  if (isImplicitProp) {
3106
3105
  str.overwrite(snippetBlock.start, snippetBlock.expression.start, '', { contentOnly: true });
3107
3106
  const transforms = ['('];
3108
- if ((_c = snippetBlock.parameters) === null || _c === void 0 ? void 0 : _c.length) {
3109
- const start = (_d = snippetBlock.parameters) === null || _d === void 0 ? void 0 : _d[0].start;
3110
- const end = snippetBlock.parameters.at(-1).end;
3107
+ if ((_e = snippetBlock.parameters) === null || _e === void 0 ? void 0 : _e.length) {
3108
+ const start = snippetBlock.parameters[0].start;
3109
+ const end = (_g = (_f = lastParameter.typeAnnotation) === null || _f === void 0 ? void 0 : _f.end) !== null && _g !== void 0 ? _g : lastParameter.end;
3111
3110
  transforms.push([start, end]);
3112
3111
  str.overwrite(snippetBlock.expression.end, start, '', {
3113
3112
  contentOnly: true
@@ -3123,14 +3122,26 @@ function handleSnippet(str, snippetBlock, component) {
3123
3122
  }
3124
3123
  else {
3125
3124
  let generic = '';
3126
- if ((_e = snippetBlock.parameters) === null || _e === void 0 ? void 0 : _e.length) {
3125
+ if ((_h = snippetBlock.parameters) === null || _h === void 0 ? void 0 : _h.length) {
3127
3126
  generic = `<[${snippetBlock.parameters
3128
3127
  .map((p) => {
3129
- var _a;
3130
- return ((_a = p.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation)
3131
- ? str.original.slice(p.typeAnnotation.typeAnnotation.start, p.typeAnnotation.typeAnnotation.end)
3132
- : // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
3133
- 'any';
3128
+ var _a, _b;
3129
+ let typeAnnotation = p.typeAnnotation;
3130
+ if (!typeAnnotation && p.type === 'AssignmentPattern') {
3131
+ typeAnnotation = (_a = p.left) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
3132
+ if (!typeAnnotation) {
3133
+ typeAnnotation = (_b = p.right) === null || _b === void 0 ? void 0 : _b.typeAnnotation;
3134
+ }
3135
+ }
3136
+ // fall back to `any` to silence "implicit any" errors; JSDoc people can't add types to snippets
3137
+ let type = 'any';
3138
+ if (typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.typeAnnotation) {
3139
+ type = str.original.slice(typeAnnotation.typeAnnotation.start, typeAnnotation.typeAnnotation.end);
3140
+ }
3141
+ if (p.optional || p.type === 'AssignmentPattern') {
3142
+ type += '?';
3143
+ }
3144
+ return type;
3134
3145
  })
3135
3146
  .join(', ')}]>`;
3136
3147
  }
@@ -3140,9 +3151,9 @@ function handleSnippet(str, snippetBlock, component) {
3140
3151
  [snippetBlock.expression.start, snippetBlock.expression.end],
3141
3152
  typeAnnotation + ' = ('
3142
3153
  ];
3143
- if ((_f = snippetBlock.parameters) === null || _f === void 0 ? void 0 : _f.length) {
3154
+ if ((_j = snippetBlock.parameters) === null || _j === void 0 ? void 0 : _j.length) {
3144
3155
  const start = snippetBlock.parameters[0].start;
3145
- const end = snippetBlock.parameters.at(-1).end;
3156
+ const end = (_l = (_k = lastParameter.typeAnnotation) === null || _k === void 0 ? void 0 : _k.end) !== null && _l !== void 0 ? _l : lastParameter.end;
3146
3157
  transforms.push([start, end]);
3147
3158
  }
3148
3159
  transforms.push(') => {async () => {'); // inner async function for potential #await blocks
package/index.mjs CHANGED
@@ -1460,8 +1460,8 @@ function parseAttributes(str, start) {
1460
1460
  return attrs;
1461
1461
  }
1462
1462
  // Regex ensures that attributes with > characters in them still result in the content being matched correctly
1463
- const scriptRegex = /(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/script>/g;
1464
- const styleRegex = /(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/style>/g;
1463
+ const scriptRegex = /(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/script>/g;
1464
+ const styleRegex = /(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/style>/g;
1465
1465
  function extractTag(htmlx, tag) {
1466
1466
  const exp = tag === 'script' ? scriptRegex : styleRegex;
1467
1467
  const matches = [];
@@ -3072,22 +3072,21 @@ function handleTransitionDirective(str, attr, element) {
3072
3072
  * ```
3073
3073
  */
3074
3074
  function handleSnippet(str, snippetBlock, component) {
3075
- var _a, _b, _c, _d, _e, _f;
3075
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
3076
3076
  const isImplicitProp = component !== undefined;
3077
3077
  const endSnippet = str.original.lastIndexOf('{', snippetBlock.end - 1);
3078
3078
  // Return something to silence the "snippet type not assignable to return type void" error
3079
3079
  str.overwrite(endSnippet, snippetBlock.end, `};return __sveltets_2_any(0)}${isImplicitProp ? '' : ';'}`, {
3080
3080
  contentOnly: true
3081
3081
  });
3082
- const startEnd = str.original.indexOf('}',
3083
- // context was the first iteration in a .next release, remove at some point
3084
- ((_b = (_a = snippetBlock.parameters) === null || _a === void 0 ? void 0 : _a.at(-1)) === null || _b === void 0 ? void 0 : _b.end) || snippetBlock.expression.end) + 1;
3082
+ const lastParameter = (_a = snippetBlock.parameters) === null || _a === void 0 ? void 0 : _a.at(-1);
3083
+ const startEnd = str.original.indexOf('}', (_d = (_c = (_b = lastParameter === null || lastParameter === void 0 ? void 0 : lastParameter.typeAnnotation) === null || _b === void 0 ? void 0 : _b.end) !== null && _c !== void 0 ? _c : lastParameter === null || lastParameter === void 0 ? void 0 : lastParameter.end) !== null && _d !== void 0 ? _d : snippetBlock.expression.end) + 1;
3085
3084
  if (isImplicitProp) {
3086
3085
  str.overwrite(snippetBlock.start, snippetBlock.expression.start, '', { contentOnly: true });
3087
3086
  const transforms = ['('];
3088
- if ((_c = snippetBlock.parameters) === null || _c === void 0 ? void 0 : _c.length) {
3089
- const start = (_d = snippetBlock.parameters) === null || _d === void 0 ? void 0 : _d[0].start;
3090
- const end = snippetBlock.parameters.at(-1).end;
3087
+ if ((_e = snippetBlock.parameters) === null || _e === void 0 ? void 0 : _e.length) {
3088
+ const start = snippetBlock.parameters[0].start;
3089
+ const end = (_g = (_f = lastParameter.typeAnnotation) === null || _f === void 0 ? void 0 : _f.end) !== null && _g !== void 0 ? _g : lastParameter.end;
3091
3090
  transforms.push([start, end]);
3092
3091
  str.overwrite(snippetBlock.expression.end, start, '', {
3093
3092
  contentOnly: true
@@ -3103,14 +3102,26 @@ function handleSnippet(str, snippetBlock, component) {
3103
3102
  }
3104
3103
  else {
3105
3104
  let generic = '';
3106
- if ((_e = snippetBlock.parameters) === null || _e === void 0 ? void 0 : _e.length) {
3105
+ if ((_h = snippetBlock.parameters) === null || _h === void 0 ? void 0 : _h.length) {
3107
3106
  generic = `<[${snippetBlock.parameters
3108
3107
  .map((p) => {
3109
- var _a;
3110
- return ((_a = p.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation)
3111
- ? str.original.slice(p.typeAnnotation.typeAnnotation.start, p.typeAnnotation.typeAnnotation.end)
3112
- : // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
3113
- 'any';
3108
+ var _a, _b;
3109
+ let typeAnnotation = p.typeAnnotation;
3110
+ if (!typeAnnotation && p.type === 'AssignmentPattern') {
3111
+ typeAnnotation = (_a = p.left) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
3112
+ if (!typeAnnotation) {
3113
+ typeAnnotation = (_b = p.right) === null || _b === void 0 ? void 0 : _b.typeAnnotation;
3114
+ }
3115
+ }
3116
+ // fall back to `any` to silence "implicit any" errors; JSDoc people can't add types to snippets
3117
+ let type = 'any';
3118
+ if (typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.typeAnnotation) {
3119
+ type = str.original.slice(typeAnnotation.typeAnnotation.start, typeAnnotation.typeAnnotation.end);
3120
+ }
3121
+ if (p.optional || p.type === 'AssignmentPattern') {
3122
+ type += '?';
3123
+ }
3124
+ return type;
3114
3125
  })
3115
3126
  .join(', ')}]>`;
3116
3127
  }
@@ -3120,9 +3131,9 @@ function handleSnippet(str, snippetBlock, component) {
3120
3131
  [snippetBlock.expression.start, snippetBlock.expression.end],
3121
3132
  typeAnnotation + ' = ('
3122
3133
  ];
3123
- if ((_f = snippetBlock.parameters) === null || _f === void 0 ? void 0 : _f.length) {
3134
+ if ((_j = snippetBlock.parameters) === null || _j === void 0 ? void 0 : _j.length) {
3124
3135
  const start = snippetBlock.parameters[0].start;
3125
- const end = snippetBlock.parameters.at(-1).end;
3136
+ const end = (_l = (_k = lastParameter.typeAnnotation) === null || _k === void 0 ? void 0 : _k.end) !== null && _l !== void 0 ? _l : lastParameter.end;
3126
3137
  transforms.push([start, end]);
3127
3138
  }
3128
3139
  transforms.push(') => {async () => {'); // inner async function for potential #await blocks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.9",
3
+ "version": "0.7.11",
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": "~3.57.0",
41
41
  "tiny-glob": "^0.2.6",
42
42
  "tslib": "^2.4.0",
43
- "typescript": "^5.4.5"
43
+ "typescript": "^5.5.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0",