@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/cli/bin.js +80 -8
- package/dist/cli/bin.js.map +1 -1
- package/dist/index.js +80 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/bin.js
CHANGED
|
@@ -1516,11 +1516,83 @@ function removeInterfaceBlock(source) {
|
|
|
1516
1516
|
out = out.slice(0, match.index) + out.slice(endIdx);
|
|
1517
1517
|
}
|
|
1518
1518
|
}
|
|
1519
|
+
function findStringEnd(source, openIdx) {
|
|
1520
|
+
const quote = source[openIdx];
|
|
1521
|
+
let i = openIdx + 1;
|
|
1522
|
+
while (i < source.length) {
|
|
1523
|
+
const ch = source[i];
|
|
1524
|
+
if (ch === "\\") {
|
|
1525
|
+
i += 2;
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (ch === quote) return i;
|
|
1529
|
+
i++;
|
|
1530
|
+
}
|
|
1531
|
+
return -1;
|
|
1532
|
+
}
|
|
1533
|
+
function maskStringLiterals(source) {
|
|
1534
|
+
const strings = [];
|
|
1535
|
+
let out = "";
|
|
1536
|
+
let i = 0;
|
|
1537
|
+
while (i < source.length) {
|
|
1538
|
+
const ch = source[i];
|
|
1539
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1540
|
+
const closeIdx = findStringEnd(source, i);
|
|
1541
|
+
if (closeIdx === -1) {
|
|
1542
|
+
out += source.slice(i);
|
|
1543
|
+
break;
|
|
1544
|
+
}
|
|
1545
|
+
const literal = source.slice(i, closeIdx + 1);
|
|
1546
|
+
out += `__RDMNT_STR_${strings.length}__`;
|
|
1547
|
+
strings.push(literal);
|
|
1548
|
+
i = closeIdx + 1;
|
|
1549
|
+
} else {
|
|
1550
|
+
out += ch;
|
|
1551
|
+
i++;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return {
|
|
1555
|
+
masked: out,
|
|
1556
|
+
restore: (s) => s.replace(/__RDMNT_STR_(\d+)__/g, (_full, idx) => strings[Number(idx)] ?? "")
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
var PROPS_DECL = /let\s*\{([^}]*)\}\s*(?::\s*\{([^}]*)\})?\s*=\s*\$props\(\)\s*;?/;
|
|
1560
|
+
function injectRestIntoProps(scriptBody) {
|
|
1561
|
+
const match = scriptBody.match(PROPS_DECL);
|
|
1562
|
+
if (!match) return scriptBody;
|
|
1563
|
+
const destructured = match[1] ?? "";
|
|
1564
|
+
if (/\.\.\.\s*\w+/.test(destructured)) return scriptBody;
|
|
1565
|
+
const trimmed = destructured.trim();
|
|
1566
|
+
const newDestructured = trimmed === "" ? " ...rest " : ` ${trimmed}, ...rest `;
|
|
1567
|
+
let replacement;
|
|
1568
|
+
if (match[2] !== void 0) {
|
|
1569
|
+
const typeBody = match[2];
|
|
1570
|
+
const hasIndexSig = /\[\s*key\s*:\s*string\s*\]\s*:/.test(typeBody);
|
|
1571
|
+
const newTypeBody = hasIndexSig ? typeBody : `${typeBody.trimEnd().replace(/;?\s*$/, "")}; [key: string]: unknown `;
|
|
1572
|
+
replacement = `let {${newDestructured}}: {${newTypeBody}} = $props();`;
|
|
1573
|
+
} else {
|
|
1574
|
+
replacement = `let {${newDestructured}} = $props();`;
|
|
1575
|
+
}
|
|
1576
|
+
return scriptBody.replace(PROPS_DECL, replacement);
|
|
1577
|
+
}
|
|
1578
|
+
var SCRIPT_BLOCK3 = /<script\b([^>]*)>([\s\S]*?)<\/script>/;
|
|
1579
|
+
var HAS_PROPS_CALL = /\$props\(\s*\)/;
|
|
1519
1580
|
function removeDollarRestProps(source) {
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1581
|
+
const next = removeInterfaceBlock(source);
|
|
1582
|
+
const scriptMatch = next.match(SCRIPT_BLOCK3);
|
|
1583
|
+
if (!scriptMatch) return next;
|
|
1584
|
+
if (!HAS_PROPS_CALL.test(scriptMatch[2] ?? "")) {
|
|
1585
|
+
return next;
|
|
1586
|
+
}
|
|
1587
|
+
const scriptInner = scriptMatch[2] ?? "";
|
|
1588
|
+
const { masked, restore } = maskStringLiterals(scriptInner);
|
|
1589
|
+
let processed = injectRestIntoProps(masked);
|
|
1590
|
+
processed = processed.replace(/\$\$restProps/g, "rest");
|
|
1591
|
+
const restoredInner = restore(processed);
|
|
1592
|
+
const newScriptBlock = scriptMatch[0].replace(scriptInner, () => restoredInner);
|
|
1593
|
+
const before = next.slice(0, scriptMatch.index);
|
|
1594
|
+
const after = next.slice(scriptMatch.index + scriptMatch[0].length);
|
|
1595
|
+
return before.replace(/\$\$restProps/g, "rest") + newScriptBlock + after.replace(/\$\$restProps/g, "rest");
|
|
1524
1596
|
}
|
|
1525
1597
|
|
|
1526
1598
|
// src/recipes/svelte-5/codemods/state-effect-sync.ts
|
|
@@ -1536,12 +1608,12 @@ function stateEffectSyncToDerived(source) {
|
|
|
1536
1608
|
var PROPS_DESTRUCTURE = /let\s*\{([\s\S]*?)\}(\s*:\s*\{([\s\S]*?)\})?\s*=\s*\$props\(\)/;
|
|
1537
1609
|
var DOLLAR_PROPS_CLASS = /\$\$props\.class\b/g;
|
|
1538
1610
|
var DOLLAR_PROPS_ANY = /\$\$props\b/;
|
|
1539
|
-
var
|
|
1611
|
+
var SCRIPT_BLOCK4 = /<script\b[^>]*>[\s\S]*?<\/script>/g;
|
|
1540
1612
|
var MIGRATION_TASK = /^<!--\s*@migration-task[\s\S]*?-->\s*\n?/gm;
|
|
1541
1613
|
var IDENT = "className";
|
|
1542
1614
|
function maskScripts(source) {
|
|
1543
1615
|
const blocks = [];
|
|
1544
|
-
const masked = source.replace(
|
|
1616
|
+
const masked = source.replace(SCRIPT_BLOCK4, (m) => {
|
|
1545
1617
|
blocks.push(m);
|
|
1546
1618
|
return `__SCRIPT_${blocks.length - 1}__`;
|
|
1547
1619
|
});
|
|
@@ -1581,7 +1653,7 @@ function dollarPropsClass(source) {
|
|
|
1581
1653
|
}
|
|
1582
1654
|
|
|
1583
1655
|
// src/recipes/svelte-5/codemods/legacy-reactive.ts
|
|
1584
|
-
var
|
|
1656
|
+
var SCRIPT_BLOCK5 = /<script\b([^>]*)>([\s\S]*?)<\/script>/g;
|
|
1585
1657
|
var SIMPLE_REACTIVE = /^([ \t]*)\$:\s*(\w+)\s*=\s*([^;\n]+);?[ \t]*$/gm;
|
|
1586
1658
|
var BLOCK_REACTIVE_HEAD = /(^|\n)([ \t]*)\$:\s*\{/g;
|
|
1587
1659
|
function findMatchingClose(source, openIdx) {
|
|
@@ -1646,7 +1718,7 @@ function transformSimple(body) {
|
|
|
1646
1718
|
});
|
|
1647
1719
|
}
|
|
1648
1720
|
function legacyReactiveToRunes(source) {
|
|
1649
|
-
return source.replace(
|
|
1721
|
+
return source.replace(SCRIPT_BLOCK5, (full, _attrs, body) => {
|
|
1650
1722
|
let next = transformBlocks(body);
|
|
1651
1723
|
next = transformSimple(next);
|
|
1652
1724
|
if (next === body) return full;
|