@blundergoat/gruff-ts 0.5.0 → 0.6.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/CONTRIBUTING.md +32 -25
  3. package/README.md +49 -50
  4. package/SECURITY.md +18 -31
  5. package/UPGRADING.md +101 -0
  6. package/bin/gruff-ts +3 -0
  7. package/docs/README.md +11 -10
  8. package/docs/agent-hook.md +32 -35
  9. package/docs/ci-integration.md +38 -24
  10. package/docs/configuration.md +160 -89
  11. package/docs/dashboard.md +12 -13
  12. package/docs/output-formats.md +100 -25
  13. package/docs/philosophy.md +2 -2
  14. package/docs/reports-and-ci.md +14 -172
  15. package/docs/rules.md +126 -98
  16. package/package.json +10 -8
  17. package/src/analyser.ts +817 -323
  18. package/src/baseline-file.ts +867 -0
  19. package/src/baseline-identity.ts +463 -0
  20. package/src/baseline-options.ts +139 -34
  21. package/src/baseline.ts +62 -68
  22. package/src/blocks.ts +512 -336
  23. package/src/changed-regions.ts +380 -79
  24. package/src/check-ignore.ts +28 -13
  25. package/src/class-rules.ts +445 -436
  26. package/src/cli-program.ts +915 -172
  27. package/src/cli.ts +9 -3
  28. package/src/comment-rules.ts +236 -418
  29. package/src/comment-scanner.ts +339 -47
  30. package/src/complexity-metrics.ts +111 -35
  31. package/src/config-load-error.ts +17 -8
  32. package/src/config-parse.ts +291 -98
  33. package/src/config-preservation.ts +81 -26
  34. package/src/config.ts +751 -223
  35. package/src/constants.ts +7 -6
  36. package/src/context-doc-rules.ts +182 -54
  37. package/src/dashboard.ts +88 -23
  38. package/src/dead-code-rules.ts +153 -74
  39. package/src/discovery.ts +493 -140
  40. package/src/doc-rules.ts +602 -126
  41. package/src/duplicate-test-group-rules.ts +359 -0
  42. package/src/findings-helpers.ts +134 -109
  43. package/src/findings.ts +47 -27
  44. package/src/fixture-purpose-rules.ts +194 -50
  45. package/src/github-actions-event-guards.ts +331 -0
  46. package/src/github-actions-rules.ts +328 -121
  47. package/src/hook-contract.ts +681 -255
  48. package/src/init-config.ts +163 -118
  49. package/src/inline-suppressions.ts +340 -0
  50. package/src/limit-band.ts +56 -0
  51. package/src/line-rules.ts +331 -468
  52. package/src/migrate-config.ts +670 -0
  53. package/src/naming-pushers.ts +32 -127
  54. package/src/parsed-script.ts +868 -314
  55. package/src/pillar-summary.ts +56 -40
  56. package/src/profiles.ts +86 -74
  57. package/src/project-config-rules.ts +324 -140
  58. package/src/project-rules.ts +237 -115
  59. package/src/public-exports.ts +102 -38
  60. package/src/report-html.ts +217 -85
  61. package/src/report-renderers.ts +821 -203
  62. package/src/rule-list.ts +166 -46
  63. package/src/rules.ts +100 -104
  64. package/src/safety-rules.ts +191 -132
  65. package/src/scoring.ts +249 -55
  66. package/src/security-flow-rules.ts +791 -115
  67. package/src/selectors.ts +169 -0
  68. package/src/sensitive-data-rules.ts +460 -387
  69. package/src/sensitive-exclusions.ts +435 -0
  70. package/src/source-text.ts +378 -104
  71. package/src/static-analysis-redundant-rules.ts +298 -41
  72. package/src/test-block-rules.ts +343 -253
  73. package/src/text-scans.ts +62 -11
  74. package/src/types.ts +220 -71
  75. package/tsconfig.json +2 -1
  76. package/src/process-exec-metadata.ts +0 -163
  77. package/src/test-fixtures.ts +0 -671
