@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,443 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { parse } from '@babel/parser';
|
|
3
|
+
import { forEachElement } from '../../ir/radix.js';
|
|
4
|
+
import { unwrap } from '../../ir/lower.js';
|
|
5
|
+
import { childNodes } from './walk.js';
|
|
6
|
+
/** Helper code written into an Angular file (it may hold decorators), as statements. */
|
|
7
|
+
export function helperStatements(code) {
|
|
8
|
+
return parse(code, { sourceType: 'module', plugins: ['typescript', ['decorators', { decoratorsBeforeExport: true }]] }).program.body;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* React's `ref` attribute in Angular. A ref the component made with `useRef` and puts on one of its own elements is a
|
|
12
|
+
* `viewChild()` query (see emit.ts). Every other ref an element takes (a callback ref, a ref a hook or a parent handed
|
|
13
|
+
* over, a function that builds one) goes through one small directive, `[bindRef]`, which does what React does with
|
|
14
|
+
* it: the element is handed to the callback, or written into the `{ current }` box, once it is in the view, and null is
|
|
15
|
+
* handed over when it leaves the view (or when the binding changes to another target, which then gets the element).
|
|
16
|
+
*/
|
|
17
|
+
/** The directive's class name, as a component's `imports` list it. */
|
|
18
|
+
export const BIND_REF = 'BindRef';
|
|
19
|
+
/** The directive's file, written once per conversion and imported by every component that binds a ref this way. */
|
|
20
|
+
export const BIND_REF_FILE = `import { Directive, effect, ElementRef, inject, input, untracked } from '@angular/core';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* React's \`ref\`: the element (or, on a component, the instance given as \`bindRefTo\`, whose members are the handle React
|
|
24
|
+
* code calls) goes to a callback or into a \`{ current }\` box once it is in the view; when it leaves (or the binding
|
|
25
|
+
* changes) the callback's cleanup runs, or the callback gets null, or the box is emptied.
|
|
26
|
+
*/
|
|
27
|
+
@Directive({ selector: '[bindRef]' })
|
|
28
|
+
export class BindRef<T> {
|
|
29
|
+
readonly bindRef = input.required<((value: T | null) => void | (() => void)) | { current: T | null } | null | undefined>();
|
|
30
|
+
readonly bindRefTo = input<T>();
|
|
31
|
+
private readonly element = inject<ElementRef<T>>(ElementRef).nativeElement;
|
|
32
|
+
|
|
33
|
+
constructor() {
|
|
34
|
+
effect((onCleanup) => {
|
|
35
|
+
const target = this.bindRef();
|
|
36
|
+
const value = this.bindRefTo() ?? this.element;
|
|
37
|
+
if (typeof target === 'function') {
|
|
38
|
+
const cleanup = untracked(() => target(value));
|
|
39
|
+
onCleanup(() => (typeof cleanup === 'function' ? cleanup() : target(null)));
|
|
40
|
+
} else if (target) {
|
|
41
|
+
target.current = value;
|
|
42
|
+
onCleanup(() => {
|
|
43
|
+
target.current = null;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}`;
|
|
49
|
+
/**
|
|
50
|
+
* A ref value with a constant choice in it (`true ? glowRef : lineRef`, left by inlining a component whose prop was a
|
|
51
|
+
* literal) as the branch it takes; anything else as it is.
|
|
52
|
+
*/
|
|
53
|
+
export function foldRef(e) {
|
|
54
|
+
const inner = unwrap(e);
|
|
55
|
+
if (!t.isConditionalExpression(inner))
|
|
56
|
+
return inner;
|
|
57
|
+
const test = constantTruth(inner.test);
|
|
58
|
+
if (test === null)
|
|
59
|
+
return inner;
|
|
60
|
+
return foldRef(test ? inner.consequent : inner.alternate);
|
|
61
|
+
}
|
|
62
|
+
/** Whether an expression is a constant (literals compared with `===` / `!==`, `&&`, `||`, `!`): its truth, or null. */
|
|
63
|
+
function constantTruth(e) {
|
|
64
|
+
const value = constantValue(e);
|
|
65
|
+
return value.known ? !!value.value : null;
|
|
66
|
+
}
|
|
67
|
+
function constantValue(e) {
|
|
68
|
+
const n = unwrap(e);
|
|
69
|
+
if (t.isBooleanLiteral(n) || t.isStringLiteral(n) || t.isNumericLiteral(n))
|
|
70
|
+
return { known: true, value: n.value };
|
|
71
|
+
if (t.isNullLiteral(n))
|
|
72
|
+
return { known: true, value: null };
|
|
73
|
+
if (t.isIdentifier(n, { name: 'undefined' }))
|
|
74
|
+
return { known: true, value: undefined };
|
|
75
|
+
if (t.isUnaryExpression(n, { operator: '!' })) {
|
|
76
|
+
const v = constantValue(n.argument);
|
|
77
|
+
return v.known ? { known: true, value: !v.value } : v;
|
|
78
|
+
}
|
|
79
|
+
if (t.isLogicalExpression(n)) {
|
|
80
|
+
const left = constantValue(n.left);
|
|
81
|
+
if (!left.known)
|
|
82
|
+
return left;
|
|
83
|
+
if (n.operator === '&&')
|
|
84
|
+
return left.value ? constantValue(n.right) : left;
|
|
85
|
+
if (n.operator === '||')
|
|
86
|
+
return left.value ? left : constantValue(n.right);
|
|
87
|
+
return left.value == null ? constantValue(n.right) : left;
|
|
88
|
+
}
|
|
89
|
+
if (t.isBinaryExpression(n) && (n.operator === '===' || n.operator === '!==') && t.isExpression(n.left)) {
|
|
90
|
+
const left = constantValue(n.left);
|
|
91
|
+
const right = constantValue(n.right);
|
|
92
|
+
if (!left.known || !right.known)
|
|
93
|
+
return { known: false };
|
|
94
|
+
return { known: true, value: n.operator === '===' ? left.value === right.value : left.value !== right.value };
|
|
95
|
+
}
|
|
96
|
+
return { known: false };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The name for a callback ref lifted into the class: from the box it fills (`el => { items.current[k] = el }` →
|
|
100
|
+
* `itemsRef`), else from the element (`buttonRef`).
|
|
101
|
+
*/
|
|
102
|
+
export function refCallbackName(fn, tag) {
|
|
103
|
+
let box = null;
|
|
104
|
+
t.traverseFast(fn.body, (n) => {
|
|
105
|
+
if (box || !t.isAssignmentExpression(n))
|
|
106
|
+
return;
|
|
107
|
+
let target = n.left;
|
|
108
|
+
while (t.isMemberExpression(target) || t.isOptionalMemberExpression(target)) {
|
|
109
|
+
if (t.isIdentifier(target.object) && !target.computed && t.isIdentifier(target.property, { name: 'current' })) {
|
|
110
|
+
box = target.object.name;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
target = target.object;
|
|
114
|
+
}
|
|
115
|
+
if (t.isIdentifier(target))
|
|
116
|
+
box = target.name;
|
|
117
|
+
});
|
|
118
|
+
const base = (box ?? tag).replace(/Ref$/, '').replace(/[^\w$]/g, '');
|
|
119
|
+
return `${base || 'element'}Ref`;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether a value is only tested or read through where it stands (`ref.current?.focus()`, `if (ref.current)`,
|
|
123
|
+
* `!ref.current`), so undefined and null read the same.
|
|
124
|
+
*/
|
|
125
|
+
export function readThrough(n, parent) {
|
|
126
|
+
if (!parent)
|
|
127
|
+
return false;
|
|
128
|
+
if ((t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.object === n)
|
|
129
|
+
return true;
|
|
130
|
+
if ((t.isCallExpression(parent) || t.isOptionalCallExpression(parent)) && parent.callee === n)
|
|
131
|
+
return true;
|
|
132
|
+
if (t.isUnaryExpression(parent, { operator: '!' }) || t.isIfStatement(parent) || t.isExpressionStatement(parent))
|
|
133
|
+
return true;
|
|
134
|
+
if (t.isConditionalExpression(parent) && parent.test === n)
|
|
135
|
+
return true;
|
|
136
|
+
if (t.isLogicalExpression(parent) && (parent.left === n || parent.operator !== '??'))
|
|
137
|
+
return true;
|
|
138
|
+
if (t.isTSNonNullExpression(parent))
|
|
139
|
+
return true;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
/** Whether an expression reads a binding of the function. */
|
|
143
|
+
export function readsBinding(e, name, ir) {
|
|
144
|
+
let found = false;
|
|
145
|
+
t.traverseFast(e, (n) => {
|
|
146
|
+
if (t.isIdentifier(n) && ir.refs.get(n) === name)
|
|
147
|
+
found = true;
|
|
148
|
+
});
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A callback ref without the statements that hand the element to the forwarded ref (`if (typeof ref === 'function')
|
|
153
|
+
* ref(node); else if (ref) ref.current = node;`), or null when it has none or reads the forwarded ref elsewhere.
|
|
154
|
+
*/
|
|
155
|
+
export function withoutForwarding(fn, forwardRef, refs) {
|
|
156
|
+
if (!t.isBlockStatement(fn.body))
|
|
157
|
+
return null;
|
|
158
|
+
const reads = (n) => {
|
|
159
|
+
let found = false;
|
|
160
|
+
t.traverseFast(n, (x) => {
|
|
161
|
+
if (t.isIdentifier(x) && refs.get(x) === forwardRef)
|
|
162
|
+
found = true;
|
|
163
|
+
});
|
|
164
|
+
return found;
|
|
165
|
+
};
|
|
166
|
+
const kept = fn.body.body.filter((st) => !reads(st));
|
|
167
|
+
if (kept.length === fn.body.body.length)
|
|
168
|
+
return null;
|
|
169
|
+
// what is left must not read it, and what went must only hand the element over (a test, a call, an assignment of it)
|
|
170
|
+
const went = fn.body.body.filter((st) => reads(st));
|
|
171
|
+
if (!went.every((st) => t.isIfStatement(st) || t.isExpressionStatement(st)))
|
|
172
|
+
return null;
|
|
173
|
+
const arrow = t.arrowFunctionExpression(fn.params, t.blockStatement(kept), fn.async);
|
|
174
|
+
return arrow;
|
|
175
|
+
}
|
|
176
|
+
/** The code a script item holds. */
|
|
177
|
+
function itemRoots(i) {
|
|
178
|
+
switch (i.kind) {
|
|
179
|
+
case 'statement':
|
|
180
|
+
return [i.node];
|
|
181
|
+
case 'effect':
|
|
182
|
+
return [i.body, ...(i.deps ?? [])];
|
|
183
|
+
case 'derived':
|
|
184
|
+
return [i.init];
|
|
185
|
+
case 'function':
|
|
186
|
+
return [i.node];
|
|
187
|
+
case 'hook':
|
|
188
|
+
return [i.call];
|
|
189
|
+
case 'state':
|
|
190
|
+
case 'ref':
|
|
191
|
+
return i.init ? [i.init] : [];
|
|
192
|
+
case 'block':
|
|
193
|
+
return i.statements;
|
|
194
|
+
case 'expose':
|
|
195
|
+
return [i.object];
|
|
196
|
+
case 'handle':
|
|
197
|
+
return [i.value];
|
|
198
|
+
default:
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** `ref={setRoot}` attributes whose callback handed the element to the forwarded ref (see forwardingCallbacks). */
|
|
203
|
+
export const FORWARDING_REFS = new WeakSet();
|
|
204
|
+
/**
|
|
205
|
+
* A component callback (`const setRoot = useCallback((node) => { rootRef.current = node; if (typeof ref === 'function')
|
|
206
|
+
* ref(node); else if (ref) ref.current = node; }, [ref])`) that is read only as one element's `ref`: the element is the
|
|
207
|
+
* public `el` query, as an inline callback's is, and the callback keeps the rest. Its `ref` attribute goes in
|
|
208
|
+
* FORWARDING_REFS.
|
|
209
|
+
*/
|
|
210
|
+
export function forwardingCallbacks(comp) {
|
|
211
|
+
const forwardRef = comp.forwardRef;
|
|
212
|
+
if (!forwardRef)
|
|
213
|
+
return;
|
|
214
|
+
const attrs = [];
|
|
215
|
+
forEachElement(comp, (el) => {
|
|
216
|
+
for (const a of el.attrs)
|
|
217
|
+
if (a.kind === 'ref' && t.isIdentifier(a.expr))
|
|
218
|
+
attrs.push({ expr: a.expr, name: comp.refs.get(a.expr) ?? a.expr.name });
|
|
219
|
+
});
|
|
220
|
+
for (const { expr, name } of attrs) {
|
|
221
|
+
const item = comp.items.find((i) => i.kind === 'function' && i.name === name);
|
|
222
|
+
if (!item || t.isFunctionDeclaration(item.node))
|
|
223
|
+
continue;
|
|
224
|
+
// read nowhere else: not by code, not by a second attribute
|
|
225
|
+
if (attrs.filter((x) => x.name === name).length > 1)
|
|
226
|
+
continue;
|
|
227
|
+
let elsewhere = false;
|
|
228
|
+
for (const other of comp.items) {
|
|
229
|
+
if (other === item)
|
|
230
|
+
continue;
|
|
231
|
+
for (const root of itemRoots(other))
|
|
232
|
+
t.traverseFast(root, (n) => {
|
|
233
|
+
if (t.isIdentifier(n) && comp.refs.get(n) === name)
|
|
234
|
+
elsewhere = true;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
let inMarkup = 0;
|
|
238
|
+
forEachElement(comp, (el) => {
|
|
239
|
+
for (const a of el.attrs) {
|
|
240
|
+
const value = a.kind === 'expr' || a.kind === 'event' || a.kind === 'spread' || a.kind === 'style' || a.kind === 'ref' ? (a.kind === 'event' ? a.handler : a.expr) : null;
|
|
241
|
+
if (value)
|
|
242
|
+
t.traverseFast(value, (n) => {
|
|
243
|
+
if (t.isIdentifier(n) && comp.refs.get(n) === name)
|
|
244
|
+
inMarkup++;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (elsewhere || inMarkup > 1)
|
|
249
|
+
continue;
|
|
250
|
+
const stripped = withoutForwarding(item.node, forwardRef, comp.refs);
|
|
251
|
+
if (!stripped)
|
|
252
|
+
continue;
|
|
253
|
+
item.node.body = stripped.body;
|
|
254
|
+
FORWARDING_REFS.add(expr);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Whether code that runs when the class is built (a hook call, a render statement, a field's value) reads a binding.
|
|
259
|
+
* `except`: readers that do not count (code moved to ngOnInit with it).
|
|
260
|
+
*/
|
|
261
|
+
export function readAtSetup(name, ir, except = () => false) {
|
|
262
|
+
const reads = (node) => {
|
|
263
|
+
let found = false;
|
|
264
|
+
if (node)
|
|
265
|
+
t.traverseFast(node, (n) => {
|
|
266
|
+
if (t.isIdentifier(n) && ir.refs.get(n) === name)
|
|
267
|
+
found = true;
|
|
268
|
+
});
|
|
269
|
+
return found;
|
|
270
|
+
};
|
|
271
|
+
return ir.items.some((item) => {
|
|
272
|
+
if (except(item))
|
|
273
|
+
return false;
|
|
274
|
+
if (item.kind === 'hook')
|
|
275
|
+
return reads(item.call);
|
|
276
|
+
if (item.kind === 'statement')
|
|
277
|
+
return reads(item.node);
|
|
278
|
+
if (item.kind === 'ref')
|
|
279
|
+
return item.name !== name && reads(item.init);
|
|
280
|
+
if (item.kind === 'derived')
|
|
281
|
+
return !item.names.some((n) => ir.bindings.get(n)?.reactive) && reads(item.init);
|
|
282
|
+
return false;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/** The value type of a `{ current }` box type (`RefObject<T>` as TypeScript saw it), or null. */
|
|
286
|
+
export function boxValueType(mapped) {
|
|
287
|
+
if (!mapped || !t.isTSTypeLiteral(mapped))
|
|
288
|
+
return null;
|
|
289
|
+
const current = mapped.members.find((m) => t.isTSPropertySignature(m) && t.isIdentifier(m.key, { name: 'current' }));
|
|
290
|
+
const value = current?.typeAnnotation?.typeAnnotation ?? null;
|
|
291
|
+
// React 19 types `useRef(value)` as a RefObject that may hold null; a ref given a first value holds that value's type
|
|
292
|
+
if (value && t.isTSUnionType(value)) {
|
|
293
|
+
const rest = value.types.filter((x) => !t.isTSNullKeyword(x));
|
|
294
|
+
return rest.length === 1 ? (rest[0] ?? null) : t.tsUnionType(rest);
|
|
295
|
+
}
|
|
296
|
+
return value;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Whether a function only reads the `.current` of its parameter at `index`: it never assigns it, and passes it on whole
|
|
300
|
+
* only to functions that, in turn, only read it (followed through their own modules; a cycle counts as reading).
|
|
301
|
+
*/
|
|
302
|
+
function onlyReads(code, index, seen, getter = false) {
|
|
303
|
+
const param = code.params[index];
|
|
304
|
+
if (!param || !t.isIdentifier(param))
|
|
305
|
+
return false;
|
|
306
|
+
// a walk already under way through this parameter (a cycle) counts as reading
|
|
307
|
+
const key = `${index}:${getter}`;
|
|
308
|
+
const own = seen.get(code) ?? new Set();
|
|
309
|
+
if (own.has(key))
|
|
310
|
+
return true;
|
|
311
|
+
own.add(key);
|
|
312
|
+
seen.set(code, own);
|
|
313
|
+
const follow = (name, at, passedGetter) => {
|
|
314
|
+
const next = code.callee?.(name);
|
|
315
|
+
return !!next && onlyReads(next, at, seen, passedGetter);
|
|
316
|
+
};
|
|
317
|
+
return !writesCurrent(code.body, [param.name], null, follow, getter);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Whether an element ref passed on whole (`useOnScreen(wrapRef)`, `useThing({ ref: rootRef })`) only goes where it is
|
|
321
|
+
* read: every place it escapes to is an argument (as it is, or passed live as `() => ref`) of a function this conversion
|
|
322
|
+
* has the code of, which never writes the parameter's `.current` and hands it on only to functions that do the same
|
|
323
|
+
* (see onlyReads). The Angular box of a query (`elementBox`) reads the element live, as React's ref object
|
|
324
|
+
* does; only a write would differ. Anything else (a library, a child component, a value kept) is not known to read.
|
|
325
|
+
*/
|
|
326
|
+
export function escapesOnlyToReaders(ir, roots, name, callee) {
|
|
327
|
+
// an effect moved into a framework-free core (`mountX(element, { fillRef })`, see shared/script buildCore) takes the
|
|
328
|
+
// ref as a box: its body is the core's, so a body that never writes the ref's `.current` nor hands it on only reads
|
|
329
|
+
const cores = ir.items.filter((i) => i.kind === 'effect' && !!i.core?.boxes.includes(name));
|
|
330
|
+
const coresRead = cores.every((i) => !writesCurrent([i.body], [name]));
|
|
331
|
+
let ok = true;
|
|
332
|
+
let found = false;
|
|
333
|
+
const visit = (n, parent, grand) => {
|
|
334
|
+
if (!ok)
|
|
335
|
+
return;
|
|
336
|
+
if (t.isIdentifier(n) && ir.refs.get(n) === name) {
|
|
337
|
+
if (parent && (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.object === n && !parent.computed && t.isIdentifier(parent.property, { name: 'current' }))
|
|
338
|
+
return;
|
|
339
|
+
if (parent && t.isJSXExpressionContainer(parent))
|
|
340
|
+
return;
|
|
341
|
+
found = true;
|
|
342
|
+
// an argument, as it is or as a property of an object argument
|
|
343
|
+
let call = null;
|
|
344
|
+
let index = -1;
|
|
345
|
+
let key = null;
|
|
346
|
+
let getter = false;
|
|
347
|
+
if (parent && t.isCallExpression(parent) && parent.arguments.includes(n)) {
|
|
348
|
+
call = parent;
|
|
349
|
+
index = parent.arguments.indexOf(n);
|
|
350
|
+
}
|
|
351
|
+
else if (parent && t.isArrowFunctionExpression(parent) && !parent.params.length && parent.body === n && grand && t.isCallExpression(grand) && grand.arguments.includes(parent)) {
|
|
352
|
+
// passed live (`useWidth(() => box)`, see ir/live-args): the callee reads it through the getter
|
|
353
|
+
call = grand;
|
|
354
|
+
index = grand.arguments.indexOf(parent);
|
|
355
|
+
getter = true;
|
|
356
|
+
}
|
|
357
|
+
else if (parent && t.isObjectProperty(parent) && parent.value === n && grand && t.isObjectExpression(grand)) {
|
|
358
|
+
key = t.isIdentifier(parent.key) ? parent.key.name : t.isStringLiteral(parent.key) ? parent.key.value : null;
|
|
359
|
+
}
|
|
360
|
+
if (key !== null && grand && t.isObjectExpression(grand)) {
|
|
361
|
+
// the object must itself be an argument of a known function (checked once the walk is done)
|
|
362
|
+
objectArgs.set(grand, key);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (!call || !t.isIdentifier(call.callee)) {
|
|
366
|
+
ok = false;
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const code = callee(call.callee.name);
|
|
370
|
+
if (!code || !onlyReads(code, index, new Map(), getter))
|
|
371
|
+
ok = false;
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// an object holding the ref, passed as an argument (`useThing({ ref: rootRef })`)
|
|
375
|
+
if (t.isCallExpression(n) && t.isIdentifier(n.callee)) {
|
|
376
|
+
n.arguments.forEach((arg, i) => {
|
|
377
|
+
if (!t.isObjectExpression(arg))
|
|
378
|
+
return;
|
|
379
|
+
pending.push({ call: n, index: i, object: arg });
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
for (const c of childNodes(n))
|
|
383
|
+
visit(c.node, n, parent);
|
|
384
|
+
};
|
|
385
|
+
const objectArgs = new Map();
|
|
386
|
+
const pending = [];
|
|
387
|
+
// a bare name as a whole template expression is the ref attribute that fills it (`ref={wrapRef}`)
|
|
388
|
+
for (const root of roots)
|
|
389
|
+
if (!(t.isIdentifier(root) && ir.refs.get(root) === name))
|
|
390
|
+
visit(root, null, null);
|
|
391
|
+
if (!ok)
|
|
392
|
+
return false;
|
|
393
|
+
// every object that holds the ref must be an argument of a known function that never writes that member's `.current`
|
|
394
|
+
for (const [object, key] of objectArgs) {
|
|
395
|
+
const at = pending.find((p) => p.object === object);
|
|
396
|
+
if (!at || !t.isIdentifier(at.call.callee))
|
|
397
|
+
return false;
|
|
398
|
+
const code = callee(at.call.callee.name);
|
|
399
|
+
const param = code?.params[at.index];
|
|
400
|
+
if (!code || !param)
|
|
401
|
+
return false;
|
|
402
|
+
// `{ ref }` destructured, or `options` read as `options.ref`
|
|
403
|
+
const locals = [];
|
|
404
|
+
if (t.isObjectPattern(param)) {
|
|
405
|
+
for (const p of param.properties)
|
|
406
|
+
if (t.isObjectProperty(p) && t.isIdentifier(p.key, { name: key }) && t.isIdentifier(p.value))
|
|
407
|
+
locals.push(p.value.name);
|
|
408
|
+
if (!locals.length)
|
|
409
|
+
return false;
|
|
410
|
+
if (writesCurrent(code.body, locals))
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
else if (t.isIdentifier(param)) {
|
|
414
|
+
if (writesCurrent(code.body, [param.name], key))
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
else
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
return (found || cores.length > 0) && coresRead;
|
|
421
|
+
}
|
|
422
|
+
/** Whether code assigns `<name>.current` (or `<name>.<key>.current`), or passes the name on to anything. */
|
|
423
|
+
function writesCurrent(body, names, key = null, follow, getter = false) {
|
|
424
|
+
let writes = false;
|
|
425
|
+
// `getter`: each name is a function returning the box (`ref().current`)
|
|
426
|
+
const box = (n) => (getter ? t.isCallExpression(n) && !n.arguments.length && t.isIdentifier(n.callee) && names.includes(n.callee.name) : t.isIdentifier(n) && names.includes(n.name));
|
|
427
|
+
const holds = (n) => {
|
|
428
|
+
if (key === null)
|
|
429
|
+
return box(n) || (getter && t.isIdentifier(n) && names.includes(n.name));
|
|
430
|
+
return t.isMemberExpression(n) && !n.computed && t.isIdentifier(n.object) && names.includes(n.object.name) && t.isIdentifier(n.property, { name: key });
|
|
431
|
+
};
|
|
432
|
+
for (const root of body) {
|
|
433
|
+
t.traverseFast(root, (n) => {
|
|
434
|
+
if (t.isAssignmentExpression(n) && t.isMemberExpression(n.left) && !n.left.computed && t.isIdentifier(n.left.property, { name: 'current' }) && holds(n.left.object))
|
|
435
|
+
writes = true;
|
|
436
|
+
// passed on whole: where it goes is not known here
|
|
437
|
+
// (a function known to only read it, when `follow` can tell)
|
|
438
|
+
if ((t.isCallExpression(n) || t.isNewExpression(n)) && n.arguments.some((a, i) => holds(a) && !(follow && t.isCallExpression(n) && t.isIdentifier(n.callee) && follow(n.callee.name, i, getter && t.isIdentifier(a)))))
|
|
439
|
+
writes = true;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
return writes;
|
|
443
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { RenderParam } from '../../ir/render-props.js';
|
|
3
|
+
/**
|
|
4
|
+
* Markup a parent passes as a value, on Angular: a `TemplateRef` input. A render prop (`actions={(picked) => <Bar />}`)
|
|
5
|
+
* is a template with a typed context the component fills (`*ngTemplateOutlet="actions(); context: { picked: rows }"`);
|
|
6
|
+
* markup passed to a node prop (`art={<Drawing />}`, or `art={ink ? <Drawing /> : undefined}`) is a template the
|
|
7
|
+
* component renders where the prop goes, and tests like the value React tested.
|
|
8
|
+
*/
|
|
9
|
+
/** `TemplateRef<{ picked: Row[] }>`: the template a render prop takes, its context named as the prop's type names the parameters. */
|
|
10
|
+
export declare function renderTemplateType(params: RenderParam[], type: (t: t.TSType | null) => t.TSType | null, api: (name: string) => string): t.TSType;
|
|
11
|
+
/** A node prop's type, which also takes a template of markup (`… | TemplateRef<unknown>`). */
|
|
12
|
+
export declare function withTemplate(type: t.TSType | null, api: (name: string) => string): t.TSType;
|
|
13
|
+
/**
|
|
14
|
+
* The `let-` bindings of a consumer's `<ng-template>` for a render function's parameters: each parameter named as the
|
|
15
|
+
* consumer named it, read from the context key the component's type names (`let-rows="picked"`). A destructured
|
|
16
|
+
* parameter (`({ id, label }) =>`) reads its object, then a `@let` per name. Null when a parameter has another shape.
|
|
17
|
+
*/
|
|
18
|
+
export declare function templateLets(fn: t.ArrowFunctionExpression | t.FunctionExpression, params: RenderParam[], alloc: (name: string) => string): {
|
|
19
|
+
lets: string[];
|
|
20
|
+
locals: string[];
|
|
21
|
+
names: string[];
|
|
22
|
+
} | null;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Markup a parent passes as a value, on Angular: a `TemplateRef` input. A render prop (`actions={(picked) => <Bar />}`)
|
|
4
|
+
* is a template with a typed context the component fills (`*ngTemplateOutlet="actions(); context: { picked: rows }"`);
|
|
5
|
+
* markup passed to a node prop (`art={<Drawing />}`, or `art={ink ? <Drawing /> : undefined}`) is a template the
|
|
6
|
+
* component renders where the prop goes, and tests like the value React tested.
|
|
7
|
+
*/
|
|
8
|
+
/** `TemplateRef<{ picked: Row[] }>`: the template a render prop takes, its context named as the prop's type names the parameters. */
|
|
9
|
+
export function renderTemplateType(params, type, api) {
|
|
10
|
+
const members = params.map((p) => {
|
|
11
|
+
const sig = t.tsPropertySignature(t.identifier(p.name), t.tsTypeAnnotation(type(p.type) ?? t.tsUnknownKeyword()));
|
|
12
|
+
sig.optional = p.optional;
|
|
13
|
+
return sig;
|
|
14
|
+
});
|
|
15
|
+
return t.tsTypeReference(t.identifier(api('TemplateRef')), t.tsTypeParameterInstantiation([t.tsTypeLiteral(members)]));
|
|
16
|
+
}
|
|
17
|
+
/** A node prop's type, which also takes a template of markup (`… | TemplateRef<unknown>`). */
|
|
18
|
+
export function withTemplate(type, api) {
|
|
19
|
+
const template = t.tsTypeReference(t.identifier(api('TemplateRef')), t.tsTypeParameterInstantiation([t.tsUnknownKeyword()]));
|
|
20
|
+
if (!type)
|
|
21
|
+
return template;
|
|
22
|
+
const members = t.isTSUnionType(type) ? type.types : [type];
|
|
23
|
+
// (a component that tells markup apart already took templates where React took a ReactNode)
|
|
24
|
+
if (members.some((m) => t.isTSTypeReference(m) && t.isIdentifier(m.typeName, { name: api('TemplateRef') })))
|
|
25
|
+
return type;
|
|
26
|
+
return t.tsUnionType([...members, template]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The `let-` bindings of a consumer's `<ng-template>` for a render function's parameters: each parameter named as the
|
|
30
|
+
* consumer named it, read from the context key the component's type names (`let-rows="picked"`). A destructured
|
|
31
|
+
* parameter (`({ id, label }) =>`) reads its object, then a `@let` per name. Null when a parameter has another shape.
|
|
32
|
+
*/
|
|
33
|
+
export function templateLets(fn, params, alloc) {
|
|
34
|
+
const lets = [];
|
|
35
|
+
const locals = [];
|
|
36
|
+
const names = [];
|
|
37
|
+
for (const [i, p] of fn.params.entries()) {
|
|
38
|
+
const key = params[i]?.name;
|
|
39
|
+
if (!key)
|
|
40
|
+
return null;
|
|
41
|
+
if (t.isIdentifier(p)) {
|
|
42
|
+
lets.push(`let-${p.name}="${key}"`);
|
|
43
|
+
names.push(p.name);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (t.isObjectPattern(p) && p.properties.every((x) => t.isObjectProperty(x) && !x.computed && t.isIdentifier(x.key) && t.isIdentifier(x.value))) {
|
|
47
|
+
const holder = alloc(key);
|
|
48
|
+
lets.push(`let-${holder}="${key}"`);
|
|
49
|
+
names.push(holder);
|
|
50
|
+
for (const x of p.properties) {
|
|
51
|
+
const name = x.value.name;
|
|
52
|
+
locals.push(`@let ${name} = ${holder}.${x.key.name};`);
|
|
53
|
+
names.push(name);
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return { lets, locals, names };
|
|
60
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as t from '@babel/types';
|
|
2
|
+
import type { WebContext } from '../shared/module.js';
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript's type for an identifier of the React source, found by its position: the checker's view of a name React
|
|
5
|
+
* left to inference (a loop row's item, a destructured field). A copy of an identifier (markup of a component written in
|
|
6
|
+
* place of its use, say) has lost its offset but keeps its line and column, which locate it as well. Null when the
|
|
7
|
+
* checker cannot say, or when the node is not an identifier of this file as written (a node the compiler made up or moved
|
|
8
|
+
* in from another file).
|
|
9
|
+
*/
|
|
10
|
+
export declare function sourceTypes(ctx: WebContext, write: (type: t.TSType) => t.TSType): (id: t.Identifier) => t.TSType | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript's type for an identifier of the React source, found by its position: the checker's view of a name React
|
|
5
|
+
* left to inference (a loop row's item, a destructured field). A copy of an identifier (markup of a component written in
|
|
6
|
+
* place of its use, say) has lost its offset but keeps its line and column, which locate it as well. Null when the
|
|
7
|
+
* checker cannot say, or when the node is not an identifier of this file as written (a node the compiler made up or moved
|
|
8
|
+
* in from another file).
|
|
9
|
+
*/
|
|
10
|
+
export function sourceTypes(ctx, write) {
|
|
11
|
+
let source = null;
|
|
12
|
+
let lines = null;
|
|
13
|
+
const own = resolve(ctx.sourceFile);
|
|
14
|
+
return (id) => {
|
|
15
|
+
if (!ctx.oracle)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
source ??= readFileSync(ctx.sourceFile, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
let start = id.start;
|
|
24
|
+
if (start == null) {
|
|
25
|
+
const loc = id.loc;
|
|
26
|
+
if (!loc || !loc.filename || resolve(loc.filename) !== own)
|
|
27
|
+
return null;
|
|
28
|
+
if (!lines) {
|
|
29
|
+
lines = [0];
|
|
30
|
+
for (let i = 0; i < source.length; i++)
|
|
31
|
+
if (source.charCodeAt(i) === 10)
|
|
32
|
+
lines.push(i + 1);
|
|
33
|
+
}
|
|
34
|
+
const line = lines[loc.start.line - 1];
|
|
35
|
+
if (line === undefined)
|
|
36
|
+
return null;
|
|
37
|
+
start = line + loc.start.column;
|
|
38
|
+
}
|
|
39
|
+
const after = source.charAt(start + id.name.length);
|
|
40
|
+
if (source.slice(start, start + id.name.length) !== id.name || /[\w$]/.test(after))
|
|
41
|
+
return null;
|
|
42
|
+
const type = ctx.oracle.typeAt(ctx.sourceFile, start);
|
|
43
|
+
return type ? write(type) : null;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { AttrNode, ComponentIR, ElementNode } from '../../ir/model.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default a component gives a prop it reads off its props object (`const { unit = '' } = props`), or null: React
|
|
5
|
+
* applies it when the prop is undefined, as a parent that passes its own props on may pass it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function propsObjectDefault(comp: ComponentIR, key: string): t.Expression | null;
|
|
8
|
+
/**
|
|
9
|
+
* The keys of a props spread that an attribute written before it also sets (`onSubmit={…} {...props}`). React's spread
|
|
10
|
+
* wins there where the parent gave the prop; the binding keeps the attribute (an input cannot tell a prop not given
|
|
11
|
+
* from one given as undefined), so where the parent does give it, React and Angular differ: said as a warning.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setBeforeSpread(n: ElementNode, attr: AttrNode, keys: string[]): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Why a component's own props object (or rest props), spread onto a child component (`<View {...DEFAULTS} {...props} />`),
|
|
16
|
+
* cannot be passed on input by input exactly, or null when it can. Each key the spread passes is bound from the
|
|
17
|
+
* component's input of that name; an attribute written after the spread wins over it, as in React. Refused, with the
|
|
18
|
+
* reason (the spread stays an `angular-spread` error, never dropped):
|
|
19
|
+
* - no key of the props object is known (its type could not be read), so nothing would reach the child;
|
|
20
|
+
* - another spread on the element passes keys that are not known, or the same key (which one wins depends, again, on
|
|
21
|
+
* whether the parent gave it);
|
|
22
|
+
* - the child takes some of the keys only through its own rest props, which its list of inputs does not carry.
|
|
23
|
+
*/
|
|
24
|
+
export declare function forwardRefusal(n: ElementNode, attr: AttrNode, keys: string[], childKeys: ReadonlySet<string> | null, child: ComponentIR | null, known: (e: t.Expression) => string[] | null): string | null;
|