@md-code/follow-architecture 0.1.1 → 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 +584 -141
- 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 +61 -18
- 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 -101
- package/entities/aliases.js +0 -10
- package/entities/invariants.js +0 -134
- package/entities/nodes.js +0 -112
- package/main.js +0 -96
- package/plugin.js +0 -5
- package/report.js +0 -73
- package/utils.js +0 -104
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyValue = void 0;
|
|
4
|
+
// One VALUE, as the parser sees it — no vocabulary of ours anywhere.
|
|
5
|
+
//
|
|
6
|
+
// css-tree knows the CSS value grammar, so a node's TYPE is the fact: a `Dimension`
|
|
7
|
+
// is a number with a unit, a `Hash` is a `#…` token, a `Function` is a call whose
|
|
8
|
+
// NAME is reported as written (`rgb`, `clamp`, `color-mix`, `light-dark`, a
|
|
9
|
+
// project's own `hex(…)`). This file has no list of colour or math functions to
|
|
10
|
+
// fall behind: whether a call paints a colour, does arithmetic or is somebody's
|
|
11
|
+
// own helper is a question for the architecture config, which filters by `name`.
|
|
12
|
+
//
|
|
13
|
+
// A value the CSS grammar does not know (`$gap`, `#{$gap}`, `math.div($a, 2)`,
|
|
14
|
+
// `map-get($m, k)`) does not parse as a CSS value at all. Returning nothing for it
|
|
15
|
+
// would say "this value
|
|
16
|
+
// has no literals", which is a LIE — so a value the grammar rejects is scanned as
|
|
17
|
+
// TOKENS instead, and `parsed: false` records which reading produced the facts.
|
|
18
|
+
//
|
|
19
|
+
// Tailwind needs no separate path: by the time a class reaches this module it is a
|
|
20
|
+
// value (`0.875rem`, `--tw-space-y-reverse`), and Tailwind's own generator is what
|
|
21
|
+
// produced it (see `tailwind.ts`).
|
|
22
|
+
const check_1 = require("./check");
|
|
23
|
+
const emptyParts = () => ({ literals: [], vars: [], functions: [], interpolations: [] });
|
|
24
|
+
// The fallback reading: a value the CSS grammar rejects is still text with the
|
|
25
|
+
// same kinds of parts. Nothing here interprets — it RECORDS:
|
|
26
|
+
// $name / --name a variable reference (`vars`)
|
|
27
|
+
// #rrggbb / #rgb a colour literal
|
|
28
|
+
// `#{ … }` an interpolation — a COMPUTED value, not a literal
|
|
29
|
+
// number + unit a dimension
|
|
30
|
+
// name( a call, name as written
|
|
31
|
+
// "…" / '…' a string literal
|
|
32
|
+
const TOKEN_RE = /#\{[^}]*\}|[A-Za-z_][\w-]*(?:\.[A-Za-z_][\w-]*)*\(|(?:\d*\.\d+|\d+)(?:%|[a-zA-Z]+)?|\$[\w-]+|--[\w-]+|#[\da-fA-F]{3,8}\b|"[^"]*"|'[^']*'/g;
|
|
33
|
+
const NUMBER_RE = /^(?:\d*\.\d+|\d+)(?:%|[a-zA-Z]+)?$/;
|
|
34
|
+
const UNIT_RE = /(%|[a-zA-Z]+)$/;
|
|
35
|
+
// The kind a written number is, by its unit: none → a number, `%` → a percentage,
|
|
36
|
+
// anything else → a dimension. One helper, no nested ternary.
|
|
37
|
+
const numberKind = (unit) => {
|
|
38
|
+
if (unit === null)
|
|
39
|
+
return "number";
|
|
40
|
+
if (unit === "%")
|
|
41
|
+
return "percentage";
|
|
42
|
+
return "dimension";
|
|
43
|
+
};
|
|
44
|
+
// One token, classified by its own spelling. A named helper per kind keeps the
|
|
45
|
+
// dispatch flat and each reading honest.
|
|
46
|
+
const tokenLiteral = (token, line) => {
|
|
47
|
+
if (token.startsWith("#"))
|
|
48
|
+
return { kind: "hash", text: token, line, unit: null };
|
|
49
|
+
if (!NUMBER_RE.test(token))
|
|
50
|
+
return null;
|
|
51
|
+
const unit = token.match(UNIT_RE)?.[1] ?? null;
|
|
52
|
+
return { kind: numberKind(unit), text: token, line, unit };
|
|
53
|
+
};
|
|
54
|
+
const tokenFacts = (value, line) => {
|
|
55
|
+
const out = emptyParts();
|
|
56
|
+
for (const match of value.matchAll(TOKEN_RE)) {
|
|
57
|
+
const token = match[0];
|
|
58
|
+
const at = { text: token, line };
|
|
59
|
+
if (token.startsWith("#{"))
|
|
60
|
+
out.interpolations.push(at);
|
|
61
|
+
else if (token.startsWith("$") || token.startsWith("--"))
|
|
62
|
+
out.vars.push(token);
|
|
63
|
+
else if (token.endsWith("("))
|
|
64
|
+
out.functions.push({ ...at, name: token.slice(0, -1) });
|
|
65
|
+
else {
|
|
66
|
+
const literal = tokenLiteral(token, line);
|
|
67
|
+
if (literal)
|
|
68
|
+
out.literals.push(literal);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
};
|
|
73
|
+
// A LEAF that is more than punctuation is a written value. The test is on what
|
|
74
|
+
// the parser generated, not on a list of node types: `,` and whitespace are
|
|
75
|
+
// separators, `16px`/`#fff`/`100%` are values. An `Identifier` is the parser's
|
|
76
|
+
// own word for a KEYWORD (`solid`, `block`), and a keyword is not a value.
|
|
77
|
+
const leafLiteral = (node, text, line) => {
|
|
78
|
+
const hasChildren = Boolean(node.children?.first);
|
|
79
|
+
const isKeyword = node.type === "Identifier";
|
|
80
|
+
// A value has a letter or a digit in it: operators (`-`, `/`), commas and
|
|
81
|
+
// whitespace do not, and they are what a `calc()`/`clamp()` is made of.
|
|
82
|
+
const hasValue = /[A-Za-z0-9]/.test(text);
|
|
83
|
+
if (hasChildren || isKeyword || !hasValue)
|
|
84
|
+
return null;
|
|
85
|
+
return { kind: node.type.toLowerCase(), text, line, unit: node.unit ?? null };
|
|
86
|
+
};
|
|
87
|
+
// A CALL is a node with children and a name; a bare identifier is a keyword,
|
|
88
|
+
// which is not a call and is not a value. `var(--x)` reads a NAME; every other
|
|
89
|
+
// call is reported by its own name.
|
|
90
|
+
const callFact = (node, text, line, out) => {
|
|
91
|
+
if (!node.children?.first || node.name === undefined)
|
|
92
|
+
return;
|
|
93
|
+
const name = node.name;
|
|
94
|
+
const first = node.children.first;
|
|
95
|
+
if (name.toLowerCase() === "var" && first?.type === "Identifier" && first.name !== undefined)
|
|
96
|
+
out.vars.push(first.name);
|
|
97
|
+
else
|
|
98
|
+
out.functions.push({ name, text, line });
|
|
99
|
+
};
|
|
100
|
+
// Walk the parsed value: every literal by node type, every call by name, and the
|
|
101
|
+
// variables a value reads. A call's ARGUMENTS are values of their own, so the walk
|
|
102
|
+
// goes INTO them (`color-mix(in srgb, #fff 40%, var(--a))` holds a hash, a
|
|
103
|
+
// percentage and a read) — nothing is skipped, nothing is interpreted.
|
|
104
|
+
const parsedFacts = (ast, line) => {
|
|
105
|
+
const out = emptyParts();
|
|
106
|
+
check_1.cssTree.walk(ast, {
|
|
107
|
+
enter(node) {
|
|
108
|
+
const text = check_1.cssTree.generate(node);
|
|
109
|
+
const literal = leafLiteral(node, text, line);
|
|
110
|
+
if (literal)
|
|
111
|
+
out.literals.push(literal);
|
|
112
|
+
callFact(node, text, line, out);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return out;
|
|
116
|
+
};
|
|
117
|
+
const classifyValue = (value, line) => {
|
|
118
|
+
const text = String(value);
|
|
119
|
+
try {
|
|
120
|
+
return { parsed: true, ...parsedFacts(check_1.cssTree.parse(text, { context: "value", positions: true }), line) };
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Not CSS: a value in a syntax we have no grammar for. `parsed: false` is
|
|
124
|
+
// the result — the tokens below are what the reader could still find, and
|
|
125
|
+
// the flag says which reading produced them. (This is called for every
|
|
126
|
+
// string an object holds, so `"x.ts"` reaching it is normal, not an error
|
|
127
|
+
// to report.)
|
|
128
|
+
return { parsed: false, ...tokenFacts(text, line) };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
exports.classifyValue = classifyValue;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { FieldValue } from "../utils/field";
|
|
2
|
+
import type { DepthCache } from "./ast/depth";
|
|
3
|
+
import type { SimilarCache } from "../nodes/similar";
|
|
4
|
+
type QueryFilter = FieldValue;
|
|
5
|
+
type ScopeValue = FieldValue | Arch | null | undefined;
|
|
6
|
+
type QueryScope = FieldValue | {
|
|
7
|
+
readonly [key: string]: ScopeValue;
|
|
8
|
+
};
|
|
9
|
+
type ReportObject = {
|
|
10
|
+
description?: string | null;
|
|
11
|
+
message?: string | null;
|
|
12
|
+
fix?: string | ReportFix | null;
|
|
13
|
+
ask?: string | null;
|
|
14
|
+
code?: string | null;
|
|
15
|
+
path?: string | null;
|
|
16
|
+
place?: string | null;
|
|
17
|
+
to?: string[];
|
|
18
|
+
from?: string | null;
|
|
19
|
+
};
|
|
20
|
+
type ReportFix = {
|
|
21
|
+
message?: string | null;
|
|
22
|
+
location?: WhereEntry | string | (WhereEntry | string)[] | null;
|
|
23
|
+
};
|
|
24
|
+
type ReportValue = string | ReportObject | null;
|
|
25
|
+
type WhereType = "role" | "node" | "glob" | "template" | "query";
|
|
26
|
+
type WhereEntry = {
|
|
27
|
+
type?: WhereType;
|
|
28
|
+
role?: string;
|
|
29
|
+
same?: boolean;
|
|
30
|
+
via?: string | null;
|
|
31
|
+
node?: string;
|
|
32
|
+
glob?: string;
|
|
33
|
+
template?: string;
|
|
34
|
+
query?: QueryFilter;
|
|
35
|
+
re?: RegExp;
|
|
36
|
+
};
|
|
37
|
+
type ScopeAccessor = {
|
|
38
|
+
scope: string;
|
|
39
|
+
segments: string[];
|
|
40
|
+
};
|
|
41
|
+
type ActionDef = {
|
|
42
|
+
where?: WhereEntry[];
|
|
43
|
+
except?: WhereEntry[];
|
|
44
|
+
of?: string;
|
|
45
|
+
scopeAccess?: ScopeAccessor[] | null;
|
|
46
|
+
};
|
|
47
|
+
type RoleDef = {
|
|
48
|
+
slug: string;
|
|
49
|
+
name: string;
|
|
50
|
+
infer: QueryFilter[];
|
|
51
|
+
report: ReportValue;
|
|
52
|
+
actions: Record<string, ActionDef>;
|
|
53
|
+
};
|
|
54
|
+
type CodeRoles = Record<string, RoleDef>;
|
|
55
|
+
type Invariant = {
|
|
56
|
+
id: string;
|
|
57
|
+
where: WhereEntry[];
|
|
58
|
+
ignore: WhereEntry[];
|
|
59
|
+
when: QueryFilter | null;
|
|
60
|
+
infer: QueryFilter[];
|
|
61
|
+
report: ReportValue;
|
|
62
|
+
dedupeBy: WhereEntry[];
|
|
63
|
+
children: Invariant[];
|
|
64
|
+
};
|
|
65
|
+
type InvariantCheck = QueryFilter & {
|
|
66
|
+
report?: ReportValue;
|
|
67
|
+
};
|
|
68
|
+
type RoleHome = {
|
|
69
|
+
template: string;
|
|
70
|
+
node: string | null;
|
|
71
|
+
};
|
|
72
|
+
type ArchClaim = {
|
|
73
|
+
index: number;
|
|
74
|
+
value: string;
|
|
75
|
+
};
|
|
76
|
+
type ArchVariant = {
|
|
77
|
+
path: string;
|
|
78
|
+
re: RegExp;
|
|
79
|
+
names: string[];
|
|
80
|
+
literalLen: number;
|
|
81
|
+
isFile: boolean;
|
|
82
|
+
claims?: ArchClaim[];
|
|
83
|
+
};
|
|
84
|
+
type ArchChild = {
|
|
85
|
+
nodeSlug: string | null;
|
|
86
|
+
name: string | null;
|
|
87
|
+
re: RegExp;
|
|
88
|
+
captures: string[];
|
|
89
|
+
folder: boolean;
|
|
90
|
+
required: boolean;
|
|
91
|
+
forbidden: boolean;
|
|
92
|
+
query: QueryFilter | null;
|
|
93
|
+
report: ReportValue;
|
|
94
|
+
roles: string[];
|
|
95
|
+
slug?: string | null;
|
|
96
|
+
};
|
|
97
|
+
type ArchNode = {
|
|
98
|
+
slug: string;
|
|
99
|
+
name: string;
|
|
100
|
+
parent?: string | string[] | null;
|
|
101
|
+
parents: (string | null)[];
|
|
102
|
+
children: ArchChild[];
|
|
103
|
+
roles: string[];
|
|
104
|
+
report?: ReportValue;
|
|
105
|
+
required?: boolean;
|
|
106
|
+
variants: ArchVariant[];
|
|
107
|
+
path: string;
|
|
108
|
+
re: RegExp;
|
|
109
|
+
prefixRe: RegExp;
|
|
110
|
+
prefixNames: string[];
|
|
111
|
+
literalLen: number;
|
|
112
|
+
isFile: boolean;
|
|
113
|
+
};
|
|
114
|
+
type ArchNodes = {
|
|
115
|
+
all: ArchNode[];
|
|
116
|
+
bySlug: Record<string, ArchNode>;
|
|
117
|
+
roots: ArchNode[];
|
|
118
|
+
roleHomes: Record<string, RoleHome[]>;
|
|
119
|
+
};
|
|
120
|
+
type Arch = {
|
|
121
|
+
nodes: ArchNodes;
|
|
122
|
+
codeRoles: CodeRoles;
|
|
123
|
+
invariants: Invariant[];
|
|
124
|
+
aliases: Record<string, string>;
|
|
125
|
+
raw: RawArch;
|
|
126
|
+
repoRoot?: string | null;
|
|
127
|
+
similarity?: number;
|
|
128
|
+
depthCache?: DepthCache;
|
|
129
|
+
similarCache?: SimilarCache;
|
|
130
|
+
};
|
|
131
|
+
type RawChildSpec = {
|
|
132
|
+
name?: string;
|
|
133
|
+
node?: string;
|
|
134
|
+
role?: string | string[];
|
|
135
|
+
required?: boolean;
|
|
136
|
+
forbidden?: boolean;
|
|
137
|
+
query?: QueryFilter | null;
|
|
138
|
+
report?: ReportValue;
|
|
139
|
+
};
|
|
140
|
+
type RawChild = string | RawChildSpec;
|
|
141
|
+
type RawNode = {
|
|
142
|
+
slug?: string;
|
|
143
|
+
name: string;
|
|
144
|
+
parent?: string | string[] | null;
|
|
145
|
+
children?: RawChild[];
|
|
146
|
+
role?: string | string[];
|
|
147
|
+
report?: ReportValue;
|
|
148
|
+
};
|
|
149
|
+
type RawRole = {
|
|
150
|
+
readonly [key: string]: FieldValue;
|
|
151
|
+
};
|
|
152
|
+
type RawCodeRoles = RawRole[] | Record<string, RawRole>;
|
|
153
|
+
type RawNodes = RawNode[] | Record<string, RawNode>;
|
|
154
|
+
type RawArch = {
|
|
155
|
+
file?: string;
|
|
156
|
+
nodes?: RawNodes | null;
|
|
157
|
+
codeRoles?: RawCodeRoles | null;
|
|
158
|
+
invariants?: FieldValue[];
|
|
159
|
+
aliases?: Record<string, FieldValue> | null;
|
|
160
|
+
report?: ReportValue;
|
|
161
|
+
};
|
|
162
|
+
export type { QueryFilter, ScopeValue, QueryScope, ReportValue, ReportObject, WhereType, WhereEntry, ScopeAccessor, ActionDef, RoleDef, CodeRoles, Invariant, InvariantCheck, RoleHome, ArchClaim, ArchVariant, ArchChild, ArchNode, ArchNodes, DepthCache, SimilarCache, Arch, RawChildSpec, RawChild, RawNode, RawNodes, RawRole, RawCodeRoles, RawArch, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Node, type CallExpression } from "ts-morph";
|
|
2
|
+
type ImportMap = ReadonlyMap<string, string>;
|
|
3
|
+
declare const bare: (node: Node) => Node;
|
|
4
|
+
declare const walkToRoot: (expr: Node) => Node;
|
|
5
|
+
declare const rootNodeOf: (expr: Node) => Node | null;
|
|
6
|
+
declare const rootNameOf: (expr: Node) => string | null;
|
|
7
|
+
declare const callRootOf: (expr: Node) => CallExpression | null;
|
|
8
|
+
declare const isLocalTarget: (lhs: Node, fn: Node) => boolean;
|
|
9
|
+
export { bare, walkToRoot, rootNodeOf, rootNameOf, callRootOf, isLocalTarget };
|
|
10
|
+
export type { ImportMap };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLocalTarget = exports.callRootOf = exports.rootNameOf = exports.rootNodeOf = exports.walkToRoot = exports.bare = void 0;
|
|
4
|
+
// The expression walkers a write is read through: what an assignment's left
|
|
5
|
+
// side is rooted in (`state.a.b` → `state`), which CALL it is written through
|
|
6
|
+
// (`f().x` → `f()`), and whether the root is a local binding of the piece. These
|
|
7
|
+
// are the same walks for every producer of a write fact, so they live once.
|
|
8
|
+
const ts_morph_1 = require("ts-morph");
|
|
9
|
+
const tree_1 = require("./tree");
|
|
10
|
+
// The identifier a written expression is rooted in: `state.a.b = …` → `state`.
|
|
11
|
+
// `x!` and `(x)` are the same value with extra syntax: unwrap them before asking
|
|
12
|
+
// what the expression is rooted in, or `getRootStore()!.level = …` looks rooted in
|
|
13
|
+
// nothing at all.
|
|
14
|
+
const bare = (node) => {
|
|
15
|
+
let n = node;
|
|
16
|
+
while (ts_morph_1.Node.isNonNullExpression(n) || ts_morph_1.Node.isParenthesizedExpression(n))
|
|
17
|
+
n = n.getExpression();
|
|
18
|
+
return n;
|
|
19
|
+
};
|
|
20
|
+
exports.bare = bare;
|
|
21
|
+
// The root of a member chain: `a.b.c` → `a`, `f().x` → `f()`, `this.x` → `this`.
|
|
22
|
+
// Both questions below ("what is written to?" and "which call is written
|
|
23
|
+
// through?") walk the same access chain, so the walk is written once.
|
|
24
|
+
const walkToRoot = (expr) => {
|
|
25
|
+
let node = bare(expr);
|
|
26
|
+
while (ts_morph_1.Node.isPropertyAccessExpression(node) || ts_morph_1.Node.isElementAccessExpression(node))
|
|
27
|
+
node = bare(node.getExpression());
|
|
28
|
+
return node;
|
|
29
|
+
};
|
|
30
|
+
exports.walkToRoot = walkToRoot;
|
|
31
|
+
const rootNodeOf = (expr) => {
|
|
32
|
+
const node = walkToRoot(expr);
|
|
33
|
+
return ts_morph_1.Node.isIdentifier(node) ? node : null;
|
|
34
|
+
};
|
|
35
|
+
exports.rootNodeOf = rootNodeOf;
|
|
36
|
+
const rootNameOf = (expr) => {
|
|
37
|
+
const node = rootNodeOf(expr);
|
|
38
|
+
return node ? node.getText() : null;
|
|
39
|
+
};
|
|
40
|
+
exports.rootNameOf = rootNameOf;
|
|
41
|
+
// The CALL a write lands in: `f().x = …` → `f()`, `f().a.b = …` → `f()`; null
|
|
42
|
+
// when the left side is not rooted in a call at all.
|
|
43
|
+
const callRootOf = (expr) => {
|
|
44
|
+
const node = walkToRoot(expr);
|
|
45
|
+
return ts_morph_1.Node.isCallExpression(node) ? node : null;
|
|
46
|
+
};
|
|
47
|
+
exports.callRootOf = callRootOf;
|
|
48
|
+
// Is an assignment's left-hand side a local binding of the enclosing function?
|
|
49
|
+
// A property/element access (`state.x = ...`) is local when its BASE object is a
|
|
50
|
+
// local binding — writing to a property of a local is still a local mutation.
|
|
51
|
+
const isLocalTarget = (lhs, fn) => {
|
|
52
|
+
let base = lhs;
|
|
53
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(base) || ts_morph_1.Node.isElementAccessExpression(base))
|
|
54
|
+
base = base.getExpression();
|
|
55
|
+
if (!ts_morph_1.Node.isIdentifier(base))
|
|
56
|
+
return false;
|
|
57
|
+
const name = base.getText();
|
|
58
|
+
if (!ts_morph_1.Node.isFunctionLikeDeclaration(fn))
|
|
59
|
+
return false;
|
|
60
|
+
const params = new Set(fn.getParameters().map((p) => p.getName()));
|
|
61
|
+
const locals = new Set(fn.getDescendantsOfKind(tree_1.SK.VariableDeclaration).map((d) => d.getName()));
|
|
62
|
+
return params.has(name) || locals.has(name);
|
|
63
|
+
};
|
|
64
|
+
exports.isLocalTarget = isLocalTarget;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Node } from "ts-morph";
|
|
2
|
+
import { type ImportMap } from "./assignments-nodes";
|
|
3
|
+
import type { AssignmentFact } from "../facts";
|
|
4
|
+
declare const plainAssignments: (node: Node, importMap: ImportMap) => AssignmentFact[];
|
|
5
|
+
declare const collectMutations: (node: Node, importMap: ImportMap) => AssignmentFact[];
|
|
6
|
+
export { plainAssignments, collectMutations };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectMutations = exports.plainAssignments = void 0;
|
|
4
|
+
// The SYNTAX pass over a write: a plain `=` into an imported binding or `this`
|
|
5
|
+
// (`state.x = …`), a `delete imported.x`, an `Object.freeze(imported)` /
|
|
6
|
+
// `Object.seal(…)`, and `f().x = …` pointed at the module that returns the
|
|
7
|
+
// object. Where a write lands in ANOTHER module's value — that is what these
|
|
8
|
+
// producers collect, from the raw AST alone.
|
|
9
|
+
const ts_morph_1 = require("ts-morph");
|
|
10
|
+
const tree_1 = require("./tree");
|
|
11
|
+
const properties_1 = require("./properties");
|
|
12
|
+
const kinds_1 = require("../kinds");
|
|
13
|
+
const assignments_nodes_1 = require("./assignments-nodes");
|
|
14
|
+
// Plain `=` assignments inside a candidate: the target, whether it is local,
|
|
15
|
+
// and the module it came from (an imported binding is somebody else's value).
|
|
16
|
+
const plainAssignments = (node, importMap) => node
|
|
17
|
+
.getDescendants()
|
|
18
|
+
.filter((d) => ts_morph_1.Node.isBinaryExpression(d) && d.getOperatorToken().getText() === "=" && (0, tree_1.inThisPiece)(node, d))
|
|
19
|
+
.map((a) => {
|
|
20
|
+
const lhs = a.getLeft();
|
|
21
|
+
const fn = (0, tree_1.isFunctionNode)(node) ? node : null;
|
|
22
|
+
return { line: lhs.getStartLineNumber(), target: lhs.getText(), via: kinds_1.VIA.ASSIGN, performed: true, value: (0, assignments_nodes_1.rootNameOf)(lhs), local: fn ? (0, assignments_nodes_1.isLocalTarget)(lhs, fn) : false, module: (0, properties_1.importModuleOf)(lhs, importMap), onThis: (0, properties_1.isThisChain)(lhs) };
|
|
23
|
+
});
|
|
24
|
+
exports.plainAssignments = plainAssignments;
|
|
25
|
+
// The write a `delete imported.x` makes, if it lands in another module.
|
|
26
|
+
const deleteWrite = (d, importMap) => {
|
|
27
|
+
if (!ts_morph_1.Node.isDeleteExpression(d))
|
|
28
|
+
return null;
|
|
29
|
+
const expr = d.getExpression();
|
|
30
|
+
const module = (0, properties_1.importModuleOf)(expr, importMap);
|
|
31
|
+
if (module)
|
|
32
|
+
return { line: d.getStartLineNumber(), target: expr.getText(), via: kinds_1.VIA.DELETE, performed: true, value: (0, assignments_nodes_1.rootNameOf)(expr), module };
|
|
33
|
+
if ((0, properties_1.isThisChain)(expr))
|
|
34
|
+
return { line: d.getStartLineNumber(), target: expr.getText(), via: kinds_1.VIA.DELETE, performed: true, value: (0, assignments_nodes_1.rootNameOf)(expr), onThis: true };
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
// `Object.freeze(x)` / `Object.seal(x)` on another module's value.
|
|
38
|
+
const freezeWrite = (d, importMap) => {
|
|
39
|
+
if (!ts_morph_1.Node.isCallExpression(d))
|
|
40
|
+
return null;
|
|
41
|
+
const callee = d.getExpression();
|
|
42
|
+
if (!ts_morph_1.Node.isPropertyAccessExpression(callee))
|
|
43
|
+
return null;
|
|
44
|
+
const fnName = callee.getName();
|
|
45
|
+
if (fnName !== "freeze" && fnName !== "seal")
|
|
46
|
+
return null;
|
|
47
|
+
const arg = d.getArguments()[0];
|
|
48
|
+
if (!arg)
|
|
49
|
+
return null;
|
|
50
|
+
const module = (0, properties_1.importModuleOf)(arg, importMap);
|
|
51
|
+
return module ? { line: d.getStartLineNumber(), target: arg.getText(), via: fnName, performed: true, value: (0, assignments_nodes_1.rootNameOf)(arg), module } : null;
|
|
52
|
+
};
|
|
53
|
+
// The assignment a `=` makes when it lands in another module's value, or in
|
|
54
|
+
// `this` — `f().x = …` points the write at the module that returns the object.
|
|
55
|
+
const assignWrite = (d, importMap) => {
|
|
56
|
+
if (!ts_morph_1.Node.isBinaryExpression(d) || d.getOperatorToken().getText() !== "=")
|
|
57
|
+
return null;
|
|
58
|
+
const lhs = d.getLeft();
|
|
59
|
+
const module = (0, properties_1.importModuleOf)(lhs, importMap);
|
|
60
|
+
if (module)
|
|
61
|
+
return { line: d.getStartLineNumber(), target: lhs.getText(), via: kinds_1.VIA.ASSIGN, performed: true, value: (0, assignments_nodes_1.rootNameOf)(lhs), module };
|
|
62
|
+
if ((0, properties_1.isThisChain)(lhs))
|
|
63
|
+
return { line: d.getStartLineNumber(), target: lhs.getText(), via: kinds_1.VIA.ASSIGN, performed: true, value: (0, assignments_nodes_1.rootNameOf)(lhs), onThis: true };
|
|
64
|
+
const call = (0, assignments_nodes_1.callRootOf)(lhs);
|
|
65
|
+
const calleeModule = call ? (0, properties_1.importModuleOf)(call.getExpression(), importMap) : null;
|
|
66
|
+
if (calleeModule)
|
|
67
|
+
return { line: d.getStartLineNumber(), target: lhs.getText(), via: kinds_1.VIA.ASSIGN, performed: true, value: (0, assignments_nodes_1.rootNameOf)(lhs), module: calleeModule };
|
|
68
|
+
return null;
|
|
69
|
+
};
|
|
70
|
+
// Writes into ANOTHER module's value: assignment to an imported binding,
|
|
71
|
+
// `delete imported.x`, and `Object.freeze(imported)` / `Object.seal(…)`.
|
|
72
|
+
// A class writes through its members, so it collects over the whole body; a
|
|
73
|
+
// function collects its own; a variable does not (its initializer's function is
|
|
74
|
+
// a candidate of its own — counting it twice would report the same write twice).
|
|
75
|
+
const collectMutations = (node, importMap) => {
|
|
76
|
+
const out = [];
|
|
77
|
+
for (const d of node.getDescendants()) {
|
|
78
|
+
if ((0, tree_1.isFunctionNode)(node) && !(0, tree_1.inThisPiece)(node, d))
|
|
79
|
+
continue;
|
|
80
|
+
const write = assignWrite(d, importMap) ?? deleteWrite(d, importMap) ?? freezeWrite(d, importMap);
|
|
81
|
+
if (write)
|
|
82
|
+
out.push(write);
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
};
|
|
86
|
+
exports.collectMutations = collectMutations;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Node, type SourceFile } from "ts-morph";
|
|
2
|
+
import { type ImportMap } from "./assignments-nodes";
|
|
3
|
+
import type { AssignmentFact } from "../facts";
|
|
4
|
+
declare const taggedWrites: (node: Node, sf: SourceFile, importMap: ImportMap, repoRoot: string) => AssignmentFact[];
|
|
5
|
+
export { taggedWrites };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taggedWrites = void 0;
|
|
4
|
+
// The TYPE pass over a write. Two shapes mean the same thing for a state-bag: an
|
|
5
|
+
// assignment into the value (`state.x = …`) and a METHOD CALL on it
|
|
6
|
+
// (`state.ranges.replace(…)`). The root identifier decides, so the parameter's
|
|
7
|
+
// name is irrelevant; the checker says whose value it is and where its type is
|
|
8
|
+
// declared.
|
|
9
|
+
const ts_morph_1 = require("ts-morph");
|
|
10
|
+
const tree_1 = require("./tree");
|
|
11
|
+
const properties_1 = require("./properties");
|
|
12
|
+
const file_1 = require("./file");
|
|
13
|
+
const notices_1 = require("../../report/notices");
|
|
14
|
+
const kinds_1 = require("../kinds");
|
|
15
|
+
const assignments_nodes_1 = require("./assignments-nodes");
|
|
16
|
+
// The resolved signature of a call, or null — a call whose import the checker
|
|
17
|
+
// cannot resolve is noticed and treated as not-a-write (never a crash).
|
|
18
|
+
const signatureOf = (call, checker) => {
|
|
19
|
+
try {
|
|
20
|
+
return checker.getResolvedSignature(call) ?? null;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const err = error;
|
|
24
|
+
(0, notices_1.notice)(`whether \`${call.getText()}\` writes could not be read`, err.message ? err.message : String(err));
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// Does a signature hand back no value? A mutating method returns `this`
|
|
29
|
+
// (`Map.set`, `Set.add`) or nothing (`state.setEnabled()`); a method that
|
|
30
|
+
// answers a question returns the answer (`has`, `get`).
|
|
31
|
+
const writesReturn = (sig) => {
|
|
32
|
+
const decl = sig.getDeclaration();
|
|
33
|
+
const retNode = decl?.getReturnTypeNode?.();
|
|
34
|
+
if (retNode) {
|
|
35
|
+
const kind = retNode.getKindName();
|
|
36
|
+
if (kind === "ThisType" || retNode.getText() === "void")
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
const text = sig.getReturnType().getText();
|
|
40
|
+
return text === "void" || text === "this";
|
|
41
|
+
};
|
|
42
|
+
// Does a method call WRITE into its receiver? A result nobody keeps
|
|
43
|
+
// (`bucket.splice(i, 1);`) was wanted for its effect; else the signature decides.
|
|
44
|
+
const methodWrites = (call, checker) => {
|
|
45
|
+
const parent = call.getParent();
|
|
46
|
+
if (parent && ts_morph_1.Node.isExpressionStatement(parent))
|
|
47
|
+
return true;
|
|
48
|
+
const sig = signatureOf(call, checker);
|
|
49
|
+
return sig ? writesReturn(sig) : false;
|
|
50
|
+
};
|
|
51
|
+
const declaredInRepo = (idNode, checker, repoRoot) => {
|
|
52
|
+
const decls = checker.getSymbolAtLocation(idNode)?.getDeclarations() ?? [];
|
|
53
|
+
if (!decls.length)
|
|
54
|
+
return true;
|
|
55
|
+
return decls.some((d) => (0, file_1.inRepo)(d.getSourceFile().getFilePath(), repoRoot));
|
|
56
|
+
};
|
|
57
|
+
// The file that declares the TYPE of a property (`state.document` → the type
|
|
58
|
+
// its declaration names, not the object literal the checker folded it into).
|
|
59
|
+
// An anonymous type has no symbol of its own, so the property's own type
|
|
60
|
+
// annotation is the only place the answer survives.
|
|
61
|
+
const declaredFileOfProp = (expr, checker, repoRoot) => {
|
|
62
|
+
if (!expr || !ts_morph_1.Node.isPropertyAccessExpression(expr))
|
|
63
|
+
return null;
|
|
64
|
+
for (const d of checker.getSymbolAtLocation(expr.getNameNode())?.getDeclarations() ?? []) {
|
|
65
|
+
const decl = d;
|
|
66
|
+
const tn = decl.getTypeNode?.();
|
|
67
|
+
const byNode = tn ? (0, file_1.declaredFileOfNode)(tn, checker, repoRoot) : null;
|
|
68
|
+
if (byNode)
|
|
69
|
+
return byNode;
|
|
70
|
+
}
|
|
71
|
+
return (0, file_1.declaredFileOfType)(expr.getType(), checker, repoRoot);
|
|
72
|
+
};
|
|
73
|
+
// The call a local holds the value through: `const ch = getRootStore()?.channel`
|
|
74
|
+
// — the initializer's call is the value's owner.
|
|
75
|
+
const initCallOf = (idNode, checker) => {
|
|
76
|
+
const decl = checker.getSymbolAtLocation(idNode)?.getDeclarations()?.[0];
|
|
77
|
+
const init = decl?.getInitializer?.();
|
|
78
|
+
if (!init)
|
|
79
|
+
return null;
|
|
80
|
+
return (0, assignments_nodes_1.callRootOf)(init) ?? (ts_morph_1.Node.isCallExpression(init) ? init : null);
|
|
81
|
+
};
|
|
82
|
+
// The initializer text a local root is an alias of (`const s = state` → `state`);
|
|
83
|
+
// null when the root is not a local with an initializer.
|
|
84
|
+
const aliasTextOf = (rootNode, checker) => {
|
|
85
|
+
const decl = checker.getSymbolAtLocation(rootNode)?.getDeclarations()?.[0];
|
|
86
|
+
return decl?.getInitializer?.()?.getText() ?? null;
|
|
87
|
+
};
|
|
88
|
+
// The parameter of the piece named `root`, when the root is one of its parameters.
|
|
89
|
+
const findParam = (node, root) => {
|
|
90
|
+
if (!root)
|
|
91
|
+
return null;
|
|
92
|
+
const params = ts_morph_1.Node.isFunctionLikeDeclaration(node) ? node.getParameters() : [];
|
|
93
|
+
return params.find((prm) => prm.getName() === root) ?? null;
|
|
94
|
+
};
|
|
95
|
+
// Which write shape a node is, or null. An assignment needs a property access on
|
|
96
|
+
// the value (`x.y = …` is a write into `x`); a call needs a mutating method on it.
|
|
97
|
+
const resolveReceiver = (d, checker) => {
|
|
98
|
+
if (ts_morph_1.Node.isBinaryExpression(d) && d.getOperatorToken().getText() === "=") {
|
|
99
|
+
const lhs = d.getLeft();
|
|
100
|
+
return ts_morph_1.Node.isPropertyAccessExpression(lhs) ? { receiver: lhs.getExpression(), via: kinds_1.VIA.ASSIGN } : null;
|
|
101
|
+
}
|
|
102
|
+
if (ts_morph_1.Node.isCallExpression(d)) {
|
|
103
|
+
const callee = d.getExpression();
|
|
104
|
+
if (!ts_morph_1.Node.isPropertyAccessExpression(callee) || !methodWrites(d, checker))
|
|
105
|
+
return null;
|
|
106
|
+
return { receiver: callee.getExpression(), via: kinds_1.VIA.CALL };
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
110
|
+
// Is the written root something the repo owns? A named root is one only if the
|
|
111
|
+
// checker declares it in the repo; a root reached through a call is one when the
|
|
112
|
+
// callee is imported or itself declared in the repo.
|
|
113
|
+
const validRoot = (rootNode, callRoot, ctx) => {
|
|
114
|
+
if (rootNode)
|
|
115
|
+
return declaredInRepo(rootNode, ctx.checker, ctx.repoRoot);
|
|
116
|
+
if (callRoot)
|
|
117
|
+
return Boolean((0, properties_1.importModuleOf)(callRoot.getExpression(), ctx.importMap)) || declaredInRepo(callRoot.getExpression(), ctx.checker, ctx.repoRoot);
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
// The root a write goes through, with the module a call-rooted value comes from.
|
|
121
|
+
const rootContext = (receiver, ctx) => {
|
|
122
|
+
const rootNode = (0, assignments_nodes_1.rootNodeOf)(receiver);
|
|
123
|
+
const callRoot = rootNode ? null : (0, assignments_nodes_1.callRootOf)(receiver);
|
|
124
|
+
if (!validRoot(rootNode, callRoot, ctx))
|
|
125
|
+
return null;
|
|
126
|
+
const root = rootNode ? rootNode.getText() : null;
|
|
127
|
+
const fromCall = callRoot ? (0, properties_1.importModuleOf)(callRoot.getExpression(), ctx.importMap) : null;
|
|
128
|
+
return { rootNode, root, fromCall };
|
|
129
|
+
};
|
|
130
|
+
// The repo file that declares the written value's TYPE, reading the nearest
|
|
131
|
+
// declared type first (`state.cache` vs `state.host` land in different files).
|
|
132
|
+
const writeDeclFile = (info, ctx) => {
|
|
133
|
+
const rootDecl = info.param ? (0, file_1.declaredFileOf)(info.param, ctx.checker, ctx.repoRoot) : (0, file_1.declaredFileOfExpr)(info.rootNode, ctx.checker, ctx.repoRoot);
|
|
134
|
+
const nearDecl = info.receiver.getText() === info.root ? null : (declaredFileOfProp(info.receiver, ctx.checker, ctx.repoRoot) ?? (0, file_1.declaredFileOfExpr)(info.receiver, ctx.checker, ctx.repoRoot));
|
|
135
|
+
const decl = nearDecl?.file && (0, file_1.inRepo)(nearDecl.file, ctx.repoRoot) ? nearDecl : rootDecl;
|
|
136
|
+
return decl?.file && (0, file_1.inRepo)(decl.file, ctx.repoRoot) ? decl.file : null;
|
|
137
|
+
};
|
|
138
|
+
// The method's own name for a call write (`state.set(…)` → `set`), or null.
|
|
139
|
+
const methodNameOf = (d, via) => {
|
|
140
|
+
if (via !== kinds_1.VIA.CALL || !ts_morph_1.Node.isCallExpression(d))
|
|
141
|
+
return null;
|
|
142
|
+
const callee = d.getExpression();
|
|
143
|
+
return ts_morph_1.Node.isPropertyAccessExpression(callee) ? callee.getName() : null;
|
|
144
|
+
};
|
|
145
|
+
// The written name and method for a tagged write: `store.x` where the root is an
|
|
146
|
+
// alias of a call is rewritten to the call (`getRootStore().x`).
|
|
147
|
+
const taggedTarget = (d, info) => {
|
|
148
|
+
const written = info.via === kinds_1.VIA.ASSIGN && ts_morph_1.Node.isBinaryExpression(d) ? d.getLeft().getText() : info.receiver.getText();
|
|
149
|
+
const target = info.aliasText && info.root && info.initCall ? written.replace(new RegExp(`^${info.root}\\b`), info.aliasText) : written;
|
|
150
|
+
return { line: (0, tree_1.startLine)(d), target, method: methodNameOf(d, info.via), via: info.via };
|
|
151
|
+
};
|
|
152
|
+
// One write into a value the piece does not own — the root resolved, its type
|
|
153
|
+
// found, its target spelled — or null when the node is no such write.
|
|
154
|
+
const taggedWriteOf = (d, ctx) => {
|
|
155
|
+
const rec = resolveReceiver(d, ctx.checker);
|
|
156
|
+
if (!rec)
|
|
157
|
+
return null;
|
|
158
|
+
const rooted = rootContext(rec.receiver, ctx);
|
|
159
|
+
if (!rooted)
|
|
160
|
+
return null;
|
|
161
|
+
const { rootNode, root, fromCall } = rooted;
|
|
162
|
+
const initCall = rootNode ? initCallOf(rootNode, ctx.checker) : null;
|
|
163
|
+
const aliasText = rootNode ? aliasTextOf(rootNode, ctx.checker) : null;
|
|
164
|
+
const fromInit = initCall ? (0, properties_1.importModuleOf)(initCall.getExpression(), ctx.importMap) : null;
|
|
165
|
+
const param = findParam(ctx.node, root);
|
|
166
|
+
const type = writeDeclFile({ rootNode, receiver: rec.receiver, root, param }, ctx);
|
|
167
|
+
const performed = rec.via === kinds_1.VIA.ASSIGN || Boolean(param);
|
|
168
|
+
return { ...taggedTarget(d, { receiver: rec.receiver, via: rec.via, root, aliasText, initCall }), value: root, performed, type, module: fromCall ?? fromInit ?? undefined, param: Boolean(param) };
|
|
169
|
+
};
|
|
170
|
+
// Writes into a value the function does not own — assignment into the value or
|
|
171
|
+
// a mutating method call on it — across the whole piece.
|
|
172
|
+
const taggedWrites = (node, sf, importMap, repoRoot) => {
|
|
173
|
+
const ctx = { node, checker: sf.getProject().getTypeChecker(), importMap, repoRoot };
|
|
174
|
+
return node
|
|
175
|
+
.getDescendants()
|
|
176
|
+
.filter((d) => (0, tree_1.inThisPiece)(node, d))
|
|
177
|
+
.map((d) => taggedWriteOf(d, ctx))
|
|
178
|
+
.filter((e) => e !== null);
|
|
179
|
+
};
|
|
180
|
+
exports.taggedWrites = taggedWrites;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Node, type SourceFile } from "ts-morph";
|
|
2
|
+
import type { ImportMap } from "./assignments-nodes";
|
|
3
|
+
import type { AssignmentFact } from "../facts";
|
|
4
|
+
declare const relationOf: (entry: Partial<AssignmentFact>, rel: string | null) => string | null;
|
|
5
|
+
declare const assignmentsFact: (node: Node, sf: SourceFile, importMap: ImportMap, ctx: {
|
|
6
|
+
repoRoot: string;
|
|
7
|
+
rel: string | null;
|
|
8
|
+
}) => AssignmentFact[];
|
|
9
|
+
export { assignmentsFact, relationOf };
|