@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,187 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { cloneWithRefs, transform } from './rewrite.js';
|
|
3
|
+
import { childAt } from './walk.js';
|
|
4
|
+
import { templateExpressions } from '../targets/shared/inline.js';
|
|
5
|
+
/**
|
|
6
|
+
* React's "latest value" ref: `const onChangeRef = useRef(onChange); onChangeRef.current = onChange;`, read later as
|
|
7
|
+
* `onChangeRef.current` in a callback, so the callback sees the value of the last render without being re-created.
|
|
8
|
+
* A Vue or Svelte callback reads props and live arguments as they are now, so the ref says nothing there: each
|
|
9
|
+
* `onChangeRef.current` reads `onChange` itself, and the ref and the watcher that kept it in step go.
|
|
10
|
+
*
|
|
11
|
+
* Only a ref written in that one render statement, from a plain read (`onChange`, `options.onChange`), and otherwise
|
|
12
|
+
* only read through `.current`.
|
|
13
|
+
*/
|
|
14
|
+
export function inlineLatestRefs(mod) {
|
|
15
|
+
for (const fn of [...mod.components, ...mod.hooks]) {
|
|
16
|
+
for (const item of [...fn.items]) {
|
|
17
|
+
if (item.kind !== 'effect' || item.body.body.length !== 1)
|
|
18
|
+
continue;
|
|
19
|
+
const stmt = item.body.body[0];
|
|
20
|
+
if (!t.isExpressionStatement(stmt) || !t.isAssignmentExpression(stmt.expression, { operator: '=' }))
|
|
21
|
+
continue;
|
|
22
|
+
const { left, right } = stmt.expression;
|
|
23
|
+
if (!t.isMemberExpression(left) || left.computed || !t.isIdentifier(left.object) || !t.isIdentifier(left.property, { name: 'current' }) || !plainRead(right))
|
|
24
|
+
continue;
|
|
25
|
+
const name = fn.refs.get(left.object);
|
|
26
|
+
const binding = name ? fn.bindings.get(name) : undefined;
|
|
27
|
+
if (!name || binding?.kind !== 'ref' || binding.refKind !== 'value' || binding.escapes)
|
|
28
|
+
continue;
|
|
29
|
+
// written in render, or by an effect of every render (`useLayoutEffect(() => { live.current = o; })`): then only a
|
|
30
|
+
// read after that effect (in a callback, or a later effect) sees the same value the plain read gives
|
|
31
|
+
if (item.phase !== 'render' && (item.deps !== null || !readAfterCommit(fn, name, item)))
|
|
32
|
+
continue;
|
|
33
|
+
// what it holds is the same everywhere it is read: a name of the function itself (a prop, a parameter), not a
|
|
34
|
+
// local of a callback
|
|
35
|
+
if (!readsOnlyOwn(fn, right))
|
|
36
|
+
continue;
|
|
37
|
+
const others = fn.items.filter((i) => i !== item);
|
|
38
|
+
// the hook's result is read like an item (`return { onDown: () => live.current.x }`)
|
|
39
|
+
const result = fn.type === 'hook' && fn.returns ? [fn.returns] : [];
|
|
40
|
+
if (inMarkup(fn, name) || writes(fn, name, [...rootsOf(others), ...result]))
|
|
41
|
+
continue;
|
|
42
|
+
replaceReads(fn, name, right, others);
|
|
43
|
+
if (fn.type === 'hook' && fn.returns)
|
|
44
|
+
fn.returns = swapReads(fn, name, right, fn.returns);
|
|
45
|
+
fn.items = fn.items.filter((i) => i !== item && !(i.kind === 'ref' && i.name === name));
|
|
46
|
+
fn.bindings.delete(name);
|
|
47
|
+
fn.diagnostics = fn.diagnostics.filter((d) => !(d.code === 'render-ref' && d.message.startsWith(`${name} is written`)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `onChange`, `options.onChange`: a read with no call, no computation; or the read of a live argument (`options()`, the
|
|
53
|
+
* getter ir/live-args made of a hook's value parameter), which is the caller's current value as the plain read was.
|
|
54
|
+
*/
|
|
55
|
+
function plainRead(e) {
|
|
56
|
+
if (t.isIdentifier(e))
|
|
57
|
+
return true;
|
|
58
|
+
if (t.isCallExpression(e))
|
|
59
|
+
return !e.arguments.length && t.isIdentifier(e.callee);
|
|
60
|
+
return t.isMemberExpression(e) && !e.computed && t.isIdentifier(e.property) && plainRead(e.object);
|
|
61
|
+
}
|
|
62
|
+
function rootOf(e) {
|
|
63
|
+
let cur = e;
|
|
64
|
+
while (t.isMemberExpression(cur))
|
|
65
|
+
cur = cur.object;
|
|
66
|
+
if (t.isCallExpression(cur) && t.isIdentifier(cur.callee))
|
|
67
|
+
return { id: cur.callee, getter: true };
|
|
68
|
+
return { id: t.isIdentifier(cur) ? cur : t.identifier(''), getter: false };
|
|
69
|
+
}
|
|
70
|
+
function readsOnlyOwn(fn, e) {
|
|
71
|
+
const root = rootOf(e);
|
|
72
|
+
const name = fn.refs.get(root.id);
|
|
73
|
+
const binding = name ? fn.bindings.get(name) : undefined;
|
|
74
|
+
// a call is a live argument's getter only: a parameter ir/live-args made reactive
|
|
75
|
+
if (root.getter)
|
|
76
|
+
return binding?.kind === 'param' && binding.reactive;
|
|
77
|
+
return binding?.kind === 'prop' || binding?.kind === 'param' || binding?.kind === 'propsObject';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether every read of the ref happens once the effect that writes it has run: inside a function (a callback, a
|
|
81
|
+
* listener), or in an effect declared after it (the same commit runs it later). A read while rendering (a value, the
|
|
82
|
+
* markup, the hook's result) would see the value of the render before.
|
|
83
|
+
*/
|
|
84
|
+
function readAfterCommit(fn, name, writer) {
|
|
85
|
+
const at = fn.items.indexOf(writer);
|
|
86
|
+
let ok = true;
|
|
87
|
+
const visit = (n, inFunction) => {
|
|
88
|
+
if (!ok)
|
|
89
|
+
return;
|
|
90
|
+
if (t.isIdentifier(n) && fn.refs.get(n) === name && !inFunction)
|
|
91
|
+
ok = false;
|
|
92
|
+
const inner = inFunction || t.isFunction(n);
|
|
93
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
94
|
+
const value = childAt(n, key);
|
|
95
|
+
if (Array.isArray(value))
|
|
96
|
+
for (const v of value)
|
|
97
|
+
if (t.isNode(v))
|
|
98
|
+
visit(v, inner);
|
|
99
|
+
if (t.isNode(value))
|
|
100
|
+
visit(value, inner);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
fn.items.forEach((item, i) => {
|
|
104
|
+
if (item === writer)
|
|
105
|
+
return;
|
|
106
|
+
// an effect body runs after commit; one declared after the writer runs after it
|
|
107
|
+
const later = item.kind === 'effect' && i > at;
|
|
108
|
+
for (const root of rootsOf([item]))
|
|
109
|
+
visit(root, later);
|
|
110
|
+
});
|
|
111
|
+
// the hook's result is read while rendering (the functions it holds, after)
|
|
112
|
+
if (fn.type === 'hook' && fn.returns)
|
|
113
|
+
visit(fn.returns, false);
|
|
114
|
+
return ok;
|
|
115
|
+
}
|
|
116
|
+
/** Whether the component's markup names the ref (its reads there are not rewritten: the ref then stays). */
|
|
117
|
+
function inMarkup(fn, name) {
|
|
118
|
+
if (fn.type !== 'component')
|
|
119
|
+
return false;
|
|
120
|
+
return templateExpressions(fn.template).some((root) => {
|
|
121
|
+
let found = false;
|
|
122
|
+
t.traverseFast(root, (n) => {
|
|
123
|
+
if (t.isIdentifier(n) && fn.refs.get(n) === name)
|
|
124
|
+
found = true;
|
|
125
|
+
});
|
|
126
|
+
return found;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** Every Babel node an item holds (its expressions, statements and lists of them). */
|
|
130
|
+
function rootsOf(items) {
|
|
131
|
+
const roots = [];
|
|
132
|
+
for (const item of items) {
|
|
133
|
+
for (const value of Object.values(item)) {
|
|
134
|
+
if (Array.isArray(value))
|
|
135
|
+
for (const v of value)
|
|
136
|
+
if (t.isNode(v))
|
|
137
|
+
roots.push(v);
|
|
138
|
+
if (t.isNode(value))
|
|
139
|
+
roots.push(value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return roots;
|
|
143
|
+
}
|
|
144
|
+
/** Whether anything but `name.current` reads the ref, or something writes it. */
|
|
145
|
+
function writes(fn, name, roots) {
|
|
146
|
+
let found = false;
|
|
147
|
+
for (const root of roots) {
|
|
148
|
+
transform(root, (n, parent) => {
|
|
149
|
+
if (!t.isIdentifier(n) || fn.refs.get(n) !== name)
|
|
150
|
+
return null;
|
|
151
|
+
const current = parent && t.isMemberExpression(parent) && parent.object === n && !parent.computed && t.isIdentifier(parent.property, { name: 'current' });
|
|
152
|
+
if (!current)
|
|
153
|
+
found = true;
|
|
154
|
+
return null;
|
|
155
|
+
});
|
|
156
|
+
transform(root, (n) => {
|
|
157
|
+
const target = t.isAssignmentExpression(n) ? n.left : t.isUpdateExpression(n) ? n.argument : null;
|
|
158
|
+
if (target && t.isMemberExpression(target) && t.isIdentifier(target.object) && fn.refs.get(target.object) === name)
|
|
159
|
+
found = true;
|
|
160
|
+
return null;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return found;
|
|
164
|
+
}
|
|
165
|
+
/** Each `name.current` under the items reads `value` instead. */
|
|
166
|
+
function swap(fn, name, value, node) {
|
|
167
|
+
return transform(node, (n) => {
|
|
168
|
+
if (t.isMemberExpression(n) && !n.computed && t.isIdentifier(n.object) && fn.refs.get(n.object) === name && t.isIdentifier(n.property, { name: 'current' }))
|
|
169
|
+
return cloneWithRefs(value, fn);
|
|
170
|
+
return null;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/** The hook's result with each `name.current` reading `value`. */
|
|
174
|
+
function swapReads(fn, name, value, result) {
|
|
175
|
+
const out = swap(fn, name, value, result);
|
|
176
|
+
return t.isExpression(out) ? out : result;
|
|
177
|
+
}
|
|
178
|
+
function replaceReads(fn, name, value, items) {
|
|
179
|
+
for (const item of items) {
|
|
180
|
+
for (const [key, v] of Object.entries(item)) {
|
|
181
|
+
if (Array.isArray(v))
|
|
182
|
+
Reflect.set(item, key, v.map((x) => (t.isNode(x) ? swap(fn, name, value, x) : x)));
|
|
183
|
+
else if (t.isNode(v))
|
|
184
|
+
Reflect.set(item, key, swap(fn, name, value, v));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { FunctionIR, HookIR, ModuleIR } from './model.js';
|
|
3
|
+
/** How a hook takes one parameter after the pass. */
|
|
4
|
+
export type ParamMode = {
|
|
5
|
+
kind: 'object';
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'value';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'callback';
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'ref';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'keep';
|
|
14
|
+
};
|
|
15
|
+
/** Rewrites a hook's parameters and body so its arguments are read where they are used; returns each parameter's mode. */
|
|
16
|
+
export declare function makeHookLive(hook: HookIR): ParamMode[];
|
|
17
|
+
/**
|
|
18
|
+
* Rewrites one call of a live hook: reactive values in an options object become getters, value arguments become
|
|
19
|
+
* `() => expr`. Returns whether every reactive argument is now live (else the caller still reports `hook-args-once`).
|
|
20
|
+
*/
|
|
21
|
+
export declare function makeCallLive(call: t.CallExpression, modes: ParamMode[], caller: FunctionIR): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The pass over one lowered module: its own hooks become live, then every call of a live hook (its own, or one it
|
|
24
|
+
* imports, through `importedModes`) passes live arguments and is marked, so no target warns about it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function liveHookArgs(mod: ModuleIR, importedModes: (local: string) => ParamMode[] | null): Map<string, ParamMode[]>;
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { childAt, setChildAt } from './walk.js';
|
|
3
|
+
import { bindingsUsed, transform } from './rewrite.js';
|
|
4
|
+
/**
|
|
5
|
+
* React runs a custom hook on every render, so `useThing({ size })` always sees the current `size`. A Vue composable,
|
|
6
|
+
* a Svelte rune function or an Angular signal function runs once: an argument passed as a value is read once. This
|
|
7
|
+
* pass keeps arguments live, the same way for every target:
|
|
8
|
+
*
|
|
9
|
+
* - a destructured options parameter `{ size = 48, label }` becomes one `options` object read where it is used
|
|
10
|
+
* (`options.size ?? 48`), and callers pass reactive values as getters (`get size() { return size; }`);
|
|
11
|
+
* - a plain value parameter becomes a getter function, read as `value()`, and callers pass `() => expr`;
|
|
12
|
+
* - callbacks (called in the hook) and ref boxes (read through `.current`) are left as they are.
|
|
13
|
+
*
|
|
14
|
+
* Reads then happen inside the hook's own computed values and effects, so they follow changes as React's do.
|
|
15
|
+
*/
|
|
16
|
+
/** The type TypeScript gives a parameter from its literal default (`enabled = true` is a boolean), else null. */
|
|
17
|
+
function literalType(value) {
|
|
18
|
+
if (t.isBooleanLiteral(value))
|
|
19
|
+
return t.tsBooleanKeyword();
|
|
20
|
+
if (t.isNumericLiteral(value) || (t.isUnaryExpression(value, { operator: '-' }) && t.isNumericLiteral(value.argument)))
|
|
21
|
+
return t.tsNumberKeyword();
|
|
22
|
+
if (t.isStringLiteral(value) || (t.isTemplateLiteral(value) && !value.expressions.length))
|
|
23
|
+
return t.tsStringKeyword();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/** Applies `visit` to every Babel node a function's script items and return hold, replacing them in place. */
|
|
27
|
+
function rewriteItems(ir, extra, visit) {
|
|
28
|
+
const fix = (node) => transform(node, visit);
|
|
29
|
+
for (const item of ir.items) {
|
|
30
|
+
for (const [key, value] of Object.entries(item)) {
|
|
31
|
+
if (key === 'kind' || key === 'core')
|
|
32
|
+
continue;
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
setChildAt(item, key, value.map((v) => (v && typeof v === 'object' && 'type' in v ? fix(v) : v)));
|
|
35
|
+
else if (value && typeof value === 'object' && 'type' in value)
|
|
36
|
+
setChildAt(item, key, fix(value));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (extra && extra.returns)
|
|
40
|
+
extra.returns = fix(extra.returns);
|
|
41
|
+
}
|
|
42
|
+
/** References to a binding of the function (by the lowering's identity links). */
|
|
43
|
+
function referencesOf(ir, name, roots) {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const root of roots) {
|
|
46
|
+
transform(root, (n, parent) => {
|
|
47
|
+
if (t.isIdentifier(n) && ir.refs.get(n) === name)
|
|
48
|
+
out.push({ node: n, parent });
|
|
49
|
+
return null;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function itemRoots(ir, returns) {
|
|
55
|
+
const roots = [];
|
|
56
|
+
for (const item of ir.items) {
|
|
57
|
+
for (const [key, value] of Object.entries(item)) {
|
|
58
|
+
if (key === 'kind' || key === 'core')
|
|
59
|
+
continue;
|
|
60
|
+
if (Array.isArray(value))
|
|
61
|
+
for (const v of value)
|
|
62
|
+
v && typeof v === 'object' && 'type' in v && roots.push(v);
|
|
63
|
+
else if (value && typeof value === 'object' && 'type' in value)
|
|
64
|
+
roots.push(value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (returns)
|
|
68
|
+
roots.push(returns);
|
|
69
|
+
return roots;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A derived value of the hook that reads a live argument more than once becomes a block that reads it once into a
|
|
73
|
+
* const of its own and computes from that: the getter's result does not narrow across calls, a const does.
|
|
74
|
+
*/
|
|
75
|
+
function snapshotReads(hook, name, fallback) {
|
|
76
|
+
hook.items = hook.items.map((item) => {
|
|
77
|
+
if (item.kind === 'effect')
|
|
78
|
+
return snapshotEffect(hook, item, name, fallback);
|
|
79
|
+
if (item.kind !== 'derived' || !t.isIdentifier(item.id))
|
|
80
|
+
return item;
|
|
81
|
+
const reads = referencesOf(hook, name, [item.init]);
|
|
82
|
+
if (reads.length < 2)
|
|
83
|
+
return item;
|
|
84
|
+
const local = `${name}Value`;
|
|
85
|
+
const init = transform(item.init, (n) => (t.isIdentifier(n) && hook.refs.get(n) === name ? t.identifier(local) : null));
|
|
86
|
+
const callee = t.identifier(name);
|
|
87
|
+
// already the getter's call: left alone by the rewrite below (no link to the parameter)
|
|
88
|
+
const read = fallback ? t.logicalExpression('??', t.callExpression(callee, []), t.cloneNode(fallback, true)) : t.callExpression(callee, []);
|
|
89
|
+
const statements = [t.variableDeclaration('const', [t.variableDeclarator(t.identifier(local), read)]), t.returnStatement(t.isExpression(init) ? init : item.init)];
|
|
90
|
+
return { kind: 'block', name: item.id.name, statements, type: item.type, returns: true };
|
|
91
|
+
});
|
|
92
|
+
// a value returned as it is (`return useMemo(() => urls && urls.length ? [...urls] : DEFAULT, [urls])`): computed as
|
|
93
|
+
// a value of its own, named after the hook, that reads the argument once
|
|
94
|
+
if (hook.returns && referencesOf(hook, name, [hook.returns]).length >= 2) {
|
|
95
|
+
const local = `${name}Value`;
|
|
96
|
+
const body = transform(hook.returns, (x) => (t.isIdentifier(x) && hook.refs.get(x) === name ? t.identifier(local) : null));
|
|
97
|
+
const callee = t.identifier(name);
|
|
98
|
+
// already the getter's call: left alone by the rewrite below (no link to the parameter)
|
|
99
|
+
const read = fallback ? t.logicalExpression('??', t.callExpression(callee, []), t.cloneNode(fallback, true)) : t.callExpression(callee, []);
|
|
100
|
+
const base = hook.name.replace(/^use/, '');
|
|
101
|
+
let value = `${base.charAt(0).toLowerCase()}${base.slice(1)}` || 'value';
|
|
102
|
+
while (hook.bindings.has(value) || value === name || value === local)
|
|
103
|
+
value = `${value}Value`;
|
|
104
|
+
const statements = [t.variableDeclaration('const', [t.variableDeclarator(t.identifier(local), read)]), t.returnStatement(t.isExpression(body) ? body : hook.returns)];
|
|
105
|
+
hook.items.push({ kind: 'block', name: value, statements, type: null, returns: true });
|
|
106
|
+
hook.bindings.set(value, { name: value, kind: 'derived', reactive: true });
|
|
107
|
+
const ret = t.identifier(value);
|
|
108
|
+
hook.refs.set(ret, value);
|
|
109
|
+
hook.returns = ret;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* An effect of the hook that reads a live argument twice, or inside a function it creates (a listener, its cleanup),
|
|
114
|
+
* reads it once when it runs, into a const: React's effect sees the value of its render, so the listener it removes on
|
|
115
|
+
* cleanup is the one it added (`addEventListener('resize', onResize)` … `removeEventListener('resize', onResize)`); two
|
|
116
|
+
* calls of a getter that builds the caller's arrow each time would give two different functions.
|
|
117
|
+
*/
|
|
118
|
+
function snapshotEffect(hook, item, name, fallback) {
|
|
119
|
+
let reads = 0;
|
|
120
|
+
let nested = false;
|
|
121
|
+
const visit = (n, depth) => {
|
|
122
|
+
if (t.isIdentifier(n) && hook.refs.get(n) === name) {
|
|
123
|
+
reads++;
|
|
124
|
+
if (depth > 0)
|
|
125
|
+
nested = true;
|
|
126
|
+
}
|
|
127
|
+
const inner = t.isFunction(n) ? depth + 1 : depth;
|
|
128
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
129
|
+
const value = childAt(n, key);
|
|
130
|
+
if (Array.isArray(value))
|
|
131
|
+
for (const v of value)
|
|
132
|
+
if (t.isNode(v))
|
|
133
|
+
visit(v, inner);
|
|
134
|
+
if (t.isNode(value))
|
|
135
|
+
visit(value, inner);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
visit(item.body, 0);
|
|
139
|
+
if (reads < 2 && !nested)
|
|
140
|
+
return item;
|
|
141
|
+
let local = `${name}Value`;
|
|
142
|
+
while (hook.bindings.has(local))
|
|
143
|
+
local = `${local}2`;
|
|
144
|
+
const body = transform(item.body, (n) => (t.isIdentifier(n) && hook.refs.get(n) === name ? t.identifier(local) : null));
|
|
145
|
+
const read = fallback ? t.logicalExpression('??', t.callExpression(t.identifier(name), []), t.cloneNode(fallback, true)) : t.callExpression(t.identifier(name), []);
|
|
146
|
+
const statements = t.isBlockStatement(body) ? body.body : item.body.body;
|
|
147
|
+
return { ...item, body: t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier(local), read)]), ...statements]) };
|
|
148
|
+
}
|
|
149
|
+
/** Rewrites a hook's parameters and body so its arguments are read where they are used; returns each parameter's mode. */
|
|
150
|
+
export function makeHookLive(hook) {
|
|
151
|
+
const modes = [];
|
|
152
|
+
const taken = new Set([...hook.bindings.keys(), ...hook.moduleNames]);
|
|
153
|
+
const fresh = (base) => {
|
|
154
|
+
let name = base;
|
|
155
|
+
for (let i = 2; taken.has(name); i++)
|
|
156
|
+
name = `${base}${i}`;
|
|
157
|
+
taken.add(name);
|
|
158
|
+
return name;
|
|
159
|
+
};
|
|
160
|
+
const listed = new Set();
|
|
161
|
+
for (const item of hook.items)
|
|
162
|
+
if ((item.kind === 'effect' || item.kind === 'derived') && item.deps)
|
|
163
|
+
for (const dep of item.deps)
|
|
164
|
+
listed.add(dep);
|
|
165
|
+
for (const b of hook.bindings.values())
|
|
166
|
+
for (const dep of b.deps ?? [])
|
|
167
|
+
listed.add(dep);
|
|
168
|
+
hook.params = hook.params.map((param) => {
|
|
169
|
+
// `{ a, b = 1 }` or `{ a, b = 1 } = {}`: one options object, each name read from it where used
|
|
170
|
+
const pattern = t.isObjectPattern(param) ? param : t.isAssignmentPattern(param) && t.isObjectPattern(param.left) ? param.left : null;
|
|
171
|
+
if (pattern) {
|
|
172
|
+
const simple = pattern.properties.every((p) => t.isObjectProperty(p) && !p.computed && t.isIdentifier(p.key) && (t.isIdentifier(p.value) || (t.isAssignmentPattern(p.value) && t.isIdentifier(p.value.left))));
|
|
173
|
+
if (!simple || !pattern.properties.length) {
|
|
174
|
+
modes.push({ kind: 'keep' });
|
|
175
|
+
return param;
|
|
176
|
+
}
|
|
177
|
+
const options = fresh('options');
|
|
178
|
+
// the options object is a reactive parameter: dependency lists and reactivity checks see it through its links
|
|
179
|
+
hook.bindings.set(options, { name: options, kind: 'param', reactive: true });
|
|
180
|
+
const reads = new Map();
|
|
181
|
+
for (const p of pattern.properties) {
|
|
182
|
+
const key = p.key.name;
|
|
183
|
+
const local = t.isIdentifier(p.value) ? p.value.name : p.value.left.name;
|
|
184
|
+
const member = t.memberExpression(t.identifier(options), t.identifier(key));
|
|
185
|
+
reads.set(local, t.isAssignmentPattern(p.value) ? t.logicalExpression('??', member, p.value.right) : member);
|
|
186
|
+
}
|
|
187
|
+
rewriteItems(hook, hook, (n) => {
|
|
188
|
+
if (!t.isIdentifier(n))
|
|
189
|
+
return null;
|
|
190
|
+
const name = hook.refs.get(n);
|
|
191
|
+
const read = name ? reads.get(name) : undefined;
|
|
192
|
+
if (!read)
|
|
193
|
+
return null;
|
|
194
|
+
const copy = t.cloneNode(read, true);
|
|
195
|
+
t.traverseFast(copy, (x) => {
|
|
196
|
+
if (t.isIdentifier(x, { name: options }))
|
|
197
|
+
hook.refs.set(x, options);
|
|
198
|
+
});
|
|
199
|
+
return copy;
|
|
200
|
+
});
|
|
201
|
+
const id = t.identifier(options);
|
|
202
|
+
id.typeAnnotation = pattern.typeAnnotation ?? null;
|
|
203
|
+
modes.push({ kind: 'object' });
|
|
204
|
+
return t.isAssignmentPattern(param) ? t.assignmentPattern(id, param.right) : id;
|
|
205
|
+
}
|
|
206
|
+
// a value (with or without a default) or a callback: read through a getter, so the hook always sees the caller's
|
|
207
|
+
// current one. A ref box (read through `.current`) is left as it is: the box itself never changes.
|
|
208
|
+
const named = t.isIdentifier(param) ? param : t.isAssignmentPattern(param) && t.isIdentifier(param.left) ? param.left : null;
|
|
209
|
+
if (named) {
|
|
210
|
+
const fallback = t.isAssignmentPattern(param) ? param.right : null;
|
|
211
|
+
// a name in a dependency list (`[ref, handler]`) is no use of its own: it only says when to run again
|
|
212
|
+
const uses = referencesOf(hook, named.name, itemRoots(hook, hook.returns)).filter((u) => !listed.has(u.node));
|
|
213
|
+
// a ref box is read through `.current` and nothing else: an options object with a member named `current` (the
|
|
214
|
+
// selected id, say) read beside its other members is a value
|
|
215
|
+
const members = uses.flatMap((u) => (u.parent && (t.isMemberExpression(u.parent) || t.isOptionalMemberExpression(u.parent)) && u.parent.object === u.node ? [u.parent] : []));
|
|
216
|
+
const box = members.length > 0 && members.every((m) => !m.computed && t.isIdentifier(m.property, { name: 'current' }));
|
|
217
|
+
if (box || !uses.length) {
|
|
218
|
+
// a ref box is passed as it is: the box never changes, only what it holds
|
|
219
|
+
modes.push({ kind: box ? 'ref' : 'keep' });
|
|
220
|
+
return param;
|
|
221
|
+
}
|
|
222
|
+
// only ever called: it stays a function, and callers pass one that calls their current callback
|
|
223
|
+
const calls = uses.every((u) => u.parent && (t.isCallExpression(u.parent) || t.isOptionalCallExpression(u.parent)) && u.parent.callee === u.node);
|
|
224
|
+
if (calls) {
|
|
225
|
+
modes.push({ kind: 'callback' });
|
|
226
|
+
return param;
|
|
227
|
+
}
|
|
228
|
+
// a value computed from the argument reads it once (`const imageUrlsValue = imageUrls()`), so a test on it narrows
|
|
229
|
+
// what follows as it did in React (`imageUrls && imageUrls.length ? [...imageUrls] : []`)
|
|
230
|
+
snapshotReads(hook, named.name, fallback);
|
|
231
|
+
rewriteItems(hook, hook, (n) => {
|
|
232
|
+
if (!t.isIdentifier(n) || hook.refs.get(n) !== named.name)
|
|
233
|
+
return null;
|
|
234
|
+
const callee = t.identifier(named.name);
|
|
235
|
+
hook.refs.set(callee, named.name);
|
|
236
|
+
const read = t.callExpression(callee, []);
|
|
237
|
+
// a default applies when the caller passed nothing, as React's does
|
|
238
|
+
return fallback ? t.logicalExpression('??', read, t.cloneNode(fallback, true)) : read;
|
|
239
|
+
});
|
|
240
|
+
// its reads are calls of the caller's getter now: effects and computed values that list it follow it
|
|
241
|
+
const binding = hook.bindings.get(named.name);
|
|
242
|
+
if (binding)
|
|
243
|
+
binding.reactive = true;
|
|
244
|
+
const id = t.identifier(named.name);
|
|
245
|
+
const written = named.typeAnnotation && t.isTSTypeAnnotation(named.typeAnnotation) ? named.typeAnnotation.typeAnnotation : (fallback && literalType(fallback));
|
|
246
|
+
if (written) {
|
|
247
|
+
const returns = fallback || named.optional ? t.tsUnionType([t.cloneNode(written, true), t.tsUndefinedKeyword()]) : t.cloneNode(written, true);
|
|
248
|
+
id.typeAnnotation = t.tsTypeAnnotation(t.tsFunctionType(null, [], t.tsTypeAnnotation(returns)));
|
|
249
|
+
}
|
|
250
|
+
modes.push({ kind: 'value' });
|
|
251
|
+
return id;
|
|
252
|
+
}
|
|
253
|
+
modes.push({ kind: 'keep' });
|
|
254
|
+
return param;
|
|
255
|
+
});
|
|
256
|
+
return modes;
|
|
257
|
+
}
|
|
258
|
+
/** Whether an expression reads something reactive in the caller (props, state, values derived from them). */
|
|
259
|
+
function reactiveIn(e, ir) {
|
|
260
|
+
for (const name of bindingsUsed(e, ir)) {
|
|
261
|
+
const b = ir.bindings.get(name);
|
|
262
|
+
if (b && (b.kind === 'prop' || b.kind === 'state' || b.kind === 'reducer' || b.kind === 'propsObject' || ((b.kind === 'derived' || b.kind === 'hook' || b.kind === 'param') && b.reactive)))
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Rewrites one call of a live hook: reactive values in an options object become getters, value arguments become
|
|
269
|
+
* `() => expr`. Returns whether every reactive argument is now live (else the caller still reports `hook-args-once`).
|
|
270
|
+
*/
|
|
271
|
+
export function makeCallLive(call, modes, caller) {
|
|
272
|
+
let live = true;
|
|
273
|
+
modes.forEach((mode, i) => {
|
|
274
|
+
const arg = call.arguments[i];
|
|
275
|
+
if (mode.kind === 'value') {
|
|
276
|
+
call.arguments[i] = arg && t.isExpression(arg) ? t.arrowFunctionExpression([], arg) : t.arrowFunctionExpression([], t.identifier('undefined'));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (mode.kind === 'ref')
|
|
280
|
+
return;
|
|
281
|
+
if (mode.kind === 'callback') {
|
|
282
|
+
// `onChange` from props: a function that calls the caller's current one, as React passes the latest each render
|
|
283
|
+
if (arg && t.isExpression(arg) && !t.isFunction(arg) && reactiveIn(arg, caller)) {
|
|
284
|
+
const args = t.identifier('args');
|
|
285
|
+
call.arguments[i] = t.arrowFunctionExpression([t.restElement(args)], t.optionalCallExpression(arg, [t.spreadElement(t.identifier('args'))], true));
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (mode.kind !== 'object' || !arg || !t.isExpression(arg)) {
|
|
290
|
+
if (arg && t.isExpression(arg) && mode.kind === 'keep' && !t.isFunction(arg) && reactiveIn(arg, caller))
|
|
291
|
+
live = false;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (!t.isObjectExpression(arg)) {
|
|
295
|
+
if (reactiveIn(arg, caller))
|
|
296
|
+
live = false;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
arg.properties = arg.properties.map((p) => {
|
|
300
|
+
if (t.isSpreadElement(p)) {
|
|
301
|
+
if (reactiveIn(p.argument, caller))
|
|
302
|
+
live = false;
|
|
303
|
+
return p;
|
|
304
|
+
}
|
|
305
|
+
if (!t.isObjectProperty(p) || p.computed || !t.isExpression(p.value) || t.isFunction(p.value) || !reactiveIn(p.value, caller))
|
|
306
|
+
return p;
|
|
307
|
+
const key = t.isIdentifier(p.key) ? t.identifier(p.key.name) : t.isStringLiteral(p.key) ? t.stringLiteral(p.key.value) : null;
|
|
308
|
+
if (!key)
|
|
309
|
+
return p;
|
|
310
|
+
return t.objectMethod('get', key, [], t.blockStatement([t.returnStatement(p.value)]));
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
return live;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The pass over one lowered module: its own hooks become live, then every call of a live hook (its own, or one it
|
|
317
|
+
* imports, through `importedModes`) passes live arguments and is marked, so no target warns about it.
|
|
318
|
+
*/
|
|
319
|
+
export function liveHookArgs(mod, importedModes) {
|
|
320
|
+
const own = new Map();
|
|
321
|
+
for (const hook of mod.hooks)
|
|
322
|
+
own.set(hook.name, makeHookLive(hook));
|
|
323
|
+
const modesOf = (name) => own.get(name) ?? importedModes(name);
|
|
324
|
+
for (const fn of [...mod.components, ...mod.hooks]) {
|
|
325
|
+
for (const item of fn.items) {
|
|
326
|
+
if (item.kind !== 'hook' || item.source !== 'local')
|
|
327
|
+
continue;
|
|
328
|
+
const modes = modesOf(item.hook);
|
|
329
|
+
if (!modes || !modes.some((m) => m.kind !== 'keep'))
|
|
330
|
+
continue;
|
|
331
|
+
item.live = makeCallLive(item.call, modes, fn);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return own;
|
|
335
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { Diagnostic } from '../types.js';
|
|
3
|
+
import type { FragmentDef, HookSignature, ModuleIR, TNode } from './model.js';
|
|
4
|
+
export interface LowerContext {
|
|
5
|
+
file: string;
|
|
6
|
+
/** a hook imported into this file, by its local name; null when it cannot be resolved */
|
|
7
|
+
importedHook: (localName: string) => HookSignature | null;
|
|
8
|
+
/**
|
|
9
|
+
* The members of a props type this file does not declare (imported: `CdPlayerProps<D>` from './types'), as the
|
|
10
|
+
* declaring files write them; null when any part cannot be seen into. Only a prop's kind reads it (a member typed
|
|
11
|
+
* React's node is markup the component renders), so a prop the component destructures from such a type renders as a
|
|
12
|
+
* slot exactly as one declared in the file does.
|
|
13
|
+
*/
|
|
14
|
+
heritageMembers?: (type: t.TSType) => ReadonlyMap<string, {
|
|
15
|
+
type: t.TSType | null;
|
|
16
|
+
}> | null;
|
|
17
|
+
/**
|
|
18
|
+
* Such a prop that code outside the markup also reads takes its declared kind too (Svelte: a snippet is a value that
|
|
19
|
+
* code can test, `header !== undefined`). Otherwise it keeps the kind 'value' (Vue: a slot is invisible to that code,
|
|
20
|
+
* so markup for it is passed as a value, VueTemplate.valueSlots).
|
|
21
|
+
*/
|
|
22
|
+
heritageNodesReadByCode?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* M4. A block of several values holding elements, of which the component reads one only, becomes that value's own
|
|
25
|
+
* block (soleMarkupMember). Vue and Svelte draw such a value; Angular's template bank writes the block of several
|
|
26
|
+
* values as it is, so it does not ask for this.
|
|
27
|
+
*/
|
|
28
|
+
soleMarkupMembers?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Framer Motion's element props; everything else on a motion element is an ordinary prop (exported for the targets). */
|
|
31
|
+
export declare const MOTION_PROPS: ReadonlySet<string>;
|
|
32
|
+
export declare function containsJSX(node: t.Node): boolean;
|
|
33
|
+
/** Strips parentheses, `as`, `satisfies` and `!` from an expression. */
|
|
34
|
+
export declare function unwrap(e: t.Expression): t.Expression;
|
|
35
|
+
/** The values a file imports from React: named ones by local name (to React's name), and namespaces (`React`). */
|
|
36
|
+
export interface ReactImports {
|
|
37
|
+
named: Map<string, string>;
|
|
38
|
+
namespaces: Set<string>;
|
|
39
|
+
}
|
|
40
|
+
export declare function reactImports(imports: t.ImportDeclaration[]): ReactImports;
|
|
41
|
+
/** The type name a reference points at: `React.ReactNode` and `ReactNode` both give 'ReactNode'. */
|
|
42
|
+
export declare function typeRefName(type: t.TSType | null | undefined): string | null;
|
|
43
|
+
export declare function isNodeType(type: t.TSType | null | undefined): boolean;
|
|
44
|
+
/** Names a declaration pattern binds. */
|
|
45
|
+
export declare function patternNames(id: t.LVal | t.Node): string[];
|
|
46
|
+
/** Functions made of a row's statements (see lowerMap): their parameters are typed from React's source in every target. */
|
|
47
|
+
export declare const ROW_HELPERS: WeakSet<t.Node>;
|
|
48
|
+
/** The paths a test proves hold a value (neither null nor undefined), when it is true (`holds`) or false. */
|
|
49
|
+
export declare function nonNullFacts(test: t.Expression, holds: boolean, out: Set<string>): void;
|
|
50
|
+
/** Wraps the reads of the given paths in `!` where TypeScript needs a value (see narrowAfterGuards). */
|
|
51
|
+
export declare function assertPaths(root: t.Node, paths: ReadonlySet<string>): void;
|
|
52
|
+
/**
|
|
53
|
+
* `let face: ReactNode; switch (design) { case 'a': face = <A/>; break; case 'b': case 'c': face = <B/>; break; default:
|
|
54
|
+
* face = <C/>; }`, or the same as an `if … else if … else` chain of assignments: every path assigns the value once and
|
|
55
|
+
* does nothing else, so the value is the choice `design === 'a' ? <A/> : design === 'b' || design === 'c' ? <B/> : <C/>`
|
|
56
|
+
* (a path that assigns nothing keeps the declared value). The switch's subject is read once per test, so it must be a
|
|
57
|
+
* plain read (a name or a member of one). Null for any other shape.
|
|
58
|
+
*/
|
|
59
|
+
export declare function assignedChoice(name: string, statements: t.Statement[]): t.Expression | null;
|
|
60
|
+
/** The value `name` holds after `chain` (a switch or an if chain assigning it once per path), from `initial`; or null. */
|
|
61
|
+
export declare function choiceAfter(name: string, initial: t.Expression, chain: t.Statement): t.Expression | null;
|
|
62
|
+
export declare function lowerModule(code: string, ctx: LowerContext): ModuleIR;
|
|
63
|
+
/**
|
|
64
|
+
* One JSX expression of module code (an exported helper's returned element, a module constant's choice, a table entry)
|
|
65
|
+
* lowered as module markup, with the TemplateCtx lowerMarkupValues uses. `locals` are the names the enclosing function
|
|
66
|
+
* binds (its parameters and consts) that the markup may read: they are plain reads, never module names, and `reads` lists
|
|
67
|
+
* the ones it reads, in source order (the markup's context). The diagnostics lowering reported are returned, not pushed:
|
|
68
|
+
* the caller decides whether the markup was taken. Nothing in the module changes, so other targets see the same module.
|
|
69
|
+
*/
|
|
70
|
+
export declare function lowerModuleMarkup(module: ModuleIR, expr: t.Expression, locals: ReadonlySet<string>): {
|
|
71
|
+
template: TNode;
|
|
72
|
+
moduleNames: string[];
|
|
73
|
+
reads: string[];
|
|
74
|
+
diagnostics: Diagnostic[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Module render helpers kept as code (`export function renderIcon(icon, size)`), each lowered as a fragment of the
|
|
78
|
+
* module (its parameters, its values, its markup), a call of another one a `render` node. Null when one of them has no
|
|
79
|
+
* fragment form or its markup is reported.
|
|
80
|
+
*/
|
|
81
|
+
export declare function lowerModuleFragments(module: ModuleIR, fns: Map<string, t.ArrowFunctionExpression | t.FunctionExpression | t.FunctionDeclaration>): FragmentDef[] | null;
|
|
82
|
+
/** All diagnostics of a lowered module, its own and its functions'. */
|
|
83
|
+
export declare function moduleDiagnostics(m: ModuleIR): Diagnostic[];
|