@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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type PrecedingNode } from "./astgrep.js";
|
|
2
|
+
import { type Container } from "./containers.js";
|
|
3
|
+
import { type Range } from "./ranges.js";
|
|
4
|
+
import type { Comment } from "./types.js";
|
|
5
|
+
/** What the shields read of a source besides its text. */
|
|
6
|
+
export interface ShieldContext {
|
|
7
|
+
/** The source's comments, in document order. */
|
|
8
|
+
comments: readonly Comment[];
|
|
9
|
+
/** The comment-only JSX container each comment in one sits in. */
|
|
10
|
+
containerOf: ReadonlyMap<Comment, Container>;
|
|
11
|
+
/** Comments and the containers that may go with theirs, sorted: what code starts after. */
|
|
12
|
+
skippable: readonly Range[];
|
|
13
|
+
/** What stands in front of each comment carrying an ast-grep suppression (see SourceAnalysis). */
|
|
14
|
+
preceding: ReadonlyMap<Comment, PrecedingNode>;
|
|
15
|
+
/** Every directive each directive comment carries (see SourceAnalysis). */
|
|
16
|
+
directives: ReadonlyMap<Comment, readonly string[]>;
|
|
17
|
+
/** The JSDoc comment that keeps the tags of an earlier one off their node (see SourceAnalysis). */
|
|
18
|
+
shadows: ReadonlyMap<Comment, Comment>;
|
|
19
|
+
/** The cast comments a parenthesized expression follows (see SourceAnalysis). */
|
|
20
|
+
casts: ReadonlySet<Comment>;
|
|
21
|
+
}
|
|
22
|
+
export interface Shielding {
|
|
23
|
+
/** The removals that remain once the comments the directives need are kept. */
|
|
24
|
+
removed: Comment[];
|
|
25
|
+
/**
|
|
26
|
+
* Lines (1-based) that a surviving directive reaches: the ones below a
|
|
27
|
+
* next-line directive, the ones a line directive stands on and the ones a
|
|
28
|
+
* coverage hint counts. Each stays a line of its own (see ShieldedLines).
|
|
29
|
+
*/
|
|
30
|
+
lines: Set<number>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Finds what the directives that stay need the removal to leave in place,
|
|
34
|
+
* so that each applies to the same code afterwards, and keeps the comments
|
|
35
|
+
* among it.
|
|
36
|
+
*
|
|
37
|
+
* Most directives reach lines: the line below a next-line directive
|
|
38
|
+
* (`@ts-expect-error`, `eslint-disable-next-line`, ...), the lines a line
|
|
39
|
+
* directive (`eslint-disable-line`, `nosemgrep` after code, ...) stands on,
|
|
40
|
+
* the lines a coverage hint counts. Those lines are shielded: emptied, one
|
|
41
|
+
* stays as an empty line, and none is joined to another — the removal edits
|
|
42
|
+
* see to both (see ShieldedLines), so the comments on them go all the same.
|
|
43
|
+
* Only a comment-only JSX container that would join such a line keeps its
|
|
44
|
+
* comments, as a line break in its place would change what the element
|
|
45
|
+
* renders. To the tools that only a line feed ends a line for (oxlint,
|
|
46
|
+
* Semgrep, ast-grep, c8, Node's test runner), a directive reaches rows that
|
|
47
|
+
* can run over several of those lines, and their lines are shielded as well.
|
|
48
|
+
*
|
|
49
|
+
* Other directives are read with the comments around them, and there a
|
|
50
|
+
* comment has to stay:
|
|
51
|
+
*
|
|
52
|
+
* - below a tsc suppression, the first line each compiler cannot step over
|
|
53
|
+
* in front of the code (see tscReach);
|
|
54
|
+
* - between a directive that only counts as the last comment before its
|
|
55
|
+
* target (`@deno-types`, a fall-through comment, ...), or a coverage hint
|
|
56
|
+
* that ast-v8-to-istanbul only applies to the node right after it, and
|
|
57
|
+
* that target, one comment (see Gap);
|
|
58
|
+
* - in front of a directive that reaches the lines below only where it
|
|
59
|
+
* opens its row, one comment that keeps it from opening it, where those
|
|
60
|
+
* lines hold code (see Front);
|
|
61
|
+
* - a JSX comment container right after a directive in a container
|
|
62
|
+
* (`{/* prettier-ignore */}`, which applies to the next sibling);
|
|
63
|
+
* - the last JSDoc comment of a node in JavaScript, where an earlier one
|
|
64
|
+
* that stays holds tags it keeps off the node;
|
|
65
|
+
* - what an ast-grep suppression is keyed to (see astGrepReach).
|
|
66
|
+
*
|
|
67
|
+
* Each directive a comment carries shields what it reaches, whichever one
|
|
68
|
+
* names the comment. Runs to a fixpoint because a comment kept here can
|
|
69
|
+
* itself be a directive (when directives are being removed selectively).
|
|
70
|
+
*/
|
|
71
|
+
export declare function shieldDirectives(source: string, removed: Comment[], kept: Comment[], skipped: Comment[], context: ShieldContext): Shielding;
|
|
72
|
+
//# sourceMappingURL=shields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shields.d.ts","sourceRoot":"","sources":["../src/shields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,EAA4B,KAAK,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAI7F,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,kEAAkE;IAClE,WAAW,EAAE,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC7C,2FAA2F;IAC3F,SAAS,EAAE,SAAS,KAAK,EAAE,CAAC;IAC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