@kongyo2/ts-comment-scanner 1.9.0 → 1.11.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 +264 -22
- package/dist/args.d.ts +2 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +25 -0
- package/dist/args.js.map +1 -1
- package/dist/directives.d.ts +41 -14
- package/dist/directives.d.ts.map +1 -1
- package/dist/directives.js +103 -32
- package/dist/directives.js.map +1 -1
- package/dist/jsx.d.ts +54 -0
- package/dist/jsx.d.ts.map +1 -0
- package/dist/jsx.js +193 -0
- package/dist/jsx.js.map +1 -0
- package/dist/ranges.d.ts +10 -0
- package/dist/ranges.d.ts.map +1 -0
- package/dist/ranges.js +19 -0
- package/dist/ranges.js.map +1 -0
- package/dist/remove.d.ts +25 -5
- package/dist/remove.d.ts.map +1 -1
- package/dist/remove.js +385 -192
- package/dist/remove.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +5 -1
- package/dist/run.js.map +1 -1
- package/dist/scanner.d.ts +18 -0
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +108 -19
- package/dist/scanner.js.map +1 -1
- package/dist/splice.d.ts +48 -0
- package/dist/splice.d.ts.map +1 -0
- package/dist/splice.js +279 -0
- package/dist/splice.js.map +1 -0
- package/package.json +1 -1
- package/src/args.ts +28 -0
- package/src/directives.ts +148 -35
- package/src/jsx.ts +263 -0
- package/src/ranges.ts +23 -0
- package/src/remove.ts +461 -199
- package/src/run.ts +5 -1
- package/src/scanner.ts +122 -19
- package/src/splice.ts +317 -0
- package/README.en.md +0 -239
package/dist/remove.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ export interface RemoveOptions {
|
|
|
5
5
|
removeDirectives?: boolean;
|
|
6
6
|
/** Also remove license/legal comments. Default: false (kept for safety). */
|
|
7
7
|
removeLegal?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Extra protection: return true to keep a comment the way directives are
|
|
10
|
+
* kept, for markers only a project's own tooling reads (a build template's
|
|
11
|
+
* placeholder, a custom linter tag). Wins over removeDirectives and
|
|
12
|
+
* removeLegal; such comments are reported in `kept`.
|
|
13
|
+
*/
|
|
14
|
+
keep?: (comment: Comment) => boolean;
|
|
8
15
|
/** Extra predicate: return false to leave a comment out of the removal entirely. */
|
|
9
16
|
shouldRemove?: (comment: Comment) => boolean;
|
|
10
17
|
}
|
|
@@ -14,11 +21,13 @@ export interface RemoveResult {
|
|
|
14
21
|
removed: Comment[];
|
|
15
22
|
/**
|
|
16
23
|
* Comments kept because they are protected: directives, license headers,
|
|
17
|
-
* comments
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
24
|
+
* comments the `keep` predicate claims, comments that make a directive
|
|
25
|
+
* trailing rather than standalone (ast-grep's suppression), comments whose
|
|
26
|
+
* removal would shift code under a next-line directive or
|
|
27
|
+
* that sit between a directive and the code it reaches past them for (or
|
|
28
|
+
* the JSX sibling it applies to), and comments whose removal would move a
|
|
29
|
+
* position-dependent directive (prettier's first-comment pragma, Deno's
|
|
30
|
+
* coverage file pragma, Bun's file-start marker) into effect.
|
|
22
31
|
*/
|
|
23
32
|
kept: Comment[];
|
|
24
33
|
/** Comments excluded from removal by the `shouldRemove` predicate. */
|
|
@@ -39,6 +48,17 @@ export interface RemoveResult {
|
|
|
39
48
|
* shebang line), the leading comment is kept instead.
|
|
40
49
|
* - A space is inserted where removing a block comment would merge two tokens,
|
|
41
50
|
* and a line break is kept where the comment acted as one (ASI stays intact).
|
|
51
|
+
* - A JSX comment goes with its braces (`{/* note */}`), unless that would
|
|
52
|
+
* change what the element renders: the braces split the text around them
|
|
53
|
+
* into separate strings, so where they stand between text that renders,
|
|
54
|
+
* `{" "}` takes their place when that keeps the strings identical, and
|
|
55
|
+
* otherwise the braces stay as `{}`. The output is re-parsed to prove every
|
|
56
|
+
* element renders the same strings, under the whitespace rules of
|
|
57
|
+
* TypeScript, esbuild and Babel alike.
|
|
58
|
+
* - Blank lines that only separated a removed comment from the code around it
|
|
59
|
+
* go with it: no pile-up of blank lines where a comment stood between two
|
|
60
|
+
* of them, and at the start or end of the file or of a block only the blank
|
|
61
|
+
* lines already against that edge stay.
|
|
42
62
|
* - A leading byte-order mark is preserved. Reported positions index into the
|
|
43
63
|
* `source` string exactly as `scanComments(source)` reports them (a BOM
|
|
44
64
|
* counts as its first character).
|
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":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,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;;;;;;;;;OASG;IACH,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,sEAAsE;IACtE,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CA0ExF"}
|