carrick 0.3.153 → 0.3.154
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/dist/contract.d.ts +27 -3
- package/dist/contract.js +8 -0
- package/dist/contract.js.map +1 -1
- package/dist/render.js +20 -7
- package/dist/render.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/scripts/install-scanned-deps.sh +25 -2
- package/sidecar/dist/src/capture/index.d.ts +1 -0
- package/sidecar/dist/src/capture/node-builder.d.ts +6 -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 +176 -17
- package/sidecar/dist/src/position-rows.d.ts +40 -4
- package/sidecar/dist/src/position-rows.js +111 -3
- package/sidecar/dist/src/project-loader.d.ts +3 -3
- package/sidecar/dist/src/project-loader.js +5 -4
- package/sidecar/dist/src/type-inferrer.d.ts +14 -0
- package/sidecar/dist/src/type-inferrer.js +34 -5
- package/sidecar/dist/src/types.d.ts +9 -0
- package/sidecar/dist/src/validators.d.ts +6 -0
- package/sidecar/dist/src/validators.js +1 -0
|
@@ -670,7 +670,7 @@ function handleListLibrarySurface(request) {
|
|
|
670
670
|
const { claimsVerifier } = projectComponents();
|
|
671
671
|
const fromDir = path.resolve(projectLoader.getRepoRoot(), request.from_dir);
|
|
672
672
|
log(`Listing the declared surface of ${request.packages.length} specifier(s) from ${fromDir}`);
|
|
673
|
-
const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, types: request.types, resultCandidates: request.result_candidates, maxHandlerMembers: request.max_handler_members });
|
|
673
|
+
const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, types: request.types, resultCandidates: request.result_candidates, maxHandlerMembers: request.max_handler_members, foreignMakerBudget: request.foreign_maker_budget });
|
|
674
674
|
return { request_id: request.request_id, status: 'success', surfaces, surface_sha256 };
|
|
675
675
|
}
|
|
676
676
|
catch (err) {
|
|
@@ -234,6 +234,8 @@ export interface SurfaceOptions {
|
|
|
234
234
|
resultCandidates?: boolean;
|
|
235
235
|
/** Handler-parameter members the whole call may list (default `HANDLER_LISTING_BUDGET`, carrick#3016). */
|
|
236
236
|
maxHandlerMembers?: number;
|
|
237
|
+
/** Estimated member makers of foreign values past which they list none (default `FOREIGN_MAKER_BUDGET`, carrick#3745). */
|
|
238
|
+
foreignMakerBudget?: number;
|
|
237
239
|
}
|
|
238
240
|
/** The name a service imports a package by: `@types/scope__name` is `@scope/name`, `@types/name` is `name`. */
|
|
239
241
|
export declare function importedNameOf(installed: string): string;
|
|
@@ -885,7 +885,13 @@ export class LibraryClaimsVerifier {
|
|
|
885
885
|
defaultImport: file.statements[at + 1],
|
|
886
886
|
};
|
|
887
887
|
};
|
|
888
|
-
const read = this.readProbe(fromDir, imports, (_checker, reader, file) =>
|
|
888
|
+
const read = this.readProbe(fromDir, imports, (_checker, reader, file) => {
|
|
889
|
+
const made = packages.map((pkg, i) => reader.exportMakers(pkg, probeOf(file, i), only[pkg]));
|
|
890
|
+
// One decision for the whole call: the checker's cost is the sum over its specifiers.
|
|
891
|
+
const estimate = made.reduce((sum, each) => sum + each.foreignMakerMembers, 0);
|
|
892
|
+
const gated = estimate > (options.foreignMakerBudget ?? FOREIGN_MAKER_BUDGET);
|
|
893
|
+
return made.map(each => reader.makersOf(each, gated));
|
|
894
|
+
});
|
|
889
895
|
const importLines = [];
|
|
890
896
|
const buildLines = [];
|
|
891
897
|
const builtIndex = new Map();
|
|
@@ -934,7 +940,8 @@ export class LibraryClaimsVerifier {
|
|
|
934
940
|
typeExports.push({ ...built, name });
|
|
935
941
|
}
|
|
936
942
|
}
|
|
937
|
-
|
|
943
|
+
const gate = { gated: read[i].gated, leftOut: read[i].makersLeftOut };
|
|
944
|
+
return reader.listPackage(pkg, probeOf(file, i), maxEntries, only[pkg], options, typeExports, gate, (name, receiver) => {
|
|
938
945
|
const index = builtIndex.get(builtKey({ package: pkg, export: name }, receiver));
|
|
939
946
|
return index === undefined ? undefined : resolvedBuild(checker, file.statements[firstBuild + index]);
|
|
940
947
|
});
|
|
@@ -1439,12 +1446,16 @@ function readLocalRanges(fromDir) {
|
|
|
1439
1446
|
* Every predicate is the contract's (carrick#1564, section 3), stated on the
|
|
1440
1447
|
* checker's public API, with the definitions the review amended.
|
|
1441
1448
|
*/
|
|
1449
|
+
/** How many deferred conditionals one object read follows into one another. */
|
|
1450
|
+
const MAX_CONDITIONAL_DEPTH = 8;
|
|
1442
1451
|
class DeclarationReader {
|
|
1443
1452
|
program;
|
|
1444
1453
|
probe;
|
|
1445
1454
|
host;
|
|
1446
1455
|
graph;
|
|
1447
1456
|
checker;
|
|
1457
|
+
/** Nesting of `isObjectConditional` reads in progress. */
|
|
1458
|
+
conditionalDepth = 0;
|
|
1448
1459
|
/** Names declaring files as position rows do: from the scan root, else the service root. */
|
|
1449
1460
|
pathNames;
|
|
1450
1461
|
/** The service root, as a realpath. */
|
|
@@ -2839,7 +2850,7 @@ class DeclarationReader {
|
|
|
2839
2850
|
if (declared === undefined)
|
|
2840
2851
|
return { rank: 1, outcome: failed('param_missing') };
|
|
2841
2852
|
if (slot.key === undefined) {
|
|
2842
|
-
const read = this.throughConditional(declared);
|
|
2853
|
+
const read = this.throughDefault(this.throughConditional(declared));
|
|
2843
2854
|
return this.acceptsString(read) ? undefined : { rank: 1, outcome: this.slotFailure(read, 'name_not_string') };
|
|
2844
2855
|
}
|
|
2845
2856
|
const view = this.viewFor(declared, new Map([[slot.key, 'name']]), given => this.runsFailure(given));
|
|
@@ -3479,7 +3490,7 @@ class DeclarationReader {
|
|
|
3479
3490
|
const declared = this.keyParameterAt(signature, arg);
|
|
3480
3491
|
if (declared === undefined)
|
|
3481
3492
|
return { rank: 1, outcome: failed('param_missing') };
|
|
3482
|
-
const slot = this.throughConditional(declared);
|
|
3493
|
+
const slot = this.throughDefault(this.throughConditional(declared));
|
|
3483
3494
|
if (!this.acceptsString(slot)) {
|
|
3484
3495
|
return { rank: 1, outcome: this.slotFailure(slot, part === 'name' ? 'name_not_string' : 'slot_not_string') };
|
|
3485
3496
|
}
|
|
@@ -4138,7 +4149,7 @@ class DeclarationReader {
|
|
|
4138
4149
|
* `built` answers the probe's no-argument build of a receiver an export
|
|
4139
4150
|
* makes, resolved, when the probe holds one.
|
|
4140
4151
|
*/
|
|
4141
|
-
listPackage(pkg, probe, maxEntries, only, options, typeExports, built) {
|
|
4152
|
+
listPackage(pkg, probe, maxEntries, only, options, typeExports, gate, built) {
|
|
4142
4153
|
this.setPackage(pkg);
|
|
4143
4154
|
// Runtime modules on: a `node:` specifier is listed from the runtime's
|
|
4144
4155
|
// types package, as the message roles read it.
|
|
@@ -4223,7 +4234,9 @@ class DeclarationReader {
|
|
|
4223
4234
|
}
|
|
4224
4235
|
};
|
|
4225
4236
|
receiverOf('export', type);
|
|
4226
|
-
|
|
4237
|
+
const all = this.makers(pkg, target, type);
|
|
4238
|
+
const listed = gate.gated && this.typedByAnotherPackage(target, type) ? all.filter(maker => !maker.member) : all;
|
|
4239
|
+
for (const maker of listed) {
|
|
4227
4240
|
const made = this.madeBy(maker.signatures, built(name, maker.receiver), target === defaultTarget);
|
|
4228
4241
|
if (!made)
|
|
4229
4242
|
continue;
|
|
@@ -4258,6 +4271,8 @@ class DeclarationReader {
|
|
|
4258
4271
|
}
|
|
4259
4272
|
if (propertiesLeftOut > 0)
|
|
4260
4273
|
surface.properties_left_out = propertiesLeftOut;
|
|
4274
|
+
if (gate.leftOut > 0)
|
|
4275
|
+
surface.makers_left_out = gate.leftOut;
|
|
4261
4276
|
return surface;
|
|
4262
4277
|
}
|
|
4263
4278
|
/**
|
|
@@ -4628,29 +4643,68 @@ class DeclarationReader {
|
|
|
4628
4643
|
return this.namedProperties(type).some(member => this.librarySignatures(this.checker.getTypeOfSymbol(member), 'call').length > 0);
|
|
4629
4644
|
}
|
|
4630
4645
|
/**
|
|
4631
|
-
*
|
|
4632
|
-
* the
|
|
4646
|
+
* Every listed export of a specifier with the receivers it can make, and
|
|
4647
|
+
* what the foreign ones (`typedByAnotherPackage`) are estimated to cost: their
|
|
4648
|
+
* member makers times their member count (carrick#3745).
|
|
4633
4649
|
*/
|
|
4634
|
-
|
|
4650
|
+
exportMakers(pkg, probe, only) {
|
|
4635
4651
|
this.setPackage(pkg);
|
|
4636
4652
|
const moduleRead = 'namespace' in probe ? this.readModule(pkg, probe.namespace, true) : undefined;
|
|
4637
4653
|
if (moduleRead?.reason)
|
|
4638
|
-
return {
|
|
4654
|
+
return { pkg, exports: [], types: [], classes: [], foreignMakerMembers: 0 };
|
|
4639
4655
|
const readable = 'namespace' in probe && !moduleRead?.globalFile;
|
|
4640
4656
|
const types = readable ? this.typeExportCandidates(probe.namespace, false) : [];
|
|
4641
4657
|
const classes = readable ? this.typeExportCandidates(probe.namespace, true) : [];
|
|
4642
|
-
|
|
4658
|
+
let foreignMakerMembers = 0;
|
|
4659
|
+
const exports = (this.listedExports(probe, only, moduleRead?.globalFile) ?? [])
|
|
4643
4660
|
.filter(({ type }) => !this.isOpenTop(type))
|
|
4644
4661
|
.map(({ name, target, type }) => {
|
|
4645
4662
|
const makers = this.makers(pkg, target, type);
|
|
4663
|
+
const foreign = this.typedByAnotherPackage(target, type);
|
|
4664
|
+
if (foreign)
|
|
4665
|
+
foreignMakerMembers += makers.filter(maker => maker.member).length * this.namedProperties(type).length;
|
|
4666
|
+
return { name, target, foreign, makers };
|
|
4667
|
+
});
|
|
4668
|
+
return { pkg, exports, types, classes, foreignMakerMembers };
|
|
4669
|
+
}
|
|
4670
|
+
/**
|
|
4671
|
+
* The receivers each export of a specifier can make, by receiver id, for
|
|
4672
|
+
* the probe statements that build them (see `LibraryClaimsVerifier.listSurface`).
|
|
4673
|
+
* `gated`: a foreign export makes no member receivers, and its scope
|
|
4674
|
+
* candidates are not asked for (carrick#3745).
|
|
4675
|
+
*/
|
|
4676
|
+
makersOf(read, gated) {
|
|
4677
|
+
this.setPackage(read.pkg);
|
|
4678
|
+
let makersLeftOut = 0;
|
|
4679
|
+
const makers = read.exports
|
|
4680
|
+
.map(({ name, target, foreign, makers: all }) => {
|
|
4681
|
+
const kept = gated && foreign ? all.filter(maker => !maker.member) : all;
|
|
4682
|
+
makersLeftOut += all.length - kept.length;
|
|
4646
4683
|
return {
|
|
4647
4684
|
export: name,
|
|
4648
|
-
receivers:
|
|
4649
|
-
scopes: this.scopeCandidates(pkg, target,
|
|
4685
|
+
receivers: kept.map(maker => maker.receiver),
|
|
4686
|
+
scopes: this.scopeCandidates(read.pkg, target, kept),
|
|
4650
4687
|
};
|
|
4651
4688
|
})
|
|
4652
4689
|
.filter(({ receivers }) => receivers.length > 0);
|
|
4653
|
-
return { makers, types, classes };
|
|
4690
|
+
return { makers, types: read.types, classes: read.classes, gated, makersLeftOut };
|
|
4691
|
+
}
|
|
4692
|
+
/**
|
|
4693
|
+
* A variable whose type's own declaration only other installed packages
|
|
4694
|
+
* write. Re-exports are judged where they are declared; a value outside
|
|
4695
|
+
* every installed package, or typed by the default library, never is.
|
|
4696
|
+
*/
|
|
4697
|
+
typedByAnotherPackage(target, type) {
|
|
4698
|
+
if ((target.flags & ts.SymbolFlags.Variable) === 0)
|
|
4699
|
+
return false;
|
|
4700
|
+
const owners = (target.declarations ?? []).map(declaration => this.packageOf(declaration.getSourceFile()));
|
|
4701
|
+
if (owners.length === 0 || owners.some(owner => owner === undefined))
|
|
4702
|
+
return false;
|
|
4703
|
+
const valueOwners = new Set(owners);
|
|
4704
|
+
return this.isDeclaredOnlyIn(type.getSymbol() ?? type.aliasSymbol, file => {
|
|
4705
|
+
const owner = this.packageOf(file);
|
|
4706
|
+
return owner !== undefined && !valueOwners.has(owner);
|
|
4707
|
+
});
|
|
4654
4708
|
}
|
|
4655
4709
|
/**
|
|
4656
4710
|
* The type-only exports of a specifier a handler's parameter may be
|
|
@@ -5290,12 +5344,36 @@ class DeclarationReader {
|
|
|
5290
5344
|
if (known !== undefined)
|
|
5291
5345
|
return known;
|
|
5292
5346
|
surfaceReadCounts.typePrints += 1;
|
|
5293
|
-
const
|
|
5294
|
-
const text = node === undefined ? this.checker.typeToString(type) : printTypeNode(this.orderUnions(node));
|
|
5295
|
-
const listed = truncate(this.scrubbed(text));
|
|
5347
|
+
const listed = this.printedWithinBudget(type);
|
|
5296
5348
|
this.printedTexts.set(type, listed);
|
|
5297
5349
|
return listed;
|
|
5298
5350
|
}
|
|
5351
|
+
/**
|
|
5352
|
+
* The print of `type`, or `NOT_PRINTED` when building it reaches more than
|
|
5353
|
+
* `PRINT_SYMBOL_BUDGET` symbol references. The compiler reports each one to
|
|
5354
|
+
* the tracker, so counting there stops the print wherever it is.
|
|
5355
|
+
*/
|
|
5356
|
+
printedWithinBudget(type) {
|
|
5357
|
+
const stop = {};
|
|
5358
|
+
let references = 0;
|
|
5359
|
+
const tracker = {
|
|
5360
|
+
trackSymbol: () => {
|
|
5361
|
+
if (++references > PRINT_SYMBOL_BUDGET)
|
|
5362
|
+
throw stop;
|
|
5363
|
+
return false;
|
|
5364
|
+
},
|
|
5365
|
+
};
|
|
5366
|
+
try {
|
|
5367
|
+
const node = this.checker.typeToTypeNode(type, undefined, PRINT_FLAGS, undefined, tracker);
|
|
5368
|
+
const text = node === undefined ? this.checker.typeToString(type) : printTypeNode(this.orderUnions(node));
|
|
5369
|
+
return truncate(this.scrubbed(text));
|
|
5370
|
+
}
|
|
5371
|
+
catch (err) {
|
|
5372
|
+
if (err === stop)
|
|
5373
|
+
return NOT_PRINTED;
|
|
5374
|
+
throw err;
|
|
5375
|
+
}
|
|
5376
|
+
}
|
|
5299
5377
|
/** `text` with the service root written as `<root>`. */
|
|
5300
5378
|
scrubbed(text) {
|
|
5301
5379
|
for (const root of this.printedRoots)
|
|
@@ -5630,6 +5708,24 @@ class DeclarationReader {
|
|
|
5630
5708
|
return (this.checker.isTypeAssignableTo(this.checker.getStringType(), slot) &&
|
|
5631
5709
|
this.parts(slot).some(part => isStringLike(part)));
|
|
5632
5710
|
}
|
|
5711
|
+
/**
|
|
5712
|
+
* A type parameter that `throughConstraint` left as it is (no constraint,
|
|
5713
|
+
* or `any` or `unknown`) and whose default takes a string reads as that
|
|
5714
|
+
* default.
|
|
5715
|
+
* Only a name, base or prefix slot reads it (T2b): the default is what a
|
|
5716
|
+
* call that infers nothing names, never a promise about a body or payload.
|
|
5717
|
+
*/
|
|
5718
|
+
throughDefault(slot) {
|
|
5719
|
+
const bare = this.throughConstraint(slot);
|
|
5720
|
+
if (bare === VARIADIC)
|
|
5721
|
+
return slot;
|
|
5722
|
+
const parts = this.parts(bare);
|
|
5723
|
+
if (parts.length !== 1 || !(parts[0].flags & ts.TypeFlags.TypeParameter))
|
|
5724
|
+
return slot;
|
|
5725
|
+
const fallback = this.checker.getDefaultFromTypeParameter(parts[0]);
|
|
5726
|
+
// A default that takes no string leaves the slot as it was: it says nothing.
|
|
5727
|
+
return fallback !== undefined && this.acceptsString(fallback) ? fallback : slot;
|
|
5728
|
+
}
|
|
5633
5729
|
/** Accepts string, or names an HTTP method as a literal in either case. */
|
|
5634
5730
|
acceptsMethod(declared) {
|
|
5635
5731
|
const slot = this.throughConstraint(declared);
|
|
@@ -5668,8 +5764,51 @@ class DeclarationReader {
|
|
|
5668
5764
|
const constraint = this.checker.getBaseConstraintOfType(type);
|
|
5669
5765
|
return constraint !== undefined && constraint !== type && this.isObjectLike(constraint);
|
|
5670
5766
|
}
|
|
5767
|
+
if (type.flags & ts.TypeFlags.Conditional)
|
|
5768
|
+
return this.isObjectConditional(type);
|
|
5671
5769
|
return false;
|
|
5672
5770
|
}
|
|
5771
|
+
/**
|
|
5772
|
+
* A conditional on a type parameter stays deferred inside a generic
|
|
5773
|
+
* signature (an options intersection whose context key is optional only
|
|
5774
|
+
* when the context is empty). It is an object when every part of its
|
|
5775
|
+
* branches' constraint is one: the constraint reads both branches as
|
|
5776
|
+
* instantiated, so `any` or `unknown` in either leaves no object. One that
|
|
5777
|
+
* infers (`T extends Def<infer X> ? X : ...`) is read as a name's is
|
|
5778
|
+
* (`throughConditional`), through its branches as declared, because its
|
|
5779
|
+
* constraint drops the branch the inferred parameter stands in.
|
|
5780
|
+
*/
|
|
5781
|
+
isObjectConditional(type) {
|
|
5782
|
+
// A branch that names the conditional again (itself, or through a second
|
|
5783
|
+
// alias) is a fresh instantiation each time round, so identity does not end
|
|
5784
|
+
// the chain: a depth cap does. Past it, as for an unreadable branch, it is
|
|
5785
|
+
// not an object.
|
|
5786
|
+
if (this.conditionalDepth >= MAX_CONDITIONAL_DEPTH)
|
|
5787
|
+
return false;
|
|
5788
|
+
this.conditionalDepth++;
|
|
5789
|
+
try {
|
|
5790
|
+
return this.readObjectConditional(type);
|
|
5791
|
+
}
|
|
5792
|
+
finally {
|
|
5793
|
+
this.conditionalDepth--;
|
|
5794
|
+
}
|
|
5795
|
+
}
|
|
5796
|
+
readObjectConditional(type) {
|
|
5797
|
+
if ((type.root.inferTypeParameters?.length ?? 0) > 0) {
|
|
5798
|
+
const node = type.root.node;
|
|
5799
|
+
const branchSaysNothing = [node.trueType, node.falseType].some(branch => {
|
|
5800
|
+
const declared = this.checker.getTypeFromTypeNode(branch);
|
|
5801
|
+
return (declared.flags & ts.TypeFlags.Never) === 0 && this.returnSaysNothing(declared);
|
|
5802
|
+
});
|
|
5803
|
+
if (branchSaysNothing)
|
|
5804
|
+
return false;
|
|
5805
|
+
}
|
|
5806
|
+
const constraint = this.checker.getBaseConstraintOfType(type);
|
|
5807
|
+
if (constraint === undefined || constraint === type)
|
|
5808
|
+
return false;
|
|
5809
|
+
const parts = this.parts(constraint);
|
|
5810
|
+
return parts.length > 0 && parts.every(part => part !== type && this.isObjectLike(part));
|
|
5811
|
+
}
|
|
5673
5812
|
/**
|
|
5674
5813
|
* The verdict when a slot fails its predicate: `unchecked` (`member_untyped`)
|
|
5675
5814
|
* when its type says nothing, `failed` with `code` when it says something
|
|
@@ -5782,10 +5921,30 @@ const HANDLER_MEMBER_CAP = 500;
|
|
|
5782
5921
|
* listed 8.99 million of them (1.3 GB) before it.
|
|
5783
5922
|
*/
|
|
5784
5923
|
const HANDLER_LISTING_BUDGET = 500_000;
|
|
5924
|
+
/**
|
|
5925
|
+
* The most members the receivers a request's foreign values' members make may
|
|
5926
|
+
* be estimated at before none of them is listed (carrick#3745). A value typed
|
|
5927
|
+
* by another package's class (a package of schema values typed by a schema
|
|
5928
|
+
* library) makes that class's whole fluent surface again at every value's
|
|
5929
|
+
* type arguments: the checker keeps every instantiation, and a package of
|
|
5930
|
+
* about 170 such values passes the builder's heap in pass 1. Measured at the
|
|
5931
|
+
* builder's heap: an estimate of 144,016 listed in 63 s, 181,636 ran out of
|
|
5932
|
+
* heap. Over it, the listing stays whole otherwise.
|
|
5933
|
+
*/
|
|
5934
|
+
const FOREIGN_MAKER_BUDGET = 160_000;
|
|
5785
5935
|
const PRINT_FLAGS = ts.NodeBuilderFlags.AllowUniqueESSymbolType |
|
|
5786
5936
|
ts.NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope |
|
|
5787
5937
|
ts.NodeBuilderFlags.IgnoreErrors |
|
|
5788
5938
|
ts.NodeBuilderFlags.NoTruncation;
|
|
5939
|
+
/**
|
|
5940
|
+
* A deferred conditional with no alias, whose branches reach more such
|
|
5941
|
+
* conditionals, doubles its print at every level and runs the lister out of
|
|
5942
|
+
* heap. A print that reaches more symbol references than this stops and lists
|
|
5943
|
+
* as `NOT_PRINTED`. Counted, never timed, so the same print stops at the same
|
|
5944
|
+
* point on every run; no finished print in the packages measured came near it.
|
|
5945
|
+
*/
|
|
5946
|
+
const PRINT_SYMBOL_BUDGET = 100_000;
|
|
5947
|
+
const NOT_PRINTED = '<not printed: too large>';
|
|
5789
5948
|
const TYPE_PRINTER = ts.createPrinter({ removeComments: true });
|
|
5790
5949
|
/**
|
|
5791
5950
|
* A type node as `typeToString` prints it with no enclosing declaration: with
|
|
@@ -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 = 6;
|
|
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. */
|
|
@@ -86,7 +91,7 @@ export declare const FLAG_RUNS_HANDED = 128;
|
|
|
86
91
|
export declare const DECL_CAP = 16;
|
|
87
92
|
/** The kinds {@link kindOf} gives a node; `decl` and `jsx` rows are written beside them. */
|
|
88
93
|
export type NodeKind = 'call' | 'member' | 'compare' | 'ident';
|
|
89
|
-
export type PositionKind = NodeKind | 'decl' | 'jsx' | 'typed_decl';
|
|
94
|
+
export type PositionKind = NodeKind | 'decl' | 'jsx' | 'typed_decl' | 'receiver_type';
|
|
90
95
|
/** `[kind, start, end, symbol, decl_file, decl_line, decl_package, type_text, flags]` */
|
|
91
96
|
export type PositionRow = [
|
|
92
97
|
PositionKind,
|
|
@@ -247,6 +252,37 @@ export declare class PositionWalker {
|
|
|
247
252
|
* A throw writes one row flagged {@link FLAG_CHECKER_THREW}.
|
|
248
253
|
*/
|
|
249
254
|
private declRows;
|
|
255
|
+
/**
|
|
256
|
+
* The `receiver_type` rows of a `member` row, at the
|
|
257
|
+
* span of the object the member is read on: the declaration of each named
|
|
258
|
+
* class the receiver's type holds, written only where the
|
|
259
|
+
* member is declared in another package than that class (an `on` the class
|
|
260
|
+
* inherits from a base package). The checker's type after
|
|
261
|
+
* `getNonNullableType` is read, so an alias of a class is already the
|
|
262
|
+
* class, and an intersection or union gives one row per named constituent
|
|
263
|
+
* (an anonymous object type has no name). The class's package is the one
|
|
264
|
+
* it is declared in, a workspace package or the checkout's own included;
|
|
265
|
+
* one with no package gives none. Sorted by file, then position; past
|
|
266
|
+
* {@link DECL_CAP} one row with {@link FLAG_TOO_MANY} and nothing else. No
|
|
267
|
+
* type text. A throw writes none: the `member` row carries the flag.
|
|
268
|
+
*/
|
|
269
|
+
private receiverTypeRows;
|
|
270
|
+
/**
|
|
271
|
+
* The name a `receiver_type` row gives a class. A class written
|
|
272
|
+
* `export default class Cursor` has the symbol name `default`, which is
|
|
273
|
+
* its package's `default` only where it is declared in the file the
|
|
274
|
+
* package's name resolves to; in an inner module it is named as written
|
|
275
|
+
* (`Cursor`), the name a package re-exports it under by convention. An
|
|
276
|
+
* anonymous default class of an inner module has no name: no row.
|
|
277
|
+
*/
|
|
278
|
+
private publishedClassName;
|
|
279
|
+
private entries;
|
|
280
|
+
/**
|
|
281
|
+
* The file `pkg` resolves to from `from`, a file of that package, so the
|
|
282
|
+
* installed copy `from` is in answers (two versions of one package resolve
|
|
283
|
+
* apart). Cached by package and directory.
|
|
284
|
+
*/
|
|
285
|
+
private packageEntry;
|
|
250
286
|
/**
|
|
251
287
|
* The `typed_decl` row of a call (carrick#2448): the callee is a value
|
|
252
288
|
* (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.
|
|
@@ -56,7 +61,7 @@ import { WriteGuard, installedPackageDirectory, isDeclarationFileName, moduleExp
|
|
|
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 = 6;
|
|
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. */
|
|
@@ -426,6 +431,9 @@ export class PositionWalker {
|
|
|
426
431
|
for (const decl of this.declRows(kind, node))
|
|
427
432
|
rows.push(['decl', row[1], row[2], ...tail(decl)]);
|
|
428
433
|
}
|
|
434
|
+
if (kind === 'member' && !(row[8] & FLAG_CHECKER_THREW)) {
|
|
435
|
+
rows.push(...this.receiverTypeRows(node, row));
|
|
436
|
+
}
|
|
429
437
|
if (kind === 'call' && !(row[8] & FLAG_CHECKER_THREW)) {
|
|
430
438
|
const typed = this.typedDeclRow(node, row[1], row[2]);
|
|
431
439
|
if (typed)
|
|
@@ -748,6 +756,105 @@ export class PositionWalker {
|
|
|
748
756
|
rows.sort((a, b) => compareNames(a.row[4], b.row[4]) || a.start - b.start);
|
|
749
757
|
return rows.map(({ row }) => row);
|
|
750
758
|
}
|
|
759
|
+
/**
|
|
760
|
+
* The `receiver_type` rows of a `member` row, at the
|
|
761
|
+
* span of the object the member is read on: the declaration of each named
|
|
762
|
+
* class the receiver's type holds, written only where the
|
|
763
|
+
* member is declared in another package than that class (an `on` the class
|
|
764
|
+
* inherits from a base package). The checker's type after
|
|
765
|
+
* `getNonNullableType` is read, so an alias of a class is already the
|
|
766
|
+
* class, and an intersection or union gives one row per named constituent
|
|
767
|
+
* (an anonymous object type has no name). The class's package is the one
|
|
768
|
+
* it is declared in, a workspace package or the checkout's own included;
|
|
769
|
+
* one with no package gives none. Sorted by file, then position; past
|
|
770
|
+
* {@link DECL_CAP} one row with {@link FLAG_TOO_MANY} and nothing else. No
|
|
771
|
+
* type text. A throw writes none: the `member` row carries the flag.
|
|
772
|
+
*/
|
|
773
|
+
receiverTypeRows(node, member) {
|
|
774
|
+
if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node))
|
|
775
|
+
return [];
|
|
776
|
+
const memberPackage = member[6];
|
|
777
|
+
if (member[4] === null)
|
|
778
|
+
return [];
|
|
779
|
+
try {
|
|
780
|
+
const receiver = node.expression;
|
|
781
|
+
const start = receiver.getStart(node.getSourceFile());
|
|
782
|
+
const end = receiver.getEnd();
|
|
783
|
+
const type = this.checker.getNonNullableType(this.checker.getTypeAtLocation(receiver));
|
|
784
|
+
const constituents = type.isUnionOrIntersection() ? type.types : [type];
|
|
785
|
+
const found = new Map();
|
|
786
|
+
for (const constituent of constituents) {
|
|
787
|
+
const held = this.checker.getNonNullableType(constituent);
|
|
788
|
+
const symbol = held.getSymbol();
|
|
789
|
+
if (!symbol || symbol.name.startsWith('__'))
|
|
790
|
+
continue;
|
|
791
|
+
// Classes only: interface rows (a framework's request and response types) were most of the rows' growth.
|
|
792
|
+
if (!(symbol.flags & ts.SymbolFlags.Class))
|
|
793
|
+
continue;
|
|
794
|
+
const declaration = this.typeDeclaration(held);
|
|
795
|
+
if (declaration)
|
|
796
|
+
found.set(declaration, symbol);
|
|
797
|
+
}
|
|
798
|
+
const rows = [];
|
|
799
|
+
for (const [declaration, symbol] of found) {
|
|
800
|
+
const file = declaration.getSourceFile();
|
|
801
|
+
const at = declaration.getStart(file);
|
|
802
|
+
const { declFile, declLine, declPackage } = this.located(file, at);
|
|
803
|
+
if (declPackage === null || declPackage === memberPackage)
|
|
804
|
+
continue;
|
|
805
|
+
const name = this.publishedClassName(symbol, declaration, declPackage);
|
|
806
|
+
if (name === undefined)
|
|
807
|
+
continue;
|
|
808
|
+
let flags = this.publication(symbol, declaration);
|
|
809
|
+
if (declFile === null)
|
|
810
|
+
flags |= FLAG_DECLARATION_UNNAMED;
|
|
811
|
+
rows.push({
|
|
812
|
+
start: at,
|
|
813
|
+
row: ['receiver_type', start, end, name, declFile, declLine, declPackage, null, flags],
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
if (rows.length > DECL_CAP) {
|
|
817
|
+
return [['receiver_type', start, end, null, null, null, null, null, FLAG_TOO_MANY]];
|
|
818
|
+
}
|
|
819
|
+
rows.sort((a, b) => compareNames(a.row[4], b.row[4]) || a.start - b.start);
|
|
820
|
+
return rows.map(({ row }) => row);
|
|
821
|
+
}
|
|
822
|
+
catch {
|
|
823
|
+
return [];
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* The name a `receiver_type` row gives a class. A class written
|
|
828
|
+
* `export default class Cursor` has the symbol name `default`, which is
|
|
829
|
+
* its package's `default` only where it is declared in the file the
|
|
830
|
+
* package's name resolves to; in an inner module it is named as written
|
|
831
|
+
* (`Cursor`), the name a package re-exports it under by convention. An
|
|
832
|
+
* anonymous default class of an inner module has no name: no row.
|
|
833
|
+
*/
|
|
834
|
+
publishedClassName(symbol, declaration, declPackage) {
|
|
835
|
+
const name = ts.symbolName(symbol);
|
|
836
|
+
if (name !== ts.InternalSymbolName.Default)
|
|
837
|
+
return name;
|
|
838
|
+
const file = declaration.getSourceFile();
|
|
839
|
+
if (this.packageEntry(declPackage, file) === file.fileName)
|
|
840
|
+
return name;
|
|
841
|
+
const own = ts.getNameOfDeclaration(declaration);
|
|
842
|
+
return own && ts.isIdentifier(own) ? own.text : undefined;
|
|
843
|
+
}
|
|
844
|
+
entries = new Map();
|
|
845
|
+
/**
|
|
846
|
+
* The file `pkg` resolves to from `from`, a file of that package, so the
|
|
847
|
+
* installed copy `from` is in answers (two versions of one package resolve
|
|
848
|
+
* apart). Cached by package and directory.
|
|
849
|
+
*/
|
|
850
|
+
packageEntry(pkg, from) {
|
|
851
|
+
const key = `${pkg}\0${from.fileName.slice(0, from.fileName.lastIndexOf('/'))}`;
|
|
852
|
+
if (!this.entries.has(key)) {
|
|
853
|
+
const resolved = ts.resolveModuleName(pkg, from.fileName, this.program.getCompilerOptions(), this.resolutionHost()).resolvedModule;
|
|
854
|
+
this.entries.set(key, resolved?.resolvedFileName);
|
|
855
|
+
}
|
|
856
|
+
return this.entries.get(key);
|
|
857
|
+
}
|
|
751
858
|
/**
|
|
752
859
|
* The `typed_decl` row of a call (carrick#2448): the callee is a value
|
|
753
860
|
* (a parameter, a property, a local) whose type is a named function's own
|
|
@@ -996,6 +1103,7 @@ function nameNodeOf(kind, node) {
|
|
|
996
1103
|
return node;
|
|
997
1104
|
case 'decl':
|
|
998
1105
|
case 'typed_decl':
|
|
1106
|
+
case 'receiver_type':
|
|
999
1107
|
return undefined;
|
|
1000
1108
|
case 'jsx':
|
|
1001
1109
|
// 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
|
|
@@ -360,13 +361,13 @@ export class ProjectLoader {
|
|
|
360
361
|
return result;
|
|
361
362
|
}
|
|
362
363
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
364
|
+
* The file system every project reads through: the default library from
|
|
365
|
+
* the compiler's own files (carrick#3509) and, under CARRICK_UNTRUSTED_TREE,
|
|
366
|
+
* nothing whose real path is outside the checkout (carrick#2230).
|
|
366
367
|
*/
|
|
367
368
|
fileSystemOption() {
|
|
368
369
|
const bound = untrustedReadBound(this.repoRoot);
|
|
369
|
-
return bound ?
|
|
370
|
+
return defaultLibraryOptions(bound ? boundedFileSystem(bound) : undefined);
|
|
370
371
|
}
|
|
371
372
|
/**
|
|
372
373
|
* A ts-morph project built from one tsconfig: with the files it lists, or
|
|
@@ -713,6 +713,20 @@ export declare class TypeInferrer {
|
|
|
713
713
|
* `{ ok: true } | { ok: false; reason: string }` result read as `sent.ok`.
|
|
714
714
|
*/
|
|
715
715
|
private projectionReadsGenericPayload;
|
|
716
|
+
/**
|
|
717
|
+
* True when the call answers a ONE-ARGUMENT result envelope: a union whose
|
|
718
|
+
* branches say whether the call worked and one of which holds the single
|
|
719
|
+
* type argument as a member (`{ success: true; data: T } | { success: false;
|
|
720
|
+
* error: string }`), carrick#3741. carrick#1376 needs two arguments to tell
|
|
721
|
+
* the success side from the failure side; with one there is nothing to tell
|
|
722
|
+
* apart, and the envelope is the client's bookkeeping around `T`.
|
|
723
|
+
*
|
|
724
|
+
* A site that reads only such an envelope's own members (its status, its
|
|
725
|
+
* error) reads no payload, so the envelope is not a response contract. A
|
|
726
|
+
* union with no type argument (`{ ok: true } | { ok: false; reason: string }`)
|
|
727
|
+
* is not an envelope here and keeps its declared answer (carrick#1375).
|
|
728
|
+
*/
|
|
729
|
+
private isOneArgumentEnvelope;
|
|
716
730
|
/**
|
|
717
731
|
* The payload a RESULT CARRIER carries, or `undefined` when `type` is not
|
|
718
732
|
* one or its success side cannot be told from its failure side
|