@cplieger/deadset-ts 8.0.0-dev.2 → 8.0.0-dev.21
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/README.md +3 -1
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/dist/bin/mapper-connection.js +2 -1
- package/dist/bin/node-host.js +24 -5
- package/dist/src/alias-chain.js +35 -9
- package/dist/src/amd.js +81 -0
- package/dist/src/analysis.js +274 -496
- package/dist/src/augmentations.js +64 -3
- package/dist/src/automatic-types.js +10 -29
- package/dist/src/bindings.js +382 -0
- package/dist/src/commands/held.js +499 -0
- package/dist/src/commands/read.js +161 -0
- package/dist/src/commands/shell.js +169 -0
- package/dist/src/commands/tools.js +1847 -0
- package/dist/src/component-files.js +3 -2
- package/dist/src/component-layer.js +4 -2
- package/dist/src/config.js +6 -82
- package/dist/src/conformance-record.js +2 -2
- package/dist/src/consumers.js +10 -38
- package/dist/src/contextual-uses.js +57 -26
- package/dist/src/contract/config.generated.js +561 -0
- package/dist/src/contract/contract.generated.js +1370 -0
- package/dist/src/contract/report.generated.js +866 -0
- package/dist/src/dependencies.js +165 -122
- package/dist/src/destructuring.js +1 -19
- package/dist/src/edges.js +38 -122
- package/dist/src/element-access.js +181 -168
- package/dist/src/entries/build-scripts.js +222 -0
- package/dist/src/{configuration-files.js → entries/configuration-files.js} +52 -256
- package/dist/src/{convention-rows.js → entries/convention-rows.js} +170 -30
- package/dist/src/entries/conventions.js +740 -0
- package/dist/src/{html-entries.js → entries/html-entries.js} +12 -42
- package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +5 -28
- package/dist/src/entries/run-directories.js +77 -0
- package/dist/src/entries/sources.js +144 -0
- package/dist/src/entries/static-module.js +670 -0
- package/dist/src/entries/test-runners.js +650 -0
- package/dist/src/entries/workflow-steps.js +345 -0
- package/dist/src/exemptions/argument-places.js +131 -0
- package/dist/src/exemptions/calls.js +338 -0
- package/dist/src/exemptions/classes.js +13 -0
- package/dist/src/{decorator.js → exemptions/decorator.js} +19 -30
- package/dist/src/exemptions/detectors.js +48 -0
- package/dist/src/{enum-group.js → exemptions/enum-group.js} +9 -16
- package/dist/src/{erased-stores.js → exemptions/erased-stores.js} +7 -11
- package/dist/src/{framework-lifecycle.js → exemptions/framework-lifecycle.js} +76 -54
- package/dist/src/exemptions/generated-file.js +241 -0
- package/dist/src/{injection-container.js → exemptions/injection-container.js} +20 -26
- package/dist/src/exemptions/installed-globals.js +173 -0
- package/dist/src/{interface-satisfaction.js → exemptions/interface-satisfaction.js} +52 -121
- package/dist/src/exemptions/lifecycle.js +150 -0
- package/dist/src/{reflective-lookup.js → exemptions/reflective-lookup.js} +3 -3
- package/dist/src/exemptions/serialization-contract.js +1276 -0
- package/dist/src/exemptions/sites.js +182 -0
- package/dist/src/{template-field.js → exemptions/template-field.js} +13 -23
- package/dist/src/{value-reach.js → exemptions/value-reach.js} +14 -7
- package/dist/src/exposure.js +400 -0
- package/dist/src/extensions.js +37 -0
- package/dist/src/facts.js +38 -0
- package/dist/src/failure.js +36 -0
- package/dist/src/file-facts.js +3 -26
- package/dist/src/findings/completion.js +109 -56
- package/dist/src/findings/dependencies-and-module-machinery.js +4 -5
- package/dist/src/findings/emitters.js +27 -41
- package/dist/src/{implementations.js → findings/implementations.js} +3 -3
- package/dist/src/{in-operands.js → findings/in-operands.js} +3 -2
- package/dist/src/findings/interfaces.js +4 -5
- package/dist/src/findings/intra-function.js +16 -13
- package/dist/src/findings/non-code-artifacts.js +17 -12
- package/dist/src/findings/reads-and-writes.js +86 -27
- package/dist/src/findings/self-check.js +44 -30
- package/dist/src/findings/unused-declarations.js +29 -45
- package/dist/src/findings/visibility-narrowing.js +23 -31
- package/dist/src/findings-pass.js +13 -21
- package/dist/src/fs/document.js +52 -0
- package/dist/src/fs/manifest.js +67 -0
- package/dist/src/fs/tree.js +88 -0
- package/dist/src/git-ignore.js +39 -26
- package/dist/src/import-bindings.js +73 -28
- package/dist/src/index/sites.js +557 -0
- package/dist/src/index/values.js +124 -0
- package/dist/src/index.js +2 -2
- package/dist/src/indexed-access.js +523 -478
- package/dist/src/intra-function-parts.js +63 -43
- package/dist/src/inventory/commonjs.js +507 -0
- package/dist/src/inventory/enumerate.js +167 -0
- package/dist/src/inventory/syntax.js +236 -0
- package/dist/src/inventory.js +323 -724
- package/dist/src/javascript-file.js +48 -0
- package/dist/src/json-document.js +198 -67
- package/dist/src/keyof-comparisons.js +126 -107
- package/dist/src/kinds.js +3 -366
- package/dist/src/{components.js → liveness/components.js} +2 -3
- package/dist/src/{graph.js → liveness/graph.js} +52 -28
- package/dist/src/liveness/matrix.js +99 -0
- package/dist/src/liveness/sweep.js +558 -0
- package/dist/src/load/classify.js +289 -0
- package/dist/src/load/diagnostics.js +87 -0
- package/dist/src/load/discover.js +285 -0
- package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
- package/dist/src/load/expected-module.js +136 -0
- package/dist/src/load/load.js +27 -0
- package/dist/src/load/module-lookup.js +37 -0
- package/dist/src/load/package-scope.js +56 -0
- package/dist/src/load/plan.js +313 -0
- package/dist/src/load/specifiers.js +113 -0
- package/dist/src/load/synthesize.js +152 -0
- package/dist/src/load/test-globals.js +207 -0
- package/dist/src/load/test-joins.js +82 -0
- package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +4 -4
- package/dist/src/{workspace-programs.js → load/workspace-programs.js} +89 -66
- package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +24 -66
- package/dist/src/{workspace-run.js → load/workspace-run.js} +7 -7
- package/dist/src/{workspace.js → load/workspace.js} +62 -124
- package/dist/src/module-declarations.js +70 -85
- package/dist/src/overrides.js +134 -112
- package/dist/src/partial.js +2 -1
- package/dist/src/paths.js +82 -16
- package/dist/src/platform-calls.js +78 -0
- package/dist/src/platform-symbols.js +134 -0
- package/dist/src/position.js +43 -1
- package/dist/src/print.js +11 -79
- package/dist/src/product.js +13 -0
- package/dist/src/query.js +95 -0
- package/dist/src/ref.js +12 -20
- package/dist/src/references/read-rule.js +1 -0
- package/dist/src/references/read-rules.js +48 -0
- package/dist/src/references/sink.js +237 -0
- package/dist/src/references/sources.js +450 -0
- package/dist/src/references.js +117 -1074
- package/dist/src/report-schema.js +51 -0
- package/dist/src/report.js +57 -41
- package/dist/src/reporters/annotations.js +15 -8
- package/dist/src/reporters/sarif.js +16 -10
- package/dist/src/reporters/template.js +4 -19
- package/dist/src/resolve.js +246 -730
- package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +22 -24
- package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +6 -15
- package/dist/src/roots/manifest.js +216 -0
- package/dist/src/roots/published-reach.js +412 -0
- package/dist/src/roots/root-set.js +487 -0
- package/dist/src/roots/unseen-loads.js +236 -0
- package/dist/src/run.js +66 -77
- package/dist/src/schema.js +320 -343
- package/dist/src/scope.js +38 -115
- package/dist/src/session.js +37 -29
- package/dist/src/source-files.js +6 -10
- package/dist/src/stores.js +4 -2
- package/dist/src/suppress-file.js +25 -28
- package/dist/src/suppress-inline.js +36 -83
- package/dist/src/suppress.js +50 -71
- package/dist/src/symbol-keys.js +92 -88
- package/dist/src/tests/file-class.js +76 -0
- package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
- package/dist/src/{test-support.js → tests/support.js} +5 -12
- package/dist/src/text/compare.js +26 -0
- package/dist/src/text/glob.js +194 -0
- package/dist/src/text/named-files.js +298 -0
- package/dist/src/text/yaml.js +684 -0
- package/dist/src/type-errors.js +11 -232
- package/dist/src/type-parameter-reads.js +178 -139
- package/dist/src/unimplemented-callees.js +262 -242
- package/dist/src/unwrap.js +23 -0
- package/dist/src/usage.js +10 -0
- package/dist/src/vendor/unbash/ansi-c.js +132 -0
- package/dist/src/vendor/unbash/arithmetic-parts.js +37 -0
- package/dist/src/vendor/unbash/arithmetic.js +591 -0
- package/dist/src/vendor/unbash/assignment.js +131 -0
- package/dist/src/vendor/unbash/chars.js +48 -0
- package/dist/src/vendor/unbash/command.js +41 -0
- package/dist/src/vendor/unbash/expansion.js +80 -0
- package/dist/src/vendor/unbash/glob.js +268 -0
- package/dist/src/vendor/unbash/heredoc.js +27 -0
- package/dist/src/vendor/unbash/internal-types.js +1 -0
- package/dist/src/vendor/unbash/lexer.js +4274 -0
- package/dist/src/vendor/unbash/limits.js +3 -0
- package/dist/src/vendor/unbash/parser.js +1366 -0
- package/dist/src/vendor/unbash/parts.js +57 -0
- package/dist/src/vendor/unbash/substitution-context.js +8 -0
- package/dist/src/vendor/unbash/traversal.js +212 -0
- package/dist/src/vendor/unbash/types.js +1 -0
- package/dist/src/vendor/unbash/word-value.js +61 -0
- package/dist/src/vendor/unbash/word.js +40 -0
- package/dist/src/verbs/analyze.js +194 -127
- package/dist/src/verbs/describe.js +13 -18
- package/dist/src/verbs/explain.js +85 -139
- package/dist/src/verbs/print-config.js +2 -1
- package/dist/src/verbs/print-projects.js +6 -4
- package/dist/src/verbs/print-retained.js +30 -6
- package/dist/src/verbs/print-roots.js +4 -2
- package/dist/src/verbs/verb.js +1 -5
- package/dist/src/verbs/version.js +14 -3
- package/jsr.json +2 -1
- package/package.json +14 -8
- package/src/alias-chain.ts +40 -11
- package/src/amd.ts +130 -0
- package/src/analysis.ts +426 -733
- package/src/augmentations.ts +93 -4
- package/src/automatic-types.ts +12 -30
- package/src/bindings.ts +460 -0
- package/src/commands/held.ts +632 -0
- package/src/commands/read.ts +242 -0
- package/src/commands/shell.ts +228 -0
- package/src/commands/tools.ts +2382 -0
- package/src/component-files.ts +4 -2
- package/src/component-layer.ts +4 -2
- package/src/config.ts +31 -302
- package/src/conformance-record.ts +2 -2
- package/src/consumers.ts +16 -66
- package/src/contextual-uses.ts +66 -34
- package/src/contract/config.generated.ts +821 -0
- package/src/contract/contract.generated.ts +1453 -0
- package/src/contract/report.generated.ts +1241 -0
- package/src/dependencies.ts +223 -128
- package/src/destructuring.ts +1 -31
- package/src/edges.ts +41 -140
- package/src/element-access.ts +190 -187
- package/src/entries/build-scripts.ts +292 -0
- package/src/{configuration-files.ts → entries/configuration-files.ts} +68 -278
- package/src/{convention-rows.ts → entries/convention-rows.ts} +227 -31
- package/src/{conventions.ts → entries/conventions.ts} +367 -583
- package/src/{html-entries.ts → entries/html-entries.ts} +22 -48
- package/src/{mdx-entries.ts → entries/mdx-entries.ts} +7 -30
- package/src/entries/run-directories.ts +108 -0
- package/src/entries/sources.ts +266 -0
- package/src/entries/static-module.ts +858 -0
- package/src/entries/test-runners.ts +835 -0
- package/src/entries/workflow-steps.ts +432 -0
- package/src/exemptions/argument-places.ts +198 -0
- package/src/exemptions/calls.ts +483 -0
- package/src/exemptions/classes.ts +49 -0
- package/src/exemptions/decorator.ts +56 -0
- package/src/exemptions/detectors.ts +75 -0
- package/src/{enum-group.ts → exemptions/enum-group.ts} +10 -19
- package/src/{erased-stores.ts → exemptions/erased-stores.ts} +7 -14
- package/src/{framework-lifecycle.ts → exemptions/framework-lifecycle.ts} +85 -66
- package/src/exemptions/generated-file.ts +318 -0
- package/src/{injection-container.ts → exemptions/injection-container.ts} +29 -34
- package/src/exemptions/installed-globals.ts +255 -0
- package/src/{interface-satisfaction.ts → exemptions/interface-satisfaction.ts} +69 -160
- package/src/exemptions/lifecycle.ts +286 -0
- package/src/{reflective-lookup.ts → exemptions/reflective-lookup.ts} +5 -5
- package/src/exemptions/serialization-contract.ts +1729 -0
- package/src/exemptions/sites.ts +293 -0
- package/src/{template-field.ts → exemptions/template-field.ts} +22 -32
- package/src/{value-reach.ts → exemptions/value-reach.ts} +16 -8
- package/src/exposure.ts +492 -0
- package/src/extensions.ts +45 -0
- package/src/facts.ts +46 -0
- package/src/failure.ts +63 -0
- package/src/file-facts.ts +15 -25
- package/src/finding.ts +10 -10
- package/src/findings/boundary.ts +11 -0
- package/src/findings/completion.ts +133 -64
- package/src/findings/dependencies-and-module-machinery.ts +4 -7
- package/src/findings/emitter.ts +9 -10
- package/src/findings/emitters.ts +38 -52
- package/src/{implementations.ts → findings/implementations.ts} +4 -4
- package/src/{in-operands.ts → findings/in-operands.ts} +4 -3
- package/src/findings/interfaces.ts +7 -9
- package/src/findings/intra-function.ts +16 -14
- package/src/findings/non-code-artifacts.ts +24 -15
- package/src/findings/reads-and-writes.ts +118 -41
- package/src/findings/self-check.ts +51 -38
- package/src/findings/unused-declarations.ts +31 -49
- package/src/findings/visibility-narrowing.ts +36 -40
- package/src/findings-pass.ts +15 -31
- package/src/fs/document.ts +70 -0
- package/src/fs/manifest.ts +96 -0
- package/src/fs/tree.ts +110 -0
- package/src/git-ignore.ts +50 -26
- package/src/host.ts +12 -5
- package/src/import-bindings.ts +98 -29
- package/src/index/sites.ts +781 -0
- package/src/index/values.ts +170 -0
- package/src/index.ts +2 -2
- package/src/indexed-access.ts +570 -527
- package/src/intra-function-parts.ts +73 -44
- package/src/inventory/commonjs.ts +696 -0
- package/src/inventory/enumerate.ts +203 -0
- package/src/inventory/syntax.ts +311 -0
- package/src/inventory.ts +442 -895
- package/src/javascript-file.ts +54 -0
- package/src/json-document.ts +241 -76
- package/src/keyof-comparisons.ts +133 -122
- package/src/kinds.ts +5 -413
- package/src/{components.ts → liveness/components.ts} +4 -6
- package/src/{graph.ts → liveness/graph.ts} +100 -35
- package/src/liveness/matrix.ts +162 -0
- package/src/liveness/sweep.ts +855 -0
- package/src/load/classify.ts +433 -0
- package/src/load/diagnostics.ts +154 -0
- package/src/load/discover.ts +471 -0
- package/src/{emit-map.ts → load/emit-map.ts} +1 -1
- package/src/load/expected-module.ts +194 -0
- package/src/load/load.ts +73 -0
- package/src/load/module-lookup.ts +50 -0
- package/src/load/package-scope.ts +74 -0
- package/src/load/plan.ts +513 -0
- package/src/load/specifiers.ts +171 -0
- package/src/load/synthesize.ts +230 -0
- package/src/load/test-globals.ts +251 -0
- package/src/load/test-joins.ts +98 -0
- package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +5 -5
- package/src/{workspace-programs.ts → load/workspace-programs.ts} +128 -85
- package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +41 -77
- package/src/{workspace-run.ts → load/workspace-run.ts} +18 -16
- package/src/{workspace.ts → load/workspace.ts} +90 -134
- package/src/module-declarations.ts +74 -98
- package/src/overrides.ts +162 -134
- package/src/partial.ts +3 -2
- package/src/paths.ts +92 -16
- package/src/platform-calls.ts +119 -0
- package/src/platform-symbols.ts +189 -0
- package/src/position.ts +44 -1
- package/src/print.ts +12 -92
- package/src/product.ts +18 -0
- package/src/query.ts +201 -10
- package/src/ref.ts +12 -20
- package/src/references/read-rule.ts +60 -0
- package/src/references/read-rules.ts +55 -0
- package/src/references/sink.ts +314 -0
- package/src/references/sources.ts +632 -0
- package/src/references.ts +187 -1450
- package/src/report-schema.ts +68 -0
- package/src/report.ts +103 -226
- package/src/reporters/annotations.ts +22 -11
- package/src/reporters/json.ts +1 -1
- package/src/reporters/reporter.ts +2 -4
- package/src/reporters/reporters.ts +1 -1
- package/src/reporters/sarif.ts +29 -16
- package/src/reporters/template.ts +4 -20
- package/src/reporters/text.ts +3 -3
- package/src/resolve.ts +284 -1115
- package/src/{configured-declarations.ts → roots/configured-declarations.ts} +26 -29
- package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +7 -16
- package/src/roots/manifest.ts +303 -0
- package/src/roots/published-reach.ts +486 -0
- package/src/{roots.ts → roots/root-set.ts} +286 -469
- package/src/roots/unseen-loads.ts +345 -0
- package/src/run.ts +75 -91
- package/src/schema.ts +391 -388
- package/src/scope.ts +46 -138
- package/src/session.ts +87 -55
- package/src/source-files.ts +6 -11
- package/src/stores.ts +15 -3
- package/src/suppress-file.ts +24 -33
- package/src/suppress-inline.ts +55 -91
- package/src/suppress.ts +78 -79
- package/src/symbol-keys.ts +104 -107
- package/src/tests/file-class.ts +135 -0
- package/src/{outside-tests.ts → tests/outside.ts} +16 -10
- package/src/{test-support.ts → tests/support.ts} +15 -21
- package/src/text/compare.ts +27 -0
- package/src/text/glob.ts +210 -0
- package/src/text/named-files.ts +388 -0
- package/src/text/yaml.ts +747 -0
- package/src/type-errors.ts +18 -288
- package/src/type-parameter-reads.ts +187 -158
- package/src/unimplemented-callees.ts +297 -280
- package/src/unwrap.ts +34 -0
- package/src/usage.ts +10 -0
- package/src/vendor/unbash/LICENSE +15 -0
- package/src/vendor/unbash/VENDORED.md +16 -0
- package/src/vendor/unbash/ansi-c.ts +132 -0
- package/src/vendor/unbash/arithmetic-parts.ts +53 -0
- package/src/vendor/unbash/arithmetic.ts +641 -0
- package/src/vendor/unbash/assignment.ts +163 -0
- package/src/vendor/unbash/chars.ts +48 -0
- package/src/vendor/unbash/command.ts +47 -0
- package/src/vendor/unbash/expansion.ts +144 -0
- package/src/vendor/unbash/glob.ts +284 -0
- package/src/vendor/unbash/heredoc.ts +34 -0
- package/src/vendor/unbash/internal-types.ts +94 -0
- package/src/vendor/unbash/lexer.ts +4352 -0
- package/src/vendor/unbash/limits.ts +3 -0
- package/src/vendor/unbash/parser.ts +1612 -0
- package/src/vendor/unbash/parts.ts +96 -0
- package/src/vendor/unbash/substitution-context.ts +20 -0
- package/src/vendor/unbash/traversal.ts +182 -0
- package/src/vendor/unbash/types.ts +660 -0
- package/src/vendor/unbash/word-value.ts +64 -0
- package/src/vendor/unbash/word.ts +50 -0
- package/src/verbs/analyze.ts +255 -164
- package/src/verbs/describe.ts +19 -17
- package/src/verbs/explain.ts +93 -169
- package/src/verbs/print-config.ts +2 -1
- package/src/verbs/print-projects.ts +6 -4
- package/src/verbs/print-retained.ts +36 -6
- package/src/verbs/print-roots.ts +4 -2
- package/src/verbs/verb.ts +2 -8
- package/src/verbs/version.ts +15 -3
- package/dist/src/base-url.js +0 -18
- package/dist/src/calls.js +0 -155
- package/dist/src/conventions.js +0 -937
- package/dist/src/discover.js +0 -468
- package/dist/src/entry-points.js +0 -529
- package/dist/src/exempt-classes.js +0 -75
- package/dist/src/exempt.js +0 -209
- package/dist/src/generated-file.js +0 -95
- package/dist/src/glob.js +0 -65
- package/dist/src/manifest.js +0 -165
- package/dist/src/matrix.js +0 -246
- package/dist/src/pnpm-workspace.js +0 -120
- package/dist/src/roots.js +0 -672
- package/dist/src/serialization-contract.js +0 -611
- package/dist/src/setup-failure.js +0 -23
- package/dist/src/sweep.js +0 -224
- package/dist/src/test-joins.js +0 -101
- package/dist/src/value-flow.js +0 -74
- package/dist/src/version.js +0 -7
- package/dist/src/workflow-steps.js +0 -185
- package/src/base-url.ts +0 -24
- package/src/calls.ts +0 -225
- package/src/decorator.ts +0 -78
- package/src/discover.ts +0 -653
- package/src/entry-points.ts +0 -687
- package/src/exempt-classes.ts +0 -123
- package/src/exempt.ts +0 -323
- package/src/generated-file.ts +0 -111
- package/src/glob.ts +0 -67
- package/src/manifest.ts +0 -234
- package/src/matrix.ts +0 -423
- package/src/pnpm-workspace.ts +0 -135
- package/src/serialization-contract.ts +0 -849
- package/src/setup-failure.ts +0 -39
- package/src/sweep.ts +0 -347
- package/src/test-joins.ts +0 -120
- package/src/value-flow.ts +0 -104
- package/src/version.ts +0 -7
- package/src/workflow-steps.ts +0 -216
|
@@ -1,849 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The serialization-contract class: the data members and `toJSON` of every type a value's
|
|
3
|
-
* static type reaches, where the value reaches `JSON.stringify` or a call `ts.serializers`
|
|
4
|
-
* names, and `toString` too where it reaches an erased parameter of a function outside the
|
|
5
|
-
* analysis, or an erased property of a type the program does not declare. A function of
|
|
6
|
-
* the project handing such a parameter to a destination is one, to a fixpoint, and a
|
|
7
|
-
* function invoked through `call`, `apply` or `bind` is the callee.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
isArrayLiteralExpression,
|
|
12
|
-
isArrowFunction,
|
|
13
|
-
isAsExpression,
|
|
14
|
-
isCallExpression,
|
|
15
|
-
isClassDeclaration,
|
|
16
|
-
isClassExpression,
|
|
17
|
-
isClassStaticBlockDeclaration,
|
|
18
|
-
isFunctionDeclaration,
|
|
19
|
-
isFunctionExpression,
|
|
20
|
-
isGetAccessorDeclaration,
|
|
21
|
-
isIdentifier,
|
|
22
|
-
isInterfaceDeclaration,
|
|
23
|
-
isMethodDeclaration,
|
|
24
|
-
isNoSubstitutionTemplateLiteral,
|
|
25
|
-
isNumericLiteral,
|
|
26
|
-
isObjectLiteralExpression,
|
|
27
|
-
isParenthesizedExpression,
|
|
28
|
-
isPropertyAccessExpression,
|
|
29
|
-
isPropertyDeclaration,
|
|
30
|
-
isSatisfiesExpression,
|
|
31
|
-
isSetAccessorDeclaration,
|
|
32
|
-
isSpreadElement,
|
|
33
|
-
isStringLiteral,
|
|
34
|
-
isTypeLiteralNode,
|
|
35
|
-
isVariableDeclaration,
|
|
36
|
-
ModifierFlags,
|
|
37
|
-
NodeFlags,
|
|
38
|
-
SyntaxKind,
|
|
39
|
-
type CallExpression,
|
|
40
|
-
type Expression,
|
|
41
|
-
type Node,
|
|
42
|
-
type ParameterDeclaration,
|
|
43
|
-
} from "@typescript/native/ast";
|
|
44
|
-
import {
|
|
45
|
-
SignatureKind,
|
|
46
|
-
SymbolFlags,
|
|
47
|
-
TypeFlags,
|
|
48
|
-
type NodeHandle,
|
|
49
|
-
type Signature,
|
|
50
|
-
type Symbol as TSSymbol,
|
|
51
|
-
type Type,
|
|
52
|
-
} from "@typescript/native/sync";
|
|
53
|
-
import { aliasChains, type AliasChains } from "./alias-chain.ts";
|
|
54
|
-
import { calleeName, resolvedTargets, valuesPassed } from "./calls.ts";
|
|
55
|
-
import { classMembers, memberComponent, typesAt } from "./class-members.ts";
|
|
56
|
-
import type { DeclarationEntry } from "./config.ts";
|
|
57
|
-
import {
|
|
58
|
-
names,
|
|
59
|
-
namesADeclaration,
|
|
60
|
-
resolveEntries,
|
|
61
|
-
spelledEntry,
|
|
62
|
-
} from "./configured-declarations.ts";
|
|
63
|
-
import type { DetectorInput, Evidence } from "./exempt.ts";
|
|
64
|
-
import { nodeKey, type Inventory } from "./inventory.ts";
|
|
65
|
-
import { renderPosition } from "./position.ts";
|
|
66
|
-
import { must } from "./query.ts";
|
|
67
|
-
import type { ProjectView } from "./session.ts";
|
|
68
|
-
import { erasedStores, type ErasedStores } from "./erased-stores.ts";
|
|
69
|
-
import { checkedTypes, CONVERSION_MEMBERS, valueReach, type Reached } from "./value-reach.ts";
|
|
70
|
-
|
|
71
|
-
/** The serializer every run reads, whatever the configuration names. */
|
|
72
|
-
const JSON_STRINGIFY: DeclarationEntry = { shape: "global", global: "JSON.stringify" };
|
|
73
|
-
|
|
74
|
-
/** The methods a serializer and a formatter resolve by name on a value that left the analysis. */
|
|
75
|
-
const CONVERSIONS: ReadonlySet<string> = new Set(["toJSON", "toString"]);
|
|
76
|
-
|
|
77
|
-
/** The method a serializer calls on a value that carries one, wherever the value goes. */
|
|
78
|
-
const SERIALIZED_CONVERSION = "toJSON";
|
|
79
|
-
|
|
80
|
-
/** The parameter types that keep nothing of the value they are given. */
|
|
81
|
-
const ERASED = TypeFlags.Any | TypeFlags.Unknown;
|
|
82
|
-
|
|
83
|
-
/** How deep a callee's result is searched for a type parameter: `Promise<Box<T>>` is two levels. */
|
|
84
|
-
const MENTION_DEPTH = 3;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* What a destination holds back of a class: its properties, or its properties and its
|
|
88
|
-
* two conversion methods. The second holds back everything the first does.
|
|
89
|
-
*/
|
|
90
|
-
type Reach = "properties" | "conversions";
|
|
91
|
-
|
|
92
|
-
/** One call of the project's own files, and the class `this` is a value of where it is written. */
|
|
93
|
-
interface Site {
|
|
94
|
-
readonly call: CallExpression;
|
|
95
|
-
readonly self: string | undefined;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** One parameter of a function of the project that may hand on what it is given. */
|
|
99
|
-
interface Parameter {
|
|
100
|
-
/** The inventory's identifier of the function's declaration. */
|
|
101
|
-
readonly fn: string;
|
|
102
|
-
readonly index: number;
|
|
103
|
-
readonly rest: boolean;
|
|
104
|
-
readonly name: Node;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** One place a function hands a parameter of its own to the argument of a call. */
|
|
108
|
-
interface Forwarded {
|
|
109
|
-
readonly parameter: Parameter;
|
|
110
|
-
readonly site: Site;
|
|
111
|
-
readonly argument: number;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** A destination at one argument: what it holds back, and the callee a record names. */
|
|
115
|
-
interface Destination {
|
|
116
|
-
readonly reach: Reach;
|
|
117
|
-
readonly callee: string;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** The wider of two reaches, where either may be absent. */
|
|
121
|
-
function wider(a: Reach | undefined, b: Reach | undefined): Reach | undefined {
|
|
122
|
-
return a === "conversions" || b === "conversions" ? "conversions" : (a ?? b);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Whether one node declares a static member, whose `this` is the class itself. */
|
|
126
|
-
function isStatic(node: Node): boolean {
|
|
127
|
-
const flags = (node as { readonly modifierFlags?: number }).modifierFlags ?? 0;
|
|
128
|
-
return (flags & ModifierFlags.Static) !== 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Whether one node opens a body whose `this` is not an instance of the enclosing class. */
|
|
132
|
-
function resetsThis(node: Node): boolean {
|
|
133
|
-
return (
|
|
134
|
-
isFunctionDeclaration(node) ||
|
|
135
|
-
isFunctionExpression(node) ||
|
|
136
|
-
isClassStaticBlockDeclaration(node) ||
|
|
137
|
-
isStatic(node) ||
|
|
138
|
-
((isMethodDeclaration(node) ||
|
|
139
|
-
isGetAccessorDeclaration(node) ||
|
|
140
|
-
isSetAccessorDeclaration(node)) &&
|
|
141
|
-
isObjectLiteralExpression(node.parent))
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** The parameters and declaring node of one function-like declaration of the project. */
|
|
146
|
-
function functionOf(
|
|
147
|
-
node: Node,
|
|
148
|
-
): { readonly declared: Node; readonly parameters: readonly ParameterDeclaration[] } | undefined {
|
|
149
|
-
if (
|
|
150
|
-
isFunctionDeclaration(node) ||
|
|
151
|
-
(isMethodDeclaration(node) && !isObjectLiteralExpression(node.parent))
|
|
152
|
-
) {
|
|
153
|
-
return { declared: node, parameters: node.parameters };
|
|
154
|
-
}
|
|
155
|
-
if (
|
|
156
|
-
isVariableDeclaration(node) &&
|
|
157
|
-
node.initializer !== undefined &&
|
|
158
|
-
(isArrowFunction(node.initializer) || isFunctionExpression(node.initializer))
|
|
159
|
-
) {
|
|
160
|
-
return { declared: node, parameters: node.initializer.parameters };
|
|
161
|
-
}
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Whether one parameter is a `this` parameter, which types `this` and binds no argument. */
|
|
166
|
-
function isThisParameter(parameter: ParameterDeclaration): boolean {
|
|
167
|
-
return isIdentifier(parameter.name) && parameter.name.text === "this";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Whether an argument is written in a form that holds no class instance, which saves a type. */
|
|
171
|
-
function holdsNoInstance(argument: Expression): boolean {
|
|
172
|
-
return (
|
|
173
|
-
isArrowFunction(argument) ||
|
|
174
|
-
isFunctionExpression(argument) ||
|
|
175
|
-
isStringLiteral(argument) ||
|
|
176
|
-
isNumericLiteral(argument) ||
|
|
177
|
-
isNoSubstitutionTemplateLiteral(argument) ||
|
|
178
|
-
argument.kind === SyntaxKind.TemplateExpression
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** The expression an argument evaluates, through parentheses and a spread. */
|
|
183
|
-
function evaluated(argument: Expression): Expression {
|
|
184
|
-
const value = isSpreadElement(argument) ? argument.expression : argument;
|
|
185
|
-
return isParenthesizedExpression(value) ? evaluated(value.expression) : value;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** The methods of `Function.prototype` that invoke a function with arguments of their own. */
|
|
189
|
-
const FUNCTION_METHODS: ReadonlySet<string> = new Set(["call", "apply", "bind"]);
|
|
190
|
-
|
|
191
|
-
/** The interfaces of the standard library that declare those methods for a function value. */
|
|
192
|
-
const FUNCTION_INTERFACES: ReadonlySet<string> = new Set([
|
|
193
|
-
"Function",
|
|
194
|
-
"CallableFunction",
|
|
195
|
-
"NewableFunction",
|
|
196
|
-
]);
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* One call as the function it invokes sees it: the expression naming that function,
|
|
200
|
-
* and the argument each of its parameters binds, in order.
|
|
201
|
-
*/
|
|
202
|
-
interface Invocation {
|
|
203
|
-
readonly callee: Expression;
|
|
204
|
-
readonly arguments: readonly Expression[];
|
|
205
|
-
/** Whether the call reaches the callee through a method of `Function.prototype`. */
|
|
206
|
-
readonly indirect: boolean;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** A call through a method of `Function.prototype`: the method's name and the invocation. */
|
|
210
|
-
interface MethodForm {
|
|
211
|
-
readonly method: Node;
|
|
212
|
-
readonly invocation: Invocation;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function unparenthesized(expression: Expression): Expression {
|
|
216
|
-
return isParenthesizedExpression(expression)
|
|
217
|
-
? unparenthesized(expression.expression)
|
|
218
|
-
: expression;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The invocation a call writes through a method of `Function.prototype`, read from
|
|
223
|
-
* the syntax alone: `f.call(self, a)`, `f.apply(self, [a])`, `f.bind(self, a)`, which
|
|
224
|
-
* binds `a`, and `f.bind(self, a)(b)`, which passes `b` after it. An `apply` argument
|
|
225
|
-
* that is no array literal is the value of the first parameter, whose elements it
|
|
226
|
-
* carries. Whether the method is the prototype's is resolution's to say.
|
|
227
|
-
*/
|
|
228
|
-
function throughMethod(call: CallExpression): MethodForm | undefined {
|
|
229
|
-
const expression = unparenthesized(call.expression);
|
|
230
|
-
if (isPropertyAccessExpression(expression) && FUNCTION_METHODS.has(expression.name.text)) {
|
|
231
|
-
const [, ...rest] = call.arguments;
|
|
232
|
-
let passed: readonly Expression[] = rest;
|
|
233
|
-
if (expression.name.text === "apply") {
|
|
234
|
-
const list = rest[0] === undefined ? undefined : unparenthesized(rest[0]);
|
|
235
|
-
passed = list === undefined ? [] : isArrayLiteralExpression(list) ? list.elements : [list];
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
method: expression.name,
|
|
239
|
-
invocation: { callee: expression.expression, arguments: passed, indirect: true },
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (isCallExpression(expression)) {
|
|
243
|
-
const bound = unparenthesized(expression.expression);
|
|
244
|
-
if (isPropertyAccessExpression(bound) && bound.name.text === "bind") {
|
|
245
|
-
return {
|
|
246
|
-
method: bound.name,
|
|
247
|
-
invocation: {
|
|
248
|
-
callee: bound.expression,
|
|
249
|
-
arguments: [...expression.arguments.slice(1), ...call.arguments],
|
|
250
|
-
indirect: true,
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** What one walk of the project's own files found: its calls and its functions' parameters. */
|
|
259
|
-
interface Walked {
|
|
260
|
-
readonly sites: readonly Site[];
|
|
261
|
-
readonly parameters: readonly Parameter[];
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Every call of the project's own files with the class `this` stands for there, and
|
|
266
|
-
* every identifier-named parameter of every function, method and function-valued
|
|
267
|
-
* variable the project declares, at the position of the argument it binds.
|
|
268
|
-
*/
|
|
269
|
-
function walkProject<Brand>(project: ProjectView<Brand>, held: Inventory): Walked {
|
|
270
|
-
const sites: Site[] = [];
|
|
271
|
-
const parameters: Parameter[] = [];
|
|
272
|
-
for (const file of project.ownSourceFiles()) {
|
|
273
|
-
const visit = (node: Node, self: string | undefined): void => {
|
|
274
|
-
let inner = self;
|
|
275
|
-
if (isClassDeclaration(node) || isClassExpression(node)) {
|
|
276
|
-
inner = held.declarations.get(nodeKey(file, node));
|
|
277
|
-
} else if (resetsThis(node)) {
|
|
278
|
-
inner = undefined;
|
|
279
|
-
}
|
|
280
|
-
if (node.kind === SyntaxKind.CallExpression) {
|
|
281
|
-
sites.push({ call: node as CallExpression, self });
|
|
282
|
-
}
|
|
283
|
-
const fn = functionOf(node);
|
|
284
|
-
const id = fn === undefined ? undefined : held.declarations.get(nodeKey(file, fn.declared));
|
|
285
|
-
if (fn !== undefined && id !== undefined) {
|
|
286
|
-
fn.parameters
|
|
287
|
-
.filter((parameter) => !isThisParameter(parameter))
|
|
288
|
-
.forEach((parameter, index) => {
|
|
289
|
-
if (isIdentifier(parameter.name)) {
|
|
290
|
-
parameters.push({
|
|
291
|
-
fn: id,
|
|
292
|
-
index,
|
|
293
|
-
rest: parameter.dotDotDotToken !== undefined,
|
|
294
|
-
name: parameter.name,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
node.forEachChild((child) => {
|
|
300
|
-
visit(child, inner);
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
file.forEachChild((child) => {
|
|
304
|
-
visit(child, undefined);
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
return { sites, parameters };
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* The parameters that keep nothing of the value they are given: one typed `unknown` or
|
|
312
|
-
* `any`, and a rest parameter whose elements are, each by its symbol.
|
|
313
|
-
*/
|
|
314
|
-
function erasedParameters<Brand>(
|
|
315
|
-
project: ProjectView<Brand>,
|
|
316
|
-
parameters: readonly Parameter[],
|
|
317
|
-
): ReadonlyMap<number, Parameter> {
|
|
318
|
-
const types = typesAt(
|
|
319
|
-
project,
|
|
320
|
-
parameters.map((parameter) => parameter.name),
|
|
321
|
-
);
|
|
322
|
-
const erased = parameters.filter((parameter, index) => {
|
|
323
|
-
const type = types[index];
|
|
324
|
-
if (type === undefined) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
if (!parameter.rest) {
|
|
328
|
-
return (type.flags & ERASED) !== 0;
|
|
329
|
-
}
|
|
330
|
-
const [element] = must(project.queries.typeArguments(type));
|
|
331
|
-
return element !== undefined && (element.flags & ERASED) !== 0;
|
|
332
|
-
});
|
|
333
|
-
const bySymbol = new Map<number, Parameter>();
|
|
334
|
-
project
|
|
335
|
-
.symbolsAt(erased.map((parameter) => project.handle(parameter.name)))
|
|
336
|
-
.map(must)
|
|
337
|
-
.forEach((symbol, index) => {
|
|
338
|
-
const parameter = erased[index];
|
|
339
|
-
if (symbol !== undefined && parameter !== undefined) {
|
|
340
|
-
bySymbol.set(symbol.id, parameter);
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
return bySymbol;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** Each place a call's argument passes one of the erased parameters it can see. */
|
|
347
|
-
function handedOn<Brand>(
|
|
348
|
-
project: ProjectView<Brand>,
|
|
349
|
-
sites: readonly Site[],
|
|
350
|
-
erased: ReadonlyMap<number, Parameter>,
|
|
351
|
-
invocationOf: (call: CallExpression) => Invocation,
|
|
352
|
-
): readonly Forwarded[] {
|
|
353
|
-
const spellings = new Set([...erased.values()].map((parameter) => parameter.name.getText()));
|
|
354
|
-
const candidates = sites.flatMap((site) =>
|
|
355
|
-
invocationOf(site.call).arguments.flatMap((argument, index) =>
|
|
356
|
-
valuesPassed(argument)
|
|
357
|
-
.filter((value) => spellings.has(value.name.getText()))
|
|
358
|
-
.map((value) => ({ site, argument: index, value })),
|
|
359
|
-
),
|
|
360
|
-
);
|
|
361
|
-
const plain = candidates.filter((one) => !one.value.shorthand);
|
|
362
|
-
const resolved = project.symbolsAt(plain.map((one) => project.handle(one.value.name))).map(must);
|
|
363
|
-
const symbolOf = new Map(plain.map((one, index) => [one, resolved[index]]));
|
|
364
|
-
return candidates.flatMap((one) => {
|
|
365
|
-
const symbol = one.value.shorthand
|
|
366
|
-
? must(project.shorthandValueAt(project.handle(one.value.name)))
|
|
367
|
-
: symbolOf.get(one);
|
|
368
|
-
const parameter = symbol === undefined ? undefined : erased.get(symbol.id);
|
|
369
|
-
return parameter === undefined ? [] : [{ parameter, site: one.site, argument: one.argument }];
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* The symbols of the interfaces and object types code of the analysis implements: those a
|
|
375
|
-
* class's `implements` and `extends` clauses name, those an object literal is typed as by
|
|
376
|
-
* a variable or property annotation or a `satisfies` or `as` expression, and every type
|
|
377
|
-
* each of those extends. Read at the first call, which asks the checker.
|
|
378
|
-
*/
|
|
379
|
-
function implementedOwners<Brand>(
|
|
380
|
-
project: ProjectView<Brand>,
|
|
381
|
-
inAnalysis: (path: string) => boolean,
|
|
382
|
-
): () => ReadonlySet<number> {
|
|
383
|
-
let owners: Set<number> | undefined;
|
|
384
|
-
return () => {
|
|
385
|
-
if (owners !== undefined) {
|
|
386
|
-
return owners;
|
|
387
|
-
}
|
|
388
|
-
const found = new Set<number>();
|
|
389
|
-
const queries = project.queries;
|
|
390
|
-
const own = project.ownPaths();
|
|
391
|
-
const files = [
|
|
392
|
-
...project.ownSourceFiles(),
|
|
393
|
-
...project.program
|
|
394
|
-
.getSourceFileNames()
|
|
395
|
-
.filter((name) => !own.has(name) && inAnalysis(name))
|
|
396
|
-
.flatMap((name) => project.program.getSourceFile(name) ?? []),
|
|
397
|
-
];
|
|
398
|
-
const naming: Node[] = [];
|
|
399
|
-
const visit = (node: Node): void => {
|
|
400
|
-
if (isClassDeclaration(node) || isClassExpression(node)) {
|
|
401
|
-
naming.push(...(node.heritageClauses ?? []).flatMap((clause) => [...clause.types]));
|
|
402
|
-
} else if (
|
|
403
|
-
(isVariableDeclaration(node) || isPropertyDeclaration(node)) &&
|
|
404
|
-
node.type !== undefined &&
|
|
405
|
-
node.initializer !== undefined &&
|
|
406
|
-
isObjectLiteralExpression(evaluated(node.initializer))
|
|
407
|
-
) {
|
|
408
|
-
naming.push(node.type);
|
|
409
|
-
} else if (
|
|
410
|
-
(isSatisfiesExpression(node) || isAsExpression(node)) &&
|
|
411
|
-
isObjectLiteralExpression(evaluated(node.expression))
|
|
412
|
-
) {
|
|
413
|
-
naming.push(node.type);
|
|
414
|
-
}
|
|
415
|
-
node.forEachChild(visit);
|
|
416
|
-
};
|
|
417
|
-
for (const file of files) {
|
|
418
|
-
file.forEachChild(visit);
|
|
419
|
-
}
|
|
420
|
-
const pending = typesAt(project, naming).filter((type) => type !== undefined);
|
|
421
|
-
const seen = new Set<number>();
|
|
422
|
-
for (let type = pending.pop(); type !== undefined; type = pending.pop()) {
|
|
423
|
-
for (const part of must(queries.constituents(type))) {
|
|
424
|
-
const target = must(queries.targetOf(part));
|
|
425
|
-
if (!seen.has(target.id)) {
|
|
426
|
-
seen.add(target.id);
|
|
427
|
-
const symbol = must(queries.symbolOfType(target));
|
|
428
|
-
if (symbol !== undefined) {
|
|
429
|
-
found.add(symbol.id);
|
|
430
|
-
}
|
|
431
|
-
pending.push(...must(queries.baseTypes(target)));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
owners = found;
|
|
436
|
-
return owners;
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/** The destination of each call's arguments, with the project's forwarding functions settled. */
|
|
441
|
-
interface Destinations {
|
|
442
|
-
/** The function one call invokes and the arguments its parameters bind. */
|
|
443
|
-
invocation(call: CallExpression): Invocation;
|
|
444
|
-
/** The destination one argument of one call is, if it is one. */
|
|
445
|
-
at(call: CallExpression, argument: number): Destination | undefined;
|
|
446
|
-
/** Whether a call can be a destination at any argument, read without a round trip. */
|
|
447
|
-
mayReceive(call: CallExpression): boolean;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* The destinations of one project's calls. A call is one at every argument where its
|
|
452
|
-
* callee is a serializer an entry names; at the arguments its resolved signature types
|
|
453
|
-
* `unknown` or `any` where its callee is declared outside the analysis or only ambiently
|
|
454
|
-
* with no implementation in it; and, where its callee is a function of the project, at each
|
|
455
|
-
* parameter the function hands on to a destination, holding back the widest of what those
|
|
456
|
-
* destinations hold back, which is settled by widening until no parameter moves.
|
|
457
|
-
*/
|
|
458
|
-
function destinations<Brand>(
|
|
459
|
-
input: DetectorInput<Brand>,
|
|
460
|
-
chains: AliasChains,
|
|
461
|
-
walked: Walked,
|
|
462
|
-
): Destinations {
|
|
463
|
-
const { project, held } = input;
|
|
464
|
-
const queries = project.queries;
|
|
465
|
-
const own = project.ownPaths();
|
|
466
|
-
const named = resolveEntries(project, held, [JSON_STRINGIFY, ...input.ts.serializers]).filter(
|
|
467
|
-
namesADeclaration,
|
|
468
|
-
);
|
|
469
|
-
const forms = new Map<CallExpression, MethodForm>();
|
|
470
|
-
for (const site of walked.sites) {
|
|
471
|
-
const form = throughMethod(site.call);
|
|
472
|
-
if (form !== undefined) {
|
|
473
|
-
forms.set(site.call, form);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
const callees = resolvedTargets(project, [
|
|
477
|
-
...walked.sites.flatMap((site) => calleeName(site.call.expression) ?? []),
|
|
478
|
-
...[...forms.values()].flatMap((form) => {
|
|
479
|
-
const name = calleeName(form.invocation.callee);
|
|
480
|
-
return name === undefined ? [form.method] : [form.method, name];
|
|
481
|
-
}),
|
|
482
|
-
]);
|
|
483
|
-
const erased = erasedParameters(project, walked.parameters);
|
|
484
|
-
const byFunction = new Map<string, Parameter[]>();
|
|
485
|
-
for (const parameter of erased.values()) {
|
|
486
|
-
byFunction.set(parameter.fn, [...(byFunction.get(parameter.fn) ?? []), parameter]);
|
|
487
|
-
}
|
|
488
|
-
const inAnalysis = (path: string): boolean =>
|
|
489
|
-
own.has(path) || input.consumers.some((root) => path === root || path.startsWith(`${root}/`));
|
|
490
|
-
const implemented = implementedOwners(project, inAnalysis);
|
|
491
|
-
/**
|
|
492
|
-
* Whether every one of `declarations`, all of the callee's by default, is outside the
|
|
493
|
-
* analysis or ambient. An ambient declaration has no body, so the code that runs is
|
|
494
|
-
* outside the analysis, unless it is a member of an interface or an object type a class
|
|
495
|
-
* or a typed object literal of the analysis implements; `settled` false skips that
|
|
496
|
-
* question, which asks the checker.
|
|
497
|
-
*/
|
|
498
|
-
const outside = (
|
|
499
|
-
target: TSSymbol,
|
|
500
|
-
settled: boolean,
|
|
501
|
-
declarations: readonly NodeHandle[] = target.declarations,
|
|
502
|
-
): boolean =>
|
|
503
|
-
declarations.length > 0 &&
|
|
504
|
-
declarations.every((handle) => {
|
|
505
|
-
if (!inAnalysis(handle.path)) {
|
|
506
|
-
return true;
|
|
507
|
-
}
|
|
508
|
-
const node = project.declarationAt(handle)?.node;
|
|
509
|
-
if (node === undefined || (node.flags & NodeFlags.Ambient) === 0) {
|
|
510
|
-
return false;
|
|
511
|
-
}
|
|
512
|
-
if (!settled || !(isInterfaceDeclaration(node.parent) || isTypeLiteralNode(node.parent))) {
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
const owner = must(queries.parentOf(target));
|
|
516
|
-
return owner === undefined || !implemented().has(owner.id);
|
|
517
|
-
});
|
|
518
|
-
/**
|
|
519
|
-
* Whether some one declaration of a callee is outside the analysis or ambient, without
|
|
520
|
-
* asking the checker. A project's declaration merged into a library's symbol leaves the
|
|
521
|
-
* library's beside it, so a call can still resolve to the library's.
|
|
522
|
-
*/
|
|
523
|
-
const mayBeOutside = (target: TSSymbol): boolean =>
|
|
524
|
-
target.declarations.some((handle) => outside(target, false, [handle]));
|
|
525
|
-
const invocation = (call: CallExpression): Invocation => {
|
|
526
|
-
const form = forms.get(call);
|
|
527
|
-
const method = form === undefined ? undefined : callees.get(form.method);
|
|
528
|
-
// Only the standard library's function methods pass their arguments on: the
|
|
529
|
-
// program's own `call` and `Reflect.apply` invoke nothing here.
|
|
530
|
-
if (
|
|
531
|
-
form !== undefined &&
|
|
532
|
-
method !== undefined &&
|
|
533
|
-
mayBeOutside(method) &&
|
|
534
|
-
FUNCTION_INTERFACES.has(must(project.queries.parentOf(method))?.name ?? "")
|
|
535
|
-
) {
|
|
536
|
-
return form.invocation;
|
|
537
|
-
}
|
|
538
|
-
return { callee: call.expression, arguments: call.arguments, indirect: false };
|
|
539
|
-
};
|
|
540
|
-
const calleeOf = (call: CallExpression): TSSymbol | undefined => {
|
|
541
|
-
const name = calleeName(invocation(call).callee);
|
|
542
|
-
return name === undefined ? undefined : callees.get(name);
|
|
543
|
-
};
|
|
544
|
-
const signatures = new Map<CallExpression, Signature | undefined>();
|
|
545
|
-
const resolvedOf = (call: CallExpression): Signature | undefined => {
|
|
546
|
-
if (!signatures.has(call)) {
|
|
547
|
-
signatures.set(call, must(queries.resolvedSignature(call)));
|
|
548
|
-
}
|
|
549
|
-
return signatures.get(call);
|
|
550
|
-
};
|
|
551
|
-
/**
|
|
552
|
-
* The declarations of a callee that the declaration of a direct call's resolved
|
|
553
|
-
* signature lies in, or all of them where it lies in none: a declaration merged into
|
|
554
|
-
* the callee's symbol that the call does not resolve to does not decide where it runs.
|
|
555
|
-
*/
|
|
556
|
-
const calledDeclarations = (call: CallExpression, target: TSSymbol): readonly NodeHandle[] => {
|
|
557
|
-
const declaration = invocation(call).indirect ? undefined : resolvedOf(call)?.declaration;
|
|
558
|
-
const signature =
|
|
559
|
-
declaration === undefined ? undefined : project.declarationAt(declaration)?.node;
|
|
560
|
-
if (declaration === undefined || signature === undefined) {
|
|
561
|
-
return target.declarations;
|
|
562
|
-
}
|
|
563
|
-
const containing = target.declarations.filter((handle) => {
|
|
564
|
-
const node =
|
|
565
|
-
handle.path === declaration.path ? project.declarationAt(handle)?.node : undefined;
|
|
566
|
-
return node !== undefined && node.pos <= signature.pos && signature.end <= node.end;
|
|
567
|
-
});
|
|
568
|
-
return containing.length === 0 ? target.declarations : containing;
|
|
569
|
-
};
|
|
570
|
-
/** Whether a type names a type parameter, through constituents, type arguments and call signatures. */
|
|
571
|
-
const mentions = (type: Type, parameter: Type, depth: number): boolean => {
|
|
572
|
-
// A conditional type an alias names, `Awaited<T>` among them, carries its arguments
|
|
573
|
-
// only on the alias the client's type object reports.
|
|
574
|
-
const aliased = (type as { readonly aliasTypeArguments?: readonly number[] })
|
|
575
|
-
.aliasTypeArguments;
|
|
576
|
-
if (type.id === parameter.id || aliased?.includes(parameter.id) === true) {
|
|
577
|
-
return true;
|
|
578
|
-
}
|
|
579
|
-
if (depth >= MENTION_DEPTH) {
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
const inner = [
|
|
583
|
-
...(type.isUnionType() || type.isIntersectionType() ? must(queries.constituents(type)) : []),
|
|
584
|
-
...must(queries.typeArguments(type)),
|
|
585
|
-
...must(queries.signaturesOf(type, SignatureKind.Call)).flatMap((signature) => [
|
|
586
|
-
...signature.parameters.map((_parameter, at) =>
|
|
587
|
-
must(queries.typeAtPosition(signature, at)),
|
|
588
|
-
),
|
|
589
|
-
...[must(queries.returnTypeOf(signature))].filter((one) => one !== undefined),
|
|
590
|
-
]),
|
|
591
|
-
];
|
|
592
|
-
return inner.some((one) => mentions(one, parameter, depth + 1));
|
|
593
|
-
};
|
|
594
|
-
const erasedArguments = new Map<CallExpression, ReadonlySet<number>>();
|
|
595
|
-
const erasedAt = (call: CallExpression, argument: number): boolean => {
|
|
596
|
-
let indexes = erasedArguments.get(call);
|
|
597
|
-
if (indexes === undefined) {
|
|
598
|
-
const invoked = invocation(call);
|
|
599
|
-
// Through a method of the prototype the resolved signature is the method's, so
|
|
600
|
-
// the parameters are read off the callee's own signatures, any one erasing.
|
|
601
|
-
const type = invoked.indirect ? must(queries.typeAt(invoked.callee)) : undefined;
|
|
602
|
-
const signatures = invoked.indirect
|
|
603
|
-
? type === undefined
|
|
604
|
-
? []
|
|
605
|
-
: must(queries.signaturesOf(type, SignatureKind.Call))
|
|
606
|
-
: [resolvedOf(call)].filter((one) => one !== undefined);
|
|
607
|
-
// A type parameter of the callee that nothing constrains and its result does not name
|
|
608
|
-
// keeps nothing of the value either: the instantiated signature names the value's own
|
|
609
|
-
// type there instead, and a result that names it hands the value back.
|
|
610
|
-
const generic = invoked.indirect ? undefined : resolvedOf(call);
|
|
611
|
-
const declared = generic === undefined ? undefined : must(queries.genericOf(generic));
|
|
612
|
-
const unconstrained = (index: number): boolean => {
|
|
613
|
-
const parameter =
|
|
614
|
-
declared === undefined ? undefined : must(queries.parameterType(declared, index));
|
|
615
|
-
const parts =
|
|
616
|
-
parameter === undefined
|
|
617
|
-
? []
|
|
618
|
-
: parameter.isUnionType()
|
|
619
|
-
? must(queries.constituents(parameter))
|
|
620
|
-
: [parameter];
|
|
621
|
-
const result = declared === undefined ? undefined : must(queries.returnTypeOf(declared));
|
|
622
|
-
return parts.some((part) => {
|
|
623
|
-
if (!part.isTypeParameter() || (result !== undefined && mentions(result, part, 0))) {
|
|
624
|
-
return false;
|
|
625
|
-
}
|
|
626
|
-
const constraint = must(queries.constraintOf(part));
|
|
627
|
-
return constraint === undefined || (constraint.flags & ERASED) !== 0;
|
|
628
|
-
});
|
|
629
|
-
};
|
|
630
|
-
indexes = new Set(
|
|
631
|
-
invoked.arguments.flatMap((_unused, index) =>
|
|
632
|
-
unconstrained(index) ||
|
|
633
|
-
signatures.some((signature) => {
|
|
634
|
-
const parameter = must(queries.parameterType(signature, index));
|
|
635
|
-
return parameter !== undefined && (parameter.flags & ERASED) !== 0;
|
|
636
|
-
})
|
|
637
|
-
? [index]
|
|
638
|
-
: [],
|
|
639
|
-
),
|
|
640
|
-
);
|
|
641
|
-
erasedArguments.set(call, indexes);
|
|
642
|
-
}
|
|
643
|
-
return indexes.has(argument);
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
const forwards = new Map<string, Reach>();
|
|
647
|
-
const keyOf = (parameter: Parameter): string => `${parameter.fn}\u0000${String(parameter.index)}`;
|
|
648
|
-
const at = (call: CallExpression, argument: number): Destination | undefined => {
|
|
649
|
-
const target = calleeOf(call);
|
|
650
|
-
if (target === undefined) {
|
|
651
|
-
return undefined;
|
|
652
|
-
}
|
|
653
|
-
const entry = named.find((one) => names(one, target, chains));
|
|
654
|
-
if (entry !== undefined) {
|
|
655
|
-
return { reach: "properties", callee: spelledEntry(entry.entry, held) };
|
|
656
|
-
}
|
|
657
|
-
if (outside(target, true, calledDeclarations(call, target))) {
|
|
658
|
-
return erasedAt(call, argument)
|
|
659
|
-
? {
|
|
660
|
-
reach: "conversions",
|
|
661
|
-
callee: invocation(call).callee.getText().replace(/\s+/gu, ""),
|
|
662
|
-
}
|
|
663
|
-
: undefined;
|
|
664
|
-
}
|
|
665
|
-
for (const fn of chains.declarationsOf(target)) {
|
|
666
|
-
const parameter = (byFunction.get(fn) ?? []).find(
|
|
667
|
-
(one) => one.index === argument || (one.rest && one.index <= argument),
|
|
668
|
-
);
|
|
669
|
-
const reach = parameter === undefined ? undefined : forwards.get(keyOf(parameter));
|
|
670
|
-
if (reach !== undefined) {
|
|
671
|
-
return { reach, callee: held.symbols.find((symbol) => symbol.id === fn)?.name ?? fn };
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
return undefined;
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
const forwarded = handedOn(project, walked.sites, erased, invocation);
|
|
678
|
-
for (let moved = true; moved;) {
|
|
679
|
-
moved = false;
|
|
680
|
-
for (const one of forwarded) {
|
|
681
|
-
const key = keyOf(one.parameter);
|
|
682
|
-
const before = forwards.get(key);
|
|
683
|
-
const after = wider(before, at(one.site.call, one.argument)?.reach);
|
|
684
|
-
if (after !== undefined && after !== before) {
|
|
685
|
-
forwards.set(key, after);
|
|
686
|
-
moved = true;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
const mayReceive = (call: CallExpression): boolean => {
|
|
692
|
-
const target = calleeOf(call);
|
|
693
|
-
if (target === undefined) {
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
if (named.some((one) => names(one, target, chains)) || mayBeOutside(target)) {
|
|
697
|
-
return true;
|
|
698
|
-
}
|
|
699
|
-
return chains
|
|
700
|
-
.declarationsOf(target)
|
|
701
|
-
.some((fn) => (byFunction.get(fn) ?? []).some((parameter) => forwards.has(keyOf(parameter))));
|
|
702
|
-
};
|
|
703
|
-
return { invocation, at, mayReceive };
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/** One value that carries classes and object types of the target into a destination. */
|
|
707
|
-
interface Flow {
|
|
708
|
-
readonly site: Node;
|
|
709
|
-
readonly classes: ReadonlySet<string>;
|
|
710
|
-
/** The members of the interfaces and object types the value carries. */
|
|
711
|
-
readonly members: readonly TSSymbol[];
|
|
712
|
-
readonly to: Destination;
|
|
713
|
-
/** What a retention names the destination by. */
|
|
714
|
-
readonly detail: string;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/** What two reaches carry together. */
|
|
718
|
-
function joined(a: Reached, b: Reached): Reached {
|
|
719
|
-
return { classes: new Set([...a.classes, ...b.classes]), members: [...a.members, ...b.members] };
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
/** Each argument of a call that can receive one whose value carries a class of the target. */
|
|
723
|
-
function flowsOf<Brand>(
|
|
724
|
-
project: ProjectView<Brand>,
|
|
725
|
-
held: Inventory,
|
|
726
|
-
sites: readonly Site[],
|
|
727
|
-
to: Destinations,
|
|
728
|
-
stores: ErasedStores,
|
|
729
|
-
): readonly Flow[] {
|
|
730
|
-
const reach = valueReach(project, held, stores.inside);
|
|
731
|
-
const arguments_ = sites.flatMap((site) =>
|
|
732
|
-
to.mayReceive(site.call)
|
|
733
|
-
? to.invocation(site.call).arguments.flatMap((argument, index) => {
|
|
734
|
-
const value = evaluated(argument);
|
|
735
|
-
return holdsNoInstance(value) ? [] : [{ site, argument: index, value }];
|
|
736
|
-
})
|
|
737
|
-
: [],
|
|
738
|
-
);
|
|
739
|
-
const asked = arguments_.filter((one) => one.value.kind !== SyntaxKind.ThisKeyword);
|
|
740
|
-
const types = typesAt(
|
|
741
|
-
project,
|
|
742
|
-
asked.map((one) => one.value),
|
|
743
|
-
);
|
|
744
|
-
const typeOf = new Map<Expression, Type | undefined>(
|
|
745
|
-
asked.map((one, index) => [one.value, types[index]]),
|
|
746
|
-
);
|
|
747
|
-
const checked = checkedTypes(
|
|
748
|
-
project,
|
|
749
|
-
arguments_.map((one) => one.value),
|
|
750
|
-
);
|
|
751
|
-
const passed = arguments_.flatMap((one, index) => {
|
|
752
|
-
const type = typeOf.get(one.value);
|
|
753
|
-
let reached: Reached = { classes: new Set<string>(), members: [] };
|
|
754
|
-
if (one.value.kind === SyntaxKind.ThisKeyword) {
|
|
755
|
-
reached = {
|
|
756
|
-
classes: new Set(one.site.self === undefined ? [] : [one.site.self]),
|
|
757
|
-
members: [],
|
|
758
|
-
};
|
|
759
|
-
} else if (type !== undefined) {
|
|
760
|
-
reached = reach.reachedFrom(type);
|
|
761
|
-
}
|
|
762
|
-
for (const stored of [...(checked[index] ?? []), ...(stores.ofVariable(one.value) ?? [])]) {
|
|
763
|
-
reached = joined(reached, reach.reachedFrom(stored));
|
|
764
|
-
}
|
|
765
|
-
const carries = reached.classes.size > 0 || reached.members.length > 0;
|
|
766
|
-
const destination = carries ? to.at(one.site.call, one.argument) : undefined;
|
|
767
|
-
return destination === undefined
|
|
768
|
-
? []
|
|
769
|
-
: [
|
|
770
|
-
{
|
|
771
|
-
site: one.value,
|
|
772
|
-
classes: reached.classes,
|
|
773
|
-
members: reached.members,
|
|
774
|
-
to: destination,
|
|
775
|
-
detail: `passed to ${destination.callee}`,
|
|
776
|
-
},
|
|
777
|
-
];
|
|
778
|
-
});
|
|
779
|
-
const left = stores.outside.flatMap((store) => {
|
|
780
|
-
const reached = reach.reachedFrom(store.type);
|
|
781
|
-
return reached.classes.size === 0 && reached.members.length === 0
|
|
782
|
-
? []
|
|
783
|
-
: [
|
|
784
|
-
{
|
|
785
|
-
site: store.value,
|
|
786
|
-
classes: reached.classes,
|
|
787
|
-
members: reached.members,
|
|
788
|
-
to: { reach: "conversions" as const, callee: store.property },
|
|
789
|
-
detail: `stored in the property ${store.property} of a type the program does not declare`,
|
|
790
|
-
},
|
|
791
|
-
];
|
|
792
|
-
});
|
|
793
|
-
return [...passed, ...left];
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* The serialization-contract detector: each data member and `toJSON` of each class,
|
|
798
|
-
* interface and object type a value that reaches a destination carries, and `toString`
|
|
799
|
-
* as well where the destination is outside the analysis, recorded at the argument with
|
|
800
|
-
* the callee named.
|
|
801
|
-
*/
|
|
802
|
-
export function serializationContract<Brand>(input: DetectorInput<Brand>): readonly Evidence[] {
|
|
803
|
-
const { project, held, targetRoot } = input;
|
|
804
|
-
const walked = walkProject(project, held);
|
|
805
|
-
const chains = aliasChains(project, held);
|
|
806
|
-
const flows = flowsOf(
|
|
807
|
-
project,
|
|
808
|
-
held,
|
|
809
|
-
walked.sites,
|
|
810
|
-
destinations(input, chains, walked),
|
|
811
|
-
erasedStores(project),
|
|
812
|
-
);
|
|
813
|
-
if (flows.length === 0) {
|
|
814
|
-
return [];
|
|
815
|
-
}
|
|
816
|
-
const members = classMembers(
|
|
817
|
-
project,
|
|
818
|
-
held,
|
|
819
|
-
new Set(flows.flatMap((flow) => [...flow.classes])),
|
|
820
|
-
"instance",
|
|
821
|
-
);
|
|
822
|
-
const byId = new Map(held.symbols.map((symbol) => [symbol.id, symbol]));
|
|
823
|
-
// A destination holds back a data member and `toJSON`, and `toString` as well where
|
|
824
|
-
// the value left the analysis.
|
|
825
|
-
const holdsBack = (flags: SymbolFlags, name: string, to: Destination): boolean =>
|
|
826
|
-
(flags & SymbolFlags.Property) !== 0 ||
|
|
827
|
-
((flags & CONVERSION_MEMBERS) !== 0 &&
|
|
828
|
-
(name === SERIALIZED_CONVERSION || (to.reach === "conversions" && CONVERSIONS.has(name))));
|
|
829
|
-
const found: Evidence[] = [];
|
|
830
|
-
for (const flow of flows) {
|
|
831
|
-
const site = renderPosition(flow.site.getSourceFile(), targetRoot, flow.site.getStart());
|
|
832
|
-
const { detail } = flow;
|
|
833
|
-
for (const member of [...flow.classes].flatMap((id) => members.get(id) ?? [])) {
|
|
834
|
-
const symbol = byId.get(member.id);
|
|
835
|
-
const name = symbol === undefined ? "" : (memberComponent(symbol, byId) ?? "");
|
|
836
|
-
if (holdsBack(member.flags, name, flow.to)) {
|
|
837
|
-
found.push({ id: member.id, detail, site });
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
for (const member of flow.members) {
|
|
841
|
-
if (holdsBack(member.flags, member.name, flow.to)) {
|
|
842
|
-
for (const id of chains.declarationsOf(member)) {
|
|
843
|
-
found.push({ id, detail, site });
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
return found;
|
|
849
|
-
}
|