carrick 0.3.138 → 0.3.139

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.
@@ -395,6 +395,20 @@ export interface CaptureStubResult {
395
395
  unresolved_dependencies: string[];
396
396
  ts_version: string;
397
397
  errors: string[];
398
+ /**
399
+ * carrick#2041: the stub captured again with the demoted aliases the
400
+ * scanner holds a literal text for re-anchored on that text, written to
401
+ * `backfillOutDir`. Absent when no alias qualified or the second surface
402
+ * could not be written. The scanner keeps one of the two stubs.
403
+ */
404
+ backfill?: CaptureBackfillResult;
405
+ }
406
+ /** The second stub of a capture with a literal backfill (carrick#2041). */
407
+ export interface CaptureBackfillResult {
408
+ /** The aliases re-anchored as literals at `anchor-backfill` origin, in anchor order. */
409
+ backfilled: string[];
410
+ /** The second stub, as a capture of the re-anchored set would answer it. */
411
+ result: CaptureStubResult;
398
412
  }
399
413
  /**
400
414
  * The stages of a capture that it reports as it reaches them (carrick#1916),
@@ -425,6 +439,15 @@ export interface CaptureStubOptions {
425
439
  * reporting. It changes nothing the capture writes.
426
440
  */
427
441
  onProgress?: (phase: CapturePhase, message: string) => void;
442
+ /**
443
+ * carrick#2041: alias -> literal type text the scanner can stand behind.
444
+ * An alias the capture demotes that has a text here is captured a second
445
+ * time, in the same request, re-anchored on the text, into
446
+ * `backfillOutDir`.
447
+ */
448
+ backfillTexts?: Record<string, string>;
449
+ /** Where the backfilled stub is written; required with `backfillTexts`. */
450
+ backfillOutDir?: string;
428
451
  }
429
452
  /** Wire protocol of a matched pair (drives the direction table). */
