@kongyo2/ts-comment-scanner 1.11.1 → 1.15.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/astgrep.d.ts +51 -0
- package/dist/astgrep.d.ts.map +1 -0
- package/dist/astgrep.js +85 -0
- package/dist/astgrep.js.map +1 -0
- package/dist/directives.d.ts +32 -4
- package/dist/directives.d.ts.map +1 -1
- package/dist/directives.js +219 -90
- package/dist/directives.js.map +1 -1
- package/dist/remove.d.ts +9 -7
- package/dist/remove.d.ts.map +1 -1
- package/dist/remove.js +163 -80
- package/dist/remove.js.map +1 -1
- package/dist/scanner.d.ts +3 -11
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +73 -23
- package/dist/scanner.js.map +1 -1
- package/dist/splice.d.ts.map +1 -1
- package/dist/splice.js +19 -9
- package/dist/splice.js.map +1 -1
- package/package.json +1 -1
- package/src/astgrep.ts +115 -0
- package/src/directives.ts +252 -94
- package/src/remove.ts +205 -85
- package/src/scanner.ts +79 -24
- package/src/splice.ts +19 -9
package/src/splice.ts
CHANGED
|
@@ -60,8 +60,12 @@ export function applyEdits(source: string, edits: readonly Edit[]): string {
|
|
|
60
60
|
lastChar = chunk.slice(-1);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Deletes everything the output holds after its last line break, and that
|
|
65
|
+
* break too when `takeBreak` asks for it and the break holds no line feed;
|
|
66
|
+
* returns whether it went.
|
|
67
|
+
*/
|
|
68
|
+
const dropCurrentLine = (takeBreak: boolean): boolean => {
|
|
65
69
|
while (segments.length > 0) {
|
|
66
70
|
const last = segments[segments.length - 1] as string;
|
|
67
71
|
const breakEnd = lastLineBreakEnd(last);
|
|
@@ -69,13 +73,15 @@ export function applyEdits(source: string, edits: readonly Edit[]): string {
|
|
|
69
73
|
segments.pop();
|
|
70
74
|
continue;
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const tookBreak = takeBreak && last.charAt(breakEnd - 1) !== "\n";
|
|
77
|
+
segments[segments.length - 1] = last.slice(0, tookBreak ? breakEnd - 1 : breakEnd);
|
|
78
|
+
lineIsBlank = !tookBreak;
|
|
79
|
+
lastChar = last.charAt(breakEnd - (tookBreak ? 2 : 1));
|
|
80
|
+
return tookBreak;
|
|
76
81
|
}
|
|
77
82
|
lineIsBlank = true;
|
|
78
83
|
lastChar = "";
|
|
84
|
+
return false;
|
|
79
85
|
};
|
|
80
86
|
|
|
81
87
|
/**
|
|
@@ -119,9 +125,13 @@ export function applyEdits(source: string, edits: readonly Edit[]): string {
|
|
|
119
125
|
const deleted = source.slice(edit.start, edit.end);
|
|
120
126
|
|
|
121
127
|
if (lineIsBlank && isBlank(restContent)) {
|
|
122
|
-
// The range occupied whole line(s): drop them entirely
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
// The range occupied whole line(s): drop them entirely, with the
|
|
129
|
+
// break that ends them — or, when that one is a line feed and the
|
|
130
|
+
// break in front of them is not, with that one instead. tree-sitter
|
|
131
|
+
// (and so ast-grep) starts a row at a line feed alone, so the rows
|
|
132
|
+
// around the dropped lines stay apart, while tsc sees one break either
|
|
133
|
+
// way.
|
|
134
|
+
cursor = dropCurrentLine(lineBreak?.[0].endsWith("\n") === true) ? contentEnd : lineEnd;
|
|
125
135
|
} else if (isBlank(restContent)) {
|
|
126
136
|
// Trailing after code: trim the gap, keep the line break.
|
|
127
137
|
trimLineEnd();
|