@md-code/follow-architecture 0.1.0 → 0.3.0
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/CHANGELOG.md +16 -0
- package/LICENSE +202 -0
- package/README.md +597 -126
- package/dist/aliases.d.ts +3 -0
- package/dist/aliases.js +12 -0
- package/dist/args.d.ts +14 -0
- package/dist/args.js +77 -0
- package/dist/bin/follow-architecture.d.ts +2 -0
- package/dist/bin/follow-architecture.js +23 -0
- package/dist/code-roles/classify.d.ts +11 -0
- package/dist/code-roles/classify.js +43 -0
- package/dist/code-roles/connector.d.ts +5 -0
- package/dist/code-roles/connector.js +114 -0
- package/dist/code-roles/project.d.ts +12 -0
- package/dist/code-roles/project.js +122 -0
- package/dist/code-roles/roles.d.ts +8 -0
- package/dist/code-roles/roles.js +190 -0
- package/dist/config-options.d.ts +53 -0
- package/dist/config-options.js +35 -0
- package/dist/config-project.d.ts +4 -0
- package/dist/config-project.js +74 -0
- package/dist/config-report.d.ts +19 -0
- package/dist/config-report.js +134 -0
- package/dist/config-rule.d.ts +70 -0
- package/dist/config-rule.js +118 -0
- package/dist/config-state.d.ts +14 -0
- package/dist/config-state.js +96 -0
- package/dist/config.d.ts +82 -0
- package/dist/config.js +38 -0
- package/dist/css/index.d.ts +27 -0
- package/dist/css/index.js +140 -0
- package/dist/css/syntax/css/gate.d.ts +2 -0
- package/dist/css/syntax/css/gate.js +69 -0
- package/dist/css/syntax/css/index.d.ts +7 -0
- package/dist/css/syntax/css/index.js +41 -0
- package/dist/css/syntax/css/reference.d.ts +3 -0
- package/dist/css/syntax/css/reference.js +24 -0
- package/dist/css/syntax/language.d.ts +25 -0
- package/dist/css/syntax/language.js +69 -0
- package/dist/css/syntax/scss/index.d.ts +25 -0
- package/dist/css/syntax/scss/index.js +85 -0
- package/dist/css/syntax/scss/reference.d.ts +3 -0
- package/dist/css/syntax/scss/reference.js +11 -0
- package/dist/css/syntax/styled/document.d.ts +68 -0
- package/dist/css/syntax/styled/document.js +241 -0
- package/dist/css/syntax/styled/markup.d.ts +6 -0
- package/dist/css/syntax/styled/markup.js +76 -0
- package/dist/css/syntax/styled/template.d.ts +23 -0
- package/dist/css/syntax/styled/template.js +61 -0
- package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
- package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
- package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
- package/dist/css/syntax/tailwind/tailwind.js +118 -0
- package/dist/css/value/check.d.ts +86 -0
- package/dist/css/value/check.js +122 -0
- package/dist/css/value/expression/arithmetic.d.ts +7 -0
- package/dist/css/value/expression/arithmetic.js +69 -0
- package/dist/css/value/expression/block.d.ts +9 -0
- package/dist/css/value/expression/block.js +91 -0
- package/dist/css/value/expression/conditional.d.ts +8 -0
- package/dist/css/value/expression/conditional.js +53 -0
- package/dist/css/value/expression/index.d.ts +5 -0
- package/dist/css/value/expression/index.js +69 -0
- package/dist/css/value/expression/map.d.ts +7 -0
- package/dist/css/value/expression/map.js +113 -0
- package/dist/css/value/object/index.d.ts +5 -0
- package/dist/css/value/object/index.js +103 -0
- package/dist/css/value/object/members.d.ts +7 -0
- package/dist/css/value/object/members.js +103 -0
- package/dist/css/value/object/node.d.ts +8 -0
- package/dist/css/value/object/node.js +129 -0
- package/dist/css/value/object/path.d.ts +10 -0
- package/dist/css/value/object/path.js +146 -0
- package/dist/css/value/pieces.d.ts +61 -0
- package/dist/css/value/pieces.js +55 -0
- package/dist/css/value/resolve.d.ts +33 -0
- package/dist/css/value/resolve.js +94 -0
- package/dist/css/value/scope.d.ts +27 -0
- package/dist/css/value/scope.js +187 -0
- package/dist/css/value/substitute.d.ts +10 -0
- package/dist/css/value/substitute.js +113 -0
- package/dist/css/value/values.d.ts +23 -0
- package/dist/css/value/values.js +131 -0
- package/dist/entities/architecture.d.ts +162 -0
- package/dist/entities/architecture.js +2 -0
- package/dist/entities/ast/assignments-nodes.d.ts +10 -0
- package/dist/entities/ast/assignments-nodes.js +64 -0
- package/dist/entities/ast/assignments-raw.d.ts +6 -0
- package/dist/entities/ast/assignments-raw.js +86 -0
- package/dist/entities/ast/assignments-tagged.d.ts +5 -0
- package/dist/entities/ast/assignments-tagged.js +180 -0
- package/dist/entities/ast/assignments.d.ts +9 -0
- package/dist/entities/ast/assignments.js +78 -0
- package/dist/entities/ast/branches.d.ts +4 -0
- package/dist/entities/ast/branches.js +32 -0
- package/dist/entities/ast/calls.d.ts +6 -0
- package/dist/entities/ast/calls.js +134 -0
- package/dist/entities/ast/classes.d.ts +5 -0
- package/dist/entities/ast/classes.js +57 -0
- package/dist/entities/ast/climb.d.ts +12 -0
- package/dist/entities/ast/climb.js +17 -0
- package/dist/entities/ast/comments.d.ts +4 -0
- package/dist/entities/ast/comments.js +100 -0
- package/dist/entities/ast/declaration.d.ts +4 -0
- package/dist/entities/ast/declaration.js +26 -0
- package/dist/entities/ast/depth.d.ts +17 -0
- package/dist/entities/ast/depth.js +149 -0
- package/dist/entities/ast/enums.d.ts +6 -0
- package/dist/entities/ast/enums.js +17 -0
- package/dist/entities/ast/file-exports.d.ts +7 -0
- package/dist/entities/ast/file-exports.js +78 -0
- package/dist/entities/ast/file-facts.d.ts +13 -0
- package/dist/entities/ast/file-facts.js +35 -0
- package/dist/entities/ast/file-imports.d.ts +5 -0
- package/dist/entities/ast/file-imports.js +77 -0
- package/dist/entities/ast/file.d.ts +5 -0
- package/dist/entities/ast/file.js +22 -0
- package/dist/entities/ast/functions.d.ts +8 -0
- package/dist/entities/ast/functions.js +102 -0
- package/dist/entities/ast/heritage.d.ts +4 -0
- package/dist/entities/ast/heritage.js +36 -0
- package/dist/entities/ast/index.d.ts +6 -0
- package/dist/entities/ast/index.js +125 -0
- package/dist/entities/ast/kind.d.ts +5 -0
- package/dist/entities/ast/kind.js +28 -0
- package/dist/entities/ast/loose.d.ts +37 -0
- package/dist/entities/ast/loose.js +2 -0
- package/dist/entities/ast/modifiers.d.ts +5 -0
- package/dist/entities/ast/modifiers.js +32 -0
- package/dist/entities/ast/project.d.ts +9 -0
- package/dist/entities/ast/project.js +75 -0
- package/dist/entities/ast/properties.d.ts +11 -0
- package/dist/entities/ast/properties.js +171 -0
- package/dist/entities/ast/resolve.d.ts +16 -0
- package/dist/entities/ast/resolve.js +307 -0
- package/dist/entities/ast/tree.d.ts +29 -0
- package/dist/entities/ast/tree.js +351 -0
- package/dist/entities/ast/types.d.ts +6 -0
- package/dist/entities/ast/types.js +45 -0
- package/dist/entities/ast/usage.d.ts +11 -0
- package/dist/entities/ast/usage.js +81 -0
- package/dist/entities/ast/variables.d.ts +8 -0
- package/dist/entities/ast/variables.js +91 -0
- package/dist/entities/context.d.ts +29 -0
- package/dist/entities/context.js +2 -0
- package/dist/entities/facts.d.ts +261 -0
- package/dist/entities/facts.js +2 -0
- package/dist/entities/findings.d.ts +19 -0
- package/dist/entities/findings.js +2 -0
- package/dist/entities/kinds.d.ts +40 -0
- package/dist/entities/kinds.js +221 -0
- package/dist/entities/location/homes.d.ts +28 -0
- package/dist/entities/location/homes.js +169 -0
- package/dist/entities/location/place.d.ts +10 -0
- package/dist/entities/location/place.js +56 -0
- package/dist/entities/location/where.d.ts +17 -0
- package/dist/entities/location/where.js +218 -0
- package/dist/entities/location.d.ts +16 -0
- package/dist/entities/location.js +140 -0
- package/dist/entities/operators.d.ts +14 -0
- package/dist/entities/operators.js +30 -0
- package/dist/entities/overview/data.d.ts +43 -0
- package/dist/entities/overview/data.js +2 -0
- package/dist/entities/overview/decision.d.ts +60 -0
- package/dist/entities/overview/decision.js +2 -0
- package/dist/entities/overview/file-tree.d.ts +10 -0
- package/dist/entities/overview/file-tree.js +2 -0
- package/dist/entities/overview/finding.d.ts +58 -0
- package/dist/entities/overview/finding.js +2 -0
- package/dist/entities/overview/graph.d.ts +65 -0
- package/dist/entities/overview/graph.js +2 -0
- package/dist/entities/overview/input.d.ts +15 -0
- package/dist/entities/overview/input.js +2 -0
- package/dist/entities/overview/summaries.d.ts +79 -0
- package/dist/entities/overview/summaries.js +2 -0
- package/dist/entities/place.d.ts +5 -0
- package/dist/entities/place.js +2 -0
- package/dist/entities/queries.d.ts +9 -0
- package/dist/entities/queries.js +305 -0
- package/dist/entities/repair.d.ts +16 -0
- package/dist/entities/repair.js +23 -0
- package/dist/entities/schema.d.ts +8 -0
- package/dist/entities/schema.js +23 -0
- package/dist/entities/story.d.ts +47 -0
- package/dist/entities/story.js +2 -0
- package/dist/entities/structure-facts.d.ts +11 -0
- package/dist/entities/structure-facts.js +2 -0
- package/dist/entities/token.d.ts +23 -0
- package/dist/entities/token.js +2 -0
- package/dist/entities/tree/build.d.ts +5 -0
- package/dist/entities/tree/build.js +252 -0
- package/dist/entities/tree/entries.d.ts +7 -0
- package/dist/entities/tree/entries.js +120 -0
- package/dist/entities/tree/index.d.ts +6 -0
- package/dist/entities/tree/index.js +21 -0
- package/dist/entities/tree/match.d.ts +17 -0
- package/dist/entities/tree/match.js +176 -0
- package/dist/frameworks/angular/index.d.ts +7 -0
- package/dist/frameworks/angular/index.js +17 -0
- package/dist/frameworks/facet.d.ts +16 -0
- package/dist/frameworks/facet.js +2 -0
- package/dist/frameworks/index.d.ts +9 -0
- package/dist/frameworks/index.js +120 -0
- package/dist/frameworks/react/index.d.ts +7 -0
- package/dist/frameworks/react/index.js +214 -0
- package/dist/frameworks/vue/index.d.ts +7 -0
- package/dist/frameworks/vue/index.js +17 -0
- package/dist/invariants/index.d.ts +6 -0
- package/dist/invariants/index.js +299 -0
- package/dist/invariants/list-vars.d.ts +5 -0
- package/dist/invariants/list-vars.js +143 -0
- package/dist/invariants/name.d.ts +16 -0
- package/dist/invariants/name.js +18 -0
- package/dist/invariants/normalize.d.ts +4 -0
- package/dist/invariants/normalize.js +95 -0
- package/dist/invariants/vars.d.ts +20 -0
- package/dist/invariants/vars.js +117 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.js +229 -0
- package/dist/nodes/child-roles.d.ts +3 -0
- package/dist/nodes/child-roles.js +12 -0
- package/dist/nodes/children.d.ts +25 -0
- package/dist/nodes/children.js +112 -0
- package/dist/nodes/finally/emit.d.ts +6 -0
- package/dist/nodes/finally/emit.js +55 -0
- package/dist/nodes/finally/index.d.ts +8 -0
- package/dist/nodes/finally/index.js +35 -0
- package/dist/nodes/finally/queries.d.ts +5 -0
- package/dist/nodes/finally/queries.js +22 -0
- package/dist/nodes/finally/relations-access.d.ts +5 -0
- package/dist/nodes/finally/relations-access.js +46 -0
- package/dist/nodes/finally/relations-edge.d.ts +29 -0
- package/dist/nodes/finally/relations-edge.js +125 -0
- package/dist/nodes/finally/relations-group.d.ts +31 -0
- package/dist/nodes/finally/relations-group.js +103 -0
- package/dist/nodes/finally/relations.d.ts +5 -0
- package/dist/nodes/finally/relations.js +81 -0
- package/dist/nodes/finally/required.d.ts +5 -0
- package/dist/nodes/finally/required.js +90 -0
- package/dist/nodes/finally/roles.d.ts +13 -0
- package/dist/nodes/finally/roles.js +41 -0
- package/dist/nodes/finally/violation.d.ts +17 -0
- package/dist/nodes/finally/violation.js +2 -0
- package/dist/nodes/similar.d.ts +21 -0
- package/dist/nodes/similar.js +156 -0
- package/dist/pipeline-facts.d.ts +11 -0
- package/dist/pipeline-facts.js +112 -0
- package/dist/pipeline-roles.d.ts +6 -0
- package/dist/pipeline-roles.js +75 -0
- package/dist/pipeline-unroled.d.ts +14 -0
- package/dist/pipeline-unroled.js +193 -0
- package/dist/pipeline.d.ts +7 -0
- package/dist/pipeline.js +73 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +3 -0
- package/dist/report/asks.d.ts +55 -0
- package/dist/report/asks.js +50 -0
- package/dist/report/cli-report.d.ts +2 -0
- package/dist/report/cli-report.js +13 -0
- package/dist/report/config-error-guard.d.ts +8 -0
- package/dist/report/config-error-guard.js +5 -0
- package/dist/report/configErrors.d.ts +98 -0
- package/dist/report/configErrors.js +75 -0
- package/dist/report/errorTypes/codes/structure.d.ts +15 -0
- package/dist/report/errorTypes/codes/structure.js +76 -0
- package/dist/report/errorTypes/decision-maker.d.ts +23 -0
- package/dist/report/errorTypes/decision-maker.js +99 -0
- package/dist/report/errorTypes/destinations.d.ts +38 -0
- package/dist/report/errorTypes/destinations.js +147 -0
- package/dist/report/errorTypes/finding-type.d.ts +11 -0
- package/dist/report/errorTypes/finding-type.js +2 -0
- package/dist/report/errorTypes/index.d.ts +15 -0
- package/dist/report/errorTypes/index.js +45 -0
- package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
- package/dist/report/errorTypes/types/fileContents.js +34 -0
- package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
- package/dist/report/errorTypes/types/unknownRole.js +22 -0
- package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
- package/dist/report/errorTypes/types/wrongAction.js +135 -0
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
- package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
- package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
- package/dist/report/errorTypes/vocabulary/ids.js +16 -0
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
- package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
- package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
- package/dist/report/errorTypes/vocabulary/places.js +36 -0
- package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
- package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
- package/dist/report/finding-from.d.ts +9 -0
- package/dist/report/finding-from.js +103 -0
- package/dist/report/notices.d.ts +4 -0
- package/dist/report/notices.js +31 -0
- package/dist/report/render-report.d.ts +12 -0
- package/dist/report/render-report.js +142 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +169 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
- package/dist/report/user-report/data/collect.d.ts +4 -0
- package/dist/report/user-report/data/collect.js +80 -0
- package/dist/report/user-report/data/file-tree.d.ts +9 -0
- package/dist/report/user-report/data/file-tree.js +72 -0
- package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
- package/dist/report/user-report/data/finding-boundary.js +21 -0
- package/dist/report/user-report/data/finding-plan.d.ts +16 -0
- package/dist/report/user-report/data/finding-plan.js +45 -0
- package/dist/report/user-report/data/finding-title.d.ts +12 -0
- package/dist/report/user-report/data/finding-title.js +36 -0
- package/dist/report/user-report/data/findings.d.ts +10 -0
- package/dist/report/user-report/data/findings.js +171 -0
- package/dist/report/user-report/data/graph-edges.d.ts +19 -0
- package/dist/report/user-report/data/graph-edges.js +109 -0
- package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
- package/dist/report/user-report/data/graph-helpers.js +67 -0
- package/dist/report/user-report/data/graph-roles.d.ts +5 -0
- package/dist/report/user-report/data/graph-roles.js +71 -0
- package/dist/report/user-report/data/graph.d.ts +11 -0
- package/dist/report/user-report/data/graph.js +90 -0
- package/dist/report/user-report/data/invariants.d.ts +7 -0
- package/dist/report/user-report/data/invariants.js +62 -0
- package/dist/report/user-report/data/nodes.d.ts +11 -0
- package/dist/report/user-report/data/nodes.js +106 -0
- package/dist/report/user-report/data/role-examples.d.ts +16 -0
- package/dist/report/user-report/data/role-examples.js +94 -0
- package/dist/report/user-report/data/role-filters.d.ts +15 -0
- package/dist/report/user-report/data/role-filters.js +79 -0
- package/dist/report/user-report/data/role-marks.d.ts +5 -0
- package/dist/report/user-report/data/role-marks.js +79 -0
- package/dist/report/user-report/data/roles.d.ts +7 -0
- package/dist/report/user-report/data/roles.js +83 -0
- package/dist/report/user-report/data/scan.d.ts +8 -0
- package/dist/report/user-report/data/scan.js +59 -0
- package/dist/report/user-report/html/shell.d.ts +3 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +8 -0
- package/dist/report/user-report/index.js +48 -0
- package/dist/report/user-report/shared/describe.d.ts +7 -0
- package/dist/report/user-report/shared/describe.js +86 -0
- package/dist/scripts/audit-report.d.ts +2 -0
- package/dist/scripts/audit-report.js +147 -0
- package/dist/utils/accumulate.d.ts +6 -0
- package/dist/utils/accumulate.js +18 -0
- package/dist/utils/article.d.ts +2 -0
- package/dist/utils/article.js +12 -0
- package/dist/utils/classify.d.ts +12 -0
- package/dist/utils/classify.js +25 -0
- package/dist/utils/configs.d.ts +25 -0
- package/dist/utils/configs.js +87 -0
- package/dist/utils/count.d.ts +7 -0
- package/dist/utils/count.js +13 -0
- package/dist/utils/dispatch.d.ts +2 -0
- package/dist/utils/dispatch.js +27 -0
- package/dist/utils/distinct.d.ts +2 -0
- package/dist/utils/distinct.js +12 -0
- package/dist/utils/field.d.ts +14 -0
- package/dist/utils/field.js +60 -0
- package/dist/utils/file-name.d.ts +2 -0
- package/dist/utils/file-name.js +11 -0
- package/dist/utils/files.d.ts +7 -0
- package/dist/utils/files.js +73 -0
- package/dist/utils/fixpoint.d.ts +2 -0
- package/dist/utils/fixpoint.js +19 -0
- package/dist/utils/gate.d.ts +2 -0
- package/dist/utils/gate.js +12 -0
- package/dist/utils/group.d.ts +3 -0
- package/dist/utils/group.js +33 -0
- package/dist/utils/host.d.ts +3 -0
- package/dist/utils/host.js +13 -0
- package/dist/utils/imports.d.ts +12 -0
- package/dist/utils/imports.js +121 -0
- package/dist/utils/judged.d.ts +5 -0
- package/dist/utils/judged.js +19 -0
- package/dist/utils/keyed.d.ts +2 -0
- package/dist/utils/keyed.js +23 -0
- package/dist/utils/map-record.d.ts +2 -0
- package/dist/utils/map-record.js +11 -0
- package/dist/utils/path-label.d.ts +6 -0
- package/dist/utils/path-label.js +35 -0
- package/dist/utils/pattern.d.ts +18 -0
- package/dist/utils/pattern.js +191 -0
- package/dist/utils/permission.d.ts +16 -0
- package/dist/utils/permission.js +16 -0
- package/dist/utils/plural.d.ts +2 -0
- package/dist/utils/plural.js +9 -0
- package/dist/utils/qualified.d.ts +2 -0
- package/dist/utils/qualified.js +21 -0
- package/dist/utils/rank.d.ts +2 -0
- package/dist/utils/rank.js +24 -0
- package/dist/utils/read-field.d.ts +12 -0
- package/dist/utils/read-field.js +50 -0
- package/dist/utils/read-when.d.ts +2 -0
- package/dist/utils/read-when.js +17 -0
- package/dist/utils/reason.d.ts +4 -0
- package/dist/utils/reason.js +9 -0
- package/dist/utils/record.d.ts +3 -0
- package/dist/utils/record.js +21 -0
- package/dist/utils/resolve.d.ts +2 -0
- package/dist/utils/resolve.js +24 -0
- package/dist/utils/search.d.ts +2 -0
- package/dist/utils/search.js +16 -0
- package/dist/utils/seen.d.ts +6 -0
- package/dist/utils/seen.js +27 -0
- package/dist/utils/span.d.ts +5 -0
- package/dist/utils/span.js +2 -0
- package/dist/utils/speak.d.ts +2 -0
- package/dist/utils/speak.js +18 -0
- package/dist/utils/split.d.ts +8 -0
- package/dist/utils/split.js +8 -0
- package/dist/utils/template.d.ts +5 -0
- package/dist/utils/template.js +5 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +42 -0
- package/dist/utils/tokenize.d.ts +2 -0
- package/dist/utils/tokenize.js +13 -0
- package/dist/utils/try-read.d.ts +4 -0
- package/dist/utils/try-read.js +24 -0
- package/dist/utils/typed-field.d.ts +3 -0
- package/dist/utils/typed-field.js +16 -0
- package/dist/utils/verdicts.d.ts +4 -0
- package/dist/utils/verdicts.js +20 -0
- package/entities/operators.ts +31 -0
- package/package.json +62 -19
- package/report/errorTypes/vocabulary/ids.ts +12 -0
- package/report/errorTypes/vocabulary/phrases.ts +161 -0
- package/report/errorTypes/vocabulary/places.ts +46 -0
- package/report/errorTypes/vocabulary/verbs.ts +31 -0
- package/report/user-report/shared/describe.ts +107 -0
- package/ast.js +0 -107
- package/bin/follow-architecture.js +0 -6
- package/config.js +0 -82
- package/entities/aliases.js +0 -10
- package/entities/invariants.js +0 -134
- package/entities/nodes.js +0 -112
- package/main.js +0 -95
- package/report.js +0 -73
- package/utils.js +0 -104
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectCandidates = exports.collectFileFacts = exports.importNameModules = exports.loadSourceFile = exports.createTsProject = void 0;
|
|
4
|
+
// The entry point of the AST layer. Every entity module collects facts about
|
|
5
|
+
// ONE kind of node; this file puts them together into a candidate — the unit a
|
|
6
|
+
// role classifies — and hands back the public API the pipeline uses.
|
|
7
|
+
//
|
|
8
|
+
// Facts are plain data: no comparisons, no predicates, no project rules. The
|
|
9
|
+
// YAML pairs a fact with a filter (entities/queries.js) to express any rule.
|
|
10
|
+
// Nothing here names a project, a framework, or a role.
|
|
11
|
+
//
|
|
12
|
+
// A candidate describes a PIECE of code with four things and nothing else:
|
|
13
|
+
// location — where it is: `path` (the file) and `piece` (the piece it sits
|
|
14
|
+
// in, null at module scope)
|
|
15
|
+
// lines — the lines it spans, as one array: start, everything inside, end
|
|
16
|
+
// parameters — what it receives
|
|
17
|
+
// actions — what it does: `calls` here (running code), `assignments`
|
|
18
|
+
// (writing into a value), `returns` (the value it yields). The
|
|
19
|
+
// relations those actions form are produced in entities/kinds.js.
|
|
20
|
+
const ts_morph_1 = require("ts-morph");
|
|
21
|
+
const tree_1 = require("./tree");
|
|
22
|
+
const file_1 = require("./file");
|
|
23
|
+
Object.defineProperty(exports, "createTsProject", { enumerable: true, get: function () { return file_1.createTsProject; } });
|
|
24
|
+
Object.defineProperty(exports, "loadSourceFile", { enumerable: true, get: function () { return file_1.loadSourceFile; } });
|
|
25
|
+
Object.defineProperty(exports, "importNameModules", { enumerable: true, get: function () { return file_1.importNameModules; } });
|
|
26
|
+
Object.defineProperty(exports, "collectFileFacts", { enumerable: true, get: function () { return file_1.collectFileFacts; } });
|
|
27
|
+
const calls_1 = require("./calls");
|
|
28
|
+
const functions_1 = require("./functions");
|
|
29
|
+
const branches_1 = require("./branches");
|
|
30
|
+
const variables_1 = require("./variables");
|
|
31
|
+
const assignments_1 = require("./assignments");
|
|
32
|
+
const classes_1 = require("./classes");
|
|
33
|
+
const types_1 = require("./types");
|
|
34
|
+
const enums_1 = require("./enums");
|
|
35
|
+
const kind_1 = require("./kind");
|
|
36
|
+
const usage_1 = require("./usage");
|
|
37
|
+
const comments_1 = require("./comments");
|
|
38
|
+
// ts-morph beyond the tree: who USES the name, and who implements the shape.
|
|
39
|
+
// Asked only for published names — a local binding's reach is its own file. The
|
|
40
|
+
// paths a use lives in are repo-relative, so a rule can ask WHERE it is used.
|
|
41
|
+
const usageOf = (node, sf, repoRoot) => (0, usage_1.usageFact)(node, sf, { exported: (0, tree_1.isExported)(node), relOf: (p) => (0, file_1.repoRelative)(p, repoRoot) ?? p });
|
|
42
|
+
// The name a candidate carries: a function-like node answers its own (an arrow
|
|
43
|
+
// takes its binding's name); anything else is its declaration's name.
|
|
44
|
+
const candidateName = (node, isFn) => {
|
|
45
|
+
if (isFn)
|
|
46
|
+
return (0, functions_1.nameOf)(node);
|
|
47
|
+
return node.getName?.() ?? null;
|
|
48
|
+
};
|
|
49
|
+
// Raw facts about a single candidate node. `rel` is the repo-relative file path
|
|
50
|
+
// — carried on the fact so location-aware operators (e.g. `location`) can match
|
|
51
|
+
// the candidate's position against node declarations.
|
|
52
|
+
const collectCandidateFacts = (node, { sf, importMap, rel, repoRoot }) => {
|
|
53
|
+
const isFn = (0, tree_1.isFunctionNode)(node);
|
|
54
|
+
const enclosing = (0, functions_1.nearestFunction)(node);
|
|
55
|
+
return {
|
|
56
|
+
name: candidateName(node, isFn),
|
|
57
|
+
// Where the code is: ONE fact. `path` is the file, `piece` the piece it is
|
|
58
|
+
// nested in — `piece: null` means module scope, a fact and not a special case.
|
|
59
|
+
// `nested` separates "no enclosing function" from "an enclosing function
|
|
60
|
+
// without a name": a `const` inside `function () {…}` is still a LOCAL, and
|
|
61
|
+
// reading its `piece: null` as module scope made the report ask the reader to
|
|
62
|
+
// give a role to a one-line alias.
|
|
63
|
+
location: { path: rel ?? null, piece: enclosing ? ((0, functions_1.nameOf)(enclosing) ?? null) : null, nested: Boolean(enclosing) },
|
|
64
|
+
lines: (0, tree_1.linesOf)(node),
|
|
65
|
+
// What it is, what is around and below it, and what it is SPELLED with.
|
|
66
|
+
kind: (0, kind_1.kindOf)(node, isFn ? null : (0, variables_1.variableInitializer)(node)),
|
|
67
|
+
returns: isFn ? (0, functions_1.returnsFact)(node) : [],
|
|
68
|
+
calls: isFn ? (0, calls_1.callsFact)(node, importMap, sf, repoRoot) : [],
|
|
69
|
+
// The control flow this piece runs ITSELF: a branch is what a name can hide.
|
|
70
|
+
branches: isFn ? (0, branches_1.branchesFact)(node) : [],
|
|
71
|
+
assignments: (0, assignments_1.assignmentsFact)(node, sf, importMap, { repoRoot, rel }),
|
|
72
|
+
parameters: isFn ? (0, functions_1.parametersFact)(node, sf, repoRoot) : [],
|
|
73
|
+
// Two facts about a DECLARATION that no action can express: is it
|
|
74
|
+
// published, and may the binding be reassigned. Both are what the
|
|
75
|
+
// language says, not a verdict.
|
|
76
|
+
exported: (0, tree_1.isExported)(node),
|
|
77
|
+
mutable: (0, tree_1.isMutable)(node),
|
|
78
|
+
// ts-morph beyond the tree: who USES the name, who IMPLEMENTS the shape.
|
|
79
|
+
// Not `kind`: these are answers from the checker, not the node's shape.
|
|
80
|
+
...usageOf(node, sf, repoRoot),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
// Is this node a classification candidate? Function-like nodes, variable
|
|
84
|
+
// declarations, classes, types and enums — plus an export assignment that
|
|
85
|
+
// publishes a value with no binding of its own (`export default { … }`;
|
|
86
|
+
// `export default name` publishes an EXISTING piece, already a candidate).
|
|
87
|
+
const isCandidateNode = (n) => {
|
|
88
|
+
if (n.getKind() === tree_1.SK.ExportAssignment)
|
|
89
|
+
return ts_morph_1.Node.isExportAssignment(n) && n.getExpression()?.getKind() !== tree_1.SK.Identifier;
|
|
90
|
+
return (0, tree_1.isFunctionNode)(n) || n.getKind() === tree_1.SK.VariableDeclaration || (0, types_1.isTypeNode)(n) || (0, tree_1.isClassNode)(n) || (0, enums_1.isEnumNode)(n);
|
|
91
|
+
};
|
|
92
|
+
// One declaration's facts: a class/type/enum adds only what its syntax has;
|
|
93
|
+
// everything else answers the generic candidate questions.
|
|
94
|
+
const declarationCandidate = (n, ctx) => {
|
|
95
|
+
if (ts_morph_1.Node.isClassDeclaration(n) || ts_morph_1.Node.isClassExpression(n))
|
|
96
|
+
return (0, classes_1.classFact)(n, collectCandidateFacts(n, ctx));
|
|
97
|
+
if ((0, enums_1.isEnumNode)(n))
|
|
98
|
+
return { ...(0, enums_1.enumFact)(n, ctx.rel ?? ""), ...usageOf(n, ctx.sf, ctx.repoRoot) };
|
|
99
|
+
if ((0, types_1.isTypeNode)(n))
|
|
100
|
+
return { ...(0, types_1.typeFact)(n, ctx.rel ?? ""), ...usageOf(n, ctx.sf, ctx.repoRoot) };
|
|
101
|
+
const facts = collectCandidateFacts(n, ctx);
|
|
102
|
+
// An export assignment has no name node; the file's default export is
|
|
103
|
+
// what a reader (and an import map) calls it.
|
|
104
|
+
if (n.getKind() === tree_1.SK.ExportAssignment && !facts.name)
|
|
105
|
+
facts.name = "default";
|
|
106
|
+
return facts;
|
|
107
|
+
};
|
|
108
|
+
// Every classification candidate in the file (function-like nodes, variable
|
|
109
|
+
// declarations, classes and type declarations, and the comments), in document
|
|
110
|
+
// order.
|
|
111
|
+
//
|
|
112
|
+
// A comment is a candidate because a project may want to say things about it —
|
|
113
|
+
// this kind must carry a reason, that banner must separate sections, no comment
|
|
114
|
+
// may sit outside an action. Those are the same questions `location`, `lines`
|
|
115
|
+
// and `kind` already answer for code, so nothing new is invented for it: it is
|
|
116
|
+
// collected as a candidate and the YAML gives it a role like anything else.
|
|
117
|
+
const collectCandidates = (sf, importMap, rel, repoRoot) => {
|
|
118
|
+
const ctx = { sf, importMap, rel, repoRoot };
|
|
119
|
+
const declarations = sf
|
|
120
|
+
.getDescendants()
|
|
121
|
+
.filter(isCandidateNode)
|
|
122
|
+
.map((n) => declarationCandidate(n, ctx));
|
|
123
|
+
return [...declarations, ...(0, comments_1.commentsOf)(sf, rel)].sort((a, b) => (a.lines?.[0] ?? 0) - (b.lines?.[0] ?? 0));
|
|
124
|
+
};
|
|
125
|
+
exports.collectCandidates = collectCandidates;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LooseNode } from "./loose";
|
|
2
|
+
import type { KindFact, Initializer } from "../facts";
|
|
3
|
+
declare const kindOf: (node: LooseNode, initializer?: Initializer | null) => KindFact;
|
|
4
|
+
declare const spelled: (kind: string) => Pick<KindFact, "own" | "modifiers" | "decorators" | "assertion" | "disposable">;
|
|
5
|
+
export { kindOf, spelled };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spelled = exports.kindOf = void 0;
|
|
4
|
+
// WHAT A DECLARATION IS, in one fact. `kind` is not only the AST node: it is
|
|
5
|
+
// also what the declaration is SPELLED with — `export`, `abstract`, `static`,
|
|
6
|
+
// `readonly`, the decorators above it, an assertion on its value, `using`. Those
|
|
7
|
+
// are all readable off the same node, so they live in the same place; a second
|
|
8
|
+
// top-level field would be the same fact spelled twice.
|
|
9
|
+
//
|
|
10
|
+
// `references` and `implementations` are NOT here: they come from the checker
|
|
11
|
+
// (ast/usage.js), and `kind` stays the answer the syntax tree alone can give.
|
|
12
|
+
const tree_1 = require("./tree");
|
|
13
|
+
const modifiers_1 = require("./modifiers");
|
|
14
|
+
const variables_1 = require("./variables");
|
|
15
|
+
// `initializer` — the variable's initializer, when the node has one: `as const`
|
|
16
|
+
// and `satisfies X` are written on the VALUE, and only a variable has one.
|
|
17
|
+
const kindOf = (node, initializer = null) => ({
|
|
18
|
+
...(0, tree_1.kindFact)(node, initializer),
|
|
19
|
+
modifiers: (0, modifiers_1.modifiersOf)(node),
|
|
20
|
+
decorators: (0, modifiers_1.decoratorsOf)(node),
|
|
21
|
+
assertion: initializer ? (0, variables_1.assertionOf)(node) : null,
|
|
22
|
+
disposable: initializer ? (0, variables_1.isDisposable)(node) : false,
|
|
23
|
+
});
|
|
24
|
+
exports.kindOf = kindOf;
|
|
25
|
+
// The `kind` of something with no node of its own (a comment is trivia): the
|
|
26
|
+
// same four fields, empty, so every candidate answers the same questions.
|
|
27
|
+
const spelled = (kind) => ({ own: { is: kind }, modifiers: [], decorators: [], assertion: null, disposable: false });
|
|
28
|
+
exports.spelled = spelled;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Node, Decorator, CommentRange } from "ts-morph";
|
|
2
|
+
type LooseNode = Node & {
|
|
3
|
+
getName?: () => string | undefined;
|
|
4
|
+
getNameNode?: () => Node | undefined;
|
|
5
|
+
getModifiers?: () => Node[] | undefined;
|
|
6
|
+
getDecorators?: () => Decorator[] | undefined;
|
|
7
|
+
getInitializer?: () => Node | undefined;
|
|
8
|
+
getLiteralText?: () => string | undefined;
|
|
9
|
+
getJsDocs?: () => Node[] | undefined;
|
|
10
|
+
getBody?: () => Node | undefined;
|
|
11
|
+
getExpression?: () => Node | undefined;
|
|
12
|
+
getTypeNode?: () => Node | undefined;
|
|
13
|
+
getReturnTypeNode?: () => Node | undefined;
|
|
14
|
+
getMembers?: () => LooseNode[] | undefined;
|
|
15
|
+
getDeclarationKind?: () => string | undefined;
|
|
16
|
+
getExtends?: () => Node | Node[] | undefined;
|
|
17
|
+
getImplements?: () => Node[] | undefined;
|
|
18
|
+
getConstructors?: () => LooseNode[] | undefined;
|
|
19
|
+
getParameters?: () => LooseNode[] | undefined;
|
|
20
|
+
getElements?: () => LooseNode[] | undefined;
|
|
21
|
+
isOptional?: () => boolean;
|
|
22
|
+
isStatic?: () => boolean;
|
|
23
|
+
findReferencesAsNodes?: () => Node[];
|
|
24
|
+
getImplementations?: () => {
|
|
25
|
+
readonly length: number;
|
|
26
|
+
};
|
|
27
|
+
getLeadingCommentRanges?: () => CommentRange[] | undefined;
|
|
28
|
+
getTrailingCommentRanges?: () => CommentRange[] | undefined;
|
|
29
|
+
getTypeArguments?: () => Node[] | undefined;
|
|
30
|
+
getExprName?: () => Node | undefined;
|
|
31
|
+
getTypeName?: () => Node | undefined;
|
|
32
|
+
getTypeNodes?: () => Node[] | undefined;
|
|
33
|
+
getElementTypeNode?: () => Node | undefined;
|
|
34
|
+
getObjectTypeNode?: () => Node | undefined;
|
|
35
|
+
getConstraint?: () => Node | undefined;
|
|
36
|
+
};
|
|
37
|
+
export type { LooseNode };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decoratorsOf = exports.modifiersOf = void 0;
|
|
4
|
+
// What a declaration is SPELLED with: `export`, `abstract`, `declare`, `async`,
|
|
5
|
+
// `static`, `readonly`, `accessor`, `override`, the visibility words — and the
|
|
6
|
+
// decorators above it. Facts, not verdicts: a rule decides what they mean.
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const tree_1 = require("./tree");
|
|
9
|
+
const properties_1 = require("./properties");
|
|
10
|
+
// A variable's words live on the STATEMENT that declares it: `export const x`
|
|
11
|
+
// and `declare const x` are written on `VariableStatement`, and the declaration
|
|
12
|
+
// node itself carries none. Asking only the node answered "nothing" for every
|
|
13
|
+
// `const`, while `exported` said the opposite about the same file.
|
|
14
|
+
// The declaration sits inside a `VariableDeclarationList`, and the list inside the
|
|
15
|
+
// statement — so the owner is a grandparent, not a parent.
|
|
16
|
+
const spelledBy = (node) => node.getKind?.() === tree_1.SK.VariableDeclaration
|
|
17
|
+
? (node.getFirstAncestorByKind?.(tree_1.SK.VariableStatement) ?? node)
|
|
18
|
+
: node;
|
|
19
|
+
// `modifiersOf` answers with the words as written, in source order.
|
|
20
|
+
const modifiersOf = (node) => {
|
|
21
|
+
const owner = spelledBy(node);
|
|
22
|
+
return (typeof owner.getModifiers === "function" ? owner.getModifiers() : []).map((m) => m.getText());
|
|
23
|
+
};
|
|
24
|
+
exports.modifiersOf = modifiersOf;
|
|
25
|
+
// Decorators by the NAME a filter can match: `@Component({…})` → "Component",
|
|
26
|
+
// `@core.Input()` → "Input". Framework-agnostic — any decorator, any framework.
|
|
27
|
+
const decoratorsOf = (node) => (typeof node.getDecorators === "function" ? node.getDecorators() : []).map((d) => {
|
|
28
|
+
const expr = d.getExpression();
|
|
29
|
+
const name = ts_morph_1.Node.isCallExpression(expr) ? ((0, properties_1.lastMemberName)(expr.getExpression()) ?? expr.getExpression().getText()) : ((0, properties_1.lastMemberName)(expr) ?? expr.getText());
|
|
30
|
+
return { name, full: expr.getText(), line: (0, tree_1.startLine)(d) };
|
|
31
|
+
});
|
|
32
|
+
exports.decoratorsOf = decoratorsOf;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Project, type SourceFile } from "ts-morph";
|
|
2
|
+
type AliasMap = Record<string, string>;
|
|
3
|
+
declare const createTsProject: ({ repoRoot, aliases }?: {
|
|
4
|
+
repoRoot?: string;
|
|
5
|
+
aliases?: AliasMap;
|
|
6
|
+
}) => Project;
|
|
7
|
+
declare const loadSourceFile: (project: Project, abs: string, text: string) => SourceFile;
|
|
8
|
+
export { createTsProject, loadSourceFile };
|
|
9
|
+
export type { AliasMap };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadSourceFile = exports.createTsProject = void 0;
|
|
4
|
+
// LOADING a source file into the run's project. One Project per run, one
|
|
5
|
+
// reader per file; single-file components keep their line grid. Nothing here
|
|
6
|
+
// knows roles, folders or rules — it only answers "give me the parsed file".
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const imports_1 = require("../../utils/imports");
|
|
9
|
+
// One Project per run. Files are added explicitly (never from tsconfig), so the
|
|
10
|
+
// engine is independent of the repo's build config; aliases come only from the
|
|
11
|
+
// YAML. `skipAddingFilesFromTsConfig` keeps the project empty until we add a file.
|
|
12
|
+
const createTsProject = ({ repoRoot, aliases } = {}) => new ts_morph_1.Project({
|
|
13
|
+
compilerOptions: {
|
|
14
|
+
allowJs: true,
|
|
15
|
+
jsx: ts_morph_1.ts.JsxEmit.Preserve,
|
|
16
|
+
esModuleInterop: true,
|
|
17
|
+
// The SAME aliases the facts resolve imports with, handed to the compiler
|
|
18
|
+
// that resolves them (`pathsOf`, in `utils/imports` — one translation). No
|
|
19
|
+
// tsconfig is read: the YAML is the only description of where a name
|
|
20
|
+
// points, so a project fact and an import fact cannot disagree.
|
|
21
|
+
...(repoRoot ? { baseUrl: repoRoot, paths: (0, imports_1.pathsOf)(aliases) } : {}),
|
|
22
|
+
},
|
|
23
|
+
skipAddingFilesFromTsConfig: true,
|
|
24
|
+
useInMemoryFileSystem: false,
|
|
25
|
+
});
|
|
26
|
+
exports.createTsProject = createTsProject;
|
|
27
|
+
// The opening `<script …>` line: everything after the tag is script text; a
|
|
28
|
+
// same-line `</script>` closes the block again.
|
|
29
|
+
const openedLine = (line, state) => {
|
|
30
|
+
const after = line.slice(line.indexOf(">") + 1);
|
|
31
|
+
if (/<\/script>/.test(after)) {
|
|
32
|
+
state.inside = false;
|
|
33
|
+
return after.replace(/<\/script>[\s\S]*$/, "");
|
|
34
|
+
}
|
|
35
|
+
state.inside = true;
|
|
36
|
+
state.opened = true;
|
|
37
|
+
return after;
|
|
38
|
+
};
|
|
39
|
+
// A line INSIDE the script block: kept until `</script>` cuts it.
|
|
40
|
+
const insideLine = (line, state) => {
|
|
41
|
+
if (/<\/script>/.test(line)) {
|
|
42
|
+
state.inside = false;
|
|
43
|
+
return line.slice(0, line.indexOf("</script>"));
|
|
44
|
+
}
|
|
45
|
+
return line;
|
|
46
|
+
};
|
|
47
|
+
// A single-file component (.vue / .svelte) holds its TypeScript inside
|
|
48
|
+
// `<script>`. Only that block is parsed; every other line is blanked so the
|
|
49
|
+
// line numbers a finding reports still match the file the editor shows.
|
|
50
|
+
const extractScript = (text) => {
|
|
51
|
+
const lines = String(text).split("\n");
|
|
52
|
+
const state = { inside: false, opened: false };
|
|
53
|
+
const kept = lines.map((line) => {
|
|
54
|
+
if (!state.inside && /<script\b[^>]*>/.test(line))
|
|
55
|
+
return openedLine(line, state);
|
|
56
|
+
if (state.inside)
|
|
57
|
+
return insideLine(line, state);
|
|
58
|
+
return "";
|
|
59
|
+
});
|
|
60
|
+
return { text: kept.join("\n"), opened: state.opened };
|
|
61
|
+
};
|
|
62
|
+
const SFC_RE = /\.(vue|svelte)$/i;
|
|
63
|
+
const sourceTextFor = (abs, text) => (SFC_RE.test(abs) ? extractScript(text).text : text);
|
|
64
|
+
// A file already loaded with the SAME text is reused: the pipeline re-reads the
|
|
65
|
+
// linted file on every check, and replacing the source would forget every node
|
|
66
|
+
// other facts (a scope's object literals) still hold — a value resolver walking
|
|
67
|
+
// a cached literal of that very file would then crash on a removed node.
|
|
68
|
+
const loadSourceFile = (project, abs, text) => {
|
|
69
|
+
const source = sourceTextFor(abs, text);
|
|
70
|
+
const existing = project.getSourceFile(abs);
|
|
71
|
+
if (existing && existing.getFullText() === source)
|
|
72
|
+
return existing;
|
|
73
|
+
return project.createSourceFile(abs, source, { overwrite: true });
|
|
74
|
+
};
|
|
75
|
+
exports.loadSourceFile = loadSourceFile;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node, type SourceFile } from "ts-morph";
|
|
2
|
+
import type { ReadFact } from "../facts";
|
|
3
|
+
type ImportMap = ReadonlyMap<string, string>;
|
|
4
|
+
declare const isPurePropertyPath: (node: Node) => boolean;
|
|
5
|
+
declare const leftmostOrigin: (expr: Node | null) => string | null;
|
|
6
|
+
declare const lastMemberName: (expr: Node | null) => string | null;
|
|
7
|
+
declare const isThisChain: (expr: Node) => boolean;
|
|
8
|
+
declare const importModuleOf: (expr: Node, importMap?: ImportMap) => string | null;
|
|
9
|
+
declare const enclosingPiece: (node: Node) => string | null;
|
|
10
|
+
declare const readsFact: (sf: SourceFile, importMap?: ImportMap) => ReadFact[];
|
|
11
|
+
export { isPurePropertyPath, leftmostOrigin, lastMemberName, isThisChain, importModuleOf, readsFact, enclosingPiece };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enclosingPiece = exports.readsFact = exports.importModuleOf = exports.isThisChain = exports.lastMemberName = exports.leftmostOrigin = exports.isPurePropertyPath = void 0;
|
|
4
|
+
// Property access: what an expression chain is rooted at (`getRoot(self).x` →
|
|
5
|
+
// "getRoot"), what member is actually used (`store.doX()` → "doX"), and which
|
|
6
|
+
// chains reach state through a configured accessor.
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const tree_1 = require("./tree");
|
|
9
|
+
const gate_1 = require("../../utils/gate");
|
|
10
|
+
// Is this node a "pure property path" — dots only, rooted in an identifier?
|
|
11
|
+
// `a.b.c` → true; `arr[0].run` → false (element access); `f().x` → false (call).
|
|
12
|
+
const isPurePropertyPath = (node) => {
|
|
13
|
+
const k = node.getKind();
|
|
14
|
+
if (k === tree_1.SK.Identifier)
|
|
15
|
+
return true;
|
|
16
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(node))
|
|
17
|
+
return isPurePropertyPath(node.getExpression());
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
exports.isPurePropertyPath = isPurePropertyPath;
|
|
21
|
+
// The origin a TERMINAL expression names on its own: a construction (`new F`),
|
|
22
|
+
// an element access (`arr[0]`), or a bare identifier (`state`). Null when the
|
|
23
|
+
// expression is not a terminal — it still has an inner expression to step into.
|
|
24
|
+
const terminalOrigin = (e) => {
|
|
25
|
+
if (ts_morph_1.Node.isNewExpression(e))
|
|
26
|
+
return `new ${(0, tree_1.nodeText)(e.getExpression())}`;
|
|
27
|
+
if (ts_morph_1.Node.isElementAccessExpression(e))
|
|
28
|
+
return (0, tree_1.nodeText)(e);
|
|
29
|
+
if (ts_morph_1.Node.isIdentifier(e))
|
|
30
|
+
return (0, tree_1.nodeText)(e);
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
// The one step INWARD an enclosing expression takes while walking to its root:
|
|
34
|
+
// a tagged template steps to its tag (`keyframes\`…\`` → `keyframes`), a call to
|
|
35
|
+
// its callee, a property access to its base. Null when there is no inner step.
|
|
36
|
+
const inwardStep = (e) => {
|
|
37
|
+
if (ts_morph_1.Node.isTaggedTemplateExpression(e))
|
|
38
|
+
return e.getTag();
|
|
39
|
+
if (ts_morph_1.Node.isCallExpression(e))
|
|
40
|
+
return e.getExpression();
|
|
41
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(e))
|
|
42
|
+
return e.getExpression();
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
// The origin of any expression chain — what the expression acts on / is rooted at:
|
|
46
|
+
// `t.model("X", {...})` → `t.model` (pure property path = the function)
|
|
47
|
+
// `a.b.c()` → `a.b.c` (pure property path = the function)
|
|
48
|
+
// `arr[0].run()` → `arr[0]` (element access → the object)
|
|
49
|
+
// `new F(...)` / `new F({}).create()` → `new F` (construction → the class)
|
|
50
|
+
// `getRoot(self).store.doAction()` → `getRoot` (call in chain → the root call)
|
|
51
|
+
// `state` (bare identifier) → `state`
|
|
52
|
+
// `[1,2,3]` (array literal) → null
|
|
53
|
+
// The YAML can match any pattern: `origin: { equals: "t.model" }`,
|
|
54
|
+
// `origin: { startsWith: "new " }`, `origin: { endsWith: ".run" }`.
|
|
55
|
+
const leftmostOrigin = (expr) => {
|
|
56
|
+
let e = expr;
|
|
57
|
+
while (e) {
|
|
58
|
+
const terminal = terminalOrigin(e);
|
|
59
|
+
if (terminal !== null)
|
|
60
|
+
return terminal;
|
|
61
|
+
const step = inwardStep(e);
|
|
62
|
+
if (!step)
|
|
63
|
+
break;
|
|
64
|
+
// A call on a pure property path: the full chain IS the function name —
|
|
65
|
+
// `a.b.c()` is rooted at `a.b.c`, not at `a`.
|
|
66
|
+
if (ts_morph_1.Node.isCallExpression(e) && isPurePropertyPath(step))
|
|
67
|
+
return (0, tree_1.nodeText)(step);
|
|
68
|
+
// A property access whose base is a bare identifier answers the ACCESS
|
|
69
|
+
// (`a.b` → `a.b`), not the identifier alone.
|
|
70
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(e) && step.getKind() === tree_1.SK.Identifier)
|
|
71
|
+
return (0, tree_1.nodeText)(e);
|
|
72
|
+
e = step;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
exports.leftmostOrigin = leftmostOrigin;
|
|
77
|
+
// The rightmost member name of an expression chain: `store.doX` → "doX",
|
|
78
|
+
// `arr[0]` → null. null for a bare identifier (it is its own name).
|
|
79
|
+
const lastMemberName = (expr) => (expr && ts_morph_1.Node.isPropertyAccessExpression(expr) ? expr.getName() : null);
|
|
80
|
+
exports.lastMemberName = lastMemberName;
|
|
81
|
+
// Is this expression `this.x…`? Writing there mutates the instance — the state
|
|
82
|
+
// of a component/service/store, in any framework.
|
|
83
|
+
const isThisChain = (expr) => {
|
|
84
|
+
let e = expr;
|
|
85
|
+
while (ts_morph_1.Node.isPropertyAccessExpression(e))
|
|
86
|
+
e = e.getExpression();
|
|
87
|
+
return e.getKind() === tree_1.SK.ThisKeyword;
|
|
88
|
+
};
|
|
89
|
+
exports.isThisChain = isThisChain;
|
|
90
|
+
// The module an expression's base identifier was imported from, if any.
|
|
91
|
+
const importModuleOf = (expr, importMap) => {
|
|
92
|
+
let base = expr;
|
|
93
|
+
while (ts_morph_1.Node.isPropertyAccessExpression(base))
|
|
94
|
+
base = base.getExpression();
|
|
95
|
+
if (!ts_morph_1.Node.isIdentifier(base))
|
|
96
|
+
return null;
|
|
97
|
+
return importMap?.get(base.getText()) ?? null;
|
|
98
|
+
};
|
|
99
|
+
exports.importModuleOf = importModuleOf;
|
|
100
|
+
// The module a MEMBER of an expression belongs to: `other.x`, `other().x`,
|
|
101
|
+
// `other.a.b` — the receiver is either an imported binding or the result of
|
|
102
|
+
// calling one (`requireRootStore().settings`). Null when the receiver is local.
|
|
103
|
+
const memberOwnerModule = (expr, importMap) => {
|
|
104
|
+
let base = expr;
|
|
105
|
+
while (ts_morph_1.Node.isPropertyAccessExpression(base) || ts_morph_1.Node.isElementAccessExpression(base))
|
|
106
|
+
base = base.getExpression();
|
|
107
|
+
if (ts_morph_1.Node.isIdentifier(base))
|
|
108
|
+
return importMap?.get(base.getText()) ?? null;
|
|
109
|
+
if (ts_morph_1.Node.isCallExpression(base))
|
|
110
|
+
return importModuleOf(base.getExpression(), importMap);
|
|
111
|
+
return null;
|
|
112
|
+
};
|
|
113
|
+
// Is this member access the WHOLE expression on its side — not the inner hop of
|
|
114
|
+
// a longer chain, not the callee of a call (that is `call`), not the target of a
|
|
115
|
+
// write (that is `mutate`)? Only the outermost access becomes one `read` edge;
|
|
116
|
+
// otherwise `store.a.b.c` would be three.
|
|
117
|
+
const isInnerHop = (parent, node) => {
|
|
118
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(parent) || ts_morph_1.Node.isElementAccessExpression(parent))
|
|
119
|
+
return parent.getExpression() === node;
|
|
120
|
+
if (ts_morph_1.Node.isCallExpression(parent))
|
|
121
|
+
return parent.getExpression() === node;
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
124
|
+
const isWholeRead = (node) => {
|
|
125
|
+
const parent = node.getParent();
|
|
126
|
+
if (!parent)
|
|
127
|
+
return true;
|
|
128
|
+
// The decision ("a read when none of the write/inner-hop verdicts fires") is
|
|
129
|
+
// the shared gate; the verdicts are the AST's own.
|
|
130
|
+
const isWriteTarget = (p) => (ts_morph_1.Node.isBinaryExpression(p) && p.getLeft() === node) ||
|
|
131
|
+
ts_morph_1.Node.isDeleteExpression(p) ||
|
|
132
|
+
((ts_morph_1.Node.isPrefixUnaryExpression(p) || ts_morph_1.Node.isPostfixUnaryExpression(p)) && p.getOperand() === node);
|
|
133
|
+
return (0, gate_1.admitsWhenNoneReject)(parent, [(p) => isInnerHop(p, node), isWriteTarget]);
|
|
134
|
+
};
|
|
135
|
+
// Every member of ANOTHER module this file looks at: `requireRootStore().settings`,
|
|
136
|
+
// `Settings.debug`, `host.workspace`. Reads are what a view does, so they are a
|
|
137
|
+
// relation of their own — "may read the store" is a permission a role needs, and
|
|
138
|
+
// calling it a use made the permission impossible to state.
|
|
139
|
+
// The named declaration a node sits in — a function or a variable, the piece of
|
|
140
|
+
// code a role belongs to. Null at module level, where the file itself is the
|
|
141
|
+
// only thing there is.
|
|
142
|
+
const FUNCTION_PIECE_KINDS = new Set([tree_1.SK.FunctionDeclaration, tree_1.SK.ArrowFunction, tree_1.SK.FunctionExpression, tree_1.SK.MethodDeclaration]);
|
|
143
|
+
const enclosingPiece = (node) => {
|
|
144
|
+
let cur = node.getParent();
|
|
145
|
+
while (cur) {
|
|
146
|
+
const kind = cur.getKind();
|
|
147
|
+
if (FUNCTION_PIECE_KINDS.has(kind) || kind === tree_1.SK.VariableDeclaration) {
|
|
148
|
+
const name = cur.getName?.() ?? null;
|
|
149
|
+
if (name)
|
|
150
|
+
return name;
|
|
151
|
+
}
|
|
152
|
+
cur = cur.getParent?.();
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
};
|
|
156
|
+
exports.enclosingPiece = enclosingPiece;
|
|
157
|
+
const readsFact = (sf, importMap) => {
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const node of sf.getDescendants()) {
|
|
160
|
+
if (!ts_morph_1.Node.isPropertyAccessExpression(node) && !ts_morph_1.Node.isElementAccessExpression(node))
|
|
161
|
+
continue;
|
|
162
|
+
if (!isWholeRead(node))
|
|
163
|
+
continue;
|
|
164
|
+
const module = memberOwnerModule(node, importMap);
|
|
165
|
+
if (!module)
|
|
166
|
+
continue;
|
|
167
|
+
out.push({ module, what: (0, tree_1.nodeText)(node), line: node.getStartLineNumber(), piece: enclosingPiece(node) });
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
};
|
|
171
|
+
exports.readsFact = readsFact;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SourceFile, type TypeChecker, type Type } from "ts-morph";
|
|
2
|
+
import type { LooseNode } from "./loose";
|
|
3
|
+
type DeclInfo = {
|
|
4
|
+
kind: string;
|
|
5
|
+
file: string;
|
|
6
|
+
node: LooseNode;
|
|
7
|
+
};
|
|
8
|
+
declare const repoRelative: (file?: string | null, repoRoot?: string | null) => string | null;
|
|
9
|
+
declare const declaredFileOfNode: (typeNode: LooseNode | null | undefined, checker: TypeChecker, repoRoot: string) => DeclInfo | null;
|
|
10
|
+
declare const declaredFileOf: (param: LooseNode, checker: TypeChecker, repoRoot: string) => DeclInfo | null;
|
|
11
|
+
declare const declaredFileOfType: (type: Type | undefined, checker: TypeChecker, repoRoot: string) => DeclInfo | null;
|
|
12
|
+
declare const inRepo: (file?: string | null, repoRoot?: string | null) => boolean;
|
|
13
|
+
declare const declaredFileOfExpr: (expr: LooseNode | null, checker: TypeChecker, repoRoot: string, depth?: number) => DeclInfo | null;
|
|
14
|
+
declare const importNameModules: (sf: SourceFile, repoRoot: string, aliases?: Record<string, string>, repoFiles?: readonly string[]) => Map<string, string>;
|
|
15
|
+
export { importNameModules, declaredFileOfNode, declaredFileOf, declaredFileOfType, declaredFileOfExpr, repoRelative, inRepo };
|
|
16
|
+
export type { DeclInfo };
|