@md-code/follow-architecture 0.1.1 → 0.3.2
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 +37 -0
- package/LICENSE +202 -0
- package/README.md +1420 -139
- package/dist/aliases.d.ts +3 -0
- package/dist/aliases.js +12 -0
- package/dist/args.d.ts +18 -0
- package/dist/args.js +94 -0
- package/dist/bin/follow-architecture.d.ts +2 -0
- package/dist/bin/follow-architecture.js +23 -0
- package/dist/closure-project.d.ts +4 -0
- package/dist/closure-project.js +132 -0
- package/dist/code-entities/classify.d.ts +11 -0
- package/dist/code-entities/classify.js +45 -0
- package/dist/code-entities/connector.d.ts +8 -0
- package/dist/code-entities/connector.js +119 -0
- package/dist/code-entities/entities.d.ts +9 -0
- package/dist/code-entities/entities.js +227 -0
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +259 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +105 -0
- package/dist/config-options.d.ts +76 -0
- package/dist/config-options.js +52 -0
- package/dist/config-project.d.ts +4 -0
- package/dist/config-project.js +92 -0
- package/dist/config-report.d.ts +19 -0
- package/dist/config-report.js +161 -0
- package/dist/config-rule.d.ts +95 -0
- package/dist/config-rule.js +211 -0
- package/dist/config-state.d.ts +25 -0
- package/dist/config-state.js +269 -0
- package/dist/config.d.ts +107 -0
- package/dist/config.js +38 -0
- package/dist/css/index.d.ts +31 -0
- package/dist/css/index.js +251 -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 +51 -0
- package/dist/css/syntax/css/reference.d.ts +3 -0
- package/dist/css/syntax/css/reference.js +36 -0
- package/dist/css/syntax/language.d.ts +25 -0
- package/dist/css/syntax/language.js +81 -0
- package/dist/css/syntax/scss/index.d.ts +25 -0
- package/dist/css/syntax/scss/index.js +95 -0
- package/dist/css/syntax/scss/reference.d.ts +3 -0
- package/dist/css/syntax/scss/reference.js +17 -0
- package/dist/css/syntax/styled/document.d.ts +68 -0
- package/dist/css/syntax/styled/document.js +261 -0
- package/dist/css/syntax/styled/markup.d.ts +6 -0
- package/dist/css/syntax/styled/markup.js +84 -0
- package/dist/css/syntax/styled/tags.d.ts +2 -0
- package/dist/css/syntax/styled/tags.js +22 -0
- package/dist/css/syntax/styled/template.d.ts +23 -0
- package/dist/css/syntax/styled/template.js +67 -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 +73 -0
- package/dist/css/value/expression/block.d.ts +9 -0
- package/dist/css/value/expression/block.js +92 -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 +73 -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 +113 -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 +134 -0
- package/dist/css/value/object/path.d.ts +10 -0
- package/dist/css/value/object/path.js +152 -0
- package/dist/css/value/pieces.d.ts +61 -0
- package/dist/css/value/pieces.js +65 -0
- package/dist/css/value/resolve.d.ts +33 -0
- package/dist/css/value/resolve.js +104 -0
- package/dist/css/value/scope.d.ts +28 -0
- package/dist/css/value/scope.js +205 -0
- package/dist/css/value/substitute.d.ts +10 -0
- package/dist/css/value/substitute.js +145 -0
- package/dist/css/value/values.d.ts +23 -0
- package/dist/css/value/values.js +131 -0
- package/dist/entities/architecture.d.ts +165 -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 +139 -0
- package/dist/entities/ast/assignments-tagged.d.ts +5 -0
- package/dist/entities/ast/assignments-tagged.js +195 -0
- package/dist/entities/ast/assignments.d.ts +9 -0
- package/dist/entities/ast/assignments.js +80 -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 +150 -0
- package/dist/entities/ast/classes.d.ts +5 -0
- package/dist/entities/ast/classes.js +61 -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 +5 -0
- package/dist/entities/ast/comments.js +130 -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 +166 -0
- package/dist/entities/ast/enums.d.ts +6 -0
- package/dist/entities/ast/enums.js +17 -0
- package/dist/entities/ast/export-chain.d.ts +15 -0
- package/dist/entities/ast/export-chain.js +171 -0
- package/dist/entities/ast/file-exports.d.ts +7 -0
- package/dist/entities/ast/file-exports.js +101 -0
- package/dist/entities/ast/file-facts.d.ts +16 -0
- package/dist/entities/ast/file-facts.js +64 -0
- package/dist/entities/ast/file-imports.d.ts +5 -0
- package/dist/entities/ast/file-imports.js +100 -0
- package/dist/entities/ast/file.d.ts +5 -0
- package/dist/entities/ast/file.js +23 -0
- package/dist/entities/ast/functions.d.ts +8 -0
- package/dist/entities/ast/functions.js +111 -0
- package/dist/entities/ast/heritage.d.ts +4 -0
- package/dist/entities/ast/heritage.js +44 -0
- package/dist/entities/ast/index.d.ts +9 -0
- package/dist/entities/ast/index.js +181 -0
- package/dist/entities/ast/kind.d.ts +5 -0
- package/dist/entities/ast/kind.js +34 -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 +106 -0
- package/dist/entities/ast/properties.d.ts +11 -0
- package/dist/entities/ast/properties.js +176 -0
- package/dist/entities/ast/resolve.d.ts +16 -0
- package/dist/entities/ast/resolve.js +317 -0
- package/dist/entities/ast/tree.d.ts +31 -0
- package/dist/entities/ast/tree.js +518 -0
- package/dist/entities/ast/types.d.ts +6 -0
- package/dist/entities/ast/types.js +46 -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 +284 -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 +332 -0
- package/dist/entities/location/homes.d.ts +28 -0
- package/dist/entities/location/homes.js +195 -0
- package/dist/entities/location/place.d.ts +10 -0
- package/dist/entities/location/place.js +63 -0
- package/dist/entities/location/where.d.ts +19 -0
- package/dist/entities/location/where.js +277 -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 +82 -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 +81 -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 +375 -0
- package/dist/entities/repair.d.ts +16 -0
- package/dist/entities/repair.js +29 -0
- package/dist/entities/schema.d.ts +22 -0
- package/dist/entities/schema.js +81 -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 +6 -0
- package/dist/entities/tree/build.js +313 -0
- package/dist/entities/tree/entries.d.ts +7 -0
- package/dist/entities/tree/entries.js +145 -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 +190 -0
- package/dist/fa-index.d.ts +16 -0
- package/dist/fa-index.js +165 -0
- package/dist/fa-open.d.ts +51 -0
- package/dist/fa-open.js +242 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +232 -0
- package/dist/fa-values.d.ts +37 -0
- package/dist/fa-values.js +104 -0
- package/dist/facts-record.d.ts +45 -0
- package/dist/facts-record.js +297 -0
- package/dist/frameworks/angular/index.d.ts +7 -0
- package/dist/frameworks/angular/index.js +18 -0
- package/dist/frameworks/facet.d.ts +18 -0
- package/dist/frameworks/facet.js +15 -0
- package/dist/frameworks/index.d.ts +9 -0
- package/dist/frameworks/index.js +134 -0
- package/dist/frameworks/react/index.d.ts +7 -0
- package/dist/frameworks/react/index.js +237 -0
- package/dist/frameworks/test/index.d.ts +6 -0
- package/dist/frameworks/test/index.js +157 -0
- package/dist/frameworks/vue/index.d.ts +7 -0
- package/dist/frameworks/vue/index.js +18 -0
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.js +62 -0
- package/dist/index-file.d.ts +43 -0
- package/dist/index-file.js +218 -0
- package/dist/index-run.d.ts +39 -0
- package/dist/index-run.js +217 -0
- package/dist/index-zone.d.ts +25 -0
- package/dist/index-zone.js +219 -0
- package/dist/main.d.ts +10 -0
- package/dist/main.js +411 -0
- package/dist/nodes/child-entities.d.ts +3 -0
- package/dist/nodes/child-entities.js +12 -0
- package/dist/nodes/children.d.ts +25 -0
- package/dist/nodes/children.js +165 -0
- package/dist/nodes/finally/emit.d.ts +6 -0
- package/dist/nodes/finally/emit.js +71 -0
- package/dist/nodes/finally/entities.d.ts +13 -0
- package/dist/nodes/finally/entities.js +42 -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 +25 -0
- package/dist/nodes/finally/relations-access.d.ts +5 -0
- package/dist/nodes/finally/relations-access.js +50 -0
- package/dist/nodes/finally/relations-edge.d.ts +29 -0
- package/dist/nodes/finally/relations-edge.js +148 -0
- package/dist/nodes/finally/relations-group.d.ts +31 -0
- package/dist/nodes/finally/relations-group.js +106 -0
- package/dist/nodes/finally/relations.d.ts +5 -0
- package/dist/nodes/finally/relations.js +85 -0
- package/dist/nodes/finally/required.d.ts +5 -0
- package/dist/nodes/finally/required.js +92 -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 +178 -0
- package/dist/piece-forms.d.ts +9 -0
- package/dist/piece-forms.js +68 -0
- package/dist/pipeline-entities.d.ts +6 -0
- package/dist/pipeline-entities.js +79 -0
- package/dist/pipeline-facts.d.ts +12 -0
- package/dist/pipeline-facts.js +114 -0
- package/dist/pipeline-unclassified.d.ts +14 -0
- package/dist/pipeline-unclassified.js +188 -0
- package/dist/pipeline.d.ts +7 -0
- package/dist/pipeline.js +28 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +3 -0
- package/dist/release-file.d.ts +3 -0
- package/dist/release-file.js +13 -0
- package/dist/report/asks.d.ts +55 -0
- package/dist/report/asks.js +60 -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 +126 -0
- package/dist/report/configErrors.js +121 -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 +109 -0
- package/dist/report/errorTypes/destinations.d.ts +38 -0
- package/dist/report/errorTypes/destinations.js +165 -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 +55 -0
- package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
- package/dist/report/errorTypes/types/fileContents.js +40 -0
- package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
- package/dist/report/errorTypes/types/unknownEntity.js +27 -0
- package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
- package/dist/report/errorTypes/types/wrongAction.js +140 -0
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
- package/dist/report/errorTypes/types/wrongPlacement.js +67 -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 +187 -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 +108 -0
- package/dist/report/notices.d.ts +9 -0
- package/dist/report/notices.js +57 -0
- package/dist/report/observed.d.ts +19 -0
- package/dist/report/observed.js +87 -0
- package/dist/report/render-report.d.ts +12 -0
- package/dist/report/render-report.js +145 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +188 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +1262 -0
- package/dist/report/user-report/data/collect.d.ts +4 -0
- package/dist/report/user-report/data/collect.js +93 -0
- package/dist/report/user-report/data/entities.d.ts +7 -0
- package/dist/report/user-report/data/entities.js +88 -0
- package/dist/report/user-report/data/entity-examples.d.ts +16 -0
- package/dist/report/user-report/data/entity-examples.js +136 -0
- package/dist/report/user-report/data/entity-filters.d.ts +15 -0
- package/dist/report/user-report/data/entity-filters.js +79 -0
- package/dist/report/user-report/data/entity-marks.d.ts +5 -0
- package/dist/report/user-report/data/entity-marks.js +79 -0
- package/dist/report/user-report/data/file-tree.d.ts +9 -0
- package/dist/report/user-report/data/file-tree.js +80 -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 +181 -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-entities.d.ts +6 -0
- package/dist/report/user-report/data/graph-entities.js +158 -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.d.ts +12 -0
- package/dist/report/user-report/data/graph.js +97 -0
- package/dist/report/user-report/data/nodes.d.ts +11 -0
- package/dist/report/user-report/data/nodes.js +116 -0
- package/dist/report/user-report/data/rules.d.ts +7 -0
- package/dist/report/user-report/data/rules.js +62 -0
- package/dist/report/user-report/data/scan.d.ts +8 -0
- package/dist/report/user-report/data/scan.js +69 -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 +58 -0
- package/dist/report/user-report/shared/describe.d.ts +7 -0
- package/dist/report/user-report/shared/describe.js +86 -0
- package/dist/rules/index.d.ts +7 -0
- package/dist/rules/index.js +327 -0
- package/dist/rules/list-vars.d.ts +5 -0
- package/dist/rules/list-vars.js +149 -0
- package/dist/rules/name.d.ts +16 -0
- package/dist/rules/name.js +18 -0
- package/dist/rules/normalize.d.ts +5 -0
- package/dist/rules/normalize.js +108 -0
- package/dist/rules/vars.d.ts +22 -0
- package/dist/rules/vars.js +117 -0
- package/dist/scan-run.d.ts +20 -0
- package/dist/scan-run.js +130 -0
- package/dist/scripts/audit-report.d.ts +2 -0
- package/dist/scripts/audit-report.js +157 -0
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +282 -0
- package/dist/usage-mode.d.ts +7 -0
- package/dist/usage-mode.js +16 -0
- package/dist/usage-pass.d.ts +19 -0
- package/dist/usage-pass.js +136 -0
- package/dist/usage-prepare.d.ts +2 -0
- package/dist/usage-prepare.js +22 -0
- package/dist/usage-sweep.d.ts +10 -0
- package/dist/usage-sweep.js +264 -0
- package/dist/utils/accumulate.d.ts +6 -0
- package/dist/utils/accumulate.js +18 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +173 -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 +97 -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 +14 -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 +77 -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 +16 -0
- package/dist/utils/imports.d.ts +12 -0
- package/dist/utils/imports.js +185 -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/packages.d.ts +15 -0
- package/dist/utils/packages.js +207 -0
- package/dist/utils/path-label.d.ts +6 -0
- package/dist/utils/path-label.js +37 -0
- package/dist/utils/pattern.d.ts +19 -0
- package/dist/utils/pattern.js +231 -0
- package/dist/utils/permission.d.ts +16 -0
- package/dist/utils/permission.js +18 -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 +21 -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 +21 -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 +18 -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 +101 -47
- package/report/errorTypes/vocabulary/ids.ts +17 -0
- package/report/errorTypes/vocabulary/phrases.ts +181 -0
- package/report/errorTypes/vocabulary/places.ts +51 -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,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keyOf = exports.literalTextOf = exports.rootIdentifierOf = exports.chainPath = exports.initializerOf = exports.pathReadings = exports.pathValueOf = exports.leafValueOf = exports.valueTextOf = exports.unwrap = void 0;
|
|
4
|
+
// THE PATH WALK: the literal at the bottom of a member path, read out of the
|
|
5
|
+
// project's object literals. An expression writes `spec.colors.section` — that is
|
|
6
|
+
// a PATH, and the value at the bottom is whatever literal the project declared
|
|
7
|
+
// there. Nothing here knows which object is "the palette": the path is matched
|
|
8
|
+
// against every object literal the scope carries, and the literals that match are
|
|
9
|
+
// the variants.
|
|
10
|
+
//
|
|
11
|
+
// A leaf is not always a literal — it may compute (`basicOffset * 2`) or point at
|
|
12
|
+
// another path (`height: screens.tabletHeight`) — so those shapes are folded to
|
|
13
|
+
// the literal they reach. A visited set makes a cyclic literal terminate instead
|
|
14
|
+
// of overflow.
|
|
15
|
+
const ts_morph_1 = require("ts-morph");
|
|
16
|
+
const tree_1 = require("@md-code/follow-architecture/entities/ast/tree");
|
|
17
|
+
const node_1 = require("./node");
|
|
18
|
+
Object.defineProperty(exports, "chainPath", { enumerable: true, get: function () { return node_1.chainPath; } });
|
|
19
|
+
Object.defineProperty(exports, "initializerOf", { enumerable: true, get: function () { return node_1.initializerOf; } });
|
|
20
|
+
Object.defineProperty(exports, "keyOf", { enumerable: true, get: function () { return node_1.keyOf; } });
|
|
21
|
+
Object.defineProperty(exports, "literalTextOf", { enumerable: true, get: function () { return node_1.literalTextOf; } });
|
|
22
|
+
Object.defineProperty(exports, "rootIdentifierOf", { enumerable: true, get: function () { return node_1.rootIdentifierOf; } });
|
|
23
|
+
Object.defineProperty(exports, "unwrap", { enumerable: true, get: function () { return node_1.unwrap; } });
|
|
24
|
+
// Two numeric arrays are folded by the operator table below; anything not in it
|
|
25
|
+
// is left to the walkers.
|
|
26
|
+
const ARITHMETIC = new Map([
|
|
27
|
+
["+", (left, right) => left + right],
|
|
28
|
+
["-", (left, right) => left - right],
|
|
29
|
+
["*", (left, right) => left * right],
|
|
30
|
+
["/", (left, right) => left / right],
|
|
31
|
+
]);
|
|
32
|
+
// One arithmetic operand as a number, or null when it is not numeric.
|
|
33
|
+
const numericOperand = (node, seen) => {
|
|
34
|
+
const text = valueTextOf(node, seen);
|
|
35
|
+
const value = text === null ? Number.NaN : Number(text);
|
|
36
|
+
return Number.isFinite(value) ? value : null;
|
|
37
|
+
};
|
|
38
|
+
const combineOperands = (combine, binary, seen) => {
|
|
39
|
+
if (!ts_morph_1.Node.isBinaryExpression(binary))
|
|
40
|
+
return null;
|
|
41
|
+
const left = numericOperand(binary.getLeft(), seen);
|
|
42
|
+
const right = numericOperand(binary.getRight(), seen);
|
|
43
|
+
if (left === null || right === null)
|
|
44
|
+
return null;
|
|
45
|
+
const result = combine(left, right);
|
|
46
|
+
return Number.isFinite(result) ? String(result) : null;
|
|
47
|
+
};
|
|
48
|
+
const arithmeticTextOf = (current, seen) => {
|
|
49
|
+
if (ts_morph_1.Node.isPrefixUnaryExpression(current) && current.getOperatorToken() === tree_1.SK.MinusToken) {
|
|
50
|
+
const operand = numericOperand(current.getOperand(), seen);
|
|
51
|
+
return operand === null ? null : String(-operand);
|
|
52
|
+
}
|
|
53
|
+
if (!ts_morph_1.Node.isBinaryExpression(current))
|
|
54
|
+
return null;
|
|
55
|
+
const combine = ARITHMETIC.get(current.getOperatorToken().getText());
|
|
56
|
+
return combine ? combineOperands(combine, current, seen) : null;
|
|
57
|
+
};
|
|
58
|
+
// A chain whose head is a name (`sizes: baseScale.font.sizes`): follow the name
|
|
59
|
+
// to its initializer, then walk the rest of the chain plus the remaining path.
|
|
60
|
+
const chainedValueOf = (node, path, seen) => {
|
|
61
|
+
if (ts_morph_1.Node.isIdentifier(node))
|
|
62
|
+
return pathValueOf((0, node_1.initializerOf)(node), path, new Set([...seen, node]));
|
|
63
|
+
if (!ts_morph_1.Node.isPropertyAccessExpression(node) && !ts_morph_1.Node.isElementAccessExpression(node))
|
|
64
|
+
return null;
|
|
65
|
+
const rest = (0, node_1.chainPath)(node);
|
|
66
|
+
const root = (0, node_1.rootIdentifierOf)(node);
|
|
67
|
+
if (!rest || !ts_morph_1.Node.isIdentifier(root))
|
|
68
|
+
return null;
|
|
69
|
+
return pathValueOf((0, node_1.initializerOf)(root), [...rest.slice(1), ...path], new Set([...seen, node]));
|
|
70
|
+
};
|
|
71
|
+
// The text a node stands for: a literal, an arithmetic fold, or a path through a
|
|
72
|
+
// local object.
|
|
73
|
+
const valueTextOf = (node, seen) => {
|
|
74
|
+
const current = (0, node_1.unwrap)(node);
|
|
75
|
+
const literal = (0, node_1.literalTextOf)(current);
|
|
76
|
+
if (literal !== null)
|
|
77
|
+
return literal;
|
|
78
|
+
const arithmetic = arithmeticTextOf(current, seen);
|
|
79
|
+
return arithmetic === null ? chainedValueOf(current, [], seen) : arithmetic;
|
|
80
|
+
};
|
|
81
|
+
exports.valueTextOf = valueTextOf;
|
|
82
|
+
// A leaf is not always a literal: a value may compute it or point at another
|
|
83
|
+
// object's member, so both shapes are folded here.
|
|
84
|
+
const leafValueOf = (node, seen) => valueTextOf(node, seen);
|
|
85
|
+
exports.leafValueOf = leafValueOf;
|
|
86
|
+
// One property of an object literal, matched against the path's head. A spread
|
|
87
|
+
// is not a named property: it is followed and the SAME path is searched there
|
|
88
|
+
// (`{...base, colors}` keeps the base's values).
|
|
89
|
+
const propertyValueOf = (property, path, seen) => {
|
|
90
|
+
if (ts_morph_1.Node.isPropertyAssignment(property) && (0, node_1.keyOf)(property.getName()) === path[0])
|
|
91
|
+
return pathValueOf(property.getInitializer(), path.slice(1), seen);
|
|
92
|
+
if (ts_morph_1.Node.isShorthandPropertyAssignment(property) && (0, node_1.keyOf)(property.getName()) === path[0])
|
|
93
|
+
return pathValueOf(property.getNameNode(), path.slice(1), seen);
|
|
94
|
+
if (ts_morph_1.Node.isSpreadAssignment(property))
|
|
95
|
+
return pathValueOf(property.getExpression(), path, seen);
|
|
96
|
+
return null;
|
|
97
|
+
};
|
|
98
|
+
const objectValueOf = (literal, path, seen) => {
|
|
99
|
+
for (const property of literal.getProperties()) {
|
|
100
|
+
const found = propertyValueOf(property, path, new Set([...seen, property]));
|
|
101
|
+
if (found !== null)
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
106
|
+
const leafReader = (node, _path, seen) => leafValueOf(node, seen);
|
|
107
|
+
const objectReader = (node, path, seen) => ts_morph_1.Node.isObjectLiteralExpression(node) ? objectValueOf(node, path, seen) : null;
|
|
108
|
+
const chainReader = (node, path, seen) => chainedValueOf(node, path, seen);
|
|
109
|
+
const readerFor = (node, path) => {
|
|
110
|
+
if (path.length === 0)
|
|
111
|
+
return leafReader;
|
|
112
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(node))
|
|
113
|
+
return objectReader;
|
|
114
|
+
return chainReader;
|
|
115
|
+
};
|
|
116
|
+
// Walk an object literal by a property path and read the literal at the bottom.
|
|
117
|
+
// A visited set makes a cyclic literal terminate instead of overflow.
|
|
118
|
+
const pathValueOf = (node, path, seen) => {
|
|
119
|
+
if (!node)
|
|
120
|
+
return null;
|
|
121
|
+
const current = (0, node_1.unwrap)(node);
|
|
122
|
+
if (seen.has(current))
|
|
123
|
+
return null;
|
|
124
|
+
return readerFor(current, path)(current, path, new Set([...seen, current]));
|
|
125
|
+
};
|
|
126
|
+
exports.pathValueOf = pathValueOf;
|
|
127
|
+
// A path is resolved by SUFFIX, longest first: `p.design.colors.section` has the
|
|
128
|
+
// suffix `colors.section`, and `design.colors.section` has the same one. The
|
|
129
|
+
// object literal is not named — whichever suffix the literals actually carry is
|
|
130
|
+
// the path. Every literal is asked: those that carry the path supply a reading,
|
|
131
|
+
// those that do not are reported `absent` (so a fixed path missing in one variant
|
|
132
|
+
// blames that literal).
|
|
133
|
+
const pathReadings = (path, scope) => {
|
|
134
|
+
for (let start = 0; start < path.length; start += 1) {
|
|
135
|
+
const suffix = path.slice(start);
|
|
136
|
+
const hits = scope.objects.map((object) => ({
|
|
137
|
+
name: object.name,
|
|
138
|
+
value: pathValueOf(object.node, suffix, new Set()),
|
|
139
|
+
}));
|
|
140
|
+
const present = hits.filter((hit) => hit.value !== null);
|
|
141
|
+
if (!present.length)
|
|
142
|
+
continue;
|
|
143
|
+
const absent = hits.filter((hit) => hit.value === null).map((hit) => hit.name);
|
|
144
|
+
const distinct = [...new Map(present.map((hit) => [hit.value, hit])).values()];
|
|
145
|
+
return {
|
|
146
|
+
readings: distinct.map((hit) => ({ text: hit.value, origin: distinct.length > 1 ? hit.name : null })),
|
|
147
|
+
absent,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
};
|
|
152
|
+
exports.pathReadings = pathReadings;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { TemplateExpr } from "@md-code/follow-architecture/css/syntax/styled/template";
|
|
2
|
+
import type { Span } from "@md-code/follow-architecture/utils/span";
|
|
3
|
+
type Piece = {
|
|
4
|
+
kind: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "expr";
|
|
8
|
+
index: number;
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
type BranchProblem = {
|
|
12
|
+
kind: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
};
|
|
16
|
+
type Branch = {
|
|
17
|
+
text: string;
|
|
18
|
+
object: string | null;
|
|
19
|
+
media: string | null;
|
|
20
|
+
problems: BranchProblem[];
|
|
21
|
+
directive?: boolean;
|
|
22
|
+
dynamic?: boolean;
|
|
23
|
+
absent?: {
|
|
24
|
+
object: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
type ObjectReading = {
|
|
29
|
+
text: string;
|
|
30
|
+
origin: string | null;
|
|
31
|
+
dynamic?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type ObjectRead = {
|
|
34
|
+
readings: ObjectReading[];
|
|
35
|
+
absent: string[];
|
|
36
|
+
};
|
|
37
|
+
type ValueResult = {
|
|
38
|
+
values: ObjectReading[];
|
|
39
|
+
problems: BranchProblem[];
|
|
40
|
+
directive?: boolean;
|
|
41
|
+
absent?: string[];
|
|
42
|
+
dynamic?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type Bindings = ReadonlyMap<string, string>;
|
|
45
|
+
declare const NO_BINDINGS: Bindings;
|
|
46
|
+
declare const DYNAMIC_PLACEHOLDER = "1";
|
|
47
|
+
declare const oneValue: (value: string) => ValueResult;
|
|
48
|
+
declare const noValue: (problem: BranchProblem) => ValueResult;
|
|
49
|
+
declare const blockResult: () => ValueResult;
|
|
50
|
+
declare const dynamicValue: () => ValueResult;
|
|
51
|
+
declare const absentResult: (read: ObjectRead) => ValueResult;
|
|
52
|
+
declare const combine: (...results: ValueResult[]) => ValueResult;
|
|
53
|
+
declare const piecesOfRange: (text: string, exprs: readonly TemplateExpr[], span: {
|
|
54
|
+
from: number;
|
|
55
|
+
to: number;
|
|
56
|
+
base: number;
|
|
57
|
+
}) => Piece[];
|
|
58
|
+
declare const rawValueOf: (pieces: Piece[]) => string;
|
|
59
|
+
declare const collapseSpaces: (text: string) => string;
|
|
60
|
+
export { NO_BINDINGS, DYNAMIC_PLACEHOLDER, oneValue, noValue, blockResult, dynamicValue, absentResult, combine, piecesOfRange, rawValueOf, collapseSpaces, };
|
|
61
|
+
export type { Piece, Branch, BranchProblem, ObjectReading, ObjectRead, ValueResult, Bindings, Span };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collapseSpaces = exports.rawValueOf = exports.piecesOfRange = exports.combine = exports.absentResult = exports.dynamicValue = exports.blockResult = exports.noValue = exports.oneValue = exports.DYNAMIC_PLACEHOLDER = exports.NO_BINDINGS = void 0;
|
|
4
|
+
const NO_BINDINGS = new Map();
|
|
5
|
+
exports.NO_BINDINGS = NO_BINDINGS;
|
|
6
|
+
// The placeholder a dynamic value contributes while a template is folded: `1`
|
|
7
|
+
// completes `1fr`, `1%`, `url(1)` — the SHAPE around it is what gets checked.
|
|
8
|
+
const DYNAMIC_PLACEHOLDER = "1";
|
|
9
|
+
exports.DYNAMIC_PLACEHOLDER = DYNAMIC_PLACEHOLDER;
|
|
10
|
+
const oneValue = (value) => ({ values: [{ text: value, origin: null }], problems: [] });
|
|
11
|
+
exports.oneValue = oneValue;
|
|
12
|
+
const noValue = (problem) => ({ values: [], problems: [problem] });
|
|
13
|
+
exports.noValue = noValue;
|
|
14
|
+
const blockResult = () => ({ values: [], problems: [], directive: true });
|
|
15
|
+
exports.blockResult = blockResult;
|
|
16
|
+
const dynamicValue = () => ({
|
|
17
|
+
values: [{ text: DYNAMIC_PLACEHOLDER, origin: null, dynamic: true }],
|
|
18
|
+
problems: [],
|
|
19
|
+
dynamic: true,
|
|
20
|
+
});
|
|
21
|
+
exports.dynamicValue = dynamicValue;
|
|
22
|
+
const absentResult = (read) => ({
|
|
23
|
+
values: read.readings,
|
|
24
|
+
problems: [],
|
|
25
|
+
absent: read.absent.length ? read.absent : undefined,
|
|
26
|
+
});
|
|
27
|
+
exports.absentResult = absentResult;
|
|
28
|
+
// Every reading and every problem of the given results, in order: the branches of
|
|
29
|
+
// a conditional or a logical chain are the union of what each arm reaches.
|
|
30
|
+
const combine = (...results) => {
|
|
31
|
+
const absent = [...new Set(results.flatMap((result) => result.absent ?? []))];
|
|
32
|
+
return {
|
|
33
|
+
values: results.flatMap((result) => result.values),
|
|
34
|
+
problems: results.flatMap((result) => result.problems),
|
|
35
|
+
absent: absent.length ? absent : undefined,
|
|
36
|
+
directive: results.some((result) => result.directive) ? true : undefined,
|
|
37
|
+
dynamic: results.some((result) => result.dynamic) ? true : undefined,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.combine = combine;
|
|
41
|
+
// The pieces of a range in `text`, using the ABSOLUTE offsets the expressions
|
|
42
|
+
// were recorded at. Both readings (a whole template, or one value string) use
|
|
43
|
+
// this one walk; `base` is the offset `text` starts at.
|
|
44
|
+
const literalPiece = (text, from, to, base) => from < to ? [{ kind: "text", text: text.slice(from - base, to - base) }] : [];
|
|
45
|
+
const piecesOfRange = (text, exprs, span) => {
|
|
46
|
+
const next = [...exprs]
|
|
47
|
+
.filter((expr) => expr.offset >= span.from && expr.offset < span.to)
|
|
48
|
+
.sort((a, b) => a.offset - b.offset)[0];
|
|
49
|
+
if (!next)
|
|
50
|
+
return literalPiece(text, span.from, span.to, span.base);
|
|
51
|
+
return [
|
|
52
|
+
...literalPiece(text, span.from, next.offset, span.base),
|
|
53
|
+
{ kind: "expr", index: next.index, text: next.text },
|
|
54
|
+
...piecesOfRange(text, exprs, { from: next.offset + next.text.length, to: span.to, base: span.base }),
|
|
55
|
+
];
|
|
56
|
+
};
|
|
57
|
+
exports.piecesOfRange = piecesOfRange;
|
|
58
|
+
// What the declaration wrote, with each expression spelled back as `${…}` so a
|
|
59
|
+
// report can quote it. This is a FACT, not a template: the blanks are gone.
|
|
60
|
+
const rawValueOf = (pieces) => pieces.map((piece) => (piece.kind === "text" ? piece.text : `\${${piece.text}}`)).join("");
|
|
61
|
+
exports.rawValueOf = rawValueOf;
|
|
62
|
+
// Whitespace in a substituted value is layout, not content: blanks and the
|
|
63
|
+
// spacing around them collapse to one space.
|
|
64
|
+
const collapseSpaces = (text) => text.replace(/\s+/g, " ").trim();
|
|
65
|
+
exports.collapseSpaces = collapseSpaces;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type BranchProblem, type Piece, type Span } from "./pieces";
|
|
2
|
+
import { type ResolveContext } from "./substitute";
|
|
3
|
+
import { type Verdict } from "./check";
|
|
4
|
+
type ResolvedValue = Verdict & {
|
|
5
|
+
value: string;
|
|
6
|
+
object: string | null;
|
|
7
|
+
mediaVariant: string | null;
|
|
8
|
+
};
|
|
9
|
+
type UnresolvedValue = BranchProblem & {
|
|
10
|
+
text: string;
|
|
11
|
+
object?: string;
|
|
12
|
+
span?: Span;
|
|
13
|
+
};
|
|
14
|
+
type ValueResolution = {
|
|
15
|
+
property: string;
|
|
16
|
+
rawValue: string;
|
|
17
|
+
resolvedValues: ResolvedValue[];
|
|
18
|
+
unresolved: UnresolvedValue[];
|
|
19
|
+
};
|
|
20
|
+
declare const resolveDeclaration: (declaration: {
|
|
21
|
+
prop: string;
|
|
22
|
+
pieces: Piece[];
|
|
23
|
+
}, context: ResolveContext) => ValueResolution;
|
|
24
|
+
export { resolveDeclaration };
|
|
25
|
+
export { resolvePieces } from "./substitute";
|
|
26
|
+
export { emptyScope, mergeScopes, normalizeScope, withObjects } from "./scope";
|
|
27
|
+
export { piecesOfRange } from "./pieces";
|
|
28
|
+
export { checkValue } from "./check";
|
|
29
|
+
export type { Piece, Span } from "./pieces";
|
|
30
|
+
export type { Scope, ScopeEntry, ObjectLiteral } from "./scope";
|
|
31
|
+
export type { ResolveContext } from "./substitute";
|
|
32
|
+
export type { ValueProblem, ProblemKind } from "./check";
|
|
33
|
+
export type { ResolvedValue, UnresolvedValue, ValueResolution };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkValue = exports.piecesOfRange = exports.withObjects = exports.normalizeScope = exports.mergeScopes = exports.emptyScope = exports.resolvePieces = exports.resolveDeclaration = void 0;
|
|
4
|
+
// THE FACT a declaration carries: what was written, every concrete reading the
|
|
5
|
+
// resolver reached, and what it could not reach. This module is the surface —
|
|
6
|
+
// the pieces, the expression folding and the variable substitution are modules
|
|
7
|
+
// of their own; a consumer asks for one resolution, not for the machinery.
|
|
8
|
+
//
|
|
9
|
+
// Every problem is STRUCTURED: a reading carries the grammar's `problems`
|
|
10
|
+
// (kind + span), and an unreached part carries a `kind` the report layer matches
|
|
11
|
+
// on. No sentence is composed here.
|
|
12
|
+
const pieces_1 = require("./pieces");
|
|
13
|
+
const substitute_1 = require("./substitute");
|
|
14
|
+
const check_1 = require("./check");
|
|
15
|
+
const readingKey = (item) => `${item.value}|${item.object ?? ""}|${item.mediaVariant ?? ""}`;
|
|
16
|
+
const problemKey = (item) => `${item.kind}|${item.text}|${item.name ?? ""}|${item.object ?? ""}`;
|
|
17
|
+
// Record a problem once; the same reason reached through several branches is one
|
|
18
|
+
// fact, not several.
|
|
19
|
+
const recordProblem = (item, list, seen) => {
|
|
20
|
+
const key = problemKey(item);
|
|
21
|
+
if (seen.has(key))
|
|
22
|
+
return;
|
|
23
|
+
seen.add(key);
|
|
24
|
+
list.push(item);
|
|
25
|
+
};
|
|
26
|
+
// A read that needs an object literal but the rule named no object entity: say
|
|
27
|
+
// that as its own kind, rather than silently resolving against nothing.
|
|
28
|
+
const objectlessKind = (problem, noObjectEntity) => noObjectEntity && problem.kind === "unresolved-expr" ? "no-object-entity" : problem.kind;
|
|
29
|
+
// Every problem ONE branch carries: the resolver's own kinds, the objects a
|
|
30
|
+
// fixed path was absent in (an object literal is incomplete, not the component),
|
|
31
|
+
// and an empty branch that is neither a nested block nor a value.
|
|
32
|
+
const collectProblems = (branch, raw, sink) => {
|
|
33
|
+
const text = (0, pieces_1.collapseSpaces)(branch.text);
|
|
34
|
+
for (const problem of branch.problems)
|
|
35
|
+
recordProblem({
|
|
36
|
+
kind: objectlessKind(problem, raw.noObjectEntity),
|
|
37
|
+
text: problem.text ?? (text || raw.rawValue),
|
|
38
|
+
name: problem.name,
|
|
39
|
+
}, sink.unresolved, sink.seen);
|
|
40
|
+
if (branch.problems.length)
|
|
41
|
+
return;
|
|
42
|
+
for (const missing of branch.absent ?? [])
|
|
43
|
+
recordProblem({ kind: "absent", text: raw.rawValue, object: missing.object }, sink.unresolved, sink.seen);
|
|
44
|
+
// A branch that was ONLY a nested block (`${aCssFragment}`) is not an empty
|
|
45
|
+
// value: the block's own declarations are checked where it was written. A
|
|
46
|
+
// dynamic branch is runtime data, not an empty value either.
|
|
47
|
+
if (!text && !branch.directive && !branch.dynamic)
|
|
48
|
+
recordProblem({ kind: "empty", text: raw.rawValue }, sink.unresolved, sink.seen);
|
|
49
|
+
};
|
|
50
|
+
// One branch that reached the bottom, as a reading (empty/directive branches
|
|
51
|
+
// have nothing to judge — they are handled by `collectProblems`). A DYNAMIC
|
|
52
|
+
// branch carries a placeholder SHAPE: when that shape is rejected, the real
|
|
53
|
+
// value is still the runtime's and the component is not blamed — the reading is
|
|
54
|
+
// dropped instead of reported.
|
|
55
|
+
const collectReading = (branch, prop, resolvedValues, seen) => {
|
|
56
|
+
const text = (0, pieces_1.collapseSpaces)(branch.text);
|
|
57
|
+
if (!text)
|
|
58
|
+
return;
|
|
59
|
+
const verdict = (0, check_1.checkValue)(prop, text);
|
|
60
|
+
if (branch.dynamic && verdict.valid === false)
|
|
61
|
+
return;
|
|
62
|
+
const item = {
|
|
63
|
+
value: text,
|
|
64
|
+
object: branch.object,
|
|
65
|
+
mediaVariant: branch.media,
|
|
66
|
+
valid: verdict.valid,
|
|
67
|
+
problems: verdict.problems,
|
|
68
|
+
};
|
|
69
|
+
const key = readingKey(item);
|
|
70
|
+
if (seen.has(key))
|
|
71
|
+
return;
|
|
72
|
+
seen.add(key);
|
|
73
|
+
resolvedValues.push(item);
|
|
74
|
+
};
|
|
75
|
+
// Resolve ONE declaration. Every branch that reaches the bottom becomes a
|
|
76
|
+
// `resolvedValue` (with its object/media label and the grammar's verdict);
|
|
77
|
+
// every branch that does not becomes an `unresolved` entry with its kind.
|
|
78
|
+
const resolveDeclaration = (declaration, context) => {
|
|
79
|
+
const rawValue = (0, pieces_1.rawValueOf)(declaration.pieces);
|
|
80
|
+
const resolvedValues = [];
|
|
81
|
+
const unresolved = [];
|
|
82
|
+
const seenReadings = new Set();
|
|
83
|
+
const seenProblems = new Set();
|
|
84
|
+
const problemSink = { unresolved, seen: seenProblems };
|
|
85
|
+
const raw = { rawValue, noObjectEntity: context.scope.objects.length === 0 };
|
|
86
|
+
for (const branch of (0, substitute_1.resolvePieces)(declaration.pieces, context)) {
|
|
87
|
+
collectProblems(branch, raw, problemSink);
|
|
88
|
+
if (!branch.problems.length)
|
|
89
|
+
collectReading(branch, declaration.prop, resolvedValues, seenReadings);
|
|
90
|
+
}
|
|
91
|
+
return { property: declaration.prop, rawValue, resolvedValues, unresolved };
|
|
92
|
+
};
|
|
93
|
+
exports.resolveDeclaration = resolveDeclaration;
|
|
94
|
+
var substitute_2 = require("./substitute");
|
|
95
|
+
Object.defineProperty(exports, "resolvePieces", { enumerable: true, get: function () { return substitute_2.resolvePieces; } });
|
|
96
|
+
var scope_1 = require("./scope");
|
|
97
|
+
Object.defineProperty(exports, "emptyScope", { enumerable: true, get: function () { return scope_1.emptyScope; } });
|
|
98
|
+
Object.defineProperty(exports, "mergeScopes", { enumerable: true, get: function () { return scope_1.mergeScopes; } });
|
|
99
|
+
Object.defineProperty(exports, "normalizeScope", { enumerable: true, get: function () { return scope_1.normalizeScope; } });
|
|
100
|
+
Object.defineProperty(exports, "withObjects", { enumerable: true, get: function () { return scope_1.withObjects; } });
|
|
101
|
+
var pieces_2 = require("./pieces");
|
|
102
|
+
Object.defineProperty(exports, "piecesOfRange", { enumerable: true, get: function () { return pieces_2.piecesOfRange; } });
|
|
103
|
+
var check_2 = require("./check");
|
|
104
|
+
Object.defineProperty(exports, "checkValue", { enumerable: true, get: function () { return check_2.checkValue; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Expression, ObjectLiteralExpression, SourceFile } from "ts-morph";
|
|
2
|
+
import { type Piece } from "./pieces";
|
|
3
|
+
import type { DocumentFacts } from "@md-code/follow-architecture/css/syntax/styled/document";
|
|
4
|
+
type ObjectLiteral = {
|
|
5
|
+
name: string;
|
|
6
|
+
node: ObjectLiteralExpression;
|
|
7
|
+
};
|
|
8
|
+
type ScopeEntry = {
|
|
9
|
+
name: string;
|
|
10
|
+
pieces: Piece[];
|
|
11
|
+
media: string | null;
|
|
12
|
+
declaredLine: number | null;
|
|
13
|
+
expression: (index: number) => Expression | null;
|
|
14
|
+
};
|
|
15
|
+
type Scope = {
|
|
16
|
+
variables: Map<string, ScopeEntry[]>;
|
|
17
|
+
objects: ObjectLiteral[];
|
|
18
|
+
};
|
|
19
|
+
declare const emptyScope: () => Scope;
|
|
20
|
+
declare const normalizeScope: (scope: Scope) => Scope;
|
|
21
|
+
declare const mergeScopes: (...scopes: Scope[]) => Scope;
|
|
22
|
+
declare const withObjects: (scope: Scope, objects: readonly ObjectLiteral[]) => Scope;
|
|
23
|
+
declare const scopeFromSourceFile: (sourceFile: SourceFile) => Scope;
|
|
24
|
+
declare const scopeFromProject: (sourceFile: SourceFile) => Scope;
|
|
25
|
+
declare const scopeFromFacts: (facts: DocumentFacts) => Scope;
|
|
26
|
+
declare const releaseSourceScope: (sourceFile: SourceFile) => void;
|
|
27
|
+
export { emptyScope, mergeScopes, normalizeScope, withObjects, scopeFromSourceFile, scopeFromProject, scopeFromFacts, releaseSourceScope, };
|
|
28
|
+
export type { Scope, ScopeEntry, ObjectLiteral };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseSourceScope = exports.scopeFromFacts = exports.scopeFromProject = exports.scopeFromSourceFile = exports.withObjects = exports.normalizeScope = exports.mergeScopes = exports.emptyScope = void 0;
|
|
4
|
+
const remeda_1 = require("remeda");
|
|
5
|
+
const tree_1 = require("@md-code/follow-architecture/entities/ast/tree");
|
|
6
|
+
const group_1 = require("@md-code/follow-architecture/utils/group");
|
|
7
|
+
const template_1 = require("@md-code/follow-architecture/css/syntax/styled/template");
|
|
8
|
+
const pieces_1 = require("./pieces");
|
|
9
|
+
const emptyScope = () => ({ variables: new Map(), objects: [] });
|
|
10
|
+
exports.emptyScope = emptyScope;
|
|
11
|
+
// Two entries are the same only when name, media query AND value agree; two
|
|
12
|
+
// object literals only when the same literal was collected twice.
|
|
13
|
+
const entryKey = (entry) => `${entry.name}|${entry.media ?? ""}|${entry.pieces.map((piece) => (piece.kind === "text" ? piece.text : `\u0000${piece.text}`)).join("")}`;
|
|
14
|
+
const objectKey = (object) => `${object.name}|${object.node.getSourceFile().getFilePath()}|${object.node.getStart()}`;
|
|
15
|
+
// Drop the duplicates a scope may have collected twice (the same template read
|
|
16
|
+
// by two walks, the same document merged twice).
|
|
17
|
+
const normalizeScope = (scope) => {
|
|
18
|
+
for (const [name, entries] of scope.variables)
|
|
19
|
+
scope.variables.set(name, (0, remeda_1.uniqueBy)(entries, entryKey));
|
|
20
|
+
scope.objects = (0, remeda_1.uniqueBy)(scope.objects, objectKey);
|
|
21
|
+
return scope;
|
|
22
|
+
};
|
|
23
|
+
exports.normalizeScope = normalizeScope;
|
|
24
|
+
// One scope out of several: a component's own templates plus a shared
|
|
25
|
+
// stylesheet a caller merges in. Duplicates collapse, the rest unions.
|
|
26
|
+
const mergeScopes = (...scopes) => {
|
|
27
|
+
const merged = emptyScope();
|
|
28
|
+
for (const scope of scopes) {
|
|
29
|
+
for (const [name, entries] of scope.variables)
|
|
30
|
+
merged.variables.set(name, [...(merged.variables.get(name) ?? []), ...entries]);
|
|
31
|
+
merged.objects.push(...scope.objects);
|
|
32
|
+
}
|
|
33
|
+
return normalizeScope(merged);
|
|
34
|
+
};
|
|
35
|
+
exports.mergeScopes = mergeScopes;
|
|
36
|
+
// The same scope with a different object set: resolution is asked of the object
|
|
37
|
+
// literals ONE rule named, not of any project-wide list.
|
|
38
|
+
const withObjects = (scope, objects) => ({ ...scope, objects: [...objects] });
|
|
39
|
+
exports.withObjects = withObjects;
|
|
40
|
+
// A custom property declaration as written inside template text. The name is
|
|
41
|
+
// CSS's own (`--x`), so no selector or property list is involved.
|
|
42
|
+
const CUSTOM_PROPERTY_RE = /(--[\w-]+)\s*:/g;
|
|
43
|
+
// The value of a declaration starts just after its `:` — but an expression is
|
|
44
|
+
// written as BLANKS, so whitespace skipping must stop at a blank's start or it
|
|
45
|
+
// would eat the expression itself.
|
|
46
|
+
const valueStartAt = (text, after, exprs) => {
|
|
47
|
+
const starts = new Set(exprs.map((expr) => expr.offset));
|
|
48
|
+
let index = after;
|
|
49
|
+
while (index < text.length && /\s/.test(text[index]) && !starts.has(index))
|
|
50
|
+
index += 1;
|
|
51
|
+
return index;
|
|
52
|
+
};
|
|
53
|
+
// Parentheses pair up inside a value (`calc((100% - 8px) / 2)`), so a `;` only
|
|
54
|
+
// ends a value at depth zero. A `}` at depth zero ends the BLOCK the declaration
|
|
55
|
+
// sits in.
|
|
56
|
+
const depthAfter = (char, depth) => {
|
|
57
|
+
if (char === "(")
|
|
58
|
+
return depth + 1;
|
|
59
|
+
if (char === ")")
|
|
60
|
+
return Math.max(0, depth - 1);
|
|
61
|
+
return depth;
|
|
62
|
+
};
|
|
63
|
+
const endsValue = (char, depth) => depth === 0 && (char === ";" || char === "}");
|
|
64
|
+
const closesQuote = (char, previous, quote) => char === quote && previous !== "\\";
|
|
65
|
+
const valueEndAt = (text, start) => {
|
|
66
|
+
let depth = 0;
|
|
67
|
+
let quote = null;
|
|
68
|
+
for (let index = start; index < text.length; index += 1) {
|
|
69
|
+
const char = text[index];
|
|
70
|
+
if (quote) {
|
|
71
|
+
if (closesQuote(char, text[index - 1], quote))
|
|
72
|
+
quote = null;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (char === '"' || char === "'") {
|
|
76
|
+
quote = char;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
depth = depthAfter(char, depth);
|
|
80
|
+
if (endsValue(char, depth))
|
|
81
|
+
return index;
|
|
82
|
+
}
|
|
83
|
+
return text.length;
|
|
84
|
+
};
|
|
85
|
+
const closingBrace = (text, open) => {
|
|
86
|
+
let depth = 0;
|
|
87
|
+
for (let index = open; index < text.length; index += 1) {
|
|
88
|
+
if (text[index] === "{")
|
|
89
|
+
depth += 1;
|
|
90
|
+
else if (text[index] === "}") {
|
|
91
|
+
depth -= 1;
|
|
92
|
+
if (depth === 0)
|
|
93
|
+
return index;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return -1;
|
|
97
|
+
};
|
|
98
|
+
// The nearest `@media` block around an offset. Several media blocks may sit side
|
|
99
|
+
// by side; the one whose braces contain the offset is the variant.
|
|
100
|
+
const MEDIA_BLOCK_RE = /@media\b([^{]*)\{/g;
|
|
101
|
+
const mediaAt = (text, position) => {
|
|
102
|
+
let found = null;
|
|
103
|
+
for (const match of text.matchAll(MEDIA_BLOCK_RE)) {
|
|
104
|
+
const open = text.indexOf("{", match.index);
|
|
105
|
+
const close = closingBrace(text, open);
|
|
106
|
+
if (position > open && (close < 0 || position < close))
|
|
107
|
+
found = `@media ${match[1].trim()}`;
|
|
108
|
+
}
|
|
109
|
+
return found;
|
|
110
|
+
};
|
|
111
|
+
const lineAt = (template, text, offset) => {
|
|
112
|
+
const before = text.slice(0, offset);
|
|
113
|
+
const newlines = (before.match(/\n/g) ?? []).length;
|
|
114
|
+
return template.getStartLineNumber() + newlines;
|
|
115
|
+
};
|
|
116
|
+
// Every custom property declaration in one template literal (tagged or nested),
|
|
117
|
+
// with its value as pieces and its media variant.
|
|
118
|
+
const collectFromLiteral = (template, add) => {
|
|
119
|
+
const { text, exprs } = (0, template_1.templateLiteralSource)(template);
|
|
120
|
+
if (!text.includes("--"))
|
|
121
|
+
return;
|
|
122
|
+
const nodes = (0, template_1.expressionNodesOf)(template);
|
|
123
|
+
for (const match of text.matchAll(CUSTOM_PROPERTY_RE)) {
|
|
124
|
+
const name = match[1];
|
|
125
|
+
const from = valueStartAt(text, match.index + match[0].length, exprs);
|
|
126
|
+
const to = valueEndAt(text, from);
|
|
127
|
+
add({
|
|
128
|
+
name,
|
|
129
|
+
pieces: (0, pieces_1.piecesOfRange)(text, exprs, { from, to, base: 0 }),
|
|
130
|
+
media: mediaAt(text, match.index),
|
|
131
|
+
declaredLine: lineAt(template, text, match.index),
|
|
132
|
+
expression: (index) => nodes[index] ?? null,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
// The scope a whole source file offers: its templates' custom properties.
|
|
137
|
+
// Cached on the file — a component's styled blocks all read the same names.
|
|
138
|
+
// Nothing project-wide is scanned: the object literals are the caller's, not
|
|
139
|
+
// this file's.
|
|
140
|
+
const SOURCE_SCOPE = new WeakMap();
|
|
141
|
+
const buildSourceScope = (sourceFile) => {
|
|
142
|
+
const scope = emptyScope();
|
|
143
|
+
const add = (entry) => {
|
|
144
|
+
(0, group_1.pushGroup)(scope.variables, entry.name, entry);
|
|
145
|
+
};
|
|
146
|
+
for (const node of sourceFile.getDescendantsOfKind(tree_1.SK.TemplateExpression))
|
|
147
|
+
collectFromLiteral(node, add);
|
|
148
|
+
for (const node of sourceFile.getDescendantsOfKind(tree_1.SK.NoSubstitutionTemplateLiteral))
|
|
149
|
+
collectFromLiteral(node, add);
|
|
150
|
+
return normalizeScope(scope);
|
|
151
|
+
};
|
|
152
|
+
// A per-key cache write that also hands the value back, so a reader is one
|
|
153
|
+
// expression: the known scope, or the built one remembered for next time.
|
|
154
|
+
const remember = (cache, key, build) => {
|
|
155
|
+
const value = build();
|
|
156
|
+
cache.set(key, value);
|
|
157
|
+
return value;
|
|
158
|
+
};
|
|
159
|
+
const scopeFromSourceFile = (sourceFile) => SOURCE_SCOPE.get(sourceFile) ?? remember(SOURCE_SCOPE, sourceFile, () => buildSourceScope(sourceFile));
|
|
160
|
+
exports.scopeFromSourceFile = scopeFromSourceFile;
|
|
161
|
+
// THE REPO-WIDE SCOPE: every source file's custom properties merged into one.
|
|
162
|
+
// A component's styles do not declare the variables they read — a shared global
|
|
163
|
+
// style does, in another file — so a value can only be walked to the bottom when
|
|
164
|
+
// the whole project is in scope. The merge is the shared `mergeScopes`; cached
|
|
165
|
+
// per project and rebuilt when the project grows (the same policy the project
|
|
166
|
+
// scope cache uses).
|
|
167
|
+
const PROJECT_SCOPE = new WeakMap();
|
|
168
|
+
const scopeFromProject = (sourceFile) => {
|
|
169
|
+
const project = sourceFile.getProject();
|
|
170
|
+
const files = project.getSourceFiles();
|
|
171
|
+
const cached = PROJECT_SCOPE.get(project);
|
|
172
|
+
if (cached && cached.count === files.length)
|
|
173
|
+
return cached.scope;
|
|
174
|
+
const scope = normalizeScope(mergeScopes(...files.map(scopeFromSourceFile)));
|
|
175
|
+
PROJECT_SCOPE.set(project, { count: files.length, scope });
|
|
176
|
+
return scope;
|
|
177
|
+
};
|
|
178
|
+
exports.scopeFromProject = scopeFromProject;
|
|
179
|
+
// The scope one parsed document offers. The LANGUAGE has already marked which
|
|
180
|
+
// declarations are variables and under what name (`variableName`); the same walk
|
|
181
|
+
// covers every syntax because the knowledge of "what a variable looks like here"
|
|
182
|
+
// lives with the language, not here.
|
|
183
|
+
const scopeFromFacts = (facts) => {
|
|
184
|
+
const scope = emptyScope();
|
|
185
|
+
for (const declaration of facts.declarations) {
|
|
186
|
+
if (!declaration.variableName)
|
|
187
|
+
continue;
|
|
188
|
+
const entry = {
|
|
189
|
+
name: declaration.variableName,
|
|
190
|
+
pieces: declaration.pieces,
|
|
191
|
+
media: declaration.media,
|
|
192
|
+
declaredLine: declaration.line,
|
|
193
|
+
expression: () => null,
|
|
194
|
+
};
|
|
195
|
+
(0, group_1.pushGroup)(scope.variables, entry.name, entry);
|
|
196
|
+
}
|
|
197
|
+
return normalizeScope(scope);
|
|
198
|
+
};
|
|
199
|
+
exports.scopeFromFacts = scopeFromFacts;
|
|
200
|
+
// Drop one file's scope. The project scope is cached separately and does not
|
|
201
|
+
// depend on this entry staying; a released file's names come back on demand.
|
|
202
|
+
const releaseSourceScope = (sourceFile) => {
|
|
203
|
+
SOURCE_SCOPE.delete(sourceFile);
|
|
204
|
+
};
|
|
205
|
+
exports.releaseSourceScope = releaseSourceScope;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Expression } from "ts-morph";
|
|
2
|
+
import type { Scope } from "./scope";
|
|
3
|
+
import type { Branch, Piece } from "./pieces";
|
|
4
|
+
type ResolveContext = {
|
|
5
|
+
scope: Scope;
|
|
6
|
+
expression: (index: number) => Expression | null;
|
|
7
|
+
};
|
|
8
|
+
declare const resolvePieces: (pieces: Piece[], context: ResolveContext, stack?: readonly string[]) => Branch[];
|
|
9
|
+
export { resolvePieces };
|
|
10
|
+
export type { ResolveContext };
|