@kongyo2/ts-comment-scanner 1.18.0 → 1.20.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/src/splice.ts CHANGED
@@ -11,6 +11,13 @@ export interface Edit extends Range {
11
11
  * those neighbours are JSX text and tags, not tokens.
12
12
  */
13
13
  jsx?: boolean;
14
+ /**
15
+ * An empty line takes the deleted range's place, instead of its lines
16
+ * vanishing or joining what surrounds them: what precedes the range on its
17
+ * first line ends there, and what follows it on its last line starts below
18
+ * the empty line.
19
+ */
20
+ blankLine?: boolean;
14
21
  }
15
22
 
16
23
  const isHorizontalSpace = (char: string | undefined): boolean => char === " " || char === "\t";
@@ -124,6 +131,23 @@ export function applyEdits(source: string, edits: readonly Edit[]): string {
124
131
  const restContent = source.slice(cursor, contentEnd);
125
132
  const deleted = source.slice(edit.start, edit.end);
126
133
 
134
+ if (edit.blankLine === true) {
135
+ // Both line breaks around the empty line end in a line feed, which tsc
136
+ // and dprint alike count, so after a lone CR, U+2028 or U+2029 one more
137
+ // goes in.
138
+ const lineFeed = source.slice(edit.start, lineEnd).includes("\r\n") ? "\r\n" : "\n";
139
+ if (lineIsBlank) {
140
+ dropCurrentLine(false);
141
+ if (lastChar !== "\n") push(lineFeed);
142
+ } else {
143
+ trimLineEnd();
144
+ push(lineFeed);
145
+ }
146
+ push(lineFeed);
147
+ cursor = isBlank(restContent) ? lineEnd : skipSpaces(cursor);
148
+ continue;
149
+ }
150
+
127
151
  if (lineIsBlank && isBlank(restContent)) {
128
152
  // The range occupied whole line(s): drop them entirely, with the
129
153
  // break that ends them — or, when that one is a line feed and the