carrick 0.3.153 → 0.3.155
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/bin/carrick.mjs +26 -4
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +37 -3
- package/dist/contract.js +8 -0
- package/dist/contract.js.map +1 -1
- package/dist/facts/diff.d.ts +27 -0
- package/dist/facts/diff.js +134 -0
- package/dist/facts/diff.js.map +1 -0
- package/dist/facts/enabled.d.ts +2 -0
- package/dist/facts/enabled.js +9 -0
- package/dist/facts/enabled.js.map +1 -0
- package/dist/facts/fetch.d.ts +48 -0
- package/dist/facts/fetch.js +235 -0
- package/dist/facts/fetch.js.map +1 -0
- package/dist/facts/files.d.ts +21 -0
- package/dist/facts/files.js +58 -0
- package/dist/facts/files.js.map +1 -0
- package/dist/facts/lines.d.ts +70 -0
- package/dist/facts/lines.js +335 -0
- package/dist/facts/lines.js.map +1 -0
- package/dist/facts/match.d.ts +91 -0
- package/dist/facts/match.js +1122 -0
- package/dist/facts/match.js.map +1 -0
- package/dist/facts/peers.d.ts +48 -0
- package/dist/facts/peers.js +143 -0
- package/dist/facts/peers.js.map +1 -0
- package/dist/facts/refresh-run.d.ts +2 -0
- package/dist/facts/refresh-run.js +18 -0
- package/dist/facts/refresh-run.js.map +1 -0
- package/dist/facts/rules/packages.d.ts +16 -0
- package/dist/facts/rules/packages.js +157 -0
- package/dist/facts/rules/packages.js.map +1 -0
- package/dist/facts/rules/same-name.d.ts +28 -0
- package/dist/facts/rules/same-name.js +131 -0
- package/dist/facts/rules/same-name.js.map +1 -0
- package/dist/facts/store.d.ts +119 -0
- package/dist/facts/store.js +341 -0
- package/dist/facts/store.js.map +1 -0
- package/dist/git-remote.d.ts +6 -0
- package/dist/git-remote.js +37 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/hook/apply-patch.d.ts +23 -0
- package/dist/hook/apply-patch.js +92 -0
- package/dist/hook/apply-patch.js.map +1 -1
- package/dist/hook/bash-targets.d.ts +8 -0
- package/dist/hook/bash-targets.js +23 -11
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/edit-flow.d.ts +29 -2
- package/dist/hook/edit-flow.js +80 -29
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/late.d.ts +29 -0
- package/dist/hook/late.js +121 -26
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-bash.js +45 -22
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.d.ts +16 -1
- package/dist/hook/post-edit.js +177 -13
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +8 -12
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.d.ts +2 -0
- package/dist/hook/post-search.js +25 -0
- package/dist/hook/post-search.js.map +1 -0
- package/dist/hook/probe.d.ts +18 -3
- package/dist/hook/probe.js +30 -6
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/rechecks.d.ts +66 -11
- package/dist/hook/rechecks.js +115 -29
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/refresh.d.ts +9 -0
- package/dist/hook/refresh.js +10 -0
- package/dist/hook/refresh.js.map +1 -1
- package/dist/hook/reuse.d.ts +16 -2
- package/dist/hook/reuse.js +49 -6
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-key.d.ts +12 -0
- package/dist/hook/session-key.js +30 -0
- package/dist/hook/session-key.js.map +1 -0
- package/dist/hook/session-start.js +14 -7
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stop-wait.d.ts +2 -9
- package/dist/hook/stop-wait.js +96 -113
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/stop.js +13 -8
- package/dist/hook/stop.js.map +1 -1
- package/dist/hook/subagent-stop.d.ts +2 -0
- package/dist/hook/subagent-stop.js +45 -0
- package/dist/hook/subagent-stop.js.map +1 -0
- package/dist/hook/timings.d.ts +72 -0
- package/dist/hook/timings.js +175 -0
- package/dist/hook/timings.js.map +1 -0
- package/dist/hook/user-prompt.js +17 -13
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hook/worktree.d.ts +11 -0
- package/dist/hook/worktree.js +27 -1
- package/dist/hook/worktree.js.map +1 -1
- package/dist/init/repo-copies.d.ts +6 -0
- package/dist/init/repo-copies.js +7 -3
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/repos.d.ts +2 -2
- package/dist/init/repos.js +1 -34
- package/dist/init/repos.js.map +1 -1
- package/dist/init/settings.js +25 -13
- package/dist/init/settings.js.map +1 -1
- package/dist/render.d.ts +8 -33
- package/dist/render.js +42 -120
- package/dist/render.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/hooks.json +44 -3
- package/scripts/install-scanned-deps.sh +25 -2
- package/sidecar/dist/src/capture/anchors.d.ts +12 -1
- package/sidecar/dist/src/capture/anchors.js +28 -47
- package/sidecar/dist/src/capture/api.d.ts +41 -1
- package/sidecar/dist/src/capture/augmentations.d.ts +2 -0
- package/sidecar/dist/src/capture/augmentations.js +1 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +12 -1
- package/sidecar/dist/src/capture/check-classify.js +43 -0
- package/sidecar/dist/src/capture/check-deep.d.ts +44 -1
- package/sidecar/dist/src/capture/check-deep.js +161 -2
- package/sidecar/dist/src/capture/check.js +23 -2
- package/sidecar/dist/src/capture/checkout.d.ts +9 -3
- package/sidecar/dist/src/capture/checkout.js +12 -5
- package/sidecar/dist/src/capture/deep-walk.d.ts +25 -0
- package/sidecar/dist/src/capture/deep-walk.js +41 -0
- package/sidecar/dist/src/capture/deno-project.d.ts +22 -0
- package/sidecar/dist/src/capture/deno-project.js +48 -1
- package/sidecar/dist/src/capture/index.d.ts +3 -1
- package/sidecar/dist/src/capture/index.js +14 -4
- package/sidecar/dist/src/capture/machinery.d.ts +8 -53
- package/sidecar/dist/src/capture/machinery.js +10 -157
- package/sidecar/dist/src/capture/node-builder.d.ts +6 -0
- package/sidecar/dist/src/capture/self-check.d.ts +7 -0
- package/sidecar/dist/src/capture/self-check.js +44 -1
- package/sidecar/dist/src/capture/site-node.d.ts +166 -0
- package/sidecar/dist/src/capture/site-node.js +570 -0
- package/sidecar/dist/src/capture/tool-env.d.ts +12 -0
- package/sidecar/dist/src/capture/tool-env.js +26 -0
- package/sidecar/dist/src/default-library.d.ts +39 -0
- package/sidecar/dist/src/default-library.js +132 -0
- package/sidecar/dist/src/definition-resolver.js +2 -0
- package/sidecar/dist/src/index.js +1 -1
- package/sidecar/dist/src/library-claims.d.ts +2 -0
- package/sidecar/dist/src/library-claims.js +387 -37
- package/sidecar/dist/src/node-index.d.ts +2 -0
- package/sidecar/dist/src/node-index.js +5 -1
- package/sidecar/dist/src/position-rows.d.ts +78 -7
- package/sidecar/dist/src/position-rows.js +343 -18
- package/sidecar/dist/src/project-loader.d.ts +3 -3
- package/sidecar/dist/src/project-loader.js +18 -9
- package/sidecar/dist/src/retype.d.ts +13 -0
- package/sidecar/dist/src/retype.js +126 -0
- package/sidecar/dist/src/type-inferrer.d.ts +47 -145
- package/sidecar/dist/src/type-inferrer.js +102 -529
- package/sidecar/dist/src/types.d.ts +64 -2
- package/sidecar/dist/src/validators.d.ts +806 -142
- package/sidecar/dist/src/validators.js +12 -1
|
@@ -35,6 +35,8 @@ export interface IndexedNode {
|
|
|
35
35
|
export declare function nodeIndexBuilds(): number;
|
|
36
36
|
/** The ts-morph node for an indexed one. */
|
|
37
37
|
export declare function wrap<T extends Node = Node>(sourceFile: SourceFile, entry: IndexedNode): T;
|
|
38
|
+
/** The ts-morph node for one of the file's compiler nodes. */
|
|
39
|
+
export declare function wrapCompilerNode<T extends Node = Node>(sourceFile: SourceFile, node: ts.Node): T;
|
|
38
40
|
/** Every descendant, in `getDescendants()` order. */
|
|
39
41
|
export declare function descendantsOf(sourceFile: SourceFile): readonly IndexedNode[];
|
|
40
42
|
/**
|
|
@@ -65,7 +65,11 @@ function buildIndex(sourceFile) {
|
|
|
65
65
|
}
|
|
66
66
|
/** The ts-morph node for an indexed one. */
|
|
67
67
|
export function wrap(sourceFile, entry) {
|
|
68
|
-
return
|
|
68
|
+
return wrapCompilerNode(sourceFile, entry.node);
|
|
69
|
+
}
|
|
70
|
+
/** The ts-morph node for one of the file's compiler nodes. */
|
|
71
|
+
export function wrapCompilerNode(sourceFile, node) {
|
|
72
|
+
return internals(sourceFile)._getNodeFromCompilerNode(node);
|
|
69
73
|
}
|
|
70
74
|
/** Every descendant, in `getDescendants()` order. */
|
|
71
75
|
export function descendantsOf(sourceFile) {
|
|
@@ -31,8 +31,13 @@
|
|
|
31
31
|
* nothing read them. Implementations are asked for where discovery stops
|
|
32
32
|
* (carrick#2432).
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Version 6 added `receiver_type` rows: beside a `member` row,
|
|
35
|
+
* at the span of the object it is read on, the declaration of each named class
|
|
36
|
+
* or interface that object's type holds, when the member is declared in
|
|
37
|
+
* another package than the class. Several share one key, ordered as `decl`.
|
|
38
|
+
*
|
|
39
|
+
* A row's key is `(start, end, kind)`, except that several `decl` and
|
|
40
|
+
* `receiver_type` rows share one: TypeScript `getStart()`/`getEnd()` of the
|
|
36
41
|
* node, in UTF-16 code units from the start of the file, which is what the scanner's `sidecar_position`
|
|
37
42
|
* gives for an SWC span. Every path written is relative to the scanned repo's
|
|
38
43
|
* root, with `/` separators.
|
|
@@ -51,7 +56,7 @@ import { ts } from 'ts-morph';
|
|
|
51
56
|
import type { ProjectLoader } from './project-loader.js';
|
|
52
57
|
import type { PositionRowsCounts } from './types.js';
|
|
53
58
|
/** The format's version, written in the header. */
|
|
54
|
-
export declare const POSITION_ROWS_VERSION =
|
|
59
|
+
export declare const POSITION_ROWS_VERSION = 7;
|
|
55
60
|
/** The type is `any`, declared or inferred. Never set with the error type. */
|
|
56
61
|
export declare const FLAG_ANY = 1;
|
|
57
62
|
/** The type is the compiler's error type: something did not resolve. */
|
|
@@ -77,16 +82,26 @@ export declare const FLAG_MODULE_DEFAULT = 64;
|
|
|
77
82
|
* function returns, or an awaitable of one), so the library runs it and
|
|
78
83
|
* hands its result back (carrick#2634). Set when the call passes at least
|
|
79
84
|
* one argument at a function-typed parameter and every such parameter
|
|
80
|
-
* meets that return. The last
|
|
81
|
-
*
|
|
82
|
-
* `src/position_rows.rs` by
|
|
85
|
+
* meets that return. The last bit of the first byte: the flags widened to
|
|
86
|
+
* sixteen bits with {@link FLAG_DECLARED_TYPE} (format 7). Pinned to
|
|
87
|
+
* `FLAG_RUNS_HANDED` in `src/position_rows.rs` by
|
|
88
|
+
* `position-rows-runs-handed.test.ts`.
|
|
83
89
|
*/
|
|
84
90
|
export declare const FLAG_RUNS_HANDED = 128;
|
|
91
|
+
/**
|
|
92
|
+
* A `receiver_type` row only: the row names the type alias a package
|
|
93
|
+
* declares that the receiver was *declared* as, not a type the value holds
|
|
94
|
+
* ("declared, not held"). The compiler's printed type of a proxy is what the
|
|
95
|
+
* alias expands to (an alias of an alias, an intersection), so a reader cannot
|
|
96
|
+
* get the alias from the value. Pinned to `FLAG_DECLARED_TYPE` in
|
|
97
|
+
* `src/position_rows.rs` by `position-rows-declared-type.test.ts`.
|
|
98
|
+
*/
|
|
99
|
+
export declare const FLAG_DECLARED_TYPE = 256;
|
|
85
100
|
/** The most `decl` rows one position lists. */
|
|
86
101
|
export declare const DECL_CAP = 16;
|
|
87
102
|
/** The kinds {@link kindOf} gives a node; `decl` and `jsx` rows are written beside them. */
|
|
88
103
|
export type NodeKind = 'call' | 'member' | 'compare' | 'ident';
|
|
89
|
-
export type PositionKind = NodeKind | 'decl' | 'jsx' | 'typed_decl';
|
|
104
|
+
export type PositionKind = NodeKind | 'decl' | 'jsx' | 'typed_decl' | 'receiver_type';
|
|
90
105
|
/** `[kind, start, end, symbol, decl_file, decl_line, decl_package, type_text, flags]` */
|
|
91
106
|
export type PositionRow = [
|
|
92
107
|
PositionKind,
|
|
@@ -247,6 +262,62 @@ export declare class PositionWalker {
|
|
|
247
262
|
* A throw writes one row flagged {@link FLAG_CHECKER_THREW}.
|
|
248
263
|
*/
|
|
249
264
|
private declRows;
|
|
265
|
+
/**
|
|
266
|
+
* The `receiver_type` rows of a `member` row, at the
|
|
267
|
+
* span of the object the member is read on: the declaration of each named
|
|
268
|
+
* class the receiver's type holds, written only where the
|
|
269
|
+
* member is declared in another package than that class (an `on` the class
|
|
270
|
+
* inherits from a base package). The checker's type after
|
|
271
|
+
* `getNonNullableType` is read, so an alias of a class is already the
|
|
272
|
+
* class, and an intersection or union gives one row per named constituent
|
|
273
|
+
* (an anonymous object type has no name). The class's package is the one
|
|
274
|
+
* it is declared in, a workspace package or the checkout's own included;
|
|
275
|
+
* one with no package gives none. Sorted by file, then position; past
|
|
276
|
+
* {@link DECL_CAP} one row with {@link FLAG_TOO_MANY} and nothing else. No
|
|
277
|
+
* type text. A throw writes none: the `member` row carries the flag.
|
|
278
|
+
*/
|
|
279
|
+
private receiverTypeRows;
|
|
280
|
+
/**
|
|
281
|
+
* The {@link FLAG_DECLARED_TYPE} row of a member read's receiver: the type
|
|
282
|
+
* alias a package declares that the receiver was declared as. Read from
|
|
283
|
+
* the declaration, never the value: the receiver symbol's annotation, else
|
|
284
|
+
* the declared return of the make its initializer calls (or the call the
|
|
285
|
+
* receiver is), walked through the checkout's own aliases to the first
|
|
286
|
+
* package alias (the first constituent of a union or intersection that has
|
|
287
|
+
* one). Only aliases: an interface or class is what the class rows are for.
|
|
288
|
+
* Only where the member read sits on a call's callee chain
|
|
289
|
+
* (`a.b.c()`); a plain property read gives none. At most one row per
|
|
290
|
+
* receiver span, outside {@link DECL_CAP}, and not subject to the
|
|
291
|
+
* same-package skip of the class rows. A throw writes none.
|
|
292
|
+
*/
|
|
293
|
+
private declaredTypeRow;
|
|
294
|
+
/** The type node a receiver is declared by: its symbol's annotation, or the declared return of the call it is made by. */
|
|
295
|
+
private declaredTypeNode;
|
|
296
|
+
/** The declared return type node of the signature a call resolves to. */
|
|
297
|
+
private returnTypeNode;
|
|
298
|
+
/**
|
|
299
|
+
* The first type alias a package declares that `typeNode` names, through
|
|
300
|
+
* the checkout's own aliases (`type Runner = Inner`), a union or an
|
|
301
|
+
* intersection, in order. An alias, interface or class of the checkout
|
|
302
|
+
* that is not an alias is a stop; so is the default library.
|
|
303
|
+
*/
|
|
304
|
+
private packageAlias;
|
|
305
|
+
/**
|
|
306
|
+
* The name a `receiver_type` row gives a class. A class written
|
|
307
|
+
* `export default class Cursor` has the symbol name `default`, which is
|
|
308
|
+
* its package's `default` only where it is declared in the file the
|
|
309
|
+
* package's name resolves to; in an inner module it is named as written
|
|
310
|
+
* (`Cursor`), the name a package re-exports it under by convention. An
|
|
311
|
+
* anonymous default class of an inner module has no name: no row.
|
|
312
|
+
*/
|
|
313
|
+
private publishedClassName;
|
|
314
|
+
private entries;
|
|
315
|
+
/**
|
|
316
|
+
* The file `pkg` resolves to from `from`, a file of that package, so the
|
|
317
|
+
* installed copy `from` is in answers (two versions of one package resolve
|
|
318
|
+
* apart). Cached by package and directory.
|
|
319
|
+
*/
|
|
320
|
+
private packageEntry;
|
|
250
321
|
/**
|
|
251
322
|
* The `typed_decl` row of a call (carrick#2448): the callee is a value
|
|
252
323
|
* (a parameter, a property, a local) whose type is a named function's own
|
|
@@ -31,8 +31,13 @@
|
|
|
31
31
|
* nothing read them. Implementations are asked for where discovery stops
|
|
32
32
|
* (carrick#2432).
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Version 6 added `receiver_type` rows: beside a `member` row,
|
|
35
|
+
* at the span of the object it is read on, the declaration of each named class
|
|
36
|
+
* or interface that object's type holds, when the member is declared in
|
|
37
|
+
* another package than the class. Several share one key, ordered as `decl`.
|
|
38
|
+
*
|
|
39
|
+
* A row's key is `(start, end, kind)`, except that several `decl` and
|
|
40
|
+
* `receiver_type` rows share one: TypeScript `getStart()`/`getEnd()` of the
|
|
36
41
|
* node, in UTF-16 code units from the start of the file, which is what the scanner's `sidecar_position`
|
|
37
42
|
* gives for an SWC span. Every path written is relative to the scanned repo's
|
|
38
43
|
* root, with `/` separators.
|
|
@@ -52,11 +57,11 @@ import * as fs from 'node:fs';
|
|
|
52
57
|
import * as path from 'node:path';
|
|
53
58
|
import * as zlib from 'node:zlib';
|
|
54
59
|
import { ts } from 'ts-morph';
|
|
55
|
-
import { WriteGuard, installedPackageDirectory, isDeclarationFileName, moduleExport, toPosix } from './capture/index.js';
|
|
60
|
+
import { WriteGuard, installedPackageDirectory, isDeclarationFileName, isRelative, moduleExport, toPosix } from './capture/index.js';
|
|
56
61
|
import { attributedDeclaration, installedPackageOf, typeDeclaration } from './declaration-attribution.js';
|
|
57
62
|
import { typeToStringAsDeclared } from './print-type.js';
|
|
58
63
|
/** The format's version, written in the header. */
|
|
59
|
-
export const POSITION_ROWS_VERSION =
|
|
64
|
+
export const POSITION_ROWS_VERSION = 7;
|
|
60
65
|
/** The type is `any`, declared or inferred. Never set with the error type. */
|
|
61
66
|
export const FLAG_ANY = 1;
|
|
62
67
|
/** The type is the compiler's error type: something did not resolve. */
|
|
@@ -82,11 +87,21 @@ export const FLAG_MODULE_DEFAULT = 64;
|
|
|
82
87
|
* function returns, or an awaitable of one), so the library runs it and
|
|
83
88
|
* hands its result back (carrick#2634). Set when the call passes at least
|
|
84
89
|
* one argument at a function-typed parameter and every such parameter
|
|
85
|
-
* meets that return. The last
|
|
86
|
-
*
|
|
87
|
-
* `src/position_rows.rs` by
|
|
90
|
+
* meets that return. The last bit of the first byte: the flags widened to
|
|
91
|
+
* sixteen bits with {@link FLAG_DECLARED_TYPE} (format 7). Pinned to
|
|
92
|
+
* `FLAG_RUNS_HANDED` in `src/position_rows.rs` by
|
|
93
|
+
* `position-rows-runs-handed.test.ts`.
|
|
88
94
|
*/
|
|
89
95
|
export const FLAG_RUNS_HANDED = 128;
|
|
96
|
+
/**
|
|
97
|
+
* A `receiver_type` row only: the row names the type alias a package
|
|
98
|
+
* declares that the receiver was *declared* as, not a type the value holds
|
|
99
|
+
* ("declared, not held"). The compiler's printed type of a proxy is what the
|
|
100
|
+
* alias expands to (an alias of an alias, an intersection), so a reader cannot
|
|
101
|
+
* get the alias from the value. Pinned to `FLAG_DECLARED_TYPE` in
|
|
102
|
+
* `src/position_rows.rs` by `position-rows-declared-type.test.ts`.
|
|
103
|
+
*/
|
|
104
|
+
export const FLAG_DECLARED_TYPE = 256;
|
|
90
105
|
/** The most `decl` rows one position lists. */
|
|
91
106
|
export const DECL_CAP = 16;
|
|
92
107
|
const COMPARE_OPERATORS = new Set([
|
|
@@ -170,6 +185,7 @@ export function writePositionRows(options) {
|
|
|
170
185
|
}
|
|
171
186
|
read.set(index, sourceFile?.getFilePath());
|
|
172
187
|
}
|
|
188
|
+
loadRequiredPackages(project, [...read.values()].filter((f) => f !== undefined));
|
|
173
189
|
// Built once, after every file the group adds. The language service's
|
|
174
190
|
// program is the one walked, as it was when go-to-implementation answered
|
|
175
191
|
// over it (carrick#2430, dropped in #2561): its rows are pinned.
|
|
@@ -426,6 +442,12 @@ export class PositionWalker {
|
|
|
426
442
|
for (const decl of this.declRows(kind, node))
|
|
427
443
|
rows.push(['decl', row[1], row[2], ...tail(decl)]);
|
|
428
444
|
}
|
|
445
|
+
if (kind === 'member' && !(row[8] & FLAG_CHECKER_THREW)) {
|
|
446
|
+
rows.push(...this.receiverTypeRows(node, row));
|
|
447
|
+
const declared = this.declaredTypeRow(node);
|
|
448
|
+
if (declared)
|
|
449
|
+
rows.push(declared);
|
|
450
|
+
}
|
|
429
451
|
if (kind === 'call' && !(row[8] & FLAG_CHECKER_THREW)) {
|
|
430
452
|
const typed = this.typedDeclRow(node, row[1], row[2]);
|
|
431
453
|
if (typed)
|
|
@@ -748,6 +770,214 @@ export class PositionWalker {
|
|
|
748
770
|
rows.sort((a, b) => compareNames(a.row[4], b.row[4]) || a.start - b.start);
|
|
749
771
|
return rows.map(({ row }) => row);
|
|
750
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* The `receiver_type` rows of a `member` row, at the
|
|
775
|
+
* span of the object the member is read on: the declaration of each named
|
|
776
|
+
* class the receiver's type holds, written only where the
|
|
777
|
+
* member is declared in another package than that class (an `on` the class
|
|
778
|
+
* inherits from a base package). The checker's type after
|
|
779
|
+
* `getNonNullableType` is read, so an alias of a class is already the
|
|
780
|
+
* class, and an intersection or union gives one row per named constituent
|
|
781
|
+
* (an anonymous object type has no name). The class's package is the one
|
|
782
|
+
* it is declared in, a workspace package or the checkout's own included;
|
|
783
|
+
* one with no package gives none. Sorted by file, then position; past
|
|
784
|
+
* {@link DECL_CAP} one row with {@link FLAG_TOO_MANY} and nothing else. No
|
|
785
|
+
* type text. A throw writes none: the `member` row carries the flag.
|
|
786
|
+
*/
|
|
787
|
+
receiverTypeRows(node, member) {
|
|
788
|
+
if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node))
|
|
789
|
+
return [];
|
|
790
|
+
const memberPackage = member[6];
|
|
791
|
+
if (member[4] === null)
|
|
792
|
+
return [];
|
|
793
|
+
try {
|
|
794
|
+
const receiver = node.expression;
|
|
795
|
+
const start = receiver.getStart(node.getSourceFile());
|
|
796
|
+
const end = receiver.getEnd();
|
|
797
|
+
const type = this.checker.getNonNullableType(this.checker.getTypeAtLocation(receiver));
|
|
798
|
+
const constituents = type.isUnionOrIntersection() ? type.types : [type];
|
|
799
|
+
const found = new Map();
|
|
800
|
+
for (const constituent of constituents) {
|
|
801
|
+
const held = this.checker.getNonNullableType(constituent);
|
|
802
|
+
const symbol = held.getSymbol();
|
|
803
|
+
if (!symbol || symbol.name.startsWith('__'))
|
|
804
|
+
continue;
|
|
805
|
+
// Classes only: interface rows (a framework's request and response types) were most of the rows' growth.
|
|
806
|
+
if (!(symbol.flags & ts.SymbolFlags.Class))
|
|
807
|
+
continue;
|
|
808
|
+
const declaration = this.typeDeclaration(held);
|
|
809
|
+
if (declaration)
|
|
810
|
+
found.set(declaration, symbol);
|
|
811
|
+
}
|
|
812
|
+
const rows = [];
|
|
813
|
+
for (const [declaration, symbol] of found) {
|
|
814
|
+
const file = declaration.getSourceFile();
|
|
815
|
+
const at = declaration.getStart(file);
|
|
816
|
+
const { declFile, declLine, declPackage } = this.located(file, at);
|
|
817
|
+
if (declPackage === null || declPackage === memberPackage)
|
|
818
|
+
continue;
|
|
819
|
+
const name = this.publishedClassName(symbol, declaration, declPackage);
|
|
820
|
+
if (name === undefined)
|
|
821
|
+
continue;
|
|
822
|
+
let flags = this.publication(symbol, declaration);
|
|
823
|
+
if (declFile === null)
|
|
824
|
+
flags |= FLAG_DECLARATION_UNNAMED;
|
|
825
|
+
rows.push({
|
|
826
|
+
start: at,
|
|
827
|
+
row: ['receiver_type', start, end, name, declFile, declLine, declPackage, null, flags],
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
if (rows.length > DECL_CAP) {
|
|
831
|
+
return [['receiver_type', start, end, null, null, null, null, null, FLAG_TOO_MANY]];
|
|
832
|
+
}
|
|
833
|
+
rows.sort((a, b) => compareNames(a.row[4], b.row[4]) || a.start - b.start);
|
|
834
|
+
return rows.map(({ row }) => row);
|
|
835
|
+
}
|
|
836
|
+
catch {
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* The {@link FLAG_DECLARED_TYPE} row of a member read's receiver: the type
|
|
842
|
+
* alias a package declares that the receiver was declared as. Read from
|
|
843
|
+
* the declaration, never the value: the receiver symbol's annotation, else
|
|
844
|
+
* the declared return of the make its initializer calls (or the call the
|
|
845
|
+
* receiver is), walked through the checkout's own aliases to the first
|
|
846
|
+
* package alias (the first constituent of a union or intersection that has
|
|
847
|
+
* one). Only aliases: an interface or class is what the class rows are for.
|
|
848
|
+
* Only where the member read sits on a call's callee chain
|
|
849
|
+
* (`a.b.c()`); a plain property read gives none. At most one row per
|
|
850
|
+
* receiver span, outside {@link DECL_CAP}, and not subject to the
|
|
851
|
+
* same-package skip of the class rows. A throw writes none.
|
|
852
|
+
*/
|
|
853
|
+
declaredTypeRow(node) {
|
|
854
|
+
if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node))
|
|
855
|
+
return undefined;
|
|
856
|
+
if (!isOnCalleeChain(node))
|
|
857
|
+
return undefined;
|
|
858
|
+
try {
|
|
859
|
+
const receiver = node.expression;
|
|
860
|
+
const typeNode = this.declaredTypeNode(receiver);
|
|
861
|
+
if (!typeNode)
|
|
862
|
+
return undefined;
|
|
863
|
+
const found = this.packageAlias(typeNode, new Set(), 0);
|
|
864
|
+
if (!found)
|
|
865
|
+
return undefined;
|
|
866
|
+
const { symbol, declaration, declFile, declLine, declPackage } = found;
|
|
867
|
+
const start = receiver.getStart(node.getSourceFile());
|
|
868
|
+
const flags = this.publication(symbol, declaration) | FLAG_DECLARED_TYPE;
|
|
869
|
+
return ['receiver_type', start, receiver.getEnd(), ts.symbolName(symbol), declFile, declLine, declPackage, null, flags];
|
|
870
|
+
}
|
|
871
|
+
catch {
|
|
872
|
+
return undefined;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
/** The type node a receiver is declared by: its symbol's annotation, or the declared return of the call it is made by. */
|
|
876
|
+
declaredTypeNode(receiver) {
|
|
877
|
+
const expression = skipWrappers(receiver);
|
|
878
|
+
if (ts.isCallExpression(expression))
|
|
879
|
+
return this.returnTypeNode(expression);
|
|
880
|
+
const name = ts.isPropertyAccessExpression(expression)
|
|
881
|
+
? expression.name
|
|
882
|
+
: ts.isIdentifier(expression)
|
|
883
|
+
? expression
|
|
884
|
+
: undefined;
|
|
885
|
+
let symbol = name ? this.checker.getSymbolAtLocation(name) : undefined;
|
|
886
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
887
|
+
symbol = this.checker.getAliasedSymbol(symbol);
|
|
888
|
+
const declaration = symbol?.valueDeclaration;
|
|
889
|
+
if (!declaration ||
|
|
890
|
+
!(ts.isVariableDeclaration(declaration) ||
|
|
891
|
+
ts.isPropertyDeclaration(declaration) ||
|
|
892
|
+
ts.isPropertySignature(declaration) ||
|
|
893
|
+
ts.isParameter(declaration))) {
|
|
894
|
+
return undefined;
|
|
895
|
+
}
|
|
896
|
+
if (declaration.type)
|
|
897
|
+
return declaration.type;
|
|
898
|
+
const initializer = 'initializer' in declaration ? declaration.initializer : undefined;
|
|
899
|
+
if (!initializer || ts.isParameter(declaration))
|
|
900
|
+
return undefined;
|
|
901
|
+
const made = skipWrappers(initializer);
|
|
902
|
+
return ts.isCallExpression(made) ? this.returnTypeNode(made) : undefined;
|
|
903
|
+
}
|
|
904
|
+
/** The declared return type node of the signature a call resolves to. */
|
|
905
|
+
returnTypeNode(call) {
|
|
906
|
+
const type = this.checker.getResolvedSignature(call)?.declaration?.type;
|
|
907
|
+
return type && ts.isTypeNode(type) ? type : undefined;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* The first type alias a package declares that `typeNode` names, through
|
|
911
|
+
* the checkout's own aliases (`type Runner = Inner`), a union or an
|
|
912
|
+
* intersection, in order. An alias, interface or class of the checkout
|
|
913
|
+
* that is not an alias is a stop; so is the default library.
|
|
914
|
+
*/
|
|
915
|
+
packageAlias(typeNode, seen, depth) {
|
|
916
|
+
if (depth > DECLARED_WALK_DEPTH)
|
|
917
|
+
return undefined;
|
|
918
|
+
if (ts.isParenthesizedTypeNode(typeNode))
|
|
919
|
+
return this.packageAlias(typeNode.type, seen, depth + 1);
|
|
920
|
+
if (ts.isUnionTypeNode(typeNode) || ts.isIntersectionTypeNode(typeNode)) {
|
|
921
|
+
for (const member of typeNode.types) {
|
|
922
|
+
const found = this.packageAlias(member, seen, depth + 1);
|
|
923
|
+
if (found)
|
|
924
|
+
return found;
|
|
925
|
+
}
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
if (!ts.isTypeReferenceNode(typeNode))
|
|
929
|
+
return undefined;
|
|
930
|
+
const name = ts.isQualifiedName(typeNode.typeName) ? typeNode.typeName.right : typeNode.typeName;
|
|
931
|
+
let symbol = this.checker.getSymbolAtLocation(name);
|
|
932
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
933
|
+
symbol = this.checker.getAliasedSymbol(symbol);
|
|
934
|
+
if (!symbol || seen.has(symbol) || !(symbol.flags & ts.SymbolFlags.TypeAlias))
|
|
935
|
+
return undefined;
|
|
936
|
+
seen.add(symbol);
|
|
937
|
+
const declaration = symbol.declarations?.find(ts.isTypeAliasDeclaration);
|
|
938
|
+
if (!declaration)
|
|
939
|
+
return undefined;
|
|
940
|
+
const file = declaration.getSourceFile();
|
|
941
|
+
const { declFile, declLine, declPackage } = this.located(file, declaration.getStart(file));
|
|
942
|
+
if (declFile === null || declFile.startsWith('lib:'))
|
|
943
|
+
return undefined;
|
|
944
|
+
if (declFile.startsWith('pkg:') || declFile.split('/').includes('node_modules')) {
|
|
945
|
+
return declPackage === null ? undefined : { symbol, declaration, declFile, declLine, declPackage };
|
|
946
|
+
}
|
|
947
|
+
return this.packageAlias(declaration.type, seen, depth + 1);
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* The name a `receiver_type` row gives a class. A class written
|
|
951
|
+
* `export default class Cursor` has the symbol name `default`, which is
|
|
952
|
+
* its package's `default` only where it is declared in the file the
|
|
953
|
+
* package's name resolves to; in an inner module it is named as written
|
|
954
|
+
* (`Cursor`), the name a package re-exports it under by convention. An
|
|
955
|
+
* anonymous default class of an inner module has no name: no row.
|
|
956
|
+
*/
|
|
957
|
+
publishedClassName(symbol, declaration, declPackage) {
|
|
958
|
+
const name = ts.symbolName(symbol);
|
|
959
|
+
if (name !== ts.InternalSymbolName.Default)
|
|
960
|
+
return name;
|
|
961
|
+
const file = declaration.getSourceFile();
|
|
962
|
+
if (this.packageEntry(declPackage, file) === file.fileName)
|
|
963
|
+
return name;
|
|
964
|
+
const own = ts.getNameOfDeclaration(declaration);
|
|
965
|
+
return own && ts.isIdentifier(own) ? own.text : undefined;
|
|
966
|
+
}
|
|
967
|
+
entries = new Map();
|
|
968
|
+
/**
|
|
969
|
+
* The file `pkg` resolves to from `from`, a file of that package, so the
|
|
970
|
+
* installed copy `from` is in answers (two versions of one package resolve
|
|
971
|
+
* apart). Cached by package and directory.
|
|
972
|
+
*/
|
|
973
|
+
packageEntry(pkg, from) {
|
|
974
|
+
const key = `${pkg}\0${from.fileName.slice(0, from.fileName.lastIndexOf('/'))}`;
|
|
975
|
+
if (!this.entries.has(key)) {
|
|
976
|
+
const resolved = ts.resolveModuleName(pkg, from.fileName, this.program.getCompilerOptions(), this.resolutionHost()).resolvedModule;
|
|
977
|
+
this.entries.set(key, resolved?.resolvedFileName);
|
|
978
|
+
}
|
|
979
|
+
return this.entries.get(key);
|
|
980
|
+
}
|
|
751
981
|
/**
|
|
752
982
|
* The `typed_decl` row of a call (carrick#2448): the callee is a value
|
|
753
983
|
* (a parameter, a property, a local) whose type is a named function's own
|
|
@@ -902,21 +1132,19 @@ export class PositionWalker {
|
|
|
902
1132
|
}
|
|
903
1133
|
/** `"m"` of a call `require("m")` to the global `require`, else `undefined`. */
|
|
904
1134
|
requireSpecifier(expression) {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const callee = expression.expression;
|
|
908
|
-
const argument = expression.arguments[0];
|
|
909
|
-
if (!ts.isIdentifier(callee) || callee.text !== 'require' || !ts.isStringLiteral(argument))
|
|
1135
|
+
const specifier = requireCallSpecifier(expression);
|
|
1136
|
+
if (specifier === undefined || !ts.isCallExpression(expression))
|
|
910
1137
|
return undefined;
|
|
911
|
-
// The global `require` is declared in a declaration file
|
|
912
|
-
//
|
|
913
|
-
|
|
914
|
-
|
|
1138
|
+
// The global `require` is declared in a declaration file, by a `declare`
|
|
1139
|
+
// in the source (carrick#3971), or nowhere; a `require` the service
|
|
1140
|
+
// writes is a declaration in its own source with a body.
|
|
1141
|
+
const own = (this.checker.getSymbolAtLocation(expression.expression)?.declarations ?? []).some((d) => !d.getSourceFile().isDeclarationFile && !isAmbient(d));
|
|
1142
|
+
return own ? undefined : specifier;
|
|
915
1143
|
}
|
|
916
1144
|
exportOfRequired(binding) {
|
|
917
1145
|
const sourceOf = (specifier) => {
|
|
918
|
-
const resolved =
|
|
919
|
-
return resolved ? this.program.getSourceFile(resolved
|
|
1146
|
+
const resolved = resolveRequired(specifier, binding.from.fileName, this.program.getCompilerOptions(), this.resolutionHost());
|
|
1147
|
+
return resolved ? this.program.getSourceFile(resolved) : undefined;
|
|
920
1148
|
};
|
|
921
1149
|
// The require that runs wins; the cast is read only when it names no file.
|
|
922
1150
|
const target = sourceOf(binding.specifier) ?? (binding.castSpecifier !== undefined ? sourceOf(binding.castSpecifier) : undefined);
|
|
@@ -932,10 +1160,106 @@ export class PositionWalker {
|
|
|
932
1160
|
return this.host;
|
|
933
1161
|
}
|
|
934
1162
|
}
|
|
1163
|
+
/** Whether a node is under a `declare`: it declares a value and gives it no body. */
|
|
1164
|
+
function isAmbient(node) {
|
|
1165
|
+
for (let current = node; current; current = current.parent) {
|
|
1166
|
+
if (ts.canHaveModifiers(current) && ts.getModifiers(current)?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword))
|
|
1167
|
+
return true;
|
|
1168
|
+
}
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
/** `"m"` of a call `require("m")` with one string literal, read from the syntax alone. */
|
|
1172
|
+
function requireCallSpecifier(expression) {
|
|
1173
|
+
if (!ts.isCallExpression(expression) || expression.arguments.length !== 1)
|
|
1174
|
+
return undefined;
|
|
1175
|
+
const callee = expression.expression;
|
|
1176
|
+
const argument = expression.arguments[0];
|
|
1177
|
+
if (!ts.isIdentifier(callee) || callee.text !== 'require' || !ts.isStringLiteral(argument))
|
|
1178
|
+
return undefined;
|
|
1179
|
+
return argument.text;
|
|
1180
|
+
}
|
|
1181
|
+
/** The file `require(specifier)` in the file `from` resolves to, as CommonJS. */
|
|
1182
|
+
function resolveRequired(specifier, from, options, host) {
|
|
1183
|
+
return ts.resolveModuleName(specifier, from, options, host, undefined, undefined, ts.ModuleKind.CommonJS).resolvedModule
|
|
1184
|
+
?.resolvedFileName;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Add to `project` the module of each package that a TypeScript file of
|
|
1188
|
+
* `fileNames` names in a `require("m")` call, before its program is built.
|
|
1189
|
+
* TypeScript follows such a call only in a JavaScript file, so a package that
|
|
1190
|
+
* is required and never imported is not in the program, and the carrick#2454
|
|
1191
|
+
* rule finds no module to name (carrick#3971). An `import` of the package
|
|
1192
|
+
* would load the same file. Relative specifiers are left as they are: a
|
|
1193
|
+
* required repo file the program does not list stays out of it. So is a
|
|
1194
|
+
* package's JavaScript: an import of a package with no types loads none.
|
|
1195
|
+
*/
|
|
1196
|
+
function loadRequiredPackages(project, fileNames) {
|
|
1197
|
+
const options = project.getCompilerOptions();
|
|
1198
|
+
let host;
|
|
1199
|
+
for (const fileName of fileNames) {
|
|
1200
|
+
if (!/\.[cm]?tsx?$/.test(fileName) || isDeclarationFileName(fileName))
|
|
1201
|
+
continue;
|
|
1202
|
+
const sourceFile = project.getSourceFile(fileName)?.compilerNode;
|
|
1203
|
+
if (!sourceFile || !sourceFile.text.includes('require'))
|
|
1204
|
+
continue;
|
|
1205
|
+
const specifiers = new Set();
|
|
1206
|
+
const visit = (node) => {
|
|
1207
|
+
if (ts.isCallExpression(node)) {
|
|
1208
|
+
const specifier = requireCallSpecifier(node);
|
|
1209
|
+
if (specifier !== undefined && !isRelative(specifier))
|
|
1210
|
+
specifiers.add(specifier);
|
|
1211
|
+
}
|
|
1212
|
+
ts.forEachChild(node, visit);
|
|
1213
|
+
};
|
|
1214
|
+
visit(sourceFile);
|
|
1215
|
+
for (const specifier of specifiers) {
|
|
1216
|
+
host ??= ts.createCompilerHost(options);
|
|
1217
|
+
const resolved = resolveRequired(specifier, sourceFile.fileName, options, host);
|
|
1218
|
+
if (!resolved || /\.[cm]?jsx?$/.test(resolved) || project.getSourceFile(resolved))
|
|
1219
|
+
continue;
|
|
1220
|
+
try {
|
|
1221
|
+
project.addSourceFileAtPath(resolved);
|
|
1222
|
+
}
|
|
1223
|
+
catch {
|
|
1224
|
+
// A module that cannot be read is left out, as before.
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
935
1229
|
/** A row's fields after its kind and span. */
|
|
936
1230
|
function tail(row) {
|
|
937
1231
|
return [row[3], row[4], row[5], row[6], row[7], row[8]];
|
|
938
1232
|
}
|
|
1233
|
+
/** How far a declared type is walked through the checkout's own aliases. */
|
|
1234
|
+
const DECLARED_WALK_DEPTH = 8;
|
|
1235
|
+
/** An expression without the wrappers that do not change what it is: `(x)`, `x!`. */
|
|
1236
|
+
function skipWrappers(expression) {
|
|
1237
|
+
let current = expression;
|
|
1238
|
+
while (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current))
|
|
1239
|
+
current = current.expression;
|
|
1240
|
+
return current;
|
|
1241
|
+
}
|
|
1242
|
+
/** Whether a member read is the callee, or an object on the callee's chain, of a call (`a.b.c()`). */
|
|
1243
|
+
function isOnCalleeChain(node) {
|
|
1244
|
+
let current = node;
|
|
1245
|
+
for (;;) {
|
|
1246
|
+
const parent = current.parent;
|
|
1247
|
+
if (!parent)
|
|
1248
|
+
return false;
|
|
1249
|
+
if (ts.isCallExpression(parent))
|
|
1250
|
+
return parent.expression === current;
|
|
1251
|
+
if (ts.isParenthesizedExpression(parent) || ts.isNonNullExpression(parent)) {
|
|
1252
|
+
current = parent;
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
if ((ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) &&
|
|
1256
|
+
parent.expression === current) {
|
|
1257
|
+
current = parent;
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
939
1263
|
/** Order two `decl_file` names, `null` last. */
|
|
940
1264
|
export function compareNames(a, b) {
|
|
941
1265
|
if (a === b)
|
|
@@ -996,6 +1320,7 @@ function nameNodeOf(kind, node) {
|
|
|
996
1320
|
return node;
|
|
997
1321
|
case 'decl':
|
|
998
1322
|
case 'typed_decl':
|
|
1323
|
+
case 'receiver_type':
|
|
999
1324
|
return undefined;
|
|
1000
1325
|
case 'jsx':
|
|
1001
1326
|
// The tag: `<Badge>`, `<ui.Button>`, `<this.Panel>`; a namespaced
|
|
@@ -120,9 +120,9 @@ export declare class ProjectLoader {
|
|
|
120
120
|
*/
|
|
121
121
|
private snapshotToCompilerOptions;
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
123
|
+
* The file system every project reads through: the default library from
|
|
124
|
+
* the compiler's own files (carrick#3509) and, under CARRICK_UNTRUSTED_TREE,
|
|
125
|
+
* nothing whose real path is outside the checkout (carrick#2230).
|
|
126
126
|
*/
|
|
127
127
|
private fileSystemOption;
|
|
128
128
|
/**
|
|
@@ -17,6 +17,7 @@ import { DenoProject, findDenoConfig, findServiceTsconfig, GoverningConfigs, ref
|
|
|
17
17
|
import { moduleFormatResolutionHost } from './module-format.js';
|
|
18
18
|
import { ExternalImports, registerExternalImports } from './origin.js';
|
|
19
19
|
import { pinProgramRoots } from './program-files.js';
|
|
20
|
+
import { defaultLibraryOptions } from './default-library.js';
|
|
20
21
|
/**
|
|
21
22
|
* Source-file patterns used when the repo declares no tsconfig, relative to
|
|
22
23
|
* the repo root. `node_modules` is excluded explicitly: a glob that matches
|
|
@@ -225,11 +226,16 @@ export class ProjectLoader {
|
|
|
225
226
|
this.buildProject = (kind) => {
|
|
226
227
|
const deno = new DenoProject(denoConfig, this.repoRoot);
|
|
227
228
|
this.denoProject = deno;
|
|
229
|
+
// Under CARRICK_UNTRUSTED_TREE the bound also admits the npm
|
|
230
|
+
// packages this graph resolved, and the resolver and the root
|
|
231
|
+
// list below hand the compiler nothing it refuses (carrick#4076).
|
|
232
|
+
const bound = untrustedReadBound(this.repoRoot, deno.readRoots);
|
|
233
|
+
deno.bindReadBound(bound);
|
|
228
234
|
// The graph's external-library verdicts, kept past the program
|
|
229
235
|
// rebuilds that drop them (carrick#1731).
|
|
230
236
|
const imports = new ExternalImports();
|
|
231
237
|
const project = new Project({
|
|
232
|
-
...this.fileSystemOption(),
|
|
238
|
+
...this.fileSystemOption(bound),
|
|
233
239
|
compilerOptions: sidecarCompilerOptions(optionsFor(kind, deno.parsed.options)),
|
|
234
240
|
skipAddingFilesFromTsConfig: true,
|
|
235
241
|
resolutionHost: imports.recording((host, getOptions) => ({
|
|
@@ -240,8 +246,12 @@ export class ProjectLoader {
|
|
|
240
246
|
registerExternalImports(project, imports);
|
|
241
247
|
pinProgramRoots(project, []);
|
|
242
248
|
if (kind === 'listed') {
|
|
243
|
-
|
|
244
|
-
|
|
249
|
+
// A listed file or a `types` root the bound refuses (a tracked
|
|
250
|
+
// link out, an outside path) is skipped, read as missing.
|
|
251
|
+
for (const file of deno.parsed.fileNames) {
|
|
252
|
+
if (!bound || bound.allows(file))
|
|
253
|
+
project.addSourceFileAtPath(file);
|
|
254
|
+
}
|
|
245
255
|
for (const diagnostic of deno.diagnostics)
|
|
246
256
|
this.logError(diagnostic);
|
|
247
257
|
}
|
|
@@ -360,13 +370,12 @@ export class ProjectLoader {
|
|
|
360
370
|
return result;
|
|
361
371
|
}
|
|
362
372
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
373
|
+
* The file system every project reads through: the default library from
|
|
374
|
+
* the compiler's own files (carrick#3509) and, under CARRICK_UNTRUSTED_TREE,
|
|
375
|
+
* nothing whose real path is outside the checkout (carrick#2230).
|
|
366
376
|
*/
|
|
367
|
-
fileSystemOption() {
|
|
368
|
-
|
|
369
|
-
return bound ? { fileSystem: boundedFileSystem(bound) } : {};
|
|
377
|
+
fileSystemOption(bound = untrustedReadBound(this.repoRoot)) {
|
|
378
|
+
return defaultLibraryOptions(bound ? boundedFileSystem(bound) : undefined);
|
|
370
379
|
}
|
|
371
380
|
/**
|
|
372
381
|
* A ts-morph project built from one tsconfig: with the files it lists, or
|