@@ -14,11 +14,11 @@ interface DiagnosticSourceFile {
14
14
 
15
15
  /**
16
16
  * Syntax-only TypeScript parser diagnostics for script files; non-script inputs stay unparsed.
17
- * Thin wrapper over the shared parse boundary so direct callers keep this signature while the
18
- * analyser consumes the boundary result once per script.
17
+ * Uses the shared parser so callers that only need diagnostics get the same summary as the analyser.
19
18
  *
20
19
  * @param file - Source metadata used to skip non-script inputs and report paths.
21
20
  * @param source - Raw file text to parse for syntax diagnostics.
21
+ * @returns One summarized parse-error diagnostic when the script fails to parse; empty for non-script inputs and clean parses.
22
22
  */
23
23
  function parseDiagnostics(file: DiagnosticSourceFile, source: string): RunDiagnostic[] {
24
24
  return parseScript(file, source)?.diagnostics ?? [];
@@ -32,11 +32,10 @@ interface DelimiterCounts {
32
32
  brackets: number;
33
33
  }
34
34
 
35
- // Lexer state for the delimiter scanner. `previousCode` is the last non-whitespace executable
36
- // character - required because `/` may start a regex or a division depending on what came before.
37
- // `templateInterpolationStack` records the brace count at each `${` so a matching `}` can re-enter
38
- // template literal mode; without it, nested-template-literal files like `\`\${x.map(n => \`\${n}\`)}\``
39
- // flip out of quote mode early and start counting code-level braces inside the string body.
35
+ // Lexer state for the delimiter and masking scanner across quotes, comments, regex literals, and nested templates.
36
+ //
37
+ // - `previousCode` tracks the last non-whitespace code character so `/` disambiguates regex literals from division;
38
+ // - `templateInterpolationStack` records the brace depth at each `${` so matching `}` re-enters template text cleanly.
40
39
  interface DelimiterScanState {
41
40
  quote: string | undefined;
42
41
  isEscaped: boolean;
@@ -61,8 +60,12 @@ interface ScanStep {
61
60
  shouldStopLine: boolean;
62
61
  }
63
62
 
64
- // All flags begin false / quote unset. `previousCode` starts empty so the first `/` in a file
65
- // is treated as a regex opener (matches the JS grammar at program start).
63
+ /**
64
+ * Builds fresh delimiter-scan state for a new file with no active literal or comment and no prior code character.
65
+ * An empty `previousCode` lets a slash at the start of code open a regex; later code updates that context.
66
+ *
67
+ * @returns Initialized `DelimiterScanState` with cleared literal, comment, and escape flags.
68
+ */
66
69
  function defaultDelimiterScanState(): DelimiterScanState {
67
70
  return {
68
71
  quote: undefined,
@@ -76,8 +79,15 @@ function defaultDelimiterScanState(): DelimiterScanState {
76
79
  };
77
80
  }
78
81
 
79
- // Walks one line, mutating `ctx.counts` and `ctx.scan` in place. The `shouldStopLine` step is the only
80
- // way out before line end; comment, string, and regex bodies merely advance offset without counting.
82
+ /**
83
+ * Updates the supplied delimiter totals and scanner state across one source line.
84
+ * Stops at a line comment because the rest of the line is comment text; block comments, string text, and regex
85
+ * bodies leave counts unchanged while template interpolations resume counting.
86
+ *
87
+ * @param line - Source line text to scan from left to right.
88
+ * @param ctx - Mutable delimiter counts and lexer state updated in place for `line`.
89
+ * @returns Nothing. Mutates `ctx.counts` and `ctx.scan` for each scanned character until EOL or a line comment.
90
+ */
81
91
  function scanDelimiterLine(line: string, ctx: DelimiterScanContext): void {
82
92
  for (let offset = 0; offset < line.length; offset += 1) {
83
93
  const step = scanDelimiterCharacter(line, offset, ctx);
@@ -88,8 +98,14 @@ function scanDelimiterLine(line: string, ctx: DelimiterScanContext): void {
88
98
  }
89
99
  }
90
100
 
91
- // State-machine dispatch: block-comment, string, regex, or code. Order matters - once inside a
92
- // block comment, characters must not be re-interpreted as a quote or regex opener.
101
+ /**
102
+ * Scans `line` at `offset` according to the lexical mode stored in `ctx`, mutating its counts and scan state.
103
+ *
104
+ * @param line - Source line text containing the character to inspect.
105
+ * @param offset - Zero-based index of the current character within `line`.
106
+ * @param ctx - Mutable delimiter counts and lexer state carried across characters.
107
+ * @returns Step telling the line walker whether to continue, skip a character, or stop at a line comment.
108
+ */
93
109
  function scanDelimiterCharacter(line: string, offset: number, ctx: DelimiterScanContext): ScanStep {
94
110
  const character = line[offset] ?? "";
95
111
  const next = line[offset + 1] ?? "";
@@ -106,8 +122,15 @@ function scanDelimiterCharacter(line: string, offset: number, ctx: DelimiterScan
106
122
  return scanCodeDelimiter(line, offset, character, next, ctx);
107
123
  }
108
124
 
109
- // Inside `/* ... */`. Returns `skip: 1` to swallow the `/` of the closing `*/`, then the next
110
- // step resumes in code mode. Block-comment contents do not affect delimiter counts.
125
+ /**
126
+ * Scans inside a block comment, leaving delimiter counts unchanged until the closing delimiter.
127
+ * Mutates `scan.isInBlockComment` to false on the closer so the next step resumes in code mode.
128
+ *
129
+ * @param character - Current character inside the block comment.
130
+ * @param next - Lookahead character immediately following `character`.
131
+ * @param scan - Mutable lexer state updated when the closing delimiter is matched.
132
+ * @returns Step with `skip: 1` to swallow the trailing `/` on a closer, or a continuing step otherwise.
133
+ */
111
134
  function scanBlockCommentDelimiter(character: string, next: string, scan: DelimiterScanState): ScanStep {
112
135
  if (character === "*" && next === "/") {
113
136
  scan.isInBlockComment = false;
@@ -116,11 +139,15 @@ function scanBlockCommentDelimiter(character: string, next: string, scan: Delimi
116
139
  return continueScan();
117
140
  }
118
141
 
119
- // Inside a string or template literal. `\` arms `isEscaped` so the next character (including a
120
- // closing quote) is treated as literal text. Necessary to handle `"\\\""` and similar correctly.
121
- // Template literals also recognise `${` as an interpolation opener - the scanner pushes the current
122
- // brace count onto a stack, exits quote mode, and counts the opening `{` so a matching `}` re-enters
123
- // template literal mode. Without this, nested-template files mis-attribute later `\`` as the closer.
142
+ /**
143
+ * Scans inside a quoted literal, mutating quote, escape, and template-interpolation state in `ctx`.
144
+ * Escapes protect the next character; template interpolation saves brace depth and resumes code until its closing brace.
145
+ *
146
+ * @param character - Current character inside the quoted literal.
147
+ * @param next - Lookahead character immediately following `character`.
148
+ * @param ctx - Mutable delimiter counts and lexer state updated on escapes, quotes, or `${`.
149
+ * @returns Continuing step, or a skip step after `${` so the opening brace is not re-counted.
150
+ */
124
151
  function scanQuotedDelimiter(character: string, next: string, ctx: DelimiterScanContext): ScanStep {
125
152
  const scan = ctx.scan;
126
153
  if (scan.isEscaped) {
@@ -144,8 +171,14 @@ function scanQuotedDelimiter(character: string, next: string, ctx: DelimiterScan
144
171
  return continueScan();
145
172
  }
146
173
 
147
- // Inside `/regex/`. `[...]` character classes can legally contain `/`, so the closing slash
148
- // is only honoured when `isInRegexCharClass` is false; otherwise `/[/]/` would terminate early.
174
+ /**
175
+ * Scans inside a regex literal, mutating `scan` for escapes, character classes, and the closing slash.
176
+ * Closing slash is only honoured when `isInRegexCharClass` is false because `[...]` can contain `/`.
177
+ *
178
+ * @param character - Current character inside the regex literal body.
179
+ * @param scan - Mutable lexer state updated for escapes, `[` / `]` class boundaries, and regex exit.
180
+ * @returns Nothing. Mutates `scan` in place and sets `scan.previousCode` to `"x"` when the regex closes.
181
+ */
149
182
  function scanRegexDelimiter(character: string, scan: DelimiterScanState): void {
150
183
  if (scan.isRegexEscaped) {
151
184
  scan.isRegexEscaped = false;
@@ -161,8 +194,17 @@ function scanRegexDelimiter(character: string, scan: DelimiterScanState): void {
161
194
  }
162
195
  }
163
196
 
164
- // In executable code. The chain order (line comment → block comment → quote → regex → plain) is
165
- // deliberate: line comments must win over block-comment openers because `/* /* */` is one comment.
197
+ /**
198
+ * Classifies `character` and lookahead `next` in executable code, using `line` and `offset` for regex detection.
199
+ * Mutates delimiter counts and lexical state in `ctx` according to the matched token handler.
200
+ *
201
+ * @param line - Source line text providing preceding context for the regex-opening heuristic.
202
+ * @param offset - Zero-based index of `character` in `line`.
203
+ * @param character - Current character in executable code.
204
+ * @param next - Lookahead character immediately following `character`.
205
+ * @param ctx - Mutable delimiter counts and lexer state updated by the matching token handler.
206
+ * @returns Matched token's scan step, or the ordinary-code step when no opener matches.
207
+ */
166
208
  function scanCodeDelimiter(line: string, offset: number, character: string, next: string, ctx: DelimiterScanContext): ScanStep {
167
209
  return (
168
210
  scanLineCommentStart(character, next) ??
@@ -173,7 +215,13 @@ function scanCodeDelimiter(line: string, offset: number, character: string, next
173
215
  );
174
216
  }
175
217
 
176
- // `//` ends the line for delimiter purposes - anything to the right is comment text.
218
+ /**
219
+ * Detects a `//` line-comment opener that ends delimiter scanning for the remainder of the line.
220
+ *
221
+ * @param character - Current character in executable code.
222
+ * @param next - Lookahead character immediately following `character`.
223
+ * @returns Stopping step when `//` is matched, or `undefined` to try another token kind.
224
+ */
177
225
  function scanLineCommentStart(character: string, next: string): ScanStep | undefined {
178
226
  if (character === "/" && next === "/") {
179
227
  return stopLineScan();
@@ -181,7 +229,15 @@ function scanLineCommentStart(character: string, next: string): ScanStep | undef
181
229
  return undefined;
182
230
  }
183
231
 
184
- // `/*` flips the scanner into block-comment mode; `skip: 1` swallows the `*` so it isn't re-evaluated.
232
+ /**
233
+ * Detects a block-comment opener (`/*`) and mutates `scan.isInBlockComment` so following text is skipped.
234
+ * Uses `skip: 1` to swallow the `*` so it is not re-evaluated as part of a closer.
235
+ *
236
+ * @param character - Current character in executable code.
237
+ * @param next - Lookahead character immediately following `character`.
238
+ * @param scan - Mutable lexer state updated when a block comment opens.
239
+ * @returns Skip step when a block comment opens, or `undefined` to try another token handler.
240
+ */
185
241
  function scanBlockCommentStart(character: string, next: string, scan: DelimiterScanState): ScanStep | undefined {
186
242
  if (character === "/" && next === "*") {
187
243
  scan.isInBlockComment = true;
@@ -190,7 +246,13 @@ function scanBlockCommentStart(character: string, next: string, scan: DelimiterS
190
246
  return undefined;
191
247
  }
192
248
 
193
- // Records which quote character opened the literal so the scanner closes on the same kind.
249
+ /**
250
+ * Recognises a string or template quote opener and stores it in `scan.quote`.
251
+ *
252
+ * @param character - Current character in executable code.
253
+ * @param scan - Mutable lexer state updated with the active quote delimiter on match.
254
+ * @returns Continuing step when `character` is a quote, or `undefined` to try another token kind.
255
+ */
194
256
  function scanQuoteStart(character: string, scan: DelimiterScanState): ScanStep | undefined {
195
257
  if (isQuote(character)) {
196
258
  scan.quote = character;
@@ -199,9 +261,16 @@ function scanQuoteStart(character: string, scan: DelimiterScanState): ScanStep |
199
261
  return undefined;
200
262
  }
201
263
 
202
- // `/` is ambiguous in JS - it can start a regex or be division. `isRegexLiteralStart` decides based
203
- // on the previous non-whitespace token; getting this wrong would let division `a / b / c` enter
204
- // regex mode and absorb everything to the next slash.
264
+ /**
265
+ * Distinguishes a regex literal opener from division using `scan.previousCode` and the line prefix before `offset`.
266
+ * Mutates `scan` regex flags when `/` opens a regex literal.
267
+ *
268
+ * @param line - Source line text containing the candidate slash.
269
+ * @param offset - Zero-based index of `character` in `line`.
270
+ * @param character - Current character in executable code.
271
+ * @param scan - Mutable lexer state supplying `previousCode` and receiving updated regex flags.
272
+ * @returns Continuing step on a regex opener, or `undefined` for the next token handler.
273
+ */
205
274
  function scanRegexStart(line: string, offset: number, character: string, scan: DelimiterScanState): ScanStep | undefined {
206
275
  if (character === "/" && isRegexLiteralStart(scan.previousCode, line.slice(0, offset))) {
207
276
  scan.isInRegex = true;
@@ -212,10 +281,14 @@ function scanRegexStart(line: string, offset: number, character: string, scan: D
212
281
  return undefined;
213
282
  }
214
283
 
215
- // Updates the delimiter tallies and remembers this character as `previousCode` so the next `/`
216
- // can decide regex-vs-division. Whitespace is not recorded; it would corrupt the regex heuristic.
217
- // Also detects when a `}` returns to a saved template-interpolation depth and transitions the
218
- // scanner back into template-literal mode.
284
+ /**
285
+ * Counts `character` in `ctx.counts` and updates `ctx.scan` so later slashes classify as regex or division.
286
+ * Ignores whitespace when recording `previousCode`; a closing interpolation brace restores template-literal mode.
287
+ *
288
+ * @param character - Current ordinary character in executable code.
289
+ * @param ctx - Mutable delimiter counts and lexer state updated in place.
290
+ * @returns Continuing scan step after updating counts and interpolation/code state.
291
+ */
219
292
  function scanPlainCodeDelimiter(character: string, ctx: DelimiterScanContext): ScanStep {
220
293
  countDelimiter(character, ctx.counts);
221
294
  if (character === "}" && ctx.scan.templateInterpolationStack.length > 0 && ctx.counts.braces === (ctx.scan.templateInterpolationStack[ctx.scan.templateInterpolationStack.length - 1] ?? -1)) {
@@ -230,8 +303,14 @@ function scanPlainCodeDelimiter(character: string, ctx: DelimiterScanContext): S
230
303
  return continueScan();
231
304
  }
232
305
 
233
- // Increment on opener, decrement on closer. Other characters are no-ops so the function can be
234
- // called unconditionally per character without a guard in the caller.
306
+ /**
307
+ * Updates the supplied delimiter totals for `character` by incrementing on openers and decrementing on closers.
308
+ * Other characters are ignored so callers can pass every code character unconditionally.
309
+ *
310
+ * @param character - Character tested against `{`, `}`, `(`, `)`, `[`, and `]`.
311
+ * @param counts - Mutable delimiter totals updated in place.
312
+ * @returns Nothing. Mutates `counts` when `character` is a tracked delimiter.
313
+ */
235
314
  function countDelimiter(character: string, counts: DelimiterCounts): void {
236
315
  if (character === "{") {
237
316
  counts.braces += 1;
@@ -248,21 +327,33 @@ function countDelimiter(character: string, counts: DelimiterCounts): void {
248
327
  }
249
328
  }
250
329
 
251
- // Negative on any of the three means a closer ran ahead of its opener - caller reports immediately
252
- // at the current line because the original mismatch is local, not at EOF.
330
+ /**
331
+ * Checks whether `counts` has any negative brace, parenthesis, or bracket balance from a closer without an opener.
332
+ *
333
+ * @param counts - Running delimiter totals to inspect.
334
+ * @returns True if any delimiter balance is below zero; otherwise false.
335
+ */
253
336
  function hasNegativeDelimiterCount(counts: DelimiterCounts): boolean {
254
337
  return counts.braces < 0 || counts.parentheses < 0 || counts.brackets < 0;
255
338
  }
256
339
 
257
- // Non-zero after the whole file means an opener was never closed. Caller reports at EOF.
340
+ /**
341
+ * Checks whether `counts` has any nonzero brace, parenthesis, or bracket balance indicating unmatched delimiters.
342
+ *
343
+ * @param counts - Final delimiter totals at end of file.
344
+ * @returns True if any delimiter count is nonzero; otherwise false.
345
+ */
258
346
  function hasUnbalancedDelimiterCount(counts: DelimiterCounts): boolean {
259
347
  return counts.braces !== 0 || counts.parentheses !== 0 || counts.brackets !== 0;
260
348
  }
261
349
 
262
- /*
263
- * Emits a `parse-error` diagnostic. The CLI exit contract forces a non-zero exit (see `exitFor`)
264
- * whenever diagnostics fire - this builder reports failures so a broken file in the scan tree
265
- * cannot hide silently rather than throw the error or recover quietly.
350
+ /**
351
+ * Builds a parse-error diagnostic for a caller to include in scan results.
352
+ *
353
+ * @param file - source metadata whose displayPath identifies the failed file
354
+ * @param line - source line to attach to the error
355
+ * @param message - explanation copied into the diagnostic
356
+ * @returns a parse-error record containing the supplied message, display path, and line
266
357
  */
267
358
  function parseErrorDiagnostic(file: DiagnosticSourceFile, line: number, message: string): RunDiagnostic {
268
359
  return {
@@ -273,15 +364,25 @@ function parseErrorDiagnostic(file: DiagnosticSourceFile, line: number, message:
273
364
  };
274
365
  }
275
366
 
276
- // Heuristic for the regex-vs-division ambiguity: `/` is a regex opener after operators, control
277
- // punctuation, or `return`; otherwise it's division. False positives would expand a regex across
278
- // real code and break delimiter balance, so this list is intentionally conservative.
367
+ /**
368
+ * Determines whether a slash looks like a regex opener using a conservative heuristic to avoid masking real code.
369
+ * Empty `previousCode`, selected punctuation, or trailing `return` before the slash permits a regex.
370
+ *
371
+ * @param previousCode - Last non-whitespace code character, synthetic operand marker, or empty start marker.
372
+ * @param beforeSlash - Preceding line slice before the candidate `/` character.
373
+ * @returns True when the slash context permits a regex literal opener; otherwise false.
374
+ */
279
375
  function isRegexLiteralStart(previousCode: string, beforeSlash: string): boolean {
280
376
  return previousCode === "" || "([{=,:!&|?;".includes(previousCode) || /\breturn$/.test(beforeSlash.trimEnd());
281
377
  }
282
378
 
283
- // Masks non-code bytes without changing offsets. Regex-driven rules rely on the 1:1 byte mapping
284
- // to report raw-source line numbers while avoiding matches inside comments, strings, and regex bodies.
379
+ /**
380
+ * Masks recognized comment and literal bodies in `source` while preserving UTF-16 code-unit offsets and newlines.
381
+ * Regex-driven rules use the unchanged positions to report source locations without matching text inside those bodies.
382
+ *
383
+ * @param source - Raw source file text to mask.
384
+ * @returns Copy of `source` with comment, string, template, and regex bodies replaced by spaces.
385
+ */
285
386
  function maskNonCode(source: string): string {
286
387
  let result = "";
287
388
  const state = defaultMaskState();
@@ -293,10 +394,13 @@ function maskNonCode(source: string): string {
293
394
  return result;
294
395
  }
295
396
 
296
- // Replaces only `` ` `` template-literal body characters with spaces. Unlike `maskNonCode`, single
297
- // and double-quoted string bodies are preserved so syntax-pattern rules (e.g. import edges) still
298
- // see the specifier text on real `import ... from "..."` lines. Used by `import-edge` style rules
299
- // that must ignore fixture content embedded in template literals without losing real imports.
397
+ /**
398
+ * Masks template-literal bodies in `source` with spaces while preserving offsets and line-feed characters.
399
+ * Single- and double-quoted bodies remain visible so syntax-pattern rules can read real import specifiers.
400
+ *
401
+ * @param source - Raw source file text to mask.
402
+ * @returns Copy of `source` with backtick template contents replaced by spaces.
403
+ */
300
404
  function maskTemplateLiteralBodies(source: string): string {
301
405
  let result = "";
302
406
  const state = templateMaskState();
@@ -319,13 +423,24 @@ interface TemplateMaskState {
319
423
  isBlockComment: boolean;
320
424
  }
321
425
 
322
- // Fresh default state for a single-file template-mask pass.
426
+ /**
427
+ * Creates fresh default state for a single-file template-mask pass.
428
+ *
429
+ * @returns Initialized `TemplateMaskState` with no active quote or comment context.
430
+ */
323
431
  function templateMaskState(): TemplateMaskState {
324
432
  return { quote: undefined, isEscaped: false, isLineComment: false, isBlockComment: false };
325
433
  }
326
434
 
327
- // Per-character dispatch: newlines clear single-line state; backtick body chars are masked; quoted
328
- // and commented chars pass through. Skips the regex branch because regex bodies cannot start an import.
435
+ /**
436
+ * Transforms `character` with lookahead `next` for template-body masking, mutating `state` in place.
437
+ * Preserves delimiters, newlines, single/double-quoted strings, and comments while masking template body text.
438
+ *
439
+ * @param character - Current character from the source text.
440
+ * @param next - Lookahead character immediately following `character`.
441
+ * @param state - Mutable quote and comment context carried across characters.
442
+ * @returns Output text and extra-character skip count; regex literals receive no dedicated handling.
443
+ */
329
444
  function templateMaskCharacter(character: string, next: string, state: TemplateMaskState): MaskStep {
330
445
  if (character === "\n") return templateMaskNewline(state);
331
446
  if (state.isLineComment) return { text: character, skip: 0 };
@@ -334,7 +449,12 @@ function templateMaskCharacter(character: string, next: string, state: TemplateM
334
449
  return templateMaskCodeCharacter(character, next, state);
335
450
  }
336
451
 
337
- // Newlines clear line-comment state and any non-template quote; template literals survive across lines.
452
+ /**
453
+ * Clears line-comment state and any non-template quote at a newline while preserving template-literal mode.
454
+ *
455
+ * @param state - Mutable template-mask state updated in place at the line boundary.
456
+ * @returns Step emitting `"\n"` with no extra-character skip.
457
+ */
338
458
  function templateMaskNewline(state: TemplateMaskState): MaskStep {
339
459
  state.isLineComment = false;
340
460
  if (state.quote !== "`") {
@@ -343,7 +463,14 @@ function templateMaskNewline(state: TemplateMaskState): MaskStep {
343
463
  return { text: "\n", skip: 0 };
344
464
  }
345
465
 
346
- // Inside a block comment: pass body through and detect the closing `*/`.
466
+ /**
467
+ * Preserves block-comment text and clears `state.isBlockComment` when the closing delimiter is reached.
468
+ *
469
+ * @param character - Current character inside the block comment.
470
+ * @param next - Lookahead character immediately following `character`.
471
+ * @param state - Mutable template-mask state updated on a block-comment closer.
472
+ * @returns Preserved text with `skip: 1` on the closing pair, or `skip: 0` otherwise.
473
+ */
347
474
  function templateMaskBlockComment(character: string, next: string, state: TemplateMaskState): MaskStep {
348
475
  if (character === "*" && next === "/") {
349
476
  state.isBlockComment = false;
@@ -352,7 +479,14 @@ function templateMaskBlockComment(character: string, next: string, state: Templa
352
479
  return { text: character, skip: 0 };
353
480
  }
354
481
 
355
- // Inside any quoted string: bodies of `` ` `` get masked, single/double-quote bodies pass through.
482
+ /**
483
+ * Processes a character inside a quoted literal, masking backtick bodies while passing single/double quotes through.
484
+ * Preserves an unescaped closing quote and mutates escape and quote flags in `state`.
485
+ *
486
+ * @param character - Current character inside the active literal.
487
+ * @param state - Mutable template-mask state tracking escapes and the active quote delimiter.
488
+ * @returns Transformed character step with `skip: 0`.
489
+ */
356
490
  function templateMaskQuotedCharacter(character: string, state: TemplateMaskState): MaskStep {
357
491
  const masked = state.quote === "`";
358
492
  if (state.isEscaped) {
@@ -370,7 +504,15 @@ function templateMaskQuotedCharacter(character: string, state: TemplateMaskState
370
504
  return { text: masked ? " " : character, skip: 0 };
371
505
  }
372
506
 
373
- // In code: detect comment openers and the three quote types, otherwise pass through.
507
+ /**
508
+ * Detects comment openers and the three quote types in code, passing ordinary characters through unchanged.
509
+ * Mutates `state` when a comment or quote opener is matched.
510
+ *
511
+ * @param character - Current character in code context.
512
+ * @param next - Lookahead character immediately following `character`.
513
+ * @param state - Mutable template-mask state updated on comment or quote entry.
514
+ * @returns Preserved text and extra-character skip count (`1` for comment openers, `0` otherwise).
515
+ */
374
516
  function templateMaskCodeCharacter(character: string, next: string, state: TemplateMaskState): MaskStep {
375
517
  if (character === "/" && next === "/") {
376
518
  state.isLineComment = true;
@@ -398,7 +540,10 @@ interface MaskState {
398
540
  isRegexCharClass: boolean;
399
541
  isRegexEscaped: boolean;
400
542
  previousCode: string;
401
- templateInterpolationDepth: number;
543
+ // One entry per open `${`, innermost last, counting the braces still open inside that interpolation. A scalar
544
+ // depth cannot tell a nested template's own `}` from the enclosing interpolation's, so it resumed code where the
545
+ // inner template body continued and masked the rest of the file.
546
+ templateInterpolationDepths: number[];
402
547
  }
403
548
 
404
549
  // `text` is what gets written for this character (space for masked, original for code, " " for
@@ -408,7 +553,11 @@ interface MaskStep {
408
553
  skip: number;
409
554
  }
410
555
 
411
- // All flags start cleared so the first scanner step treats source as code.
556
+ /**
557
+ * Builds fresh `MaskState` with all flags cleared so the first scanner step treats source as code.
558
+ *
559
+ * @returns Initialized `MaskState` with empty prior code and no active literal or comment flags.
560
+ */
412
561
  function defaultMaskState(): MaskState {
413
562
  return {
414
563
  quote: undefined,
@@ -419,12 +568,19 @@ function defaultMaskState(): MaskState {
419
568
  isRegexCharClass: false,
420
569
  isRegexEscaped: false,
421
570
  previousCode: "",
422
- templateInterpolationDepth: 0,
571
+ templateInterpolationDepths: [],
423
572
  };
424
573
  }
425
574
 
426
- // Newlines short-circuit first - single-line `//` comments must clear at line end, and ordinary
427
- // quotes do too, but template literals (` ` `) survive across lines.
575
+ /**
576
+ * Masks or preserves `source[index]` according to `state`, mutating `state` as comments and literals open or close.
577
+ * Newlines end line comments and single-line quote or regex state while template literals and block comments remain active.
578
+ *
579
+ * @param source - Complete source text being masked.
580
+ * @param index - Zero-based UTF-16 offset of the current character in `source`.
581
+ * @param state - Mutable masking context carried across characters.
582
+ * @returns Output text and extra-character skip count for the current character or opener/closer pair.
583
+ */
428
584
  function maskNonCodeCharacter(source: string, index: number, state: MaskState): MaskStep {
429
585
  const character = source[index] ?? "";
430
586
  const next = source[index + 1] ?? "";
@@ -446,8 +602,13 @@ function maskNonCodeCharacter(source: string, index: number, state: MaskState):
446
602
  return maskCodeCharacter(source, index, character, next, state);
447
603
  }
448
604
 
449
- // At a newline: drop line-comment / single-quote / regex state, but preserve template-literal state
450
- // because backtick strings legitimately span multiple lines. Emits `\n` verbatim to keep offsets aligned.
605
+ /**
606
+ * Updates `state` at a newline by clearing line-comment, single-quote, double-quote, and regex modes.
607
+ * Keeps template-literal and block-comment modes because both can span lines, preserving source offsets.
608
+ *
609
+ * @param state - Mutable mask state updated in place at the newline.
610
+ * @returns Step emitting `"\n"` with `skip: 0`.
611
+ */
451
612
  function maskNewline(state: MaskState): MaskStep {
452
613
  state.isLineComment = false;
453
614
  if (state.quote !== "`") {
@@ -459,8 +620,15 @@ function maskNewline(state: MaskState): MaskStep {
459
620
  return { text: "\n", skip: 0 };
460
621
  }
461
622
 
462
- // Replaces block-comment text with spaces; the closing `*/` becomes " " so the two output
463
- // characters line up with the two consumed characters.
623
+ /**
624
+ * Replaces block-comment text with spaces, turning the closing delimiter into two spaces to preserve character alignment.
625
+ * Clears `state.isBlockComment` when the closing pair is consumed.
626
+ *
627
+ * @param character - Current character inside the block comment.
628
+ * @param next - Lookahead character immediately following `character`.
629
+ * @param state - Mutable mask state updated when the block comment closes.
630
+ * @returns Two spaces with `skip: 1` on a closer, or a single masked space step otherwise.
631
+ */
464
632
  function maskBlockComment(character: string, next: string, state: MaskState): MaskStep {
465
633
  if (character === "*" && next === "/") {
466
634
  state.isBlockComment = false;
@@ -469,8 +637,15 @@ function maskBlockComment(character: string, next: string, state: MaskState): Ma
469
637
  return maskSingleCharacter();
470
638
  }
471
639
 
472
- // Inside a string: mask body characters but emit the closing quote unchanged so downstream rules
473
- // can still see the quote boundary. `\` arms `isEscaped` to keep the next character literal.
640
+ /**
641
+ * Masks characters inside a quoted literal while keeping the closing quote and template `${` openers visible.
642
+ * Mutates `state` for escapes, closing quotes, and pushing brace depth when a template interpolation opens.
643
+ *
644
+ * @param character - Current character inside the quoted literal.
645
+ * @param next - Lookahead character immediately following `character`.
646
+ * @param state - Mutable mask state tracking escape, quote, and template interpolation stack state.
647
+ * @returns Masking step with spaces for literal body text, `"${"` on interpolation, or the closing quote.
648
+ */
474
649
  function maskQuotedCharacter(character: string, next: string, state: MaskState): MaskStep {
475
650
  if (state.isEscaped) {
476
651
  state.isEscaped = false;
@@ -482,7 +657,7 @@ function maskQuotedCharacter(character: string, next: string, state: MaskState):
482
657
  }
483
658
  if (state.quote === "`" && character === "$" && next === "{") {
484
659
  state.quote = undefined;
485
- state.templateInterpolationDepth += 1;
660
+ state.templateInterpolationDepths.push(1);
486
661
  state.previousCode = "{";
487
662
  return { text: "${", skip: 1 };
488
663
  }
@@ -494,8 +669,14 @@ function maskQuotedCharacter(character: string, next: string, state: MaskState):
494
669
  return maskSingleCharacter();
495
670
  }
496
671
 
497
- // Inside `/.../`: mask body characters and pass through the closing `/`. `[ ... ]` character classes
498
- // suspend the closing-slash check so `/[/]/` does not terminate at the inner slash.
672
+ /**
673
+ * Masks regex literal body characters and passes through the closing `/`, tracking escapes and `[...]` classes.
674
+ * Character classes suspend the closing-slash check so `/[/]/` does not terminate at the inner slash.
675
+ *
676
+ * @param character - Current character inside the regex literal.
677
+ * @param state - Mutable mask state updated for escapes, class boundaries, and regex exit.
678
+ * @returns Space-mask step for body characters, or the closing `/` with `skip: 0`.
679
+ */
499
680
  function maskRegexCharacter(character: string, state: MaskState): MaskStep {
500
681
  if (state.isRegexEscaped) {
501
682
  state.isRegexEscaped = false;
@@ -521,8 +702,17 @@ function maskRegexCharacter(character: string, state: MaskState): MaskStep {
521
702
  return maskSingleCharacter();
522
703
  }
523
704
 
524
- // Dispatch order in code mode matters: detect comment openers before regex, since `/*` would
525
- // otherwise be misread as a regex start; detect regex before quote because no quote begins with `/`.
705
+ /**
706
+ * Dispatches code-context masking for `source[index]`, mutating `state` on openers, braces, or code tokens.
707
+ * Checks comment openers before regex starts so a comment opener cannot enter regex mode, preserving offsets.
708
+ *
709
+ * @param source - Complete source text used to inspect context before a candidate regex slash.
710
+ * @param index - Zero-based offset of `character` in `source`.
711
+ * @param character - Current character in code context.
712
+ * @param next - Lookahead character immediately following `character`.
713
+ * @param state - Mutable mask state updated by the matching detector or plain-code fallback.
714
+ * @returns Output text and extra-character skip count from the first matching detector.
715
+ */
526
716
  function maskCodeCharacter(source: string, index: number, character: string, next: string, state: MaskState): MaskStep {
527
717
  return (
528
718
  maskTemplateInterpolationBrace(character, state) ??
@@ -534,21 +724,30 @@ function maskCodeCharacter(source: string, index: number, character: string, nex
534
724
  );
535
725
  }
536
726
 
537
- // While inside a template `${...}` expression, braces are executable code and must stay visible.
538
- // The depth counter returns to backtick masking only after the matching interpolation closer.
727
+ /**
728
+ * Tracks `{` and `}` inside the active template interpolation, mutating only its innermost brace depth.
729
+ * Closing the final brace pops the interpolation entry and resumes template-body masking.
730
+ *
731
+ * @param character - Current character in code context.
732
+ * @param state - Mutable mask state carrying `templateInterpolationDepths` and `previousCode`.
733
+ * @returns Step preserving the brace with `skip: 0`, or `undefined` outside interpolations or for other characters.
734
+ */
539
735
  function maskTemplateInterpolationBrace(character: string, state: MaskState): MaskStep | undefined {
540
- if (state.templateInterpolationDepth === 0) {
736
+ const openBraceDepths = state.templateInterpolationDepths;
737
+ const innermost = openBraceDepths.length - 1;
738
+ if (innermost < 0) {
541
739
  return undefined;
542
740
  }
543
741
  if (character === "{") {
544
- state.templateInterpolationDepth += 1;
742
+ openBraceDepths[innermost] = (openBraceDepths[innermost] ?? 0) + 1;
545
743
  state.previousCode = character;
546
744
  return { text: character, skip: 0 };
547
745
  }
548
746
  if (character === "}") {
549
- state.templateInterpolationDepth -= 1;
747
+ openBraceDepths[innermost] = (openBraceDepths[innermost] ?? 0) - 1;
550
748
  state.previousCode = character;
551
- if (state.templateInterpolationDepth === 0) {
749
+ if (openBraceDepths[innermost] === 0) {
750
+ openBraceDepths.pop();
552
751
  state.quote = "`";
553
752
  }
554
753
  return { text: character, skip: 0 };
@@ -556,8 +755,14 @@ function maskTemplateInterpolationBrace(character: string, state: MaskState): Ma
556
755
  return undefined;
557
756
  }
558
757
 
559
- // Detects `//` and arms line-comment mode; the actual masking happens on subsequent characters
560
- // via the `state.isLineComment` branch in `maskNonCodeCharacter`.
758
+ /**
759
+ * Detects a `//` line-comment opener and mutates `state.isLineComment` so the rest of the line is masked.
760
+ *
761
+ * @param character - Current character in code context.
762
+ * @param next - Lookahead character immediately following `character`.
763
+ * @param state - Mutable mask state updated when a line comment starts.
764
+ * @returns Two spaces with `skip: 1` on match, or `undefined` for the next detector.
765
+ */
561
766
  function maskLineCommentStart(character: string, next: string, state: MaskState): MaskStep | undefined {
562
767
  if (character === "/" && next === "/") {
563
768
  state.isLineComment = true;
@@ -566,7 +771,14 @@ function maskLineCommentStart(character: string, next: string, state: MaskState)
566
771
  return undefined;
567
772
  }
568
773
 
569
- // Detects `/*` and masks the two opener characters. State flips so subsequent chars route to `maskBlockComment`.
774
+ /**
775
+ * Detects a block-comment opener (`/*`) and mutates `state.isBlockComment` so comment text is masked.
776
+ *
777
+ * @param character - Current character in code context.
778
+ * @param next - Lookahead character immediately following `character`.
779
+ * @param state - Mutable mask state updated when a block comment starts.
780
+ * @returns Two spaces with `skip: 1` on match, or `undefined` for the next detector.
781
+ */
570
782
  function maskBlockCommentStart(character: string, next: string, state: MaskState): MaskStep | undefined {
571
783
  if (character === "/" && next === "*") {
572
784
  state.isBlockComment = true;
@@ -575,8 +787,15 @@ function maskBlockCommentStart(character: string, next: string, state: MaskState
575
787
  return undefined;
576
788
  }
577
789
 
578
- // Same regex-vs-division heuristic as `parseDiagnostics`, but with up to 80 prior characters of
579
- // context (rather than just one) to recognise the `return /pattern/` case across multi-token expressions.
790
+ /**
791
+ * Detects a regex literal opener using up to 80 characters before `index` and mutates `state.isRegex`.
792
+ *
793
+ * @param source - Complete source text supplying preceding context for the regex-start heuristic.
794
+ * @param index - Zero-based offset of `character` in `source`.
795
+ * @param character - Current character in code context.
796
+ * @param state - Mutable mask state supplying `previousCode` and updated on regex entry.
797
+ * @returns Step preserving `/` with `skip: 0` on match, or `undefined` for the next detector.
798
+ */
580
799
  function maskRegexStart(source: string, index: number, character: string, state: MaskState): MaskStep | undefined {
581
800
  if (character === "/" && isRegexLiteralStart(state.previousCode, source.slice(Math.max(0, index - 80), index))) {
582
801
  state.isRegex = true;
@@ -586,8 +805,14 @@ function maskRegexStart(source: string, index: number, character: string, state:
586
805
  return undefined;
587
806
  }
588
807
 
589
- // Opening quote is emitted unchanged so downstream rules can detect string boundaries; subsequent
590
- // body characters get masked by `maskQuotedCharacter`.
808
+ /**
809
+ * Detects a string or template quote opener and mutates `state.quote` and `state.previousCode`.
810
+ * Later calls mask literal text while keeping quote boundaries and template interpolation code visible.
811
+ *
812
+ * @param character - Current character in code context.
813
+ * @param state - Mutable mask state updated with the active quote delimiter.
814
+ * @returns Step preserving the quote with `skip: 0` on match, or `undefined` for the plain-code fallback.
815
+ */
591
816
  function maskQuoteStart(character: string, state: MaskState): MaskStep | undefined {
592
817
  if (isQuote(character)) {
593
818
  state.quote = character;
@@ -597,8 +822,14 @@ function maskQuoteStart(character: string, state: MaskState): MaskStep | undefin
597
822
  return undefined;
598
823
  }
599
824
 
600
- // Code characters survive into the masked output; only non-whitespace updates `previousCode` because
601
- // the regex-start heuristic must look at the last real token, not at the space before it.
825
+ /**
826
+ * Passes an ordinary code character through into masked output, updating `state.previousCode` only for non-whitespace.
827
+ * Only non-whitespace updates `previousCode` because the regex-start heuristic must see the last real token.
828
+ *
829
+ * @param character - Current ordinary character in code context.
830
+ * @param state - Mutable mask state whose `previousCode` is updated for non-whitespace characters.
831
+ * @returns Step preserving `character` with `skip: 0`.
832
+ */
602
833
  function maskPlainCodeCharacter(character: string, state: MaskState): MaskStep {
603
834
  if (isNonWhitespaceCharacter(character)) {
604
835
  state.previousCode = character;
@@ -606,14 +837,22 @@ function maskPlainCodeCharacter(character: string, state: MaskState): MaskStep {
606
837
  return { text: character, skip: 0 };
607
838
  }
608
839
 
609
- // One space per masked byte. Preserves overall length so byte offsets in masked text map 1:1 to source.
840
+ /**
841
+ * Builds a single-space mask step to obscure one UTF-16 code unit while preserving source offsets.
842
+ *
843
+ * @returns `MaskStep` emitting `" "` with `skip: 0`.
844
+ */
610
845
  function maskSingleCharacter(): MaskStep {
611
846
  return { text: " ", skip: 0 };
612
847
  }
613
848
 
614
- // Cheaper, line-local mask used when rules don't need full lexer state - strips line-comments and
615
- // string bodies but does not track block comments. Use `maskNonCode` instead when state must
616
- // survive across lines.
849
+ /**
850
+ * Strips string bodies and line comments from a single line while leaving quote delimiters for matching.
851
+ * This line-local scanner has no block-comment state; use `maskNonCode` to preserve state across lines.
852
+ *
853
+ * @param line - Single source line to strip for local pattern matching.
854
+ * @returns Line text with quoted contents and trailing line comments removed.
855
+ */
617
856
  function codeLineForMatching(line: string): string {
618
857
  let result = "";
619
858
  const state: CodeLineState = { quote: undefined, isEscaped: false };
@@ -640,8 +879,15 @@ interface CodeLineStep {
640
879
  shouldStopLine: boolean;
641
880
  }
642
881
 
643
- // Quotes are emitted (so callers can see the literal boundary) but their bodies are dropped, while
644
- // any `//` outside a string truncates the rest of the line.
882
+ /**
883
+ * Evaluates `line[index]` for line-local matching, mutating `state` to track string delimiters and escapes.
884
+ * A line-comment opener outside a string emits empty text and stops the line; other characters continue scanning.
885
+ *
886
+ * @param line - Raw source line being scanned.
887
+ * @param index - Zero-based offset of the current character in `line`.
888
+ * @param state - Mutable quote and escape state carried along the line.
889
+ * @returns Output text (keeping quotes and code, dropping string bodies) and `shouldStopLine` flag.
890
+ */
645
891
  function codeLineCharacter(line: string, index: number, state: CodeLineState): CodeLineStep {
646
892
  const character = line[index] ?? "";
647
893
  const next = line[index + 1] ?? "";
@@ -658,8 +904,14 @@ function codeLineCharacter(line: string, index: number, state: CodeLineState): C
658
904
  return { text: character, shouldStopLine: false };
659
905
  }
660
906
 
661
- // Body characters of a string are dropped so `"// not a comment"` doesn't truncate the line, but
662
- // the closing quote is emitted so the caller still sees a balanced literal.
907
+ /**
908
+ * Suppresses quoted literal contents while keeping the unescaped closing quote visible as the literal boundary.
909
+ * Mutates `state` to track escapes and clears `state.quote` when the literal closes.
910
+ *
911
+ * @param character - Current character inside the quoted literal.
912
+ * @param state - Mutable quote and escape state updated in place.
913
+ * @returns Closing quote or empty text, always with `shouldStopLine: false`.
914
+ */
663
915
  function quotedCodeLineCharacter(character: string, state: CodeLineState): CodeLineStep {
664
916
  if (state.isEscaped) {
665
917
  state.isEscaped = false;
@@ -676,28 +928,50 @@ function quotedCodeLineCharacter(character: string, state: CodeLineState): CodeL
676
928
  return { text: "", shouldStopLine: false };
677
929
  }
678
930
 
679
- // Default step: caller advances by one, line continues. Centralised so callers stay symmetrical.
931
+ /**
932
+ * Default scan step advancing by one character while keeping the line scan active.
933
+ *
934
+ * @returns `ScanStep` with `skip: 0` and `shouldStopLine: false`.
935
+ */
680
936
  function continueScan(): ScanStep {
681
937
  return { skip: 0, shouldStopLine: false };
682
938
  }
683
939
 
684
- // Skip one extra character - used to swallow the second half of a two-character token like `*/`.
940
+ /**
941
+ * Builds a scan step that skips the second character of a two-character token and keeps scanning.
942
+ *
943
+ * @returns `ScanStep` with `skip: 1` and `shouldStopLine: false`.
944
+ */
685
945
  function skipNextCharacter(): ScanStep {
686
946
  return { skip: 1, shouldStopLine: false };
687
947
  }
688
948
 
689
- // End-of-line short circuit returned when a `//` line comment starts.
949
+ /**
950
+ * Builds a scan step that ends the current line scan at a line comment so remaining text contributes no delimiters.
951
+ *
952
+ * @returns `ScanStep` with `skip: 0` and `shouldStopLine: true`.
953
+ */
690
954
  function stopLineScan(): ScanStep {
691
955
  return { skip: 0, shouldStopLine: true };
692
956
  }
693
957
 
694
- // String, template literal, and char-class quotes recognised by every lexer in this module.
958
+ /**
959
+ * Checks whether `character` can delimit a single-quoted string, double-quoted string, or template literal.
960
+ *
961
+ * @param character - Single character to check against `"`, `'`, and `` ` ``.
962
+ * @returns True when `character` is one of the three JS/TS quote delimiters; otherwise false.
963
+ */
695
964
  function isQuote(character: string): boolean {
696
965
  return character === "\"" || character === "'" || character === "`";
697
966
  }
698
967
 
699
- // Used by `maskPlainCodeCharacter` to decide whether a character should overwrite `previousCode`.
700
- // Whitespace must not, otherwise the regex-vs-division heuristic would be fed the wrong token.
968
+ /**
969
+ * Checks whether `character` is non-empty and not horizontal or vertical ASCII whitespace.
970
+ * Used by `maskPlainCodeCharacter` so whitespace must not overwrite `previousCode` for the regex heuristic.
971
+ *
972
+ * @param character - Character inspected before updating `previousCode`.
973
+ * @returns True if `character` is non-empty and not space, tab, CR, or LF; otherwise false.
974
+ */
701
975
  function isNonWhitespaceCharacter(character: string): boolean {
702
976
  return character !== "" && character !== " " && character !== "\t" && character !== "\r" && character !== "\n";
703
977
  }