430
453
  export type ProbeProtocol = 'http' | 'graphql' | 'socket' | 'pubsub';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The literal backfill (carrick#2041): which aliases a capture captures a
3
+ * second time, and the host that lets the second surface reuse what the first
4
+ * one parsed.
5
+ *
6
+ * When a capture demotes an alias (its anchor did not resolve, or its module's
7
+ * declaration emit was skipped) and the scanner holds a usable literal type
8
+ * text for it, the same capture writes a second stub with that alias anchored
9
+ * on the text instead (`anchor_origin: anchor-backfill`). The scanner reads
10
+ * both record sets and keeps the second stub only when every backfilled alias
11
+ * self-checked clean and no sibling degraded.
12
+ */
13
+ import ts from 'typescript';
14
+ import type { CaptureAnchorRequest } from './api.js';
15
+ import type { ResolvedAnchor } from './anchors.js';
16
+ /** The anchors of the second surface, and the aliases it re-anchors. */
17
+ export interface BackfillPlan {
18
+ anchors: CaptureAnchorRequest[];
19
+ /** The re-anchored aliases, in anchor order. */
20
+ backfilled: string[];
21
+ }
22
+ /**
23
+ * Every alias the first surface demoted (`failureReason` is set exactly for a
24
+ * demoted anchor) for which a text is held becomes a literal anchor on that
25
+ * text at `anchor-backfill` origin, keeping the replaced anchor's file. An
26
+ * anchor that is already a literal is never re-anchored: the text tier is
27
+ * the one it is on. `undefined` when no alias qualifies.
28
+ */
29
+ export declare function backfillRerun(anchors: readonly CaptureAnchorRequest[], resolved: ReadonlyArray<Pick<ResolvedAnchor, 'request' | 'failureReason'>>, texts: Readonly<Record<string, string>> | undefined): BackfillPlan | undefined;
30
+ /**
31
+ * `host` answering every file parsed once into `parsed` with the same source
32
+ * file, except the files `fresh` names. Programs built on such hosts under
33
+ * the same options share their parsed (and bound) files, as an editor's
34
+ * programs do: the backfill's emit reuses the first emit's files, and the two
35
+ * stubs' self-checks reuse the declarations of the installed packages.
36
+ */
37
+ export declare function sharingHost(host: ts.CompilerHost, fresh: (fileName: string) => boolean, parsed?: Map<string, ts.SourceFile | undefined>): ts.CompilerHost;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The literal backfill (carrick#2041): which aliases a capture captures a
3
+ * second time, and the host that lets the second surface reuse what the first
4
+ * one parsed.
5
+ *
6
+ * When a capture demotes an alias (its anchor did not resolve, or its module's
7
+ * declaration emit was skipped) and the scanner holds a usable literal type
8
+ * text for it, the same capture writes a second stub with that alias anchored
9
+ * on the text instead (`anchor_origin: anchor-backfill`). The scanner reads
10
+ * both record sets and keeps the second stub only when every backfilled alias
11
+ * self-checked clean and no sibling degraded.
12
+ */
13
+ /**
14
+ * Every alias the first surface demoted (`failureReason` is set exactly for a
15
+ * demoted anchor) for which a text is held becomes a literal anchor on that
16
+ * text at `anchor-backfill` origin, keeping the replaced anchor's file. An
17
+ * anchor that is already a literal is never re-anchored: the text tier is
18
+ * the one it is on. `undefined` when no alias qualifies.
19
+ */
20
+ export function backfillRerun(anchors, resolved, texts) {
21
+ if (!texts)
22
+ return undefined;
23
+ const backfill = new Set();
24
+ for (const anchor of resolved) {
25
+ if (anchor.failureReason === undefined || anchor.request.kind === 'literal')
26
+ continue;
27
+ if (Object.prototype.hasOwnProperty.call(texts, anchor.request.alias))
28
+ backfill.add(anchor.request.alias);
29
+ }
30
+ if (backfill.size === 0)
31
+ return undefined;
32
+ const backfilled = [];
33
+ const rerun = anchors.map((anchor) => {
34
+ if (!backfill.has(anchor.alias))
35
+ return anchor;
36
+ backfilled.push(anchor.alias);
37
+ const sourceFile = 'source_file' in anchor ? anchor.source_file : undefined;
38
+ return {
39
+ kind: 'literal',
40
+ alias: anchor.alias,
41
+ type_text: texts[anchor.alias],
42
+ anchor_origin: 'anchor-backfill',
43
+ ...(sourceFile ? { source_file: sourceFile } : {}),
44
+ };
45
+ });
46
+ return { anchors: rerun, backfilled };
47
+ }
48
+ /**
49
+ * `host` answering every file parsed once into `parsed` with the same source
50
+ * file, except the files `fresh` names. Programs built on such hosts under
51
+ * the same options share their parsed (and bound) files, as an editor's
52
+ * programs do: the backfill's emit reuses the first emit's files, and the two
53
+ * stubs' self-checks reuse the declarations of the installed packages.
54
+ */
55
+ export function sharingHost(host, fresh, parsed = new Map()) {
56
+ const getSourceFile = host.getSourceFile.bind(host);
57
+ host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreate) => {
58
+ if (fresh(fileName))
59
+ return getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreate);
60
+ const key = `${fileName}\0${parseKey(languageVersionOrOptions)}`;
61
+ if (!shouldCreate && parsed.has(key))
62
+ return parsed.get(key);
63
+ const sourceFile = getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreate);
64
+ parsed.set(key, sourceFile);
65
+ return sourceFile;
66
+ };
67
+ return host;
68
+ }
69
+ /** What a file's parse depends on beside its text. */
70
+ function parseKey(languageVersionOrOptions) {
71
+ if (typeof languageVersionOrOptions !== 'object')
72
+ return String(languageVersionOrOptions);
73
+ const { languageVersion, impliedNodeFormat, jsDocParsingMode } = languageVersionOrOptions;
74
+ return `${languageVersion}:${impliedNodeFormat ?? ''}:${jsDocParsingMode ?? ''}`;
75
+ }