@antheo/morph 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +266 -2
- package/SKILL.md +61 -0
- package/dist/ai/cli-provider.d.ts +80 -0
- package/dist/ai/cli-provider.js +250 -0
- package/dist/ai/gate.d.ts +39 -0
- package/dist/ai/gate.js +124 -0
- package/dist/ai/provider.d.ts +36 -0
- package/dist/ai/provider.js +168 -0
- package/dist/ai/repair.d.ts +90 -0
- package/dist/ai/repair.js +172 -0
- package/dist/analyzer/deps.d.ts +30 -0
- package/dist/analyzer/deps.js +265 -0
- package/dist/analyzer/manifest.d.ts +5 -0
- package/dist/analyzer/manifest.js +119 -0
- package/dist/analyzer/parse.d.ts +21 -0
- package/dist/analyzer/parse.js +29 -0
- package/dist/batch-worker.d.ts +16 -0
- package/dist/batch-worker.js +10 -0
- package/dist/batch.d.ts +26 -0
- package/dist/batch.js +227 -0
- package/dist/bridge/index.d.ts +26 -0
- package/dist/bridge/index.js +138 -0
- package/dist/bridge/props.d.ts +56 -0
- package/dist/bridge/props.js +191 -0
- package/dist/bridge/wrappers.d.ts +24 -0
- package/dist/bridge/wrappers.js +276 -0
- package/dist/cli/format.d.ts +7 -0
- package/dist/cli/format.js +30 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +492 -0
- package/dist/fonts/carry.d.ts +34 -0
- package/dist/fonts/carry.js +113 -0
- package/dist/fonts/fallback.d.ts +11 -0
- package/dist/fonts/fallback.js +21 -0
- package/dist/fonts/google.d.ts +65 -0
- package/dist/fonts/google.js +343 -0
- package/dist/fonts/index.d.ts +27 -0
- package/dist/fonts/index.js +48 -0
- package/dist/fonts/local.d.ts +46 -0
- package/dist/fonts/local.js +150 -0
- package/dist/fonts/sfnt.d.ts +19 -0
- package/dist/fonts/sfnt.js +174 -0
- package/dist/fonts/shim.d.ts +14 -0
- package/dist/fonts/shim.js +96 -0
- package/dist/gate.d.ts +105 -0
- package/dist/gate.js +157 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +74 -0
- package/dist/ir/annotate.d.ts +16 -0
- package/dist/ir/annotate.js +145 -0
- package/dist/ir/as-child.d.ts +18 -0
- package/dist/ir/as-child.js +239 -0
- package/dist/ir/compounds.d.ts +27 -0
- package/dist/ir/compounds.js +183 -0
- package/dist/ir/contexts.d.ts +26 -0
- package/dist/ir/contexts.js +185 -0
- package/dist/ir/dom.d.ts +11 -0
- package/dist/ir/dom.js +60 -0
- package/dist/ir/effect-returns.d.ts +10 -0
- package/dist/ir/effect-returns.js +25 -0
- package/dist/ir/extract-ui-types.d.ts +33 -0
- package/dist/ir/extract-ui-types.js +224 -0
- package/dist/ir/extract-ui.d.ts +34 -0
- package/dist/ir/extract-ui.js +567 -0
- package/dist/ir/falsy.d.ts +13 -0
- package/dist/ir/falsy.js +66 -0
- package/dist/ir/forward-refs.d.ts +11 -0
- package/dist/ir/forward-refs.js +155 -0
- package/dist/ir/fragment-source.d.ts +4 -0
- package/dist/ir/fragment-source.js +13 -0
- package/dist/ir/fragments.d.ts +32 -0
- package/dist/ir/fragments.js +192 -0
- package/dist/ir/helper-snippets.d.ts +30 -0
- package/dist/ir/helper-snippets.js +550 -0
- package/dist/ir/latest-refs.d.ts +11 -0
- package/dist/ir/latest-refs.js +187 -0
- package/dist/ir/live-args.d.ts +26 -0
- package/dist/ir/live-args.js +335 -0
- package/dist/ir/lower.d.ts +83 -0
- package/dist/ir/lower.js +6016 -0
- package/dist/ir/markup-values.d.ts +16 -0
- package/dist/ir/markup-values.js +188 -0
- package/dist/ir/model.d.ts +605 -0
- package/dist/ir/model.js +1 -0
- package/dist/ir/oracle.d.ts +91 -0
- package/dist/ir/oracle.js +610 -0
- package/dist/ir/radix.d.ts +122 -0
- package/dist/ir/radix.js +344 -0
- package/dist/ir/rename.d.ts +15 -0
- package/dist/ir/rename.js +151 -0
- package/dist/ir/render-props.d.ts +31 -0
- package/dist/ir/render-props.js +67 -0
- package/dist/ir/rewrite.d.ts +44 -0
- package/dist/ir/rewrite.js +381 -0
- package/dist/ir/running-index.d.ts +11 -0
- package/dist/ir/running-index.js +217 -0
- package/dist/ir/snapshots.d.ts +12 -0
- package/dist/ir/snapshots.js +140 -0
- package/dist/ir/style.d.ts +19 -0
- package/dist/ir/style.js +76 -0
- package/dist/ir/types.d.ts +42 -0
- package/dist/ir/types.js +271 -0
- package/dist/ir/walk.d.ts +11 -0
- package/dist/ir/walk.js +18 -0
- package/dist/mcp/server.d.ts +81 -0
- package/dist/mcp/server.js +518 -0
- package/dist/pipeline.d.ts +26 -0
- package/dist/pipeline.js +750 -0
- package/dist/registry/add.d.ts +91 -0
- package/dist/registry/add.js +273 -0
- package/dist/registry/fetch.d.ts +40 -0
- package/dist/registry/fetch.js +186 -0
- package/dist/registry/ip.d.ts +18 -0
- package/dist/registry/ip.js +153 -0
- package/dist/registry/item.d.ts +39 -0
- package/dist/registry/item.js +131 -0
- package/dist/registry/load.d.ts +35 -0
- package/dist/registry/load.js +106 -0
- package/dist/registry/paths.d.ts +8 -0
- package/dist/registry/paths.js +43 -0
- package/dist/registry/publish.d.ts +119 -0
- package/dist/registry/publish.js +439 -0
- package/dist/targets/angular/bank/bank.d.ts +39 -0
- package/dist/targets/angular/bank/bank.js +61 -0
- package/dist/targets/angular/bank/helpers.d.ts +64 -0
- package/dist/targets/angular/bank/helpers.js +246 -0
- package/dist/targets/angular/bank/kept.d.ts +98 -0
- package/dist/targets/angular/bank/kept.js +791 -0
- package/dist/targets/angular/bank/plan-helpers.d.ts +17 -0
- package/dist/targets/angular/bank/plan-helpers.js +286 -0
- package/dist/targets/angular/bank/plan.d.ts +22 -0
- package/dist/targets/angular/bank/plan.js +152 -0
- package/dist/targets/angular/bank/receivers.d.ts +66 -0
- package/dist/targets/angular/bank/receivers.js +293 -0
- package/dist/targets/angular/bank/runtime.d.ts +14 -0
- package/dist/targets/angular/bank/runtime.js +152 -0
- package/dist/targets/angular/controlled.d.ts +7 -0
- package/dist/targets/angular/controlled.js +37 -0
- package/dist/targets/angular/dynamic-tags.d.ts +34 -0
- package/dist/targets/angular/dynamic-tags.js +192 -0
- package/dist/targets/angular/emit.d.ts +41 -0
- package/dist/targets/angular/emit.js +5970 -0
- package/dist/targets/angular/exports.d.ts +48 -0
- package/dist/targets/angular/exports.js +243 -0
- package/dist/targets/angular/helpers.d.ts +15 -0
- package/dist/targets/angular/helpers.js +33 -0
- package/dist/targets/angular/host-boundary.d.ts +5 -0
- package/dist/targets/angular/host-boundary.js +166 -0
- package/dist/targets/angular/host-form.d.ts +150 -0
- package/dist/targets/angular/host-form.js +727 -0
- package/dist/targets/angular/markup-values.d.ts +58 -0
- package/dist/targets/angular/markup-values.js +661 -0
- package/dist/targets/angular/motion-directive.d.ts +12 -0
- package/dist/targets/angular/motion-directive.js +257 -0
- package/dist/targets/angular/motion-hooks.d.ts +73 -0
- package/dist/targets/angular/motion-hooks.js +293 -0
- package/dist/targets/angular/motion-layout.d.ts +14 -0
- package/dist/targets/angular/motion-layout.js +74 -0
- package/dist/targets/angular/motion-templates.d.ts +10 -0
- package/dist/targets/angular/motion-templates.js +65 -0
- package/dist/targets/angular/motion.d.ts +57 -0
- package/dist/targets/angular/motion.js +202 -0
- package/dist/targets/angular/narrowing.d.ts +24 -0
- package/dist/targets/angular/narrowing.js +205 -0
- package/dist/targets/angular/ngc.d.ts +23 -0
- package/dist/targets/angular/ngc.js +134 -0
- package/dist/targets/angular/passed-handle.d.ts +39 -0
- package/dist/targets/angular/passed-handle.js +154 -0
- package/dist/targets/angular/projected.d.ts +9 -0
- package/dist/targets/angular/projected.js +63 -0
- package/dist/targets/angular/radix/cores/alert-dialog.d.ts +13 -0
- package/dist/targets/angular/radix/cores/alert-dialog.js +388 -0
- package/dist/targets/angular/radix/cores/index.d.ts +17 -0
- package/dist/targets/angular/radix/cores/index.js +50 -0
- package/dist/targets/angular/radix/cores/slider.d.ts +8 -0
- package/dist/targets/angular/radix/cores/slider.js +202 -0
- package/dist/targets/angular/radix/index.d.ts +21 -0
- package/dist/targets/angular/radix/index.js +35 -0
- package/dist/targets/angular/radix/packages.d.ts +3 -0
- package/dist/targets/angular/radix/packages.js +558 -0
- package/dist/targets/angular/radix/part.d.ts +236 -0
- package/dist/targets/angular/radix/part.js +71 -0
- package/dist/targets/angular/radix/prepare.d.ts +66 -0
- package/dist/targets/angular/radix/prepare.js +548 -0
- package/dist/targets/angular/radix/template.d.ts +43 -0
- package/dist/targets/angular/radix/template.js +172 -0
- package/dist/targets/angular/refs.d.ts +68 -0
- package/dist/targets/angular/refs.js +443 -0
- package/dist/targets/angular/slots.d.ts +22 -0
- package/dist/targets/angular/slots.js +60 -0
- package/dist/targets/angular/source-types.d.ts +10 -0
- package/dist/targets/angular/source-types.js +45 -0
- package/dist/targets/angular/spread-forward.d.ts +24 -0
- package/dist/targets/angular/spread-forward.js +72 -0
- package/dist/targets/angular/spread.d.ts +32 -0
- package/dist/targets/angular/spread.js +182 -0
- package/dist/targets/angular/svg-hosts.d.ts +25 -0
- package/dist/targets/angular/svg-hosts.js +107 -0
- package/dist/targets/angular/template-expr.d.ts +36 -0
- package/dist/targets/angular/template-expr.js +287 -0
- package/dist/targets/angular/types.d.ts +9 -0
- package/dist/targets/angular/types.js +63 -0
- package/dist/targets/angular/walk.d.ts +11 -0
- package/dist/targets/angular/walk.js +26 -0
- package/dist/targets/react-native/emit.d.ts +14 -0
- package/dist/targets/react-native/emit.js +585 -0
- package/dist/targets/react-native/fidelity.d.ts +5 -0
- package/dist/targets/react-native/fidelity.js +43 -0
- package/dist/targets/react-native/motion.d.ts +10 -0
- package/dist/targets/react-native/motion.js +290 -0
- package/dist/targets/react-native/skia.d.ts +30 -0
- package/dist/targets/react-native/skia.js +358 -0
- package/dist/targets/shared/context.d.ts +47 -0
- package/dist/targets/shared/context.js +195 -0
- package/dist/targets/shared/foreign.d.ts +10 -0
- package/dist/targets/shared/foreign.js +72 -0
- package/dist/targets/shared/fragments.d.ts +21 -0
- package/dist/targets/shared/fragments.js +309 -0
- package/dist/targets/shared/handles.d.ts +65 -0
- package/dist/targets/shared/handles.js +299 -0
- package/dist/targets/shared/inline.d.ts +53 -0
- package/dist/targets/shared/inline.js +524 -0
- package/dist/targets/shared/layout.d.ts +70 -0
- package/dist/targets/shared/layout.js +224 -0
- package/dist/targets/shared/markup.d.ts +26 -0
- package/dist/targets/shared/markup.js +65 -0
- package/dist/targets/shared/module.d.ts +84 -0
- package/dist/targets/shared/module.js +468 -0
- package/dist/targets/shared/motion-hooks.d.ts +37 -0
- package/dist/targets/shared/motion-hooks.js +87 -0
- package/dist/targets/shared/motion-layout.d.ts +70 -0
- package/dist/targets/shared/motion-layout.js +392 -0
- package/dist/targets/shared/portal.d.ts +10 -0
- package/dist/targets/shared/portal.js +23 -0
- package/dist/targets/shared/prop-writes.d.ts +11 -0
- package/dist/targets/shared/prop-writes.js +32 -0
- package/dist/targets/shared/prune.d.ts +54 -0
- package/dist/targets/shared/prune.js +405 -0
- package/dist/targets/shared/react-libs.d.ts +25 -0
- package/dist/targets/shared/react-libs.js +142 -0
- package/dist/targets/shared/react-types.d.ts +16 -0
- package/dist/targets/shared/react-types.js +374 -0
- package/dist/targets/shared/react-values.d.ts +20 -0
- package/dist/targets/shared/react-values.js +145 -0
- package/dist/targets/shared/ref-callback.d.ts +16 -0
- package/dist/targets/shared/ref-callback.js +114 -0
- package/dist/targets/shared/script.d.ts +65 -0
- package/dist/targets/shared/script.js +406 -0
- package/dist/targets/shared/unused.d.ts +12 -0
- package/dist/targets/shared/unused.js +146 -0
- package/dist/targets/svelte/dom-spread.d.ts +27 -0
- package/dist/targets/svelte/dom-spread.js +146 -0
- package/dist/targets/svelte/emit.d.ts +15 -0
- package/dist/targets/svelte/emit.js +3784 -0
- package/dist/targets/svelte/handle-branches.d.ts +22 -0
- package/dist/targets/svelte/handle-branches.js +146 -0
- package/dist/targets/svelte/html-keys.d.ts +9 -0
- package/dist/targets/svelte/html-keys.js +40 -0
- package/dist/targets/svelte/markup-data/data.d.ts +51 -0
- package/dist/targets/svelte/markup-data/data.js +305 -0
- package/dist/targets/svelte/markup-data/helper.d.ts +12 -0
- package/dist/targets/svelte/markup-data/helper.js +81 -0
- package/dist/targets/svelte/markup-data/module-data.d.ts +21 -0
- package/dist/targets/svelte/markup-data/module-data.js +473 -0
- package/dist/targets/svelte/markup-data/sites.d.ts +52 -0
- package/dist/targets/svelte/markup-data/sites.js +303 -0
- package/dist/targets/svelte/motion-layout.d.ts +13 -0
- package/dist/targets/svelte/motion-layout.js +70 -0
- package/dist/targets/svelte/motion-table.d.ts +14 -0
- package/dist/targets/svelte/motion-table.js +308 -0
- package/dist/targets/svelte/motion.d.ts +46 -0
- package/dist/targets/svelte/motion.js +405 -0
- package/dist/targets/svelte/presence.d.ts +71 -0
- package/dist/targets/svelte/presence.js +318 -0
- package/dist/targets/svelte/radix/accordion.d.ts +9 -0
- package/dist/targets/svelte/radix/accordion.js +24 -0
- package/dist/targets/svelte/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/svelte/radix/aspect-ratio.js +8 -0
- package/dist/targets/svelte/radix/avatar.d.ts +6 -0
- package/dist/targets/svelte/radix/avatar.js +10 -0
- package/dist/targets/svelte/radix/checkbox.d.ts +10 -0
- package/dist/targets/svelte/radix/checkbox.js +24 -0
- package/dist/targets/svelte/radix/collapsible.d.ts +7 -0
- package/dist/targets/svelte/radix/collapsible.js +16 -0
- package/dist/targets/svelte/radix/context-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/context-menu.js +49 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.d.ts +17 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.js +449 -0
- package/dist/targets/svelte/radix/cores/collapsible.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/collapsible.js +214 -0
- package/dist/targets/svelte/radix/cores/core.d.ts +32 -0
- package/dist/targets/svelte/radix/cores/core.js +80 -0
- package/dist/targets/svelte/radix/cores/direction.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/direction.js +64 -0
- package/dist/targets/svelte/radix/cores/index.d.ts +19 -0
- package/dist/targets/svelte/radix/cores/index.js +85 -0
- package/dist/targets/svelte/radix/cores/modal-layer.d.ts +11 -0
- package/dist/targets/svelte/radix/cores/modal-layer.js +244 -0
- package/dist/targets/svelte/radix/cores/presence.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/presence.js +129 -0
- package/dist/targets/svelte/radix/cores/slider-logic.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/slider-logic.js +287 -0
- package/dist/targets/svelte/radix/cores/slider.d.ts +13 -0
- package/dist/targets/svelte/radix/cores/slider.js +267 -0
- package/dist/targets/svelte/radix/dialog.d.ts +8 -0
- package/dist/targets/svelte/radix/dialog.js +20 -0
- package/dist/targets/svelte/radix/dropdown-menu.d.ts +9 -0
- package/dist/targets/svelte/radix/dropdown-menu.js +38 -0
- package/dist/targets/svelte/radix/emit.d.ts +12 -0
- package/dist/targets/svelte/radix/emit.js +1339 -0
- package/dist/targets/svelte/radix/hover-card.d.ts +7 -0
- package/dist/targets/svelte/radix/hover-card.js +22 -0
- package/dist/targets/svelte/radix/index.d.ts +12 -0
- package/dist/targets/svelte/radix/index.js +28 -0
- package/dist/targets/svelte/radix/label.d.ts +3 -0
- package/dist/targets/svelte/radix/label.js +5 -0
- package/dist/targets/svelte/radix/menubar.d.ts +7 -0
- package/dist/targets/svelte/radix/menubar.js +34 -0
- package/dist/targets/svelte/radix/navigation-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/navigation-menu.js +25 -0
- package/dist/targets/svelte/radix/packages.d.ts +34 -0
- package/dist/targets/svelte/radix/packages.js +100 -0
- package/dist/targets/svelte/radix/part.d.ts +161 -0
- package/dist/targets/svelte/radix/part.js +85 -0
- package/dist/targets/svelte/radix/popover.d.ts +7 -0
- package/dist/targets/svelte/radix/popover.js +15 -0
- package/dist/targets/svelte/radix/progress.d.ts +11 -0
- package/dist/targets/svelte/radix/progress.js +27 -0
- package/dist/targets/svelte/radix/radio-group.d.ts +9 -0
- package/dist/targets/svelte/radix/radio-group.js +26 -0
- package/dist/targets/svelte/radix/scroll-area.d.ts +7 -0
- package/dist/targets/svelte/radix/scroll-area.js +19 -0
- package/dist/targets/svelte/radix/select.d.ts +13 -0
- package/dist/targets/svelte/radix/select.js +81 -0
- package/dist/targets/svelte/radix/separator.d.ts +3 -0
- package/dist/targets/svelte/radix/separator.js +5 -0
- package/dist/targets/svelte/radix/slider.d.ts +6 -0
- package/dist/targets/svelte/radix/slider.js +8 -0
- package/dist/targets/svelte/radix/switch.d.ts +6 -0
- package/dist/targets/svelte/radix/switch.js +10 -0
- package/dist/targets/svelte/radix/tabs.d.ts +8 -0
- package/dist/targets/svelte/radix/tabs.js +15 -0
- package/dist/targets/svelte/radix/toggle-group.d.ts +9 -0
- package/dist/targets/svelte/radix/toggle-group.js +17 -0
- package/dist/targets/svelte/radix/toggle.d.ts +6 -0
- package/dist/targets/svelte/radix/toggle.js +9 -0
- package/dist/targets/svelte/radix/tooltip.d.ts +6 -0
- package/dist/targets/svelte/radix/tooltip.js +24 -0
- package/dist/targets/svelte/strip.d.ts +2 -0
- package/dist/targets/svelte/strip.js +5 -0
- package/dist/targets/vue/emit.d.ts +15 -0
- package/dist/targets/vue/emit.js +4092 -0
- package/dist/targets/vue/events.d.ts +11 -0
- package/dist/targets/vue/events.js +13 -0
- package/dist/targets/vue/module-builders.d.ts +28 -0
- package/dist/targets/vue/module-builders.js +258 -0
- package/dist/targets/vue/motion-layout.d.ts +19 -0
- package/dist/targets/vue/motion-layout.js +79 -0
- package/dist/targets/vue/motion.d.ts +12 -0
- package/dist/targets/vue/motion.js +46 -0
- package/dist/targets/vue/radix/accordion.d.ts +3 -0
- package/dist/targets/vue/radix/accordion.js +12 -0
- package/dist/targets/vue/radix/alert-dialog.d.ts +6 -0
- package/dist/targets/vue/radix/alert-dialog.js +18 -0
- package/dist/targets/vue/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/vue/radix/aspect-ratio.js +8 -0
- package/dist/targets/vue/radix/avatar.d.ts +3 -0
- package/dist/targets/vue/radix/avatar.js +7 -0
- package/dist/targets/vue/radix/checkbox.d.ts +3 -0
- package/dist/targets/vue/radix/checkbox.js +9 -0
- package/dist/targets/vue/radix/collapsible.d.ts +7 -0
- package/dist/targets/vue/radix/collapsible.js +11 -0
- package/dist/targets/vue/radix/context-menu.d.ts +3 -0
- package/dist/targets/vue/radix/context-menu.js +30 -0
- package/dist/targets/vue/radix/dialog.d.ts +3 -0
- package/dist/targets/vue/radix/dialog.js +12 -0
- package/dist/targets/vue/radix/direction.d.ts +7 -0
- package/dist/targets/vue/radix/direction.js +9 -0
- package/dist/targets/vue/radix/dropdown-menu.d.ts +3 -0
- package/dist/targets/vue/radix/dropdown-menu.js +29 -0
- package/dist/targets/vue/radix/hover-card.d.ts +3 -0
- package/dist/targets/vue/radix/hover-card.js +11 -0
- package/dist/targets/vue/radix/index.d.ts +65 -0
- package/dist/targets/vue/radix/index.js +225 -0
- package/dist/targets/vue/radix/label.d.ts +3 -0
- package/dist/targets/vue/radix/label.js +5 -0
- package/dist/targets/vue/radix/menubar.d.ts +6 -0
- package/dist/targets/vue/radix/menubar.js +29 -0
- package/dist/targets/vue/radix/navigation-menu.d.ts +6 -0
- package/dist/targets/vue/radix/navigation-menu.js +21 -0
- package/dist/targets/vue/radix/part.d.ts +41 -0
- package/dist/targets/vue/radix/part.js +46 -0
- package/dist/targets/vue/radix/popover.d.ts +3 -0
- package/dist/targets/vue/radix/popover.js +11 -0
- package/dist/targets/vue/radix/progress.d.ts +3 -0
- package/dist/targets/vue/radix/progress.js +6 -0
- package/dist/targets/vue/radix/radio-group.d.ts +3 -0
- package/dist/targets/vue/radix/radio-group.js +10 -0
- package/dist/targets/vue/radix/scroll-area.d.ts +3 -0
- package/dist/targets/vue/radix/scroll-area.js +11 -0
- package/dist/targets/vue/radix/select.d.ts +3 -0
- package/dist/targets/vue/radix/select.js +29 -0
- package/dist/targets/vue/radix/separator.d.ts +3 -0
- package/dist/targets/vue/radix/separator.js +5 -0
- package/dist/targets/vue/radix/slider.d.ts +3 -0
- package/dist/targets/vue/radix/slider.js +13 -0
- package/dist/targets/vue/radix/switch.d.ts +3 -0
- package/dist/targets/vue/radix/switch.js +9 -0
- package/dist/targets/vue/radix/tabs.d.ts +3 -0
- package/dist/targets/vue/radix/tabs.js +12 -0
- package/dist/targets/vue/radix/toggle-group.d.ts +3 -0
- package/dist/targets/vue/radix/toggle-group.js +10 -0
- package/dist/targets/vue/radix/toggle.d.ts +3 -0
- package/dist/targets/vue/radix/toggle.js +8 -0
- package/dist/targets/vue/radix/tooltip.d.ts +3 -0
- package/dist/targets/vue/radix/tooltip.js +14 -0
- package/dist/targets/vue/render-fn/h.d.ts +52 -0
- package/dist/targets/vue/render-fn/h.js +442 -0
- package/dist/targets/vue/render-fn.d.ts +21 -0
- package/dist/targets/vue/render-fn.js +357 -0
- package/dist/targets/vue/slot.d.ts +9 -0
- package/dist/targets/vue/slot.js +57 -0
- package/dist/typecheck/host.d.ts +45 -0
- package/dist/typecheck/host.js +309 -0
- package/dist/typecheck/index.d.ts +16 -0
- package/dist/typecheck/index.js +17 -0
- package/dist/typecheck/lucide.d.ts +8 -0
- package/dist/typecheck/lucide.js +45 -0
- package/dist/typecheck/sourcemap.d.ts +9 -0
- package/dist/typecheck/sourcemap.js +54 -0
- package/dist/typecheck/svelte.d.ts +9 -0
- package/dist/typecheck/svelte.js +116 -0
- package/dist/typecheck/vue.d.ts +8 -0
- package/dist/typecheck/vue.js +78 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +11 -0
- package/dist/utils/cleanup.d.ts +32 -0
- package/dist/utils/cleanup.js +119 -0
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/errors.js +15 -0
- package/dist/utils/fs-safe.d.ts +14 -0
- package/dist/utils/fs-safe.js +64 -0
- package/dist/validate.d.ts +16 -0
- package/dist/validate.js +204 -0
- package/dist/verify/auto-steps.d.ts +107 -0
- package/dist/verify/auto-steps.js +471 -0
- package/dist/verify/bundle.d.ts +68 -0
- package/dist/verify/bundle.js +548 -0
- package/dist/verify/diff.d.ts +31 -0
- package/dist/verify/diff.js +133 -0
- package/dist/verify/leaks.d.ts +25 -0
- package/dist/verify/leaks.js +261 -0
- package/dist/verify/link-worker.d.ts +1 -0
- package/dist/verify/link-worker.js +27 -0
- package/dist/verify/runner.d.ts +57 -0
- package/dist/verify/runner.js +867 -0
- package/dist/verify/sandbox.d.ts +40 -0
- package/dist/verify/sandbox.js +496 -0
- package/dist/verify/steps.d.ts +42 -0
- package/dist/verify/steps.js +475 -0
- package/dist/verify/verdict.d.ts +15 -0
- package/dist/verify/verdict.js +19 -0
- package/package.json +118 -4
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { templateExpressions } from '../shared/inline.js';
|
|
3
|
+
/**
|
|
4
|
+
* A component that tells markup apart itself (`isValidElement(art) ? art : art[state]`, the "art" family): on Angular
|
|
5
|
+
* the markup a parent passes is a `TemplateRef`, so React's element test is `art instanceof TemplateRef`, React's
|
|
6
|
+
* `ReactNode` in the component's types also takes a `TemplateRef`, and a value that may hold markup renders through
|
|
7
|
+
* `ngTemplateOutlet` where React renders it (`{picture}`). That is exact only when every read of such a value is one
|
|
8
|
+
* this module can follow: a presence or `typeof` test, a member read, a value carried to a derived value (`picture`),
|
|
9
|
+
* or the rendered value itself. `markupReads` says whether it is, and which rendered values are templates.
|
|
10
|
+
*/
|
|
11
|
+
/** The rendered `{picture}` nodes whose value may be a template (printed with the outlet). */
|
|
12
|
+
export const TEMPLATE_VALUES = new WeakSet();
|
|
13
|
+
/**
|
|
14
|
+
* Whether a component takes a parent's markup as templates (null) or why not, decided once per component: the
|
|
15
|
+
* component's own emission and a parent's (which asks before passing templates) see the same answer, whichever file
|
|
16
|
+
* is emitted first.
|
|
17
|
+
*/
|
|
18
|
+
const DECIDED = new WeakMap();
|
|
19
|
+
export function takesMarkupTemplates(comp, testsElements, isElement, moduleFn = () => null) {
|
|
20
|
+
const known = DECIDED.get(comp);
|
|
21
|
+
if (known !== undefined)
|
|
22
|
+
return known;
|
|
23
|
+
const why = !testsElements() && !(isElement && rendersDerivedMarkup(comp, isElement)) ? `${comp.name} does not tell markup apart (no isValidElement test)` : !isElement ? 'no types to follow the value with' : markupReads(comp, isElement, moduleFn);
|
|
24
|
+
DECIDED.set(comp, why);
|
|
25
|
+
return why;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The module functions a component's markup reads were followed into (`isPerState(art)`), each with the index of the
|
|
29
|
+
* parameter that takes the value: their tests of that parameter are React's element tests too.
|
|
30
|
+
*/
|
|
31
|
+
export const FOLLOWED_FNS = new WeakMap();
|
|
32
|
+
const WIDENED = new WeakSet();
|
|
33
|
+
/** The functions a module declares at its top level, by name. */
|
|
34
|
+
export function moduleFnIn(mod) {
|
|
35
|
+
return (name) => {
|
|
36
|
+
for (const st of mod.moduleBody) {
|
|
37
|
+
const decl = t.isExportNamedDeclaration(st) ? st.declaration : st;
|
|
38
|
+
if (t.isFunctionDeclaration(decl) && decl.id?.name === name)
|
|
39
|
+
return decl;
|
|
40
|
+
if (!t.isVariableDeclaration(decl) || decl.kind !== 'const')
|
|
41
|
+
continue;
|
|
42
|
+
for (const d of decl.declarations) {
|
|
43
|
+
if (t.isIdentifier(d.id, { name }) && (t.isArrowFunctionExpression(d.init) || t.isFunctionExpression(d.init)))
|
|
44
|
+
return d.init;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Each followed parameter of `fn` also takes a template. A parameter typed as one of the component's props
|
|
52
|
+
* (`art: Props['art']`) takes that prop's type with every `ReactNode` in it widened, as the input is; any other type
|
|
53
|
+
* takes a template beside it.
|
|
54
|
+
*/
|
|
55
|
+
export function templateParams(fn, params, comp, templateRef) {
|
|
56
|
+
// a function two components hand their values to is widened once
|
|
57
|
+
if (WIDENED.has(fn))
|
|
58
|
+
return;
|
|
59
|
+
WIDENED.add(fn);
|
|
60
|
+
for (const i of params) {
|
|
61
|
+
const param = fn.params[i];
|
|
62
|
+
if (!t.isIdentifier(param) || !t.isTSTypeAnnotation(param.typeAnnotation))
|
|
63
|
+
continue;
|
|
64
|
+
const type = param.typeAnnotation.typeAnnotation;
|
|
65
|
+
const key = t.isTSIndexedAccessType(type) && t.isTSTypeReference(type.objectType) && t.isIdentifier(type.objectType.typeName, { name: comp.propsTypeName ?? '' }) && t.isTSLiteralType(type.indexType) && t.isStringLiteral(type.indexType.literal)
|
|
66
|
+
? type.indexType.literal.value
|
|
67
|
+
: null;
|
|
68
|
+
const declared = key ? comp.declared.get(key) : undefined;
|
|
69
|
+
const own = declared?.type ? t.cloneNode(declared.type, true) : null;
|
|
70
|
+
const optional = own && declared?.optional ? t.tsUnionType([own, t.tsUndefinedKeyword()]) : own;
|
|
71
|
+
param.typeAnnotation.typeAnnotation = optional ? withTemplateType(optional, templateRef) : namesReactNode(type) ? withTemplateType(type, templateRef) : t.tsUnionType([type, templateRef()]);
|
|
72
|
+
// a type guard of that parameter (`art is Record<Mood, ReactNode>`) narrows to entries that take a template too
|
|
73
|
+
const guard = t.isTSTypeAnnotation(fn.returnType) ? fn.returnType.typeAnnotation : null;
|
|
74
|
+
if (t.isTSTypePredicate(guard) && t.isIdentifier(guard.parameterName, { name: param.name }) && guard.typeAnnotation)
|
|
75
|
+
guard.typeAnnotation.typeAnnotation = withTemplateType(guard.typeAnnotation.typeAnnotation, templateRef);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** React's brand test of an element, `'$$typeof' in x`, as Angular's: `x instanceof TemplateRef` (in place). */
|
|
79
|
+
export function brandTestsAsTemplateTests(root, templateRef) {
|
|
80
|
+
const seen = new WeakSet();
|
|
81
|
+
const walk = (value) => {
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
value.forEach((v, i) => {
|
|
84
|
+
if (t.isNode(v) && isElementBrandTest(v))
|
|
85
|
+
value[i] = t.binaryExpression('instanceof', v.right, templateRef());
|
|
86
|
+
walk(value[i]);
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
91
|
+
return;
|
|
92
|
+
seen.add(value);
|
|
93
|
+
if (t.isNode(value)) {
|
|
94
|
+
for (const key of t.VISITOR_KEYS[value.type] ?? []) {
|
|
95
|
+
const child = Reflect.get(value, key);
|
|
96
|
+
if (t.isNode(child) && isElementBrandTest(child))
|
|
97
|
+
Reflect.set(value, key, t.binaryExpression('instanceof', child.right, templateRef()));
|
|
98
|
+
walk(Reflect.get(value, key));
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
for (const v of Object.values(value))
|
|
103
|
+
walk(v);
|
|
104
|
+
};
|
|
105
|
+
walk(root);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether the component renders a value computed from others that React's types say may be an element
|
|
109
|
+
* (`const picture = isPerState(art) ? art[state] : art`, `{picture}`): such a value holds a parent's markup as often as
|
|
110
|
+
* text, so it renders as a template where it holds one, whether or not the component tells markup apart itself.
|
|
111
|
+
*/
|
|
112
|
+
export function rendersDerivedMarkup(comp, isElement) {
|
|
113
|
+
const roots = new Set();
|
|
114
|
+
const walk = (n) => {
|
|
115
|
+
if (n.type === 'expr' && t.isIdentifier(n.expr))
|
|
116
|
+
roots.add(n.expr);
|
|
117
|
+
if (n.type === 'element')
|
|
118
|
+
for (const a of n.attrs)
|
|
119
|
+
if (a.kind === 'slotProp')
|
|
120
|
+
a.children.forEach(walk);
|
|
121
|
+
if (n.type === 'if')
|
|
122
|
+
for (const b of n.branches)
|
|
123
|
+
b.children.forEach(walk);
|
|
124
|
+
else if (n.type === 'slot')
|
|
125
|
+
n.fallback.forEach(walk);
|
|
126
|
+
else if ('children' in n && Array.isArray(n.children))
|
|
127
|
+
n.children.forEach(walk);
|
|
128
|
+
};
|
|
129
|
+
walk(comp.template);
|
|
130
|
+
for (const f of comp.fragments)
|
|
131
|
+
walk(f.template);
|
|
132
|
+
for (const r of roots)
|
|
133
|
+
if (t.isIdentifier(r) && comp.bindings.get(r.name)?.kind === 'derived' && isElement(r))
|
|
134
|
+
return true;
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
/** The keys a React element has as own properties: an `in` test of one of them tells an element from a template. */
|
|
138
|
+
const ELEMENT_KEYS = new Set(['$$typeof', 'type', 'props', 'key', 'ref', '_owner', '_store', '_self', '_source']);
|
|
139
|
+
/** `'$$typeof' in x`: React's own brand test of an element (as isValidElement), a template test on Angular. */
|
|
140
|
+
export function isElementBrandTest(n) {
|
|
141
|
+
return t.isBinaryExpression(n, { operator: 'in' }) && t.isStringLiteral(n.left, { value: '$$typeof' }) && t.isExpression(n.right);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Whether `x in value` (value at the right) reads only a key no element and no template has (a state name, a symbol):
|
|
145
|
+
* false for both, as React's test is false for an element. A key read from a callback's parameter counts when the
|
|
146
|
+
* callback runs over a list of plain string literals (`['good', 'watch'].some((k) => k in art)`).
|
|
147
|
+
*/
|
|
148
|
+
function plainKeyTest(p, parents, at) {
|
|
149
|
+
const left = p.left;
|
|
150
|
+
if (t.isStringLiteral(left))
|
|
151
|
+
return !ELEMENT_KEYS.has(left.value);
|
|
152
|
+
if (t.isMemberExpression(left) && !left.computed && t.isIdentifier(left.object, { name: 'Symbol' }))
|
|
153
|
+
return true;
|
|
154
|
+
if (!t.isIdentifier(left))
|
|
155
|
+
return false;
|
|
156
|
+
for (let i = at - 1; i >= 1; i--) {
|
|
157
|
+
const fn = parents[i];
|
|
158
|
+
if (!t.isArrowFunctionExpression(fn) && !t.isFunctionExpression(fn))
|
|
159
|
+
continue;
|
|
160
|
+
if (!fn.params.some((q) => t.isIdentifier(q, { name: left.name })))
|
|
161
|
+
return false;
|
|
162
|
+
const call = parents[i - 1];
|
|
163
|
+
if (!t.isCallExpression(call) || !call.arguments.includes(fn) || !t.isMemberExpression(call.callee))
|
|
164
|
+
return false;
|
|
165
|
+
const list = call.callee.object;
|
|
166
|
+
return t.isArrayExpression(list) && list.elements.every((e) => t.isStringLiteral(e) && !ELEMENT_KEYS.has(e.value));
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Whether every read of parameter `index` of module function `fn` only tests the value (presence, `typeof`, React's
|
|
172
|
+
* element tests, `Array.isArray`, a key test no element passes) and the parameter is never written: the value then
|
|
173
|
+
* goes no further than the function, whose result is about it, not it.
|
|
174
|
+
*/
|
|
175
|
+
function testsParamOnly(fn, index) {
|
|
176
|
+
const param = fn.params[index];
|
|
177
|
+
if (!t.isIdentifier(param))
|
|
178
|
+
return false;
|
|
179
|
+
const name = param.name;
|
|
180
|
+
let ok = true;
|
|
181
|
+
const visit = (n, parents) => {
|
|
182
|
+
if (!ok)
|
|
183
|
+
return;
|
|
184
|
+
if (t.isTSType(n) || t.isTSTypeAnnotation(n))
|
|
185
|
+
return;
|
|
186
|
+
// a nested function declaring the same name hides the parameter
|
|
187
|
+
if (n !== fn && t.isFunction(n) && n.params.some((q) => t.isIdentifier(q, { name })))
|
|
188
|
+
return;
|
|
189
|
+
if (t.isIdentifier(n, { name }) && parents.length && isReadPosition(n, parents[parents.length - 1])) {
|
|
190
|
+
if (!testOnly(n, parents))
|
|
191
|
+
ok = false;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if ((t.isAssignmentExpression(n) || t.isUpdateExpression(n)) && t.isIdentifier(t.isAssignmentExpression(n) ? n.left : n.argument, { name })) {
|
|
195
|
+
ok = false;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
199
|
+
const value = Reflect.get(n, key);
|
|
200
|
+
if (Array.isArray(value)) {
|
|
201
|
+
for (const c of value)
|
|
202
|
+
if (t.isNode(c))
|
|
203
|
+
visit(c, [...parents, n]);
|
|
204
|
+
}
|
|
205
|
+
else if (t.isNode(value))
|
|
206
|
+
visit(value, [...parents, n]);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
for (const [i, p] of fn.params.entries())
|
|
210
|
+
if (i !== index)
|
|
211
|
+
visit(p, [fn]);
|
|
212
|
+
visit(fn.body, [fn]);
|
|
213
|
+
return ok;
|
|
214
|
+
}
|
|
215
|
+
/** Whether the read `n` (inside `parents`) is a test of the value and nothing else. */
|
|
216
|
+
function testOnly(n, parents) {
|
|
217
|
+
let cur = n;
|
|
218
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
219
|
+
const p = parents[i];
|
|
220
|
+
if (!p)
|
|
221
|
+
return false;
|
|
222
|
+
if (t.isTSAsExpression(p) || t.isTSNonNullExpression(p) || t.isTSSatisfiesExpression(p) || t.isParenthesizedExpression(p)) {
|
|
223
|
+
cur = p;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (t.isUnaryExpression(p) && (p.operator === '!' || p.operator === 'typeof'))
|
|
227
|
+
return true;
|
|
228
|
+
if (t.isCallExpression(p) && p.arguments.length === 1 && p.arguments[0] === cur && isElementTestCallee(p.callee))
|
|
229
|
+
return true;
|
|
230
|
+
if (isElementBrandTest(p) && p.right === cur)
|
|
231
|
+
return true;
|
|
232
|
+
if (t.isBinaryExpression(p, { operator: 'in' }) && p.right === cur)
|
|
233
|
+
return plainKeyTest(p, parents, i);
|
|
234
|
+
if (t.isLogicalExpression(p) && p.operator === '&&' && p.left === cur)
|
|
235
|
+
return true;
|
|
236
|
+
if (t.isConditionalExpression(p) && p.test === cur)
|
|
237
|
+
return true;
|
|
238
|
+
if (t.isIfStatement(p) && p.test === cur)
|
|
239
|
+
return true;
|
|
240
|
+
if (t.isBinaryExpression(p) && ['===', '!==', '==', '!='].includes(p.operator) && (t.isNullLiteral(p.left === cur ? p.right : p.left) || t.isIdentifier(p.left === cur ? p.right : p.left, { name: 'undefined' })))
|
|
241
|
+
return true;
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Markup a component's own markup holds in a prop's data (`art={ink ? { list: artList } : undefined}`,
|
|
248
|
+
* `ComponentIR.markupValues`): printed as `<ng-template #artList>` in the component's template, which the attribute
|
|
249
|
+
* reads by name, when every read of each name is such a value of an attribute of a component that takes templates
|
|
250
|
+
* for that prop (`receives` gives why not), and none is inside a loop (a template outside the loop would not see the
|
|
251
|
+
* row). Null when printed; else why not.
|
|
252
|
+
*/
|
|
253
|
+
export function markupValuesPrinted(comp, receives) {
|
|
254
|
+
const names = new Set((comp.markupValues ?? []).map((v) => v.name));
|
|
255
|
+
if (!names.size)
|
|
256
|
+
return null;
|
|
257
|
+
let all = 0;
|
|
258
|
+
const count = (n) => {
|
|
259
|
+
t.traverseFast(n, (x) => {
|
|
260
|
+
if (t.isIdentifier(x) && names.has(x.name))
|
|
261
|
+
all++;
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
for (const e of [...templateExpressions(comp.template), ...comp.fragments.flatMap((f) => templateExpressions(f.template))])
|
|
265
|
+
count(e);
|
|
266
|
+
for (const item of comp.items)
|
|
267
|
+
for (const v of Object.values(item))
|
|
268
|
+
if (t.isNode(v))
|
|
269
|
+
count(v);
|
|
270
|
+
for (const v of comp.markupValues ?? [])
|
|
271
|
+
for (const e of templateExpressions(v.template))
|
|
272
|
+
count(e);
|
|
273
|
+
let placed = 0;
|
|
274
|
+
let why = null;
|
|
275
|
+
const walk = (n, inLoop) => {
|
|
276
|
+
if (why)
|
|
277
|
+
return;
|
|
278
|
+
if (n.type === 'element') {
|
|
279
|
+
for (const a of n.attrs) {
|
|
280
|
+
if (a.kind === 'slotProp')
|
|
281
|
+
a.children.forEach((c) => walk(c, inLoop));
|
|
282
|
+
if (a.kind !== 'expr')
|
|
283
|
+
continue;
|
|
284
|
+
const refs = valueRefs(a.expr, names);
|
|
285
|
+
if (refs === null) {
|
|
286
|
+
why = `"${a.name}" on <${n.tag}> uses the markup in a way other than as a value of its data`;
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (!refs)
|
|
290
|
+
continue;
|
|
291
|
+
if (inLoop) {
|
|
292
|
+
why = `"${a.name}" on <${n.tag}> is inside a loop`;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const no = n.component ? receives(n.tag, a.name) : `<${n.tag}> is not a component`;
|
|
296
|
+
if (no) {
|
|
297
|
+
why = no;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
placed += refs;
|
|
301
|
+
}
|
|
302
|
+
n.children.forEach((c) => walk(c, inLoop));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (n.type === 'if')
|
|
306
|
+
for (const b of n.branches)
|
|
307
|
+
b.children.forEach((c) => walk(c, inLoop));
|
|
308
|
+
else if (n.type === 'for')
|
|
309
|
+
n.children.forEach((c) => walk(c, true));
|
|
310
|
+
else if (n.type === 'slot')
|
|
311
|
+
n.fallback.forEach((c) => walk(c, inLoop));
|
|
312
|
+
else if ('children' in n && Array.isArray(n.children))
|
|
313
|
+
n.children.forEach((c) => walk(c, inLoop));
|
|
314
|
+
};
|
|
315
|
+
walk(comp.template, false);
|
|
316
|
+
if (why)
|
|
317
|
+
return why;
|
|
318
|
+
return placed === all ? null : `${comp.name} reads the markup outside the attribute that passes it`;
|
|
319
|
+
}
|
|
320
|
+
/** How many times `e` names one of `names` as a value of its data (an object member, a branch, `&&`/`||`); null when one is used otherwise. */
|
|
321
|
+
function valueRefs(e, names) {
|
|
322
|
+
let n = 0;
|
|
323
|
+
let bad = false;
|
|
324
|
+
const visit = (x, parent) => {
|
|
325
|
+
if (bad)
|
|
326
|
+
return;
|
|
327
|
+
if (t.isIdentifier(x) && names.has(x.name)) {
|
|
328
|
+
const ok = !parent ||
|
|
329
|
+
(t.isObjectProperty(parent) && parent.value === x && !parent.computed) ||
|
|
330
|
+
(t.isConditionalExpression(parent) && parent.test !== x) ||
|
|
331
|
+
(t.isLogicalExpression(parent) && parent.right === x);
|
|
332
|
+
if (ok)
|
|
333
|
+
n++;
|
|
334
|
+
else
|
|
335
|
+
bad = true;
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
// a holder of the value must itself sit where a value goes
|
|
339
|
+
if (parent && !(t.isObjectExpression(x) || t.isObjectProperty(x) || t.isConditionalExpression(x) || t.isLogicalExpression(x))) {
|
|
340
|
+
let hit = false;
|
|
341
|
+
t.traverseFast(x, (y) => {
|
|
342
|
+
if (t.isIdentifier(y) && names.has(y.name))
|
|
343
|
+
hit = true;
|
|
344
|
+
});
|
|
345
|
+
if (hit)
|
|
346
|
+
bad = true;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
for (const key of t.VISITOR_KEYS[x.type] ?? []) {
|
|
350
|
+
const value = Reflect.get(x, key);
|
|
351
|
+
if (Array.isArray(value)) {
|
|
352
|
+
for (const c of value)
|
|
353
|
+
if (t.isNode(c))
|
|
354
|
+
visit(c, x);
|
|
355
|
+
}
|
|
356
|
+
else if (t.isNode(value))
|
|
357
|
+
visit(value, x);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
visit(e, null);
|
|
361
|
+
return bad ? null : n;
|
|
362
|
+
}
|
|
363
|
+
/** Each name of `names` in the component's markup replaced by `undefined` (the markup is not converted). */
|
|
364
|
+
export function withoutMarkupValues(n, names) {
|
|
365
|
+
const clear = (e) => {
|
|
366
|
+
if (t.isIdentifier(e) && names.has(e.name))
|
|
367
|
+
return t.identifier('undefined');
|
|
368
|
+
t.traverseFast(e, (x) => {
|
|
369
|
+
for (const key of t.VISITOR_KEYS[x.type] ?? []) {
|
|
370
|
+
const value = Reflect.get(x, key);
|
|
371
|
+
if (Array.isArray(value))
|
|
372
|
+
value.forEach((c, i) => {
|
|
373
|
+
if (t.isNode(c) && t.isIdentifier(c) && names.has(c.name))
|
|
374
|
+
value[i] = t.identifier('undefined');
|
|
375
|
+
});
|
|
376
|
+
else if (t.isNode(value) && t.isIdentifier(value) && names.has(value.name) && !(t.isObjectProperty(x) && x.key === value && !x.computed) && !((t.isMemberExpression(x) || t.isOptionalMemberExpression(x)) && x.property === value && !x.computed))
|
|
377
|
+
Reflect.set(x, key, t.identifier('undefined'));
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
return e;
|
|
381
|
+
};
|
|
382
|
+
const children = (list) => list.forEach((c) => withoutMarkupValues(c, names));
|
|
383
|
+
if (n.type === 'element') {
|
|
384
|
+
for (const a of n.attrs) {
|
|
385
|
+
if (a.kind === 'expr')
|
|
386
|
+
a.expr = clear(a.expr);
|
|
387
|
+
if (a.kind === 'slotProp')
|
|
388
|
+
children(a.children);
|
|
389
|
+
}
|
|
390
|
+
children(n.children);
|
|
391
|
+
}
|
|
392
|
+
else if (n.type === 'if')
|
|
393
|
+
for (const b of n.branches)
|
|
394
|
+
children(b.children);
|
|
395
|
+
else if (n.type === 'slot')
|
|
396
|
+
children(n.fallback);
|
|
397
|
+
else if ('children' in n && Array.isArray(n.children))
|
|
398
|
+
children(n.children);
|
|
399
|
+
}
|
|
400
|
+
/** Why the component's element test cannot become `instanceof TemplateRef`, or null when every read is followed. */
|
|
401
|
+
export function markupReads(comp, isElement, moduleFn = () => null) {
|
|
402
|
+
// a module function the value is handed to that only tests it (`isPerState(art)`)
|
|
403
|
+
const fns = new Map();
|
|
404
|
+
const intoFn = (call, at) => {
|
|
405
|
+
const fn = t.isIdentifier(call.callee) ? moduleFn(call.callee.name) : null;
|
|
406
|
+
if (!fn || !testsParamOnly(fn, at))
|
|
407
|
+
return false;
|
|
408
|
+
fns.set(fn, new Set([...(fns.get(fn) ?? []), at]));
|
|
409
|
+
return true;
|
|
410
|
+
};
|
|
411
|
+
const tests = new Set();
|
|
412
|
+
const rendered = new Map();
|
|
413
|
+
const slotsOfRead = [];
|
|
414
|
+
// the falsy-number branch (`@else if (typeof picture() === 'number') {{ picture() }}`) prints a number
|
|
415
|
+
const numbers = new Set();
|
|
416
|
+
// (any value tested so: `typeof (!picture && icon) === 'number'` prints `!picture && icon`, a number there)
|
|
417
|
+
const numberTested = (e) => t.isLogicalExpression(e, { operator: '&&' })
|
|
418
|
+
? [...numberTested(e.left), ...numberTested(e.right)]
|
|
419
|
+
: t.isBinaryExpression(e, { operator: '===' }) && t.isUnaryExpression(e.left, { operator: 'typeof' }) && t.isStringLiteral(e.right, { value: 'number' })
|
|
420
|
+
? [e.left.argument]
|
|
421
|
+
: [];
|
|
422
|
+
const walk = (n) => {
|
|
423
|
+
if (n.type === 'if') {
|
|
424
|
+
for (const b of n.branches) {
|
|
425
|
+
if (!b.test)
|
|
426
|
+
continue;
|
|
427
|
+
tests.add(b.test);
|
|
428
|
+
const tested = numberTested(b.test);
|
|
429
|
+
for (const c of b.children)
|
|
430
|
+
if (c.type === 'expr' && tested.some((x) => t.isNodesEquivalent(x, c.expr)))
|
|
431
|
+
numbers.add(c.expr);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (n.type === 'expr' && t.isIdentifier(n.expr))
|
|
435
|
+
rendered.set(n.expr, n);
|
|
436
|
+
if (n.type === 'slot' && n.prop)
|
|
437
|
+
slotsOfRead.push(n.prop);
|
|
438
|
+
if (n.type === 'element')
|
|
439
|
+
for (const a of n.attrs)
|
|
440
|
+
if (a.kind === 'slotProp')
|
|
441
|
+
a.children.forEach(walk);
|
|
442
|
+
if (n.type === 'if')
|
|
443
|
+
for (const b of n.branches)
|
|
444
|
+
b.children.forEach(walk);
|
|
445
|
+
else if (n.type === 'slot')
|
|
446
|
+
n.fallback.forEach(walk);
|
|
447
|
+
else if ('children' in n && Array.isArray(n.children))
|
|
448
|
+
n.children.forEach(walk);
|
|
449
|
+
};
|
|
450
|
+
walk(comp.template);
|
|
451
|
+
for (const f of comp.fragments)
|
|
452
|
+
walk(f.template);
|
|
453
|
+
// a prop rendered in place (a slot) and read in code: the slot prints it as text
|
|
454
|
+
const readInCode = new Set();
|
|
455
|
+
for (const item of comp.items) {
|
|
456
|
+
for (const v of Object.values(item)) {
|
|
457
|
+
if (t.isNode(v))
|
|
458
|
+
t.traverseFast(v, (x) => {
|
|
459
|
+
if (t.isIdentifier(x))
|
|
460
|
+
readInCode.add(x.name);
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const prop = slotsOfRead.find((name) => readInCode.has(name) && comp.props.some((p) => p.local === name));
|
|
465
|
+
if (prop)
|
|
466
|
+
return `${prop} is rendered in place and read in code`;
|
|
467
|
+
const values = [];
|
|
468
|
+
for (const root of [...templateExpressions(comp.template), ...comp.fragments.flatMap((f) => templateExpressions(f.template))]) {
|
|
469
|
+
if (numbers.has(root))
|
|
470
|
+
continue;
|
|
471
|
+
const node = rendered.get(root);
|
|
472
|
+
if (node && t.isIdentifier(root) && isElement(root)) {
|
|
473
|
+
const binding = comp.bindings.get(root.name);
|
|
474
|
+
if (binding?.kind !== 'derived' && !comp.props.some((p) => p.local === root.name))
|
|
475
|
+
return `${root.name} renders markup held in a value that is neither a prop nor a derived value`;
|
|
476
|
+
values.push(node);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const bad = unfollowed(root, tests.has(root) ? 'test' : 'print', isElement, intoFn);
|
|
480
|
+
if (bad)
|
|
481
|
+
return bad;
|
|
482
|
+
}
|
|
483
|
+
for (const item of comp.items) {
|
|
484
|
+
for (const v of Object.values(item)) {
|
|
485
|
+
if (!t.isNode(v) || t.isTSType(v))
|
|
486
|
+
continue;
|
|
487
|
+
const bad = unfollowed(v, item.kind === 'derived' ? 'carry' : 'print', isElement, intoFn);
|
|
488
|
+
if (bad)
|
|
489
|
+
return bad;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// a prop that takes a template, handed to a module function, whatever the types say at that place: the function's
|
|
493
|
+
// parameter takes a template too, so it must only test it
|
|
494
|
+
const widened = new Set(comp.props.filter((p) => namesReactNode(p.type)).map((p) => p.local));
|
|
495
|
+
let handed = null;
|
|
496
|
+
for (const item of comp.items) {
|
|
497
|
+
for (const v of Object.values(item)) {
|
|
498
|
+
if (!t.isNode(v) || t.isTSType(v))
|
|
499
|
+
continue;
|
|
500
|
+
t.traverseFast(v, (x) => {
|
|
501
|
+
if (handed || !t.isCallExpression(x) || !t.isIdentifier(x.callee) || !moduleFn(x.callee.name))
|
|
502
|
+
return;
|
|
503
|
+
x.arguments.forEach((a, i) => {
|
|
504
|
+
if (!handed && t.isIdentifier(a) && widened.has(a.name) && !intoFn(x, i))
|
|
505
|
+
handed = `${a.name} is handed to ${t.isIdentifier(x.callee) ? x.callee.name : 'a function'}, which uses it as more than a test`;
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (handed)
|
|
511
|
+
return handed;
|
|
512
|
+
for (const n of values)
|
|
513
|
+
TEMPLATE_VALUES.add(n);
|
|
514
|
+
if (fns.size)
|
|
515
|
+
FOLLOWED_FNS.set(comp, fns);
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* The first read of a value that may hold markup in a place this module cannot follow (as source text), or null.
|
|
520
|
+
* `test`: the root is a branch's test (truthiness only); `carry`: the root is a derived value's initializer, whose value
|
|
521
|
+
* may hold markup (its own reads are checked where they are); `print`: the root's value is used as it is.
|
|
522
|
+
*/
|
|
523
|
+
function unfollowed(root, mode, isElement, intoFn) {
|
|
524
|
+
let found = null;
|
|
525
|
+
const visit = (n, parents) => {
|
|
526
|
+
if (found)
|
|
527
|
+
return;
|
|
528
|
+
if (t.isTSType(n) || t.isTSTypeAnnotation(n) || t.isTSTypeParameterInstantiation(n))
|
|
529
|
+
return;
|
|
530
|
+
if ((t.isIdentifier(n) || t.isMemberExpression(n) || t.isOptionalMemberExpression(n)) && n.loc && isReadPosition(n, parents[parents.length - 1]) && isElement(n)) {
|
|
531
|
+
if (!followed(n, parents, mode, intoFn))
|
|
532
|
+
found = `${n.loc.start.line}`;
|
|
533
|
+
}
|
|
534
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
535
|
+
const value = Reflect.get(n, key);
|
|
536
|
+
if (Array.isArray(value)) {
|
|
537
|
+
for (const c of value)
|
|
538
|
+
if (t.isNode(c))
|
|
539
|
+
visit(c, [...parents, n]);
|
|
540
|
+
}
|
|
541
|
+
else if (t.isNode(value))
|
|
542
|
+
visit(value, [...parents, n]);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
visit(root, []);
|
|
546
|
+
return found ? `a value that may hold markup is used at line ${found} in a way a template cannot hold` : null;
|
|
547
|
+
}
|
|
548
|
+
/** An identifier that reads a value (not a property key, a declared name or a member's name). */
|
|
549
|
+
function isReadPosition(n, parent) {
|
|
550
|
+
if (!parent)
|
|
551
|
+
return true;
|
|
552
|
+
if ((t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.property === n && !parent.computed)
|
|
553
|
+
return false;
|
|
554
|
+
if (t.isObjectProperty(parent) && parent.key === n && !parent.computed)
|
|
555
|
+
return false;
|
|
556
|
+
if (t.isVariableDeclarator(parent) && parent.id === n)
|
|
557
|
+
return false;
|
|
558
|
+
if (t.isFunction(parent) && parent.params.some((p) => p === n))
|
|
559
|
+
return false;
|
|
560
|
+
return true;
|
|
561
|
+
}
|
|
562
|
+
function followed(n, parents, mode, intoFn) {
|
|
563
|
+
let cur = n;
|
|
564
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
565
|
+
const p = parents[i];
|
|
566
|
+
if (!p)
|
|
567
|
+
break;
|
|
568
|
+
// a presence or type test: a template is there and an object, as an element is
|
|
569
|
+
if (t.isUnaryExpression(p) && (p.operator === '!' || p.operator === 'typeof'))
|
|
570
|
+
return true;
|
|
571
|
+
// React's element test (replaced by `instanceof TemplateRef`), and `Array.isArray(x)`
|
|
572
|
+
if (t.isCallExpression(p) && p.arguments.some((a) => a === cur) && isElementTestCallee(p.callee))
|
|
573
|
+
return true;
|
|
574
|
+
// React's brand test (`'$$typeof' in x`, replaced the same way), and a key test no element and no template passes
|
|
575
|
+
if (isElementBrandTest(p) && p.right === cur)
|
|
576
|
+
return true;
|
|
577
|
+
if (t.isBinaryExpression(p, { operator: 'in' }) && p.right === cur)
|
|
578
|
+
return plainKeyTest(p, parents, i);
|
|
579
|
+
// handed to a module function that only tests it
|
|
580
|
+
if (t.isCallExpression(p) && p.arguments.some((a) => a === cur) && intoFn(p, p.arguments.findIndex((a) => a === cur)))
|
|
581
|
+
return true;
|
|
582
|
+
// a member read of the value: `(art as Record<…>)[state]` (the read is checked itself when it may hold markup)
|
|
583
|
+
if ((t.isMemberExpression(p) || t.isOptionalMemberExpression(p)) && p.object === cur)
|
|
584
|
+
return true;
|
|
585
|
+
if (t.isConditionalExpression(p) && p.test === cur)
|
|
586
|
+
return true;
|
|
587
|
+
if (t.isLogicalExpression(p) && p.operator === '&&' && p.left === cur)
|
|
588
|
+
return true;
|
|
589
|
+
if (t.isBinaryExpression(p) && ['===', '!==', '==', '!='].includes(p.operator) && (t.isNullLiteral(p.left === cur ? p.right : p.left) || t.isIdentifier(p.left === cur ? p.right : p.left, { name: 'undefined' })))
|
|
590
|
+
return true;
|
|
591
|
+
// the value goes on: its holder decides
|
|
592
|
+
if (t.isConditionalExpression(p) || t.isLogicalExpression(p) || t.isTSAsExpression(p) || t.isTSNonNullExpression(p) || t.isTSSatisfiesExpression(p) || t.isParenthesizedExpression(p)) {
|
|
593
|
+
cur = p;
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
// the root itself: a test reads its truthiness; a derived value carries it to where the value is read
|
|
599
|
+
return mode === 'test' || mode === 'carry';
|
|
600
|
+
}
|
|
601
|
+
function isElementTestCallee(callee) {
|
|
602
|
+
if (t.isIdentifier(callee, { name: 'isValidElement' }))
|
|
603
|
+
return true;
|
|
604
|
+
if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.property)) {
|
|
605
|
+
if (callee.property.name === 'isValidElement')
|
|
606
|
+
return true;
|
|
607
|
+
return t.isIdentifier(callee.object, { name: 'Array' }) && callee.property.name === 'isArray';
|
|
608
|
+
}
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
const NODE_NAMES = new Set(['ReactNode', 'ReactElement']);
|
|
612
|
+
function isNodeTypeName(name) {
|
|
613
|
+
if (t.isIdentifier(name))
|
|
614
|
+
return NODE_NAMES.has(name.name);
|
|
615
|
+
return t.isIdentifier(name.right) && NODE_NAMES.has(name.right.name);
|
|
616
|
+
}
|
|
617
|
+
/** Whether a type names React's `ReactNode` (or `ReactElement`) itself, where withTemplateType widens it (not through an alias). */
|
|
618
|
+
export function namesReactNode(type) {
|
|
619
|
+
let found = false;
|
|
620
|
+
if (type)
|
|
621
|
+
t.traverseFast(type, (x) => {
|
|
622
|
+
if (t.isTSTypeReference(x) && isNodeTypeName(x.typeName))
|
|
623
|
+
found = true;
|
|
624
|
+
});
|
|
625
|
+
return found;
|
|
626
|
+
}
|
|
627
|
+
/** A type that is React's `ReactNode` itself also takes a template; one that holds it is widened inside (see withTemplateNodes). */
|
|
628
|
+
export function withTemplateType(type, templateRef) {
|
|
629
|
+
if (t.isTSTypeReference(type) && isNodeTypeName(type.typeName))
|
|
630
|
+
return t.tsUnionType([type, templateRef()]);
|
|
631
|
+
withTemplateNodes(type, templateRef);
|
|
632
|
+
return type;
|
|
633
|
+
}
|
|
634
|
+
/** React's `ReactNode` (and `ReactElement`) in `node`'s types, each also taking a template: `ReactNode | TemplateRef<unknown>`. */
|
|
635
|
+
export function withTemplateNodes(node, templateRef) {
|
|
636
|
+
const widen = (x) => (t.isTSTypeReference(x) && isNodeTypeName(x.typeName) ? t.tsUnionType([x, templateRef()]) : null);
|
|
637
|
+
const visit = (n) => {
|
|
638
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
639
|
+
const value = Reflect.get(n, key);
|
|
640
|
+
if (Array.isArray(value)) {
|
|
641
|
+
value.forEach((c, i) => {
|
|
642
|
+
if (!t.isNode(c))
|
|
643
|
+
return;
|
|
644
|
+
const wide = widen(c);
|
|
645
|
+
if (wide)
|
|
646
|
+
value[i] = wide;
|
|
647
|
+
else
|
|
648
|
+
visit(c);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
else if (t.isNode(value)) {
|
|
652
|
+
const wide = widen(value);
|
|
653
|
+
if (wide)
|
|
654
|
+
Reflect.set(n, key, wide);
|
|
655
|
+
else
|
|
656
|
+
visit(value);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
visit(node);
|
|
661
|
+
}
|