@reddoorla/maintenance 0.6.3 → 0.6.4

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/dist/index.js CHANGED
@@ -1242,11 +1242,83 @@ function removeInterfaceBlock(source) {
1242
1242
  out = out.slice(0, match.index) + out.slice(endIdx);
1243
1243
  }
1244
1244
  }
1245
+ function findStringEnd(source, openIdx) {
1246
+ const quote = source[openIdx];
1247
+ let i = openIdx + 1;
1248
+ while (i < source.length) {
1249
+ const ch = source[i];
1250
+ if (ch === "\\") {
1251
+ i += 2;
1252
+ continue;
1253
+ }
1254
+ if (ch === quote) return i;
1255
+ i++;
1256
+ }
1257
+ return -1;
1258
+ }
1259
+ function maskStringLiterals(source) {
1260
+ const strings = [];
1261
+ let out = "";
1262
+ let i = 0;
1263
+ while (i < source.length) {
1264
+ const ch = source[i];
1265
+ if (ch === '"' || ch === "'" || ch === "`") {
1266
+ const closeIdx = findStringEnd(source, i);
1267
+ if (closeIdx === -1) {
1268
+ out += source.slice(i);
1269
+ break;
1270
+ }
1271
+ const literal = source.slice(i, closeIdx + 1);
1272
+ out += `__RDMNT_STR_${strings.length}__`;
1273
+ strings.push(literal);
1274
+ i = closeIdx + 1;
1275
+ } else {
1276
+ out += ch;
1277
+ i++;
1278
+ }
1279
+ }
1280
+ return {
1281
+ masked: out,
1282
+ restore: (s) => s.replace(/__RDMNT_STR_(\d+)__/g, (_full, idx) => strings[Number(idx)] ?? "")
1283
+ };
1284
+ }
1285
+ var PROPS_DECL = /let\s*\{([^}]*)\}\s*(?::\s*\{([^}]*)\})?\s*=\s*\$props\(\)\s*;?/;
1286
+ function injectRestIntoProps(scriptBody) {
1287
+ const match = scriptBody.match(PROPS_DECL);
1288
+ if (!match) return scriptBody;
1289
+ const destructured = match[1] ?? "";
1290
+ if (/\.\.\.\s*\w+/.test(destructured)) return scriptBody;
1291
+ const trimmed = destructured.trim();
1292
+ const newDestructured = trimmed === "" ? " ...rest " : ` ${trimmed}, ...rest `;
1293
+ let replacement;
1294
+ if (match[2] !== void 0) {
1295
+ const typeBody = match[2];
1296
+ const hasIndexSig = /\[\s*key\s*:\s*string\s*\]\s*:/.test(typeBody);
1297
+ const newTypeBody = hasIndexSig ? typeBody : `${typeBody.trimEnd().replace(/;?\s*$/, "")}; [key: string]: unknown `;
1298
+ replacement = `let {${newDestructured}}: {${newTypeBody}} = $props();`;
1299
+ } else {
1300
+ replacement = `let {${newDestructured}} = $props();`;
1301
+ }
1302
+ return scriptBody.replace(PROPS_DECL, replacement);
1303
+ }
1304
+ var SCRIPT_BLOCK3 = /<script\b([^>]*)>([\s\S]*?)<\/script>/;
1305
+ var HAS_PROPS_CALL = /\$props\(\s*\)/;
1245
1306
  function removeDollarRestProps(source) {
1246
- let next = source;
1247
- next = next.replace(/\$\$restProps/g, "rest");
1248
- next = removeInterfaceBlock(next);
1249
- return next;
1307
+ const next = removeInterfaceBlock(source);
1308
+ const scriptMatch = next.match(SCRIPT_BLOCK3);
1309
+ if (!scriptMatch) return next;
1310
+ if (!HAS_PROPS_CALL.test(scriptMatch[2] ?? "")) {
1311
+ return next;
1312
+ }
1313
+ const scriptInner = scriptMatch[2] ?? "";
1314
+ const { masked, restore } = maskStringLiterals(scriptInner);
1315
+ let processed = injectRestIntoProps(masked);
1316
+ processed = processed.replace(/\$\$restProps/g, "rest");
1317
+ const restoredInner = restore(processed);
1318
+ const newScriptBlock = scriptMatch[0].replace(scriptInner, () => restoredInner);
1319
+ const before = next.slice(0, scriptMatch.index);
1320
+ const after = next.slice(scriptMatch.index + scriptMatch[0].length);
1321
+ return before.replace(/\$\$restProps/g, "rest") + newScriptBlock + after.replace(/\$\$restProps/g, "rest");
1250
1322
  }
1251
1323
 
1252
1324
  // src/recipes/svelte-5/codemods/state-effect-sync.ts
@@ -1262,12 +1334,12 @@ function stateEffectSyncToDerived(source) {
1262
1334
  var PROPS_DESTRUCTURE = /let\s*\{([\s\S]*?)\}(\s*:\s*\{([\s\S]*?)\})?\s*=\s*\$props\(\)/;
1263
1335
  var DOLLAR_PROPS_CLASS = /\$\$props\.class\b/g;
1264
1336
  var DOLLAR_PROPS_ANY = /\$\$props\b/;
1265
- var SCRIPT_BLOCK3 = /<script\b[^>]*>[\s\S]*?<\/script>/g;
1337
+ var SCRIPT_BLOCK4 = /<script\b[^>]*>[\s\S]*?<\/script>/g;
1266
1338
  var MIGRATION_TASK = /^<!--\s*@migration-task[\s\S]*?-->\s*\n?/gm;
1267
1339
  var IDENT = "className";
1268
1340
  function maskScripts(source) {
1269
1341
  const blocks = [];
1270
- const masked = source.replace(SCRIPT_BLOCK3, (m) => {
1342
+ const masked = source.replace(SCRIPT_BLOCK4, (m) => {
1271
1343
  blocks.push(m);
1272
1344
  return `__SCRIPT_${blocks.length - 1}__`;
1273
1345
  });
@@ -1307,7 +1379,7 @@ function dollarPropsClass(source) {
1307
1379
  }
1308
1380
 
1309
1381
  // src/recipes/svelte-5/codemods/legacy-reactive.ts
1310
- var SCRIPT_BLOCK4 = /<script\b([^>]*)>([\s\S]*?)<\/script>/g;
1382
+ var SCRIPT_BLOCK5 = /<script\b([^>]*)>([\s\S]*?)<\/script>/g;
1311
1383
  var SIMPLE_REACTIVE = /^([ \t]*)\$:\s*(\w+)\s*=\s*([^;\n]+);?[ \t]*$/gm;
1312
1384
  var BLOCK_REACTIVE_HEAD = /(^|\n)([ \t]*)\$:\s*\{/g;
1313
1385
  function findMatchingClose(source, openIdx) {
@@ -1372,7 +1444,7 @@ function transformSimple(body) {
1372
1444
  });
1373
1445
  }
1374
1446
  function legacyReactiveToRunes(source) {
1375
- return source.replace(SCRIPT_BLOCK4, (full, _attrs, body) => {
1447
+ return source.replace(SCRIPT_BLOCK5, (full, _attrs, body) => {
1376
1448
  let next = transformBlocks(body);
1377
1449
  next = transformSimple(next);
1378
1450
  if (next === body) return full;