@cplieger/deadset-ts 8.0.0-dev.16 → 8.0.0-dev.18

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 (161) hide show
  1. package/dist/src/alias-chain.js +0 -5
  2. package/dist/src/amd.js +81 -0
  3. package/dist/src/analysis.js +82 -91
  4. package/dist/src/augmentations.js +24 -25
  5. package/dist/src/bindings.js +382 -0
  6. package/dist/src/calls.js +279 -43
  7. package/dist/src/commands/tools.js +5 -9
  8. package/dist/src/component-files.js +3 -2
  9. package/dist/src/conformance-record.js +1 -1
  10. package/dist/src/consumers.js +6 -9
  11. package/dist/src/contextual-uses.js +1 -17
  12. package/dist/src/contract/config.generated.js +4 -1
  13. package/dist/src/contract/contract.generated.js +2 -2
  14. package/dist/src/contract/report.generated.js +6 -2
  15. package/dist/src/dependencies.js +25 -29
  16. package/dist/src/destructuring.js +1 -19
  17. package/dist/src/element-access.js +179 -164
  18. package/dist/src/entries/build-scripts.js +2 -2
  19. package/dist/src/entries/configuration-files.js +3 -7
  20. package/dist/src/entries/conventions.js +2 -2
  21. package/dist/src/entries/html-entries.js +7 -10
  22. package/dist/src/entries/mdx-entries.js +2 -2
  23. package/dist/src/entries/static-module.js +2 -1
  24. package/dist/src/exempt.js +0 -26
  25. package/dist/src/exposure.js +400 -0
  26. package/dist/src/facts.js +4 -4
  27. package/dist/src/findings/completion.js +44 -21
  28. package/dist/src/findings/emitters.js +22 -33
  29. package/dist/src/{implementations.js → findings/implementations.js} +3 -3
  30. package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
  31. package/dist/src/findings/intra-function.js +3 -3
  32. package/dist/src/findings/reads-and-writes.js +71 -15
  33. package/dist/src/findings/unused-declarations.js +2 -22
  34. package/dist/src/findings/visibility-narrowing.js +14 -20
  35. package/dist/src/framework-lifecycle.js +41 -14
  36. package/dist/src/import-bindings.js +73 -28
  37. package/dist/src/index/sites.js +557 -0
  38. package/dist/src/indexed-access.js +523 -478
  39. package/dist/src/interface-satisfaction.js +1 -1
  40. package/dist/src/inventory.js +18 -0
  41. package/dist/src/keyof-comparisons.js +124 -103
  42. package/dist/src/{components.js → liveness/components.js} +1 -1
  43. package/dist/src/{graph.js → liveness/graph.js} +45 -20
  44. package/dist/src/liveness/matrix.js +99 -0
  45. package/dist/src/liveness/sweep.js +558 -0
  46. package/dist/src/load/expected-module.js +2 -2
  47. package/dist/src/load/specifiers.js +2 -4
  48. package/dist/src/load/synthesize.js +5 -0
  49. package/dist/src/load/workspace-resolution.js +2 -2
  50. package/dist/src/module-declarations.js +70 -85
  51. package/dist/src/overrides.js +134 -112
  52. package/dist/src/paths.js +46 -7
  53. package/dist/src/platform-calls.js +2 -2
  54. package/dist/src/platform-symbols.js +13 -19
  55. package/dist/src/query.js +46 -0
  56. package/dist/src/references/read-rule.js +1 -0
  57. package/dist/src/references/read-rules.js +48 -0
  58. package/dist/src/references/sink.js +237 -0
  59. package/dist/src/references/sources.js +450 -0
  60. package/dist/src/references.js +110 -1285
  61. package/dist/src/roots/configured-declarations.js +3 -0
  62. package/dist/src/roots/published-reach.js +4 -4
  63. package/dist/src/roots/root-set.js +1 -1
  64. package/dist/src/roots/unseen-loads.js +38 -10
  65. package/dist/src/serialization-contract.js +8 -3
  66. package/dist/src/stores.js +4 -2
  67. package/dist/src/symbol-keys.js +89 -83
  68. package/dist/src/tests/file-class.js +76 -0
  69. package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
  70. package/dist/src/{test-support.js → tests/support.js} +2 -11
  71. package/dist/src/type-parameter-reads.js +178 -139
  72. package/dist/src/unimplemented-callees.js +262 -242
  73. package/dist/src/verbs/analyze.js +3 -3
  74. package/dist/src/verbs/explain.js +75 -132
  75. package/dist/src/verbs/print-retained.js +3 -3
  76. package/jsr.json +1 -1
  77. package/package.json +2 -2
  78. package/src/alias-chain.ts +0 -7
  79. package/src/amd.ts +130 -0
  80. package/src/analysis.ts +125 -128
  81. package/src/augmentations.ts +42 -28
  82. package/src/bindings.ts +460 -0
  83. package/src/calls.ts +338 -46
  84. package/src/commands/tools.ts +5 -11
  85. package/src/component-files.ts +4 -2
  86. package/src/conformance-record.ts +1 -1
  87. package/src/consumers.ts +8 -11
  88. package/src/contextual-uses.ts +2 -22
  89. package/src/contract/config.generated.ts +4 -1
  90. package/src/contract/contract.generated.ts +2 -2
  91. package/src/contract/report.generated.ts +6 -2
  92. package/src/dependencies.ts +27 -28
  93. package/src/destructuring.ts +1 -31
  94. package/src/element-access.ts +188 -182
  95. package/src/entries/build-scripts.ts +2 -2
  96. package/src/entries/configuration-files.ts +11 -8
  97. package/src/entries/conventions.ts +2 -1
  98. package/src/entries/html-entries.ts +15 -14
  99. package/src/entries/mdx-entries.ts +2 -2
  100. package/src/entries/static-module.ts +2 -1
  101. package/src/exempt.ts +31 -46
  102. package/src/exposure.ts +492 -0
  103. package/src/facts.ts +5 -3
  104. package/src/finding.ts +1 -1
  105. package/src/findings/boundary.ts +9 -0
  106. package/src/findings/completion.ts +48 -23
  107. package/src/findings/emitter.ts +1 -1
  108. package/src/findings/emitters.ts +23 -41
  109. package/src/{implementations.ts → findings/implementations.ts} +4 -4
  110. package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
  111. package/src/findings/interfaces.ts +3 -3
  112. package/src/findings/intra-function.ts +3 -3
  113. package/src/findings/reads-and-writes.ts +99 -26
  114. package/src/findings/unused-declarations.ts +4 -28
  115. package/src/findings/visibility-narrowing.ts +25 -26
  116. package/src/framework-lifecycle.ts +42 -14
  117. package/src/import-bindings.ts +98 -29
  118. package/src/index/sites.ts +781 -0
  119. package/src/indexed-access.ts +570 -527
  120. package/src/interface-satisfaction.ts +2 -2
  121. package/src/inventory.ts +19 -0
  122. package/src/keyof-comparisons.ts +131 -116
  123. package/src/{components.ts → liveness/components.ts} +3 -3
  124. package/src/{graph.ts → liveness/graph.ts} +93 -27
  125. package/src/liveness/matrix.ts +162 -0
  126. package/src/liveness/sweep.ts +855 -0
  127. package/src/load/expected-module.ts +8 -2
  128. package/src/load/specifiers.ts +8 -5
  129. package/src/load/synthesize.ts +6 -0
  130. package/src/load/workspace-resolution.ts +9 -2
  131. package/src/module-declarations.ts +74 -98
  132. package/src/overrides.ts +162 -134
  133. package/src/paths.ts +54 -8
  134. package/src/platform-calls.ts +3 -3
  135. package/src/platform-symbols.ts +11 -27
  136. package/src/query.ts +81 -0
  137. package/src/references/read-rule.ts +60 -0
  138. package/src/references/read-rules.ts +55 -0
  139. package/src/references/sink.ts +314 -0
  140. package/src/references/sources.ts +632 -0
  141. package/src/references.ts +175 -1733
  142. package/src/report.ts +1 -1
  143. package/src/roots/configured-declarations.ts +3 -0
  144. package/src/roots/published-reach.ts +9 -4
  145. package/src/roots/root-set.ts +1 -1
  146. package/src/roots/unseen-loads.ts +49 -11
  147. package/src/serialization-contract.ts +8 -3
  148. package/src/stores.ts +15 -3
  149. package/src/symbol-keys.ts +102 -102
  150. package/src/tests/file-class.ts +135 -0
  151. package/src/{outside-tests.ts → tests/outside.ts} +16 -10
  152. package/src/{test-support.ts → tests/support.ts} +9 -20
  153. package/src/type-parameter-reads.ts +187 -158
  154. package/src/unimplemented-callees.ts +297 -280
  155. package/src/verbs/analyze.ts +3 -2
  156. package/src/verbs/explain.ts +83 -158
  157. package/src/verbs/print-retained.ts +3 -3
  158. package/dist/src/matrix.js +0 -273
  159. package/dist/src/sweep.js +0 -222
  160. package/src/matrix.ts +0 -463
  161. package/src/sweep.ts +0 -361
@@ -56,16 +56,12 @@ interface ContextualUse {
56
56
  readonly ids: readonly string[];
57
57
  }
58
58
 
59
- /** What the contextual types of one project's literals and values use, and what asking cost. */
59
+ /** What the contextual types of one project's literals and values use. */
60
60
  interface ContextualUses {
61
61
  /** Each literal property that writes a member, by the property's node. */
62
62
  readonly writes: readonly ContextualUse[];
63
63
  /** Each value whose members a position typed by another object type reads. */
64
64
  readonly reads: readonly ContextualUse[];
65
- /** The batched lookups: contextual types and value types, one per capped run. */
66
- readonly batches: number;
67
- /** The per-type lookups: each distinct type's constituents, properties and declaring symbol. */
68
- readonly lookups: number;
69
65
  }
70
66
 
71
67
  /**
@@ -169,9 +165,6 @@ export function contextualUses<Brand>(
169
165
  .filter((symbol) => symbol.visibility === "private-name")
170
166
  .map((symbol) => symbol.id),
171
167
  );
172
- let batches = 0;
173
- let lookups = 0;
174
- const batchesOf = (count: number): number => Math.ceil(count / cap);
175
168
 
176
169
  const parts = new Map<number, readonly Type[]>();
177
170
  /** The object types one type is: itself, or its constituents at any depth. */
@@ -182,7 +175,6 @@ export function contextualUses<Brand>(
182
175
  }
183
176
  let found: readonly Type[] = [];
184
177
  if (type.isUnionType() || type.isIntersectionType()) {
185
- lookups += 1;
186
178
  const constituents = queries.constituents(type);
187
179
  found = isAnswered(constituents) ? constituents.flatMap(partsOf) : [];
188
180
  } else if (type.isObjectType()) {
@@ -201,7 +193,6 @@ export function contextualUses<Brand>(
201
193
  }
202
194
  const table = new Map<string, Member>();
203
195
  const read = properties.of(type);
204
- lookups += read.asked ? 1 : 0;
205
196
  for (const property of isAnswered(read.properties) ? read.properties : []) {
206
197
  table.set(property.name, {
207
198
  ids: chains
@@ -222,7 +213,6 @@ export function contextualUses<Brand>(
222
213
  };
223
214
 
224
215
  const writes: ContextualUse[] = [];
225
- batches += batchesOf(literals.length);
226
216
  const contexts = queries.contextualTypes(
227
217
  literals.map((one) => one.literal),
228
218
  cap,
@@ -238,7 +228,6 @@ export function contextualUses<Brand>(
238
228
  return name !== undefined && name.text === undefined ? [name.node] : [];
239
229
  }),
240
230
  );
241
- batches += batchesOf(computed.length);
242
231
  const keys = new Map<Node, string>();
243
232
  (computed.length === 0
244
233
  ? []
@@ -272,7 +261,6 @@ export function contextualUses<Brand>(
272
261
  });
273
262
 
274
263
  const carried = flows.filter((flow) => !isObjectLiteralExpression(flow.value));
275
- batches += batchesOf(carried.length);
276
264
  const types = queries.typesAt(
277
265
  carried.map((flow) => flow.value),
278
266
  cap,
@@ -327,11 +315,9 @@ export function contextualUses<Brand>(
327
315
  if (elements.has(type.id)) {
328
316
  return elements.get(type.id);
329
317
  }
330
- lookups += 1;
331
318
  const isArray = queries.isArray(type);
332
319
  let element: Type | undefined;
333
320
  if (isAnswered(isArray) && isArray) {
334
- lookups += 1;
335
321
  const held = queries.typeArguments(type);
336
322
  element = isAnswered(held) ? held[0] : undefined;
337
323
  }
@@ -346,7 +332,6 @@ export function contextualUses<Brand>(
346
332
  if (known !== undefined) {
347
333
  return known;
348
334
  }
349
- lookups += type.isTypeReference() ? 1 : 0;
350
335
  const held = queries.typeArguments(type);
351
336
  const found = isAnswered(held) ? held : [];
352
337
  argumentsOf.set(type.id, found);
@@ -363,11 +348,9 @@ export function contextualUses<Brand>(
363
348
  if (known !== undefined) {
364
349
  return known;
365
350
  }
366
- lookups += 1;
367
351
  let kind = SignatureKind.Call;
368
352
  let signatures = queries.signaturesOf(type, kind);
369
353
  if (isAnswered(signatures) && signatures.length === 0) {
370
- lookups += 1;
371
354
  kind = SignatureKind.Construct;
372
355
  signatures = queries.signaturesOf(type, kind);
373
356
  }
@@ -376,7 +359,6 @@ export function contextualUses<Brand>(
376
359
  queries.parameterType(signature, index),
377
360
  );
378
361
  const result = queries.returnTypeOf(signature);
379
- lookups += parameters.length + 1;
380
362
  return {
381
363
  kind,
382
364
  parameters: parameters.map((one) => (isAnswered(one) ? one : undefined)),
@@ -474,7 +456,6 @@ export function contextualUses<Brand>(
474
456
  const type = types[index];
475
457
  return type === undefined || !isAnswered(type) || !mayCarry(type) ? [] : [{ flow, type }];
476
458
  });
477
- batches += batchesOf(sourced.length);
478
459
  const positions = queries.contextualTypes(
479
460
  sourced.map((one) => one.flow.value),
480
461
  cap,
@@ -556,7 +537,6 @@ export function contextualUses<Brand>(
556
537
  isSpreadAssignment(property) ? [{ value: property.expression, from }] : [],
557
538
  ),
558
539
  );
559
- batches += batchesOf(spreads.length);
560
540
  const spreadTypes = queries.typesAt(
561
541
  spreads.map((one) => one.value),
562
542
  cap,
@@ -583,5 +563,5 @@ export function contextualUses<Brand>(
583
563
  reads.push({ at: value, from, ids });
584
564
  }
585
565
  });
586
- return { writes, reads, batches, lookups };
566
+ return { writes, reads };
587
567
  }
@@ -501,7 +501,10 @@ export const SETTINGS: readonly SettingRow[] = [
501
501
  key: "provenance",
502
502
  role: "ignored",
503
503
  read: true,
504
- value: { type: "string", pattern: "^(default|(repository|central|flag): [^\\r\\n]+)$" },
504
+ value: {
505
+ type: "string",
506
+ pattern: "^(default|(repository|central|flag): ([^\\r\\n]|[\\r\\n])+)$",
507
+ },
505
508
  keyPattern: "^[a-z][a-z_]*(\\.[A-Za-z0-9_]+)*$",
506
509
  },
507
510
  ];
@@ -423,7 +423,7 @@ export const KIND_ROWS = [
423
423
  holdsLive: true,
424
424
  rule: "An exported symbol whose every reference is inside the symbol's own package or module, reported as a candidate for unexporting. The subject is a package-level declaration or a method. Three subjects are excluded. An interface method is excluded because its exportedness is the contract of the interface that declares it. A struct field is excluded because an encoder reads it by name. A method that satisfies an interface some symbol uses as a type is excluded because it cannot be unexported without its type ceasing to satisfy that interface, and so is a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, because that interface fixes them whether or not the program converts the method's type to it. The finding names the narrower visibility the references support. A declared cross-language edge counts as an out-of-package reference. Where the edge's other side is unknown to the analyzer, the finding is emitted pending. A reference from a Go external test package, a test file whose package clause names its directory's package with the suffix _test, is a reference from outside the package, because that test builds as another package and needs the export.",
425
425
  precondition:
426
- "Closed world only. A Go main package, and an internal/ directory tree for importers outside its parent, are closed worlds whatever the configuration declares, because no other program can import them, so this finding is reported there always. A published package is a closed world only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type that a parameter or a result of an exported function or method of its own package names is not reported when a reference from outside the package references that function or method, because the caller holds values of the type, and unexporting it would leave an exported signature naming a type its callers cannot name. A package-level declaration whose name a string literal spells carries the class grammar/analysis/confidence.md gives it.",
426
+ "Closed world only. A Go main package, and an internal/ directory tree for importers outside its parent, are closed worlds whatever the configuration declares, because no other program can import them, so this finding is reported there always. A published package is a closed world only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type is not reported when a reference from outside the package reaches its values through its own package's exported declarations: a reference to an exported function or method whose parameters or results name the type, to an exported variable or constant whose type names it, to an exported field or property whose type names it, an embedded field included, or to an exported member of the type itself, a field promoted through an embedding included. A type a reference from outside the package names, or whose values such a reference reaches, passes the reach on to each type its definition names other than through an unexported member, whether it is exported or not, so an unexported type an exported function returns passes it to the types its exported fields name. A type names another through every composite that spells it: a pointer, an array, a slice, a map key or value, a channel, a function signature and a type argument. The referencing code holds values of the type, so unexporting it would leave an exported declaration naming a type its users cannot name. A package-level declaration whose name a string literal spells carries the class grammar/analysis/confidence.md gives it.",
427
427
  details: { narrower_visibility: "required", name_literal: "optional" },
428
428
  defaultEnabled: true,
429
429
  defaultSeverity: "warn",
@@ -439,7 +439,7 @@ export const KIND_ROWS = [
439
439
  holdsLive: true,
440
440
  rule: "An exported symbol of a non-internal package whose every reference is inside the target module, reported as a candidate for relocation behind an internal boundary. The subject is a package-level declaration or a method. Three subjects are excluded. An interface method is excluded because its exportedness is the contract of the interface that declares it. A struct field is excluded because an encoder reads it by name. A method that satisfies an interface some symbol uses as a type is excluded because it cannot be unexported without its type ceasing to satisfy that interface, and so is a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, because that interface fixes them whether or not the program converts the method's type to it. The finding names the narrower visibility the references support. A declared cross-language edge counts as an out-of-package reference. Where the edge's other side is unknown to the analyzer, the finding is emitted pending. A reference from a Go external test package, a test file whose package clause names its directory's package with the suffix _test, is a reference from outside the package, because that test builds as another package and needs the export.",
441
441
  precondition:
442
- "Closed world only. Reported always for a main package and an internal/ directory tree, and for a published package only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type that a parameter or a result of an exported function or method of its own package names is not reported when a reference from outside the target module references that function or method, because the caller holds values of the type, and moving it behind an internal boundary would leave an exported signature naming a type its callers cannot name.",
442
+ "Closed world only. Reported always for a main package and an internal/ directory tree, and for a published package only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type is not reported when a reference from outside the target module reaches its values through its own package's exported declarations, as DS1501 defines that reach, because the referencing code holds values of the type, and moving it behind an internal boundary would leave an exported declaration naming a type its users cannot name.",
443
443
  details: { narrower_visibility: "required", name_literal: "optional" },
444
444
  defaultEnabled: true,
445
445
  defaultSeverity: "warn",
@@ -408,6 +408,11 @@ export const REPORT_SCHEMAS = {
408
408
  },
409
409
  else: { properties: { configurations: { minItems: 1 }, target: { required: ["kind"] } } },
410
410
  },
411
+ {
412
+ if: { required: ["merged_from"], properties: { merged_from: { maxItems: 0 } } },
413
+ then: { properties: { analyzer: { properties: { languages: { maxItems: 0 } } } } },
414
+ else: { properties: { analyzer: { properties: { languages: { minItems: 1 } } } } },
415
+ },
411
416
  ],
412
417
  properties: {
413
418
  schema_version: { type: "string", pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
@@ -424,7 +429,6 @@ export const REPORT_SCHEMAS = {
424
429
  },
425
430
  languages: {
426
431
  type: "array",
427
- minItems: 1,
428
432
  uniqueItems: true,
429
433
  items: { type: "string", enum: ["go", "ts", "proto"] },
430
434
  },
@@ -460,7 +464,7 @@ export const REPORT_SCHEMAS = {
460
464
  pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$",
461
465
  },
462
466
  digest: { type: "string", pattern: "^sha256:[0-9a-f]{64}$" },
463
- languages: { $ref: "#/properties/analyzer/properties/languages" },
467
+ languages: { $ref: "#/properties/analyzer/properties/languages", minItems: 1 },
464
468
  totals: { $ref: "#/properties/totals" },
465
469
  },
466
470
  },
@@ -29,6 +29,7 @@ import {
29
29
  type Node,
30
30
  type SourceFile,
31
31
  } from "@typescript/native/ast";
32
+ import { amdLoadOf, amdPlatform } from "./amd.ts";
32
33
  import { automaticTypes, type AutomaticTypes } from "./automatic-types.ts";
33
34
  import {
34
35
  declaredIn as declaredBeside,
@@ -41,12 +42,13 @@ import {
41
42
  } from "./entries/configuration-files.ts";
42
43
  import type { FindingPosition } from "./finding.ts";
43
44
  import type { Host } from "./host.ts";
45
+ import { declarationBindings } from "./import-bindings.ts";
44
46
  import { nodeKey, type Inventory } from "./inventory.ts";
45
47
  import { packageScope } from "./load/package-scope.ts";
46
48
  import {
47
49
  ancestors,
50
+ cannotStartPackageName,
48
51
  dirnamePath,
49
- isAbsolutePath,
50
52
  joinPath,
51
53
  relativePath,
52
54
  resolvePath,
@@ -302,7 +304,7 @@ function configurationPackages(
302
304
  }
303
305
  seen.add(file);
304
306
  for (const entry of extendsOf(host, file, parse)) {
305
- if (entry.startsWith(".") || isAbsolutePath(entry)) {
307
+ if (cannotStartPackageName(entry)) {
306
308
  const local = resolvePath(dirnamePath(file), entry);
307
309
  pending.push(local.endsWith(".json") ? local : `${local}.json`);
308
310
  } else {
@@ -332,26 +334,9 @@ function importOf(specifier: Node): Node | undefined {
332
334
 
333
335
  /** The local names one import declaration binds. */
334
336
  function bindingsOf(node: Node | undefined): readonly Texted[] {
335
- if (node === undefined) {
336
- return [];
337
- }
338
- if (isImportEqualsDeclaration(node)) {
339
- return [node.name];
340
- }
341
- if (!isImportDeclaration(node) || node.importClause === undefined) {
342
- return [];
343
- }
344
- const clause = node.importClause;
345
- const names: Texted[] = clause.name === undefined ? [] : [clause.name];
346
- const bindings = clause.namedBindings;
347
- if (bindings !== undefined) {
348
- if (bindings.kind === SyntaxKind.NamespaceImport) {
349
- names.push(bindings.name);
350
- } else {
351
- names.push(...bindings.elements.map((element) => element.name));
352
- }
353
- }
354
- return names;
337
+ return node !== undefined && (isImportDeclaration(node) || isImportEqualsDeclaration(node))
338
+ ? declarationBindings(node).map((binding) => binding.name)
339
+ : [];
355
340
  }
356
341
 
357
342
  /**
@@ -653,6 +638,7 @@ function fileNeeds<Brand>(
653
638
  }
654
639
  const loads = runtimeLoads(file);
655
640
  const callees = loads.flatMap((load) => load.callees);
641
+ const amdCallees = new Set(loads.flatMap((load) => (load.amd ? load.callees : [])));
656
642
 
657
643
  const asked = [
658
644
  ...specifiers,
@@ -748,11 +734,13 @@ function fileNeeds<Brand>(
748
734
  unansweredCallees.add(callee);
749
735
  return;
750
736
  }
751
- // The decision reads the callee's symbol and its written name, and nothing else of it.
752
- const key = symbol === undefined ? undefined : `${symbol.id}\u0000${callee.text}`;
737
+ // The decision reads the callee's symbol, its written name and its platform name, and nothing else.
738
+ const platform = amdCallees.has(callee) ? amdPlatform(callee) : "require";
739
+ const key =
740
+ symbol === undefined ? undefined : `${symbol.id}\u0000${platform}\u0000${callee.text}`;
753
741
  const answer =
754
742
  (key === undefined ? undefined : decided.get(key)) ??
755
- callsPlatform(project, "require", callee, symbol, () => undefined);
743
+ callsPlatform(project, platform, callee, symbol);
756
744
  if (key !== undefined) {
757
745
  decided.set(key, answer);
758
746
  }
@@ -779,6 +767,8 @@ interface RuntimeLoad {
779
767
  readonly specifier: Texted;
780
768
  readonly named: string;
781
769
  readonly callees: readonly Identifier[];
770
+ /** Whether the specifier is an id of an AMD call's dependency list, its callee AMD's `define` or `require`. */
771
+ readonly amd: boolean;
782
772
  }
783
773
 
784
774
  /**
@@ -786,12 +776,21 @@ interface RuntimeLoad {
786
776
  * argument is literal text naming a package: a `require()` call, which the compiler lists among
787
777
  * a file's imports only in a JavaScript file and only through the bare name; a `.resolve` of
788
778
  * another name, which needs it where that name is a `require`; and `import.meta.resolve` or
789
- * a `.resolve` of the name `require`, whatever it names, a use where it stands.
779
+ * a `.resolve` of the name `require`, whatever it names, a use where it stands; and each id of
780
+ * an AMD dependency list (references-ts.37), which needs it where the call is AMD's.
790
781
  */
791
782
  function runtimeLoads(file: SourceFile): readonly RuntimeLoad[] {
792
783
  const found: RuntimeLoad[] = [];
793
784
  const visit = (node: Node): void => {
794
- if (isCallExpression(node)) {
785
+ const amd = amdLoadOf(node);
786
+ if (amd !== undefined) {
787
+ for (const { id } of amd.ids) {
788
+ const named = packageOfSpecifier(id.text);
789
+ if (named !== undefined) {
790
+ found.push({ specifier: id, named, callees: [amd.callee], amd: true });
791
+ }
792
+ }
793
+ } else if (isCallExpression(node)) {
795
794
  const [argument] = node.arguments;
796
795
  if (argument !== undefined && isLiteralText(argument)) {
797
796
  const named = packageOfSpecifier(argument.text);
@@ -811,7 +810,7 @@ function runtimeLoads(file: SourceFile): readonly RuntimeLoad[] {
811
810
  receiver === undefined ? undefined : writtenName(receiver),
812
811
  ].filter((one) => one !== undefined);
813
812
  if (named !== undefined && (stands || callees.length > 0)) {
814
- found.push({ specifier: argument, named, callees });
813
+ found.push({ specifier: argument, named, callees, amd: false });
815
814
  }
816
815
  }
817
816
  }
@@ -213,17 +213,6 @@ function sourceOf(target: Node): Source | undefined {
213
213
  }
214
214
  }
215
215
 
216
- /** What resolving one project's property reads cost at the client boundary. */
217
- interface DestructuringCost {
218
- /** Batched type lookups, one per capped run of a file's patterns and assigned values. */
219
- readonly patternBatches: number;
220
- /**
221
- * Per-type lookups: one property table per distinct destructured type, and each step
222
- * an assignment target takes into its assigned value.
223
- */
224
- readonly patternLookups: number;
225
- }
226
-
227
216
  /** Resolves property reads to the symbols the destructured values' types declare. */
228
217
  interface Destructuring {
229
218
  /**
@@ -232,7 +221,6 @@ interface Destructuring {
232
221
  * {@link UNANSWERED} where a question about the value's type went unanswered.
233
222
  */
234
223
  resolve(reads: readonly PropertyRead[]): readonly Answer<TSSymbol | undefined>[];
235
- readonly cost: DestructuringCost;
236
224
  }
237
225
 
238
226
  /** A type along a destructuring, or the mark that a question about it went unanswered. */
@@ -250,8 +238,6 @@ export function destructuring<Brand>(
250
238
  ): Destructuring {
251
239
  const queries = project.queries;
252
240
  const tables = new Map<number, Answer<ReadonlyMap<string, TSSymbol>>>();
253
- let patternBatches = 0;
254
- let patternLookups = 0;
255
241
 
256
242
  const tableOf = (type: Type): Answer<ReadonlyMap<string, TSSymbol>> => {
257
243
  const known = tables.get(type.id);
@@ -261,7 +247,6 @@ export function destructuring<Brand>(
261
247
  let table: Answer<ReadonlyMap<string, TSSymbol>> = new Map<string, TSSymbol>();
262
248
  if ((type.flags & TypeFlags.AnyOrUnknown) === 0) {
263
249
  const read = properties.of(type);
264
- patternLookups += read.asked ? 1 : 0;
265
250
  table = isAnswered(read.properties)
266
251
  ? new Map(read.properties.map((property) => [property.name, property]))
267
252
  : UNANSWERED;
@@ -274,7 +259,6 @@ export function destructuring<Brand>(
274
259
  if ((type.flags & TypeFlags.Union) === 0) {
275
260
  return type;
276
261
  }
277
- patternLookups += 1;
278
262
  return queries.nonNullable(type);
279
263
  };
280
264
 
@@ -290,11 +274,9 @@ export function destructuring<Brand>(
290
274
  if (index === undefined) {
291
275
  return undefined;
292
276
  }
293
- patternLookups += 1;
294
277
  const elements = queries.typeArguments(type);
295
278
  return isAnswered(elements) ? elements[index] : UNANSWERED;
296
279
  }
297
- patternLookups += 1;
298
280
  const array = queries.isArray(type);
299
281
  if (!isAnswered(array)) {
300
282
  return UNANSWERED;
@@ -302,7 +284,6 @@ export function destructuring<Brand>(
302
284
  if (!array) {
303
285
  return undefined;
304
286
  }
305
- patternLookups += 1;
306
287
  const elements = queries.typeArguments(type);
307
288
  return isAnswered(elements) ? elements[0] : UNANSWERED;
308
289
  };
@@ -320,7 +301,6 @@ export function destructuring<Brand>(
320
301
  if (more.length > 0) {
321
302
  return UNANSWERED;
322
303
  }
323
- patternLookups += 1;
324
304
  return queries.typeOfSymbol(property);
325
305
  };
326
306
 
@@ -328,7 +308,6 @@ export function destructuring<Brand>(
328
308
  if (callee === undefined || callee === UNANSWERED) {
329
309
  return callee;
330
310
  }
331
- patternLookups += 1;
332
311
  const signatures = queries.signaturesOf(callee, SignatureKind.Call);
333
312
  if (!isAnswered(signatures)) {
334
313
  return UNANSWERED;
@@ -337,7 +316,6 @@ export function destructuring<Brand>(
337
316
  if (signature === undefined) {
338
317
  return undefined;
339
318
  }
340
- patternLookups += 1;
341
319
  return queries.returnTypeOf(signature);
342
320
  };
343
321
 
@@ -369,7 +347,6 @@ export function destructuring<Brand>(
369
347
  if (result !== undefined && result !== UNANSWERED) {
370
348
  let parts: Answer<readonly Type[]> = [result];
371
349
  if (result.isUnionType()) {
372
- patternLookups += 1;
373
350
  parts = queries.constituents(result);
374
351
  }
375
352
  const values: readonly Found[] = isAnswered(parts)
@@ -403,7 +380,6 @@ export function destructuring<Brand>(
403
380
  if (property === undefined) {
404
381
  return undefined;
405
382
  }
406
- patternLookups += 1;
407
383
  return queries.typeOfSymbol(property);
408
384
  }
409
385
  return elementOf(defined, next.index);
@@ -425,7 +401,6 @@ export function destructuring<Brand>(
425
401
  }
426
402
  }
427
403
  const asked = [...asking];
428
- patternBatches += Math.ceil(asked.length / cap);
429
404
  const answered = new Map<Node, Found>();
430
405
  queries.typesAt(asked, cap).forEach((type, index) => {
431
406
  const node = asked[index];
@@ -456,10 +431,5 @@ export function destructuring<Brand>(
456
431
  });
457
432
  };
458
433
 
459
- return {
460
- resolve,
461
- get cost() {
462
- return { patternBatches, patternLookups };
463
- },
464
- };
434
+ return { resolve };
465
435
  }