pruny 1.21.0 → 1.22.0
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 +52 -40
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10068,15 +10068,24 @@ function removeExportFromLine(rootDir, exp) {
|
|
|
10068
10068
|
}
|
|
10069
10069
|
}
|
|
10070
10070
|
function findDeclarationIndex(lines, name, hintIndex) {
|
|
10071
|
-
|
|
10071
|
+
let searchName = name;
|
|
10072
|
+
if (/^(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|ALL)$/.test(name)) {
|
|
10073
|
+
searchName = "@" + name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
|
10074
|
+
}
|
|
10075
|
+
if (hintIndex >= 0 && hintIndex < lines.length && lines[hintIndex] && lines[hintIndex].includes(searchName)) {
|
|
10072
10076
|
return hintIndex;
|
|
10077
|
+
}
|
|
10073
10078
|
for (let i = 1;i < 50; i++) {
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10079
|
+
const prev = hintIndex - i;
|
|
10080
|
+
if (prev >= 0 && prev < lines.length && lines[prev] && lines[prev].includes(searchName)) {
|
|
10081
|
+
return prev;
|
|
10082
|
+
}
|
|
10083
|
+
const next = hintIndex + i;
|
|
10084
|
+
if (next >= 0 && next < lines.length && lines[next] && lines[next].includes(searchName)) {
|
|
10085
|
+
return next;
|
|
10086
|
+
}
|
|
10078
10087
|
}
|
|
10079
|
-
return lines.findIndex((l) => l.includes(
|
|
10088
|
+
return lines.findIndex((l) => l && l.includes(searchName));
|
|
10080
10089
|
}
|
|
10081
10090
|
function findDeclarationStart(lines, lineIndex) {
|
|
10082
10091
|
let current = lineIndex;
|
|
@@ -10085,7 +10094,19 @@ function findDeclarationStart(lines, lineIndex) {
|
|
|
10085
10094
|
if (prevLine.startsWith("@") || prevLine.startsWith("//") || prevLine.startsWith("/*")) {
|
|
10086
10095
|
current--;
|
|
10087
10096
|
} else if (prevLine === "") {
|
|
10088
|
-
|
|
10097
|
+
let foundDecoratorAbove = false;
|
|
10098
|
+
for (let k = 1;k <= 3; k++) {
|
|
10099
|
+
if (current - 1 - k >= 0) {
|
|
10100
|
+
const checkLine = lines[current - 1 - k].trim();
|
|
10101
|
+
if (checkLine.startsWith("@")) {
|
|
10102
|
+
foundDecoratorAbove = true;
|
|
10103
|
+
break;
|
|
10104
|
+
}
|
|
10105
|
+
if (checkLine !== "")
|
|
10106
|
+
break;
|
|
10107
|
+
}
|
|
10108
|
+
}
|
|
10109
|
+
if (foundDecoratorAbove) {
|
|
10089
10110
|
current--;
|
|
10090
10111
|
} else {
|
|
10091
10112
|
break;
|
|
@@ -10112,59 +10133,50 @@ function deleteDeclaration(lines, startLine, name) {
|
|
|
10112
10133
|
return 0;
|
|
10113
10134
|
let endLine = startLine;
|
|
10114
10135
|
let braceCount = 0;
|
|
10136
|
+
let foundMethodDefinition = false;
|
|
10115
10137
|
let foundBodyOpening = false;
|
|
10116
|
-
let reachedSignature = name === null;
|
|
10117
10138
|
let foundClosing = false;
|
|
10139
|
+
const methodDefRegex = /^(?:export\s+)?(?:public|private|protected|static|async|readonly|\s)*[a-zA-Z0-9_$]+\s*[=(<]/;
|
|
10140
|
+
const methodDefRegexSimple = /^[a-zA-Z0-9_$]+\s*\(/;
|
|
10118
10141
|
for (let i = startLine;i < lines.length; i++) {
|
|
10119
10142
|
const line = lines[i];
|
|
10120
10143
|
const trimmed = line.trim();
|
|
10121
|
-
|
|
10122
|
-
|
|
10144
|
+
const isCommentOrEmpty = trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed === "";
|
|
10145
|
+
const isDecorator = trimmed.startsWith("@");
|
|
10146
|
+
if (!foundMethodDefinition && !isDecorator && !isCommentOrEmpty && braceCount === 0) {
|
|
10147
|
+
if (methodDefRegex.test(trimmed) || methodDefRegexSimple.test(trimmed) || name && (trimmed.includes(` ${name}(`) || trimmed.startsWith(`${name}(`))) {
|
|
10148
|
+
foundMethodDefinition = true;
|
|
10149
|
+
}
|
|
10123
10150
|
}
|
|
10124
10151
|
const openBraces = (line.match(/{/g) || []).length;
|
|
10125
10152
|
const closeBraces = (line.match(/}/g) || []).length;
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
foundBodyOpening
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
foundClosing = true;
|
|
10133
|
-
break;
|
|
10134
|
-
}
|
|
10135
|
-
if (reachedSignature && !foundBodyOpening && braceCount === 0) {
|
|
10136
|
-
if (trimmed.endsWith(";") || trimmed.includes("};")) {
|
|
10153
|
+
if (foundMethodDefinition) {
|
|
10154
|
+
braceCount += openBraces - closeBraces;
|
|
10155
|
+
if (!foundBodyOpening && openBraces > 0) {
|
|
10156
|
+
foundBodyOpening = true;
|
|
10157
|
+
}
|
|
10158
|
+
if (foundBodyOpening && braceCount <= 0) {
|
|
10137
10159
|
endLine = i;
|
|
10138
10160
|
foundClosing = true;
|
|
10139
10161
|
break;
|
|
10140
10162
|
}
|
|
10141
|
-
if (
|
|
10142
|
-
endLine = i
|
|
10163
|
+
if (!foundBodyOpening && trimmed.endsWith(";") && braceCount === 0) {
|
|
10164
|
+
endLine = i;
|
|
10143
10165
|
foundClosing = true;
|
|
10144
10166
|
break;
|
|
10145
10167
|
}
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
foundClosing = true;
|
|
10168
|
+
} else {
|
|
10169
|
+
if (i > startLine + 50) {
|
|
10149
10170
|
break;
|
|
10150
10171
|
}
|
|
10151
10172
|
}
|
|
10152
10173
|
}
|
|
10153
|
-
if (
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
endLine = k;
|
|
10158
|
-
foundClosing = true;
|
|
10159
|
-
break;
|
|
10160
|
-
}
|
|
10161
|
-
}
|
|
10174
|
+
if (foundClosing) {
|
|
10175
|
+
const linesToDelete = endLine - startLine + 1;
|
|
10176
|
+
lines.splice(startLine, linesToDelete);
|
|
10177
|
+
return linesToDelete;
|
|
10162
10178
|
}
|
|
10163
|
-
|
|
10164
|
-
endLine = startLine;
|
|
10165
|
-
const linesToDelete = endLine - startLine + 1;
|
|
10166
|
-
lines.splice(startLine, linesToDelete);
|
|
10167
|
-
return linesToDelete;
|
|
10179
|
+
return 0;
|
|
10168
10180
|
}
|
|
10169
10181
|
function isFileEmpty(content) {
|
|
10170
10182
|
return content.split(`
|