@kongyo2/ts-comment-scanner 1.20.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/README.md +240 -52
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +23 -19
- package/dist/args.js.map +1 -1
- package/dist/astgrep.d.ts +5 -3
- package/dist/astgrep.d.ts.map +1 -1
- package/dist/astgrep.js +10 -12
- package/dist/astgrep.js.map +1 -1
- package/dist/containers.d.ts +48 -0
- package/dist/containers.d.ts.map +1 -0
- package/dist/containers.js +82 -0
- package/dist/containers.js.map +1 -0
- package/dist/coverage.d.ts +45 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +92 -0
- package/dist/coverage.js.map +1 -0
- package/dist/directives.d.ts +21 -3
- package/dist/directives.d.ts.map +1 -1
- package/dist/directives.js +31 -23
- package/dist/directives.js.map +1 -1
- package/dist/files.d.ts +7 -3
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +129 -82
- package/dist/files.js.map +1 -1
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js +14 -8
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jsx.d.ts.map +1 -1
- package/dist/jsx.js +5 -6
- package/dist/jsx.js.map +1 -1
- package/dist/lines.d.ts +24 -5
- package/dist/lines.d.ts.map +1 -1
- package/dist/lines.js +50 -16
- package/dist/lines.js.map +1 -1
- package/dist/ranges.d.ts +8 -0
- package/dist/ranges.d.ts.map +1 -1
- package/dist/ranges.js +12 -0
- package/dist/ranges.js.map +1 -1
- package/dist/remove.d.ts +18 -14
- package/dist/remove.d.ts.map +1 -1
- package/dist/remove.js +69 -630
- package/dist/remove.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +21 -28
- package/dist/run.js.map +1 -1
- package/dist/scanner.d.ts +34 -0
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +137 -31
- package/dist/scanner.js.map +1 -1
- package/dist/shields.d.ts +72 -0
- package/dist/shields.d.ts.map +1 -0
- package/dist/shields.js +624 -0
- package/dist/shields.js.map +1 -0
- package/dist/splice.d.ts +42 -11
- package/dist/splice.d.ts.map +1 -1
- package/dist/splice.js +189 -56
- package/dist/splice.js.map +1 -1
- package/package.json +2 -1
- package/src/args.ts +21 -21
- package/src/astgrep.ts +11 -13
- package/src/containers.ts +128 -0
- package/src/coverage.ts +110 -0
- package/src/directives.ts +38 -20
- package/src/files.ts +169 -91
- package/src/imports.ts +15 -8
- package/src/index.ts +1 -0
- package/src/jsx.ts +5 -6
- package/src/lines.ts +55 -14
- package/src/ranges.ts +17 -0
- package/src/remove.ts +82 -730
- package/src/run.ts +22 -34
- package/src/scanner.ts +180 -32
- package/src/shields.ts +701 -0
- package/src/splice.ts +224 -60
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { scanComments, type ScanOptions } from "./scanner.js";
|
|
2
|
-
export { collectFiles, decodeFileText, encodeFileText, isJsxFile, readFileText, scanFile, scanPaths, writeFileAtomic, type CollectOptions, type FileEncoding, type FileText, } from "./files.js";
|
|
2
|
+
export { collectFiles, decodeFileText, encodeFileText, isJavaScriptFile, isJsxFile, readFileText, scanFile, scanPaths, writeFileAtomic, type CollectOptions, type FileEncoding, type FileText, } from "./files.js";
|
|
3
3
|
export { changedFiles } from "./git.js";
|
|
4
4
|
export { removeComments, type RemoveOptions, type RemoveResult } from "./remove.js";
|
|
5
5
|
export { detectDirective, isLegalComment, type DirectivePlacement } from "./directives.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,E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ist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { scanComments } from "./scanner.js";
|
|
2
|
-
export { collectFiles, decodeFileText, encodeFileText, isJsxFile, readFileText, scanFile, scanPaths, writeFileAtomic, } from "./files.js";
|
|
2
|
+
export { collectFiles, decodeFileText, encodeFileText, isJavaScriptFile, isJsxFile, readFileText, scanFile, scanPaths, writeFileAtomic, } from "./files.js";
|
|
3
3
|
export { changedFiles } from "./git.js";
|
|
4
4
|
export { removeComments } from "./remove.js";
|
|
5
5
|
export { detectDirective, isLegalComment } from "./directives.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,eAAe,GAIhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAyC,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,cAAc,EAA2B,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,eAAe,GAIhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAyC,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,cAAc,EAA2B,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/jsx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEhE;;;;;;;;;;;GAWG;AAEH,mGAAmG;AACnG,MAAM,WAAW,YAAa,SAAQ,KAAK;IACzC,8FAA8F;IAC9F,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,qEAAqE;IACrE,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,2DAA2D;IAC3D,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,sDAAsD;IACtD,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EACpD,QAAQ,EAAE,SAAS,KAAK,EAAE,GACzB,SAAS,CA4CX"}
|
package/dist/jsx.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { LINE_TERMINATOR, isBlank } from "./lines.js";
|
|
3
|
-
import {
|
|
3
|
+
import { byStart, rangesWithin } from "./ranges.js";
|
|
4
4
|
/**
|
|
5
5
|
* Lays out the children of the given JSX elements and fragments. `comments`
|
|
6
6
|
* are the source's comments, sorted, so containers holding nothing but
|
|
@@ -47,7 +47,7 @@ export function jsxLayout(source, sourceFile, parents, comments) {
|
|
|
47
47
|
}
|
|
48
48
|
segments.push(renderParts(parts));
|
|
49
49
|
}
|
|
50
|
-
containers.sort(
|
|
50
|
+
containers.sort(byStart);
|
|
51
51
|
return { segments, containers, openingTagEnds, closingTagStarts };
|
|
52
52
|
}
|
|
53
53
|
const BOUNDARY = Symbol("boundary");
|
|
@@ -82,16 +82,15 @@ function commentOnlyContainer(source, sourceFile, child, comments) {
|
|
|
82
82
|
// merge-conflict marker, which is no comment.
|
|
83
83
|
const start = child.getStart(sourceFile);
|
|
84
84
|
const end = child.end;
|
|
85
|
+
const inside = rangesWithin(comments, { start, end });
|
|
85
86
|
let cursor = start + 1;
|
|
86
87
|
let uncommented = "";
|
|
87
|
-
|
|
88
|
-
for (let comment = comments[index]; comment !== undefined && comment.end < end; comment = comments[index]) {
|
|
88
|
+
for (const comment of inside) {
|
|
89
89
|
uncommented += source.slice(cursor, comment.start);
|
|
90
90
|
cursor = comment.end;
|
|
91
|
-
index += 1;
|
|
92
91
|
}
|
|
93
92
|
uncommented += source.slice(cursor, end - 1);
|
|
94
|
-
return
|
|
93
|
+
return inside.length > 0 && isBlank(uncommented)
|
|
95
94
|
? { start, end, segment: -1, suspect: false, next: undefined }
|
|
96
95
|
: undefined;
|
|
97
96
|
}
|
package/dist/jsx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.js","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACtD,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrE,IAAI,OAAO,KAAK,EAAE;YAAE,SAAS;QAC7B,QAAQ,IAAI,KAAK,KAAK,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC;IACnE,CAAC;IACD,OAAO,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;AAChD,CAAC;AAED,MAAM,eAAe,GAA6B;IAChD,+DAA+D;IAC/D,cAAc,CAAC,0BAA0B,CAAC;IAC1C,oEAAoE;IACpE,cAAc,CAAC,oBAAoB,CAAC;IACpC,cAAc;CACf,CAAC"}
|
package/dist/lines.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type Range } from "./ranges.js";
|
|
1
2
|
/**
|
|
2
|
-
* Line handling shared by the scanner's consumers.
|
|
3
|
-
* lines the way the TypeScript scanner does:
|
|
4
|
-
* end a line, and CRLF is a single break.
|
|
3
|
+
* Line handling shared by the scanner's consumers. Unless given another line
|
|
4
|
+
* break, everything here counts lines the way the TypeScript scanner does:
|
|
5
|
+
* LF, CR, U+2028 and U+2029 each end a line, and CRLF is a single break.
|
|
5
6
|
*/
|
|
6
7
|
/** Matches one ECMAScript line terminator character. */
|
|
7
8
|
export declare const LINE_TERMINATOR: RegExp;
|
|
@@ -9,10 +10,28 @@ export declare const LINE_TERMINATOR: RegExp;
|
|
|
9
10
|
export declare const LINE_BREAK: RegExp;
|
|
10
11
|
/** True when the text holds nothing but whitespace (a byte-order mark included). */
|
|
11
12
|
export declare function isBlank(text: string): boolean;
|
|
13
|
+
/** True for a space or a tab, the blanks that hold the tokens on a line apart. */
|
|
14
|
+
export declare function isHorizontalSpace(char: string | undefined): boolean;
|
|
12
15
|
/** Splits on every line break, so exotic terminators never leak into single-line output. */
|
|
13
16
|
export declare function splitLines(text: string): string[];
|
|
14
17
|
/** The literal last line of the text, exactly as tsc slices a block comment's closing line. */
|
|
15
18
|
export declare function lastLine(text: string): string;
|
|
16
|
-
/**
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Start offset of every line, numbered the way the scanner numbers them
|
|
21
|
+
* (line 1 starts at index 0) — or, given another `lineBreak`, the way that
|
|
22
|
+
* pattern breaks lines.
|
|
23
|
+
*/
|
|
24
|
+
export declare function lineStartOffsets(source: string, lineBreak?: RegExp): number[];
|
|
25
|
+
/** Index of the line holding the offset, given every line's start offset (see lineStartOffsets). */
|
|
26
|
+
export declare function lineIndexAt(lineStarts: readonly number[], offset: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* True when nothing but whitespace shares the range's first and last lines.
|
|
29
|
+
* Lines are delimited by any ECMAScript line terminator, matching how the
|
|
30
|
+
* scanner numbers them (a lone `\r`, U+2028 and U+2029 count too).
|
|
31
|
+
*/
|
|
32
|
+
export declare function occupiesWholeLines(source: string, range: Range): boolean;
|
|
33
|
+
/** True when nothing but whitespace follows the range on its last line. */
|
|
34
|
+
export declare function closesItsLine(source: string, range: Range): boolean;
|
|
35
|
+
/** True when nothing but whitespace precedes the range on its first line. */
|
|
36
|
+
export declare function opensItsLine(source: string, range: Range): boolean;
|
|
18
37
|
//# sourceMappingURL=lines.d.ts.map
|
package/dist/lines.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../src/lines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kB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAExE;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAEnE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAElE"}
|
package/dist/lines.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { firstIndexAtOrAfter } from "./ranges.js";
|
|
1
2
|
/**
|
|
2
|
-
* Line handling shared by the scanner's consumers.
|
|
3
|
-
* lines the way the TypeScript scanner does:
|
|
4
|
-
* end a line, and CRLF is a single break.
|
|
3
|
+
* Line handling shared by the scanner's consumers. Unless given another line
|
|
4
|
+
* break, everything here counts lines the way the TypeScript scanner does:
|
|
5
|
+
* LF, CR, U+2028 and U+2029 each end a line, and CRLF is a single break.
|
|
5
6
|
*/
|
|
6
7
|
/** Matches one ECMAScript line terminator character. */
|
|
7
8
|
export const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
|
|
@@ -11,6 +12,10 @@ export const LINE_BREAK = /\r\n|[\n\r\u2028\u2029]/;
|
|
|
11
12
|
export function isBlank(text) {
|
|
12
13
|
return /^\s*$/.test(text);
|
|
13
14
|
}
|
|
15
|
+
/** True for a space or a tab, the blanks that hold the tokens on a line apart. */
|
|
16
|
+
export function isHorizontalSpace(char) {
|
|
17
|
+
return char === " " || char === "\t";
|
|
18
|
+
}
|
|
14
19
|
/** Splits on every line break, so exotic terminators never leak into single-line output. */
|
|
15
20
|
export function splitLines(text) {
|
|
16
21
|
return text.split(LINE_BREAK);
|
|
@@ -20,21 +25,50 @@ export function lastLine(text) {
|
|
|
20
25
|
const lines = splitLines(text);
|
|
21
26
|
return lines[lines.length - 1];
|
|
22
27
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Start offset of every line, numbered the way the scanner numbers them
|
|
30
|
+
* (line 1 starts at index 0) — or, given another `lineBreak`, the way that
|
|
31
|
+
* pattern breaks lines.
|
|
32
|
+
*/
|
|
33
|
+
export function lineStartOffsets(source, lineBreak = LINE_BREAK) {
|
|
25
34
|
const starts = [0];
|
|
26
|
-
for (
|
|
27
|
-
|
|
28
|
-
if (char === "\r") {
|
|
29
|
-
// A CRLF pair is one break: skip the LF so it does not open a second line.
|
|
30
|
-
if (source[index + 1] === "\n")
|
|
31
|
-
index += 1;
|
|
32
|
-
starts.push(index + 1);
|
|
33
|
-
}
|
|
34
|
-
else if (char === "\n" || char === "\u2028" || char === "\u2029") {
|
|
35
|
-
starts.push(index + 1);
|
|
36
|
-
}
|
|
35
|
+
for (const match of source.matchAll(new RegExp(lineBreak, "g"))) {
|
|
36
|
+
starts.push(match.index + match[0].length);
|
|
37
37
|
}
|
|
38
38
|
return starts;
|
|
39
39
|
}
|
|
40
|
+
/** Index of the line holding the offset, given every line's start offset (see lineStartOffsets). */
|
|
41
|
+
export function lineIndexAt(lineStarts, offset) {
|
|
42
|
+
return firstIndexAtOrAfter(lineStarts, offset + 1, (start) => start) - 1;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* True when nothing but whitespace shares the range's first and last lines.
|
|
46
|
+
* Lines are delimited by any ECMAScript line terminator, matching how the
|
|
47
|
+
* scanner numbers them (a lone `\r`, U+2028 and U+2029 count too).
|
|
48
|
+
*/
|
|
49
|
+
export function occupiesWholeLines(source, range) {
|
|
50
|
+
return opensItsLine(source, range) && closesItsLine(source, range);
|
|
51
|
+
}
|
|
52
|
+
/** True when nothing but whitespace follows the range on its last line. */
|
|
53
|
+
export function closesItsLine(source, range) {
|
|
54
|
+
return blankToLineEdge(source, range.end, 1);
|
|
55
|
+
}
|
|
56
|
+
/** True when nothing but whitespace precedes the range on its first line. */
|
|
57
|
+
export function opensItsLine(source, range) {
|
|
58
|
+
return blankToLineEdge(source, range.start - 1, -1);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* True when nothing but whitespace lies from the offset on, in the direction
|
|
62
|
+
* of `step`, up to the line break or the edge of the source.
|
|
63
|
+
*/
|
|
64
|
+
function blankToLineEdge(source, from, step) {
|
|
65
|
+
for (let index = from; index >= 0 && index < source.length; index += step) {
|
|
66
|
+
const char = source[index];
|
|
67
|
+
if (LINE_TERMINATOR.test(char))
|
|
68
|
+
return true;
|
|
69
|
+
if (!isBlank(char))
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
40
74
|
//# sourceMappingURL=lines.js.map
|
package/dist/lines.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines.js","sourceRoot":"","sources":["../src/lines.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wDAAwD;AACxD,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAEpD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAEpD,oFAAoF;AACpF,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAW,CAAC;AAC3C,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"lines.js","sourceRoot":"","sources":["../src/lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAc,MAAM,aAAa,CAAC;AAE9D;;;;GAIG;AAEH,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,CAAC,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,KAAY;IAC7D,OAAO,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAY;IACxD,OAAO,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,KAAY;IACvD,OAAO,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,MAAc,EAAE,IAAY,EAAE,IAAY;IACjE,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAW,CAAC;QACrC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/ranges.d.ts
CHANGED
|
@@ -3,8 +3,16 @@ export interface Range {
|
|
|
3
3
|
start: number;
|
|
4
4
|
end: number;
|
|
5
5
|
}
|
|
6
|
+
/** Sort comparator for document order: ranges are ordered by where they start. */
|
|
7
|
+
export declare function byStart(a: Range, b: Range): number;
|
|
6
8
|
/** Index of the first item whose key is at least `value`, by binary search over ascending keys. */
|
|
7
9
|
export declare function firstIndexAtOrAfter<T>(items: readonly T[], value: number, key: (item: T) => number): number;
|
|
8
10
|
/** The range among sorted, non-overlapping ones that contains the offset, if any. */
|
|
9
11
|
export declare function rangeAt<T extends Range>(ranges: readonly T[], offset: number): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The ranges among sorted, non-overlapping ones that lie within the span.
|
|
14
|
+
* Their ends ascend as their starts do, so they are the ones from the first
|
|
15
|
+
* starting at or after the span's start up to the first ending past its end.
|
|
16
|
+
*/
|
|
17
|
+
export declare function rangesWithin<T extends Range>(ranges: readonly T[], span: Range): T[];
|
|
10
18
|
//# sourceMappingURL=ranges.d.ts.map
|
package/dist/ranges.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAS3G;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAG5F"}
|
|
1
|
+
{"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAElD;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAS3G;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAG5F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,CAKpF"}
|
package/dist/ranges.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** Sort comparator for document order: ranges are ordered by where they start. */
|
|
2
|
+
export function byStart(a, b) {
|
|
3
|
+
return a.start - b.start;
|
|
4
|
+
}
|
|
1
5
|
/** Index of the first item whose key is at least `value`, by binary search over ascending keys. */
|
|
2
6
|
export function firstIndexAtOrAfter(items, value, key) {
|
|
3
7
|
let low = 0;
|
|
@@ -16,4 +20,12 @@ export function rangeAt(ranges, offset) {
|
|
|
16
20
|
const range = ranges[firstIndexAtOrAfter(ranges, offset + 1, (candidate) => candidate.start) - 1];
|
|
17
21
|
return range !== undefined && offset < range.end ? range : undefined;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The ranges among sorted, non-overlapping ones that lie within the span.
|
|
25
|
+
* Their ends ascend as their starts do, so they are the ones from the first
|
|
26
|
+
* starting at or after the span's start up to the first ending past its end.
|
|
27
|
+
*/
|
|
28
|
+
export function rangesWithin(ranges, span) {
|
|
29
|
+
return ranges.slice(firstIndexAtOrAfter(ranges, span.start, (range) => range.start), firstIndexAtOrAfter(ranges, span.end + 1, (range) => range.end));
|
|
30
|
+
}
|
|
19
31
|
//# sourceMappingURL=ranges.js.map
|
package/dist/ranges.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ranges.js","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAMA,mGAAmG;AACnG,MAAM,UAAU,mBAAmB,CAAI,KAAmB,EAAE,KAAa,EAAE,GAAwB;IACjG,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IACxB,OAAO,GAAG,GAAG,IAAI,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAM,CAAC,GAAG,KAAK;YAAE,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC;;YACjD,IAAI,GAAG,MAAM,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,OAAO,CAAkB,MAAoB,EAAE,MAAc;IAC3E,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAClG,OAAO,KAAK,KAAK,SAAS,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC"}
|
|
1
|
+
{"version":3,"file":"ranges.js","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAMA,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAC,CAAQ,EAAE,CAAQ;IACxC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;AAC3B,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,mBAAmB,CAAI,KAAmB,EAAE,KAAa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|
jsx?: boolean;
|
|
4
|
+
/** The source is JavaScript (see ScanOptions.javascript). */
|
|
5
|
+
javascript?: boolean;
|
|
4
6
|
/** Also remove compiler/linter directive comments. Default: false (kept for safety). */
|
|
5
7
|
removeDirectives?: boolean;
|
|
6
8
|
/** Also remove license/legal comments. Default: false (kept for safety). */
|
|
@@ -21,15 +23,12 @@ export interface RemoveResult {
|
|
|
21
23
|
removed: Comment[];
|
|
22
24
|
/**
|
|
23
25
|
* Comments kept because they are protected: directives, license headers,
|
|
24
|
-
* comments the `keep` predicate claims, comments
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* would move a position-dependent directive
|
|
31
|
-
* (prettier's first-comment pragma, Deno's coverage file pragma, Bun's
|
|
32
|
-
* file-start marker) into effect.
|
|
26
|
+
* comments the `keep` predicate claims, and the comments a directive that
|
|
27
|
+
* stays is read with — one that stands between it and the code it would
|
|
28
|
+
* otherwise apply to, or in front of it where it would otherwise open its
|
|
29
|
+
* line (see shieldDirectives) — or whose removal would move a
|
|
30
|
+
* position-dependent directive (prettier's first-comment pragma, Deno's
|
|
31
|
+
* coverage file pragma, Bun's file-start marker) into effect.
|
|
33
32
|
*/
|
|
34
33
|
kept: Comment[];
|
|
35
34
|
/** Comments excluded from removal by the `shouldRemove` predicate. */
|
|
@@ -43,11 +42,16 @@ export interface RemoveResult {
|
|
|
43
42
|
* - AST-based ranges: strings, template literals and regexes are never affected.
|
|
44
43
|
* - Directives (`@ts-expect-error`, `eslint-disable`, ...) and license headers are
|
|
45
44
|
* kept by default, since deleting them changes build/lint behaviour.
|
|
46
|
-
* - Surviving comments keep their directive semantics
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
45
|
+
* - Surviving comments keep their directive semantics. The lines a directive
|
|
46
|
+
* covers stay lines of their own: where deleting the comments on one would
|
|
47
|
+
* empty it, an empty line stays in its place, so that the code below moves
|
|
48
|
+
* up under no next-line directive or counted coverage hint, and where it
|
|
49
|
+
* would join one to another line, the comment's own line breaks stay. A
|
|
50
|
+
* comment stays only where a tool reads the directive with it: one between
|
|
51
|
+
* a directive and the code it would otherwise apply to, or one whose
|
|
52
|
+
* removal would newly activate a position-dependent directive (prettier's
|
|
53
|
+
* `@format` docblock pragma counts only as the file's first comment, Bun's
|
|
54
|
+
* `// @bun` only at the very start or right after a shebang line).
|
|
51
55
|
* - A space is inserted where removing a block comment would merge two tokens,
|
|
52
56
|
* and a line break is kept where the comment acted as one (ASI stays intact).
|
|
53
57
|
* - A JSX comment goes with its braces (`{/* note */}`), unless that would
|
package/dist/remove.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../src/remove.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../src/remove.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IACrC,oFAAoF;IACpF,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CAC9C;AAED,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB;;;;;;;;OAQG;IACH,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,sEAAsE;IACtE,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CAsGxF"}
|