@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,374 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { transform } from '../../ir/rewrite.js';
|
|
3
|
+
import { typeRefName } from '../../ir/lower.js';
|
|
4
|
+
// React 19.2's SubmitEvent (onSubmit), InputEvent (onBeforeInput) and ToggleEvent (onToggle) are the DOM's events of
|
|
5
|
+
// those names, which Vue's and Svelte's handlers for them take too
|
|
6
|
+
const DOM_EVENTS = new Set(['MouseEvent', 'KeyboardEvent', 'PointerEvent', 'FocusEvent', 'DragEvent', 'TouchEvent', 'WheelEvent', 'AnimationEvent', 'TransitionEvent', 'ClipboardEvent', 'CompositionEvent', 'SubmitEvent', 'InputEvent', 'ToggleEvent']);
|
|
7
|
+
const GENERIC_EVENTS = new Set(['ChangeEvent', 'FormEvent', 'SyntheticEvent', 'UIEvent', 'BaseSyntheticEvent', 'InvalidEvent']);
|
|
8
|
+
/** React's HTML attribute types under their Svelte names. */
|
|
9
|
+
const SVELTE_ATTRS = {
|
|
10
|
+
HTMLAttributes: 'HTMLAttributes', AllHTMLAttributes: 'HTMLAttributes', ButtonHTMLAttributes: 'HTMLButtonAttributes',
|
|
11
|
+
InputHTMLAttributes: 'HTMLInputAttributes', AnchorHTMLAttributes: 'HTMLAnchorAttributes', ImgHTMLAttributes: 'HTMLImgAttributes',
|
|
12
|
+
TextareaHTMLAttributes: 'HTMLTextareaAttributes', SelectHTMLAttributes: 'HTMLSelectAttributes', LabelHTMLAttributes: 'HTMLLabelAttributes',
|
|
13
|
+
FormHTMLAttributes: 'HTMLFormAttributes', CanvasHTMLAttributes: 'HTMLCanvasAttributes', VideoHTMLAttributes: 'HTMLVideoAttributes',
|
|
14
|
+
SVGProps: 'SVGAttributes', SVGAttributes: 'SVGAttributes',
|
|
15
|
+
};
|
|
16
|
+
const VUE_ATTRS = new Set(['HTMLAttributes', 'ButtonHTMLAttributes', 'InputHTMLAttributes', 'AnchorHTMLAttributes', 'ImgHTMLAttributes', 'TextareaHTMLAttributes', 'SelectHTMLAttributes', 'LabelHTMLAttributes', 'FormHTMLAttributes', 'CanvasHTMLAttributes', 'VideoHTMLAttributes', 'SVGAttributes']);
|
|
17
|
+
/** Svelte attribute types are generic over the element only for the base HTMLAttributes. */
|
|
18
|
+
const SVELTE_GENERIC = new Set(['HTMLAttributes', 'SVGAttributes']);
|
|
19
|
+
function ref(name, params) {
|
|
20
|
+
return t.tsTypeReference(t.identifier(name), params?.length ? t.tsTypeParameterInstantiation(params) : null);
|
|
21
|
+
}
|
|
22
|
+
function union(...types) {
|
|
23
|
+
return t.tsUnionType(types);
|
|
24
|
+
}
|
|
25
|
+
const STRING_OR_NUMBER = () => union(t.tsStringKeyword(), t.tsNumberKeyword());
|
|
26
|
+
/**
|
|
27
|
+
* React-only type names a module or component uses (from `import type { X } from 'react'` or `React.X`), mapped to the
|
|
28
|
+
* target's own types. `reactNames` is the set of identifiers imported from react; `React.X` is always mapped.
|
|
29
|
+
*/
|
|
30
|
+
/** React names imported under another name, per module's set of React names: local → the name React exports. */
|
|
31
|
+
const ALIASES = new WeakMap();
|
|
32
|
+
export function reactAlias(names, local, imported) {
|
|
33
|
+
const map = ALIASES.get(names) ?? new Map();
|
|
34
|
+
map.set(local, imported);
|
|
35
|
+
ALIASES.set(names, map);
|
|
36
|
+
}
|
|
37
|
+
/** Modules (by their set of React names) whose project compiles with React 19's types (see ModuleIR.reactTypes19). */
|
|
38
|
+
const REACT_19 = new WeakSet();
|
|
39
|
+
export function markReactTypes19(names) {
|
|
40
|
+
REACT_19.add(names);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Angular modules (by their set of React names) that render markup held as data through the template bank
|
|
44
|
+
* (targets/angular/bank): there React's element types are the bank runtime's node type, `{ source, name }` to import.
|
|
45
|
+
* Set only by the Angular emitter, for such a module; unset, the mapping is the usual one.
|
|
46
|
+
*/
|
|
47
|
+
const ANGULAR_MARKUP_NODE = new WeakMap();
|
|
48
|
+
export function angularMarkupNode(names, source, name) {
|
|
49
|
+
ANGULAR_MARKUP_NODE.set(names, { source, name });
|
|
50
|
+
}
|
|
51
|
+
/** Framer Motion types a module imports, per module's set of React names: local → the name Framer exports. */
|
|
52
|
+
const MOTION_TYPES = new WeakMap();
|
|
53
|
+
export function motionTypeAlias(names, local, imported) {
|
|
54
|
+
const map = MOTION_TYPES.get(names) ?? new Map();
|
|
55
|
+
map.set(local, imported);
|
|
56
|
+
MOTION_TYPES.set(names, map);
|
|
57
|
+
}
|
|
58
|
+
/** React's HTML attributes for a target with no attribute types (Angular): the common ones by name, any other. */
|
|
59
|
+
function attributeObject() {
|
|
60
|
+
const member = (name, type) => Object.assign(t.tsPropertySignature(t.identifier(name), t.tsTypeAnnotation(type)), { optional: true });
|
|
61
|
+
const index = t.tsIndexSignature([Object.assign(t.identifier('attribute'), { typeAnnotation: t.tsTypeAnnotation(t.tsStringKeyword()) })], t.tsTypeAnnotation(t.tsUnknownKeyword()));
|
|
62
|
+
return t.tsTypeLiteral([
|
|
63
|
+
member('className', t.tsStringKeyword()),
|
|
64
|
+
member('style', ref('Record', [t.tsStringKeyword(), union(t.tsStringKeyword(), t.tsNumberKeyword())])),
|
|
65
|
+
member('id', t.tsStringKeyword()),
|
|
66
|
+
member('title', t.tsStringKeyword()),
|
|
67
|
+
member('role', t.tsStringKeyword()),
|
|
68
|
+
member('tabIndex', t.tsNumberKeyword()),
|
|
69
|
+
index,
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
/** Svelte's attribute type for an element written as `HTMLMotionProps<'button'>`. */
|
|
73
|
+
const SVELTE_TAG_ATTRS = { button: 'HTMLButtonAttributes', input: 'HTMLInputAttributes', a: 'HTMLAnchorAttributes', img: 'HTMLImgAttributes', textarea: 'HTMLTextareaAttributes', select: 'HTMLSelectAttributes', label: 'HTMLLabelAttributes', form: 'HTMLFormAttributes', canvas: 'HTMLCanvasAttributes', video: 'HTMLVideoAttributes' };
|
|
74
|
+
/**
|
|
75
|
+
* A Framer Motion type whose target library names or shapes it differently, or null to keep it as imported:
|
|
76
|
+
* `Variants` is motion-v's `variants` prop (motion-dom's `Variants` allows resolvers motion-v does not take), and
|
|
77
|
+
* `HTMLMotionProps<'button'>` is an element's motion props and attributes (Svelte: the element's attributes, which the
|
|
78
|
+
* action-based output passes on).
|
|
79
|
+
*/
|
|
80
|
+
function mapMotionType(imported, n, target, need) {
|
|
81
|
+
const first = n.typeParameters?.params[0];
|
|
82
|
+
if (target === 'vue' && imported === 'Variants') {
|
|
83
|
+
need('motion-v', 'MotionProps');
|
|
84
|
+
return ref('NonNullable', [t.tsIndexedAccessType(ref('MotionProps'), t.tsLiteralType(t.stringLiteral('variants')))]);
|
|
85
|
+
}
|
|
86
|
+
if (imported === 'HTMLMotionProps' && first) {
|
|
87
|
+
if (target === 'vue') {
|
|
88
|
+
need('motion-v', 'MotionProps');
|
|
89
|
+
need('motion-v', 'MotionHTMLAttributes');
|
|
90
|
+
return t.tsIntersectionType([ref('MotionProps', [t.cloneNode(first, true)]), ref('MotionHTMLAttributes', [t.cloneNode(first, true)])]);
|
|
91
|
+
}
|
|
92
|
+
if (target === 'svelte') {
|
|
93
|
+
const tag = t.isTSLiteralType(first) && t.isStringLiteral(first.literal) ? first.literal.value : '';
|
|
94
|
+
const name = SVELTE_TAG_ATTRS[tag];
|
|
95
|
+
need('svelte/elements', name ?? 'HTMLAttributes');
|
|
96
|
+
return name ? ref(name) : ref('HTMLAttributes', [ref('HTMLElement')]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// (S4, Svelte) `motion` exports none of these React types of Framer's: `MotionProps` is motion-dom's
|
|
100
|
+
// `MotionNodeOptions` (which `motion` re-exports) and React's `style` and `children` (a Svelte element's own attribute
|
|
101
|
+
// and snippet); `UseInViewOptions` is `InViewOptions` with a ref for its root (Svelte holds the element itself);
|
|
102
|
+
// `DOMMotionComponents` is keyed by the HTML and SVG tags, as the DOM's tag maps are (Svelte's SvelteHTMLElements
|
|
103
|
+
// has an index signature, so its keys are any string)
|
|
104
|
+
if (target === 'svelte' && imported === 'MotionProps') {
|
|
105
|
+
need('motion', 'MotionNodeOptions');
|
|
106
|
+
return ref('MotionNodeOptions');
|
|
107
|
+
}
|
|
108
|
+
if (target === 'svelte' && imported === 'UseInViewOptions') {
|
|
109
|
+
// (motion does not export InViewOptions by name: the options inView takes)
|
|
110
|
+
const inView = t.tsTypeQuery(t.tsImportType(t.stringLiteral('motion'), t.identifier('inView')));
|
|
111
|
+
return ref('NonNullable', [t.tsIndexedAccessType(ref('Parameters', [inView]), t.tsLiteralType(t.numericLiteral(2)))]);
|
|
112
|
+
}
|
|
113
|
+
if (target === 'svelte' && imported === 'DOMMotionComponents')
|
|
114
|
+
return t.tsIntersectionType([ref('HTMLElementTagNameMap'), ref('SVGElementTagNameMap')]);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
export function mapReactTypes(node, target, reactNames, imports) {
|
|
118
|
+
const need = (source, name) => {
|
|
119
|
+
if (!imports.some((i) => i.source === source && i.name === name))
|
|
120
|
+
imports.push({ source, name });
|
|
121
|
+
};
|
|
122
|
+
const mapRef = (n) => {
|
|
123
|
+
const name = n.typeName;
|
|
124
|
+
const motion = t.isIdentifier(name) ? MOTION_TYPES.get(reactNames)?.get(name.name) : undefined;
|
|
125
|
+
if (motion)
|
|
126
|
+
return mapMotionType(motion, n, target, need);
|
|
127
|
+
const qualified = t.isTSQualifiedName(name) && t.isIdentifier(name.left) && (name.left.name === 'React' || name.left.name === 'JSX');
|
|
128
|
+
const simple = t.isIdentifier(name) && reactNames.has(name.name);
|
|
129
|
+
if (!qualified && !simple)
|
|
130
|
+
return null;
|
|
131
|
+
const base = (simple && t.isIdentifier(name) ? ALIASES.get(reactNames)?.get(name.name) : undefined) ?? typeRefName(n) ?? '';
|
|
132
|
+
const params = n.typeParameters?.params ?? [];
|
|
133
|
+
const first = params[0];
|
|
134
|
+
if (base === 'ReactNode' || base === 'ReactElement' || base === 'Element' || base === 'ReactChild' || base === 'ReactPortal' || base === 'JSXElementConstructor') {
|
|
135
|
+
if (target === 'svelte') {
|
|
136
|
+
// beside a function in a union (`ReactNode | ((p: number) => ReactNode)`) a snippet would be a function too, and
|
|
137
|
+
// code that tells the two apart (`typeof art === 'function' ? art(p) : art`) would call it as the render
|
|
138
|
+
// function: there the markup comes through the function only (`() => snippet`), as on Vue
|
|
139
|
+
if (besideFunction.has(n))
|
|
140
|
+
return union(t.tsStringKeyword(), t.tsNumberKeyword(), t.tsBooleanKeyword(), t.tsNullKeyword(), t.tsUndefinedKeyword());
|
|
141
|
+
need('svelte', 'Snippet');
|
|
142
|
+
return union(ref('Snippet'), t.tsStringKeyword(), t.tsNumberKeyword(), t.tsBooleanKeyword(), t.tsNullKeyword(), t.tsUndefinedKeyword());
|
|
143
|
+
}
|
|
144
|
+
// a module that renders markup held as data: the bank runtime's node (markup, text, a list, or nothing)
|
|
145
|
+
const bank = target === 'angular' ? ANGULAR_MARKUP_NODE.get(reactNames) : undefined;
|
|
146
|
+
if (bank) {
|
|
147
|
+
need(bank.source, bank.name);
|
|
148
|
+
return ref(bank.name);
|
|
149
|
+
}
|
|
150
|
+
// React's ReactNode includes booleans (`icon = true`); the markup part becomes a slot
|
|
151
|
+
if (target === 'angular')
|
|
152
|
+
return union(t.tsStringKeyword(), t.tsNumberKeyword(), t.tsBooleanKeyword(), t.tsNullKeyword(), t.tsUndefinedKeyword());
|
|
153
|
+
// markup held as a value (in data, or passed as a prop's value) is a functional component, except beside a
|
|
154
|
+
// function in a union (`ReactNode | ((p: number) => ReactNode)`), where a function is the render function
|
|
155
|
+
if (besideFunction.has(n))
|
|
156
|
+
return union(t.tsStringKeyword(), t.tsNumberKeyword(), t.tsBooleanKeyword(), t.tsNullKeyword(), t.tsUndefinedKeyword());
|
|
157
|
+
need('vue', 'FunctionalComponent');
|
|
158
|
+
return union(ref('FunctionalComponent'), t.tsStringKeyword(), t.tsNumberKeyword(), t.tsBooleanKeyword(), t.tsNullKeyword(), t.tsUndefinedKeyword());
|
|
159
|
+
}
|
|
160
|
+
if (base === 'CSSProperties') {
|
|
161
|
+
if (target === 'vue') {
|
|
162
|
+
need('vue', 'CSSProperties');
|
|
163
|
+
return ref('CSSProperties');
|
|
164
|
+
}
|
|
165
|
+
return ref('Record', [t.tsStringKeyword(), union(t.tsStringKeyword(), t.tsNumberKeyword(), t.tsUndefinedKeyword())]);
|
|
166
|
+
}
|
|
167
|
+
if (base === 'RefObject' || base === 'MutableRefObject' || base === 'Ref' || base === 'RefCallback' || base === 'ForwardedRef') {
|
|
168
|
+
// every target hands refs around as `{ current }` boxes (a Vue element ref travels as a live box over its Ref),
|
|
169
|
+
// so the type is the box. A mutable ref holds its value as given, and so does React 19's RefObject (`useRef(value)`
|
|
170
|
+
// returns one; `useRef<T>(null)` is a RefObject<T | null>); the others may hold null.
|
|
171
|
+
const inner = first ?? t.tsUnknownKeyword();
|
|
172
|
+
const nullable = t.isTSNullKeyword(inner) || (t.isTSUnionType(inner) && inner.types.some((m) => t.isTSNullKeyword(m)));
|
|
173
|
+
const exact = base === 'MutableRefObject' || (base === 'RefObject' && REACT_19.has(reactNames));
|
|
174
|
+
const value = exact || nullable ? inner : union(inner, t.tsNullKeyword());
|
|
175
|
+
return t.tsTypeLiteral([t.tsPropertySignature(t.identifier('current'), t.tsTypeAnnotation(value))]);
|
|
176
|
+
}
|
|
177
|
+
if (base === 'SetStateAction' && first) {
|
|
178
|
+
return union(first, t.tsFunctionType(null, [Object.assign(t.identifier('prev'), { typeAnnotation: t.tsTypeAnnotation(first) })], t.tsTypeAnnotation(first)));
|
|
179
|
+
}
|
|
180
|
+
if (base === 'Dispatch' && first) {
|
|
181
|
+
return t.tsFunctionType(null, [Object.assign(t.identifier('value'), { typeAnnotation: t.tsTypeAnnotation(first) })], t.tsTypeAnnotation(t.tsVoidKeyword()));
|
|
182
|
+
}
|
|
183
|
+
// React's event types promise the element they are bound on (`PointerEvent<HTMLDivElement>`); the DOM's do not
|
|
184
|
+
const on = (event) => {
|
|
185
|
+
// with no element named, React's own default (`Element`): the handler's element is still there, never null
|
|
186
|
+
const element = first ?? t.tsTypeReference(t.identifier('Element'));
|
|
187
|
+
const members = [t.tsPropertySignature(t.identifier('currentTarget'), t.tsTypeAnnotation(t.cloneNode(element, true)))];
|
|
188
|
+
// ChangeEvent and FormEvent: the target is the field itself (a Svelte field handler reads it as currentTarget)
|
|
189
|
+
if (event === 'Event' && first && !fieldEvents.has(n))
|
|
190
|
+
members.push(t.tsPropertySignature(t.identifier('target'), t.tsTypeAnnotation(t.cloneNode(first, true))));
|
|
191
|
+
return t.tsIntersectionType([ref(event), t.tsTypeLiteral(members)]);
|
|
192
|
+
};
|
|
193
|
+
if (DOM_EVENTS.has(base))
|
|
194
|
+
return on(base);
|
|
195
|
+
if (GENERIC_EVENTS.has(base))
|
|
196
|
+
return on('Event');
|
|
197
|
+
if (base.endsWith('EventHandler')) {
|
|
198
|
+
// `ChangeEventHandler<HTMLSelectElement>` keeps its element in Svelte, whose own handler types carry it; Vue and
|
|
199
|
+
// Angular hand on the plain DOM event
|
|
200
|
+
const ev = base.slice(0, -'Handler'.length);
|
|
201
|
+
const plain = DOM_EVENTS.has(ev) ? ev : 'Event';
|
|
202
|
+
const eventType = target === 'svelte' ? on(plain) : ref(plain);
|
|
203
|
+
return t.tsFunctionType(null, [Object.assign(t.identifier('event'), { typeAnnotation: t.tsTypeAnnotation(eventType) })], t.tsTypeAnnotation(t.tsVoidKeyword()));
|
|
204
|
+
}
|
|
205
|
+
if (base === 'ComponentType' || base === 'FC' || base === 'FunctionComponent' || base === 'ElementType' || base === 'ComponentClass') {
|
|
206
|
+
if (target === 'angular') {
|
|
207
|
+
need('@angular/core', 'Type');
|
|
208
|
+
return ref('Type', [t.tsUnknownKeyword()]);
|
|
209
|
+
}
|
|
210
|
+
need(target === 'vue' ? 'vue' : 'svelte', 'Component');
|
|
211
|
+
// an ElementType is a tag name or a component, and Vue's <component :is> takes either
|
|
212
|
+
if (base === 'ElementType' && target === 'vue')
|
|
213
|
+
return t.tsUnionType([t.tsStringKeyword(), ref('Component')]);
|
|
214
|
+
return ref('Component');
|
|
215
|
+
}
|
|
216
|
+
if (base === 'PropsWithChildren' && first)
|
|
217
|
+
return first;
|
|
218
|
+
if (base === 'Key')
|
|
219
|
+
return STRING_OR_NUMBER();
|
|
220
|
+
if (base === 'ComponentProps' || base === 'ComponentPropsWithoutRef' || base === 'ComponentPropsWithRef' || base === 'DetailedHTMLProps') {
|
|
221
|
+
if (target === 'angular')
|
|
222
|
+
return attributeObject();
|
|
223
|
+
// a component's props (`ComponentProps<typeof PaginationLink>`): Svelte's own ComponentProps of that component,
|
|
224
|
+
// which the file imports under the same name
|
|
225
|
+
if (target === 'svelte' && base === 'ComponentProps' && t.isTSTypeQuery(first) && t.isIdentifier(first.exprName) && /^[A-Z]/.test(first.exprName.name)) {
|
|
226
|
+
need('svelte', 'ComponentProps');
|
|
227
|
+
return ref('ComponentProps', [t.cloneNode(first, true)]);
|
|
228
|
+
}
|
|
229
|
+
// an element by its tag (`ComponentProps<'input'>`): that element's own attribute type, from the target's map of
|
|
230
|
+
// elements (Vue's IntrinsicElementAttributes, Svelte's SvelteHTMLElements), so `type` on an input is typed
|
|
231
|
+
const tag = t.isTSLiteralType(first) && t.isStringLiteral(first.literal) && /^[a-z][a-z0-9]*$/.test(first.literal.value) ? first.literal.value : null;
|
|
232
|
+
if (tag) {
|
|
233
|
+
const map = target === 'vue' ? 'IntrinsicElementAttributes' : 'SvelteHTMLElements';
|
|
234
|
+
need(target === 'vue' ? 'vue' : 'svelte/elements', map);
|
|
235
|
+
return t.tsIndexedAccessType(ref(map), t.tsLiteralType(t.stringLiteral(tag)));
|
|
236
|
+
}
|
|
237
|
+
if (target === 'vue') {
|
|
238
|
+
need('vue', 'HTMLAttributes');
|
|
239
|
+
return ref('HTMLAttributes');
|
|
240
|
+
}
|
|
241
|
+
need('svelte/elements', 'HTMLAttributes');
|
|
242
|
+
return ref('HTMLAttributes', [ref('HTMLElement')]);
|
|
243
|
+
}
|
|
244
|
+
if (target === 'vue' && VUE_ATTRS.has(base === 'SVGProps' ? 'SVGAttributes' : base)) {
|
|
245
|
+
const vueName = base === 'SVGProps' ? 'SVGAttributes' : base;
|
|
246
|
+
need('vue', vueName);
|
|
247
|
+
return ref(vueName);
|
|
248
|
+
}
|
|
249
|
+
if (target === 'svelte' && SVELTE_ATTRS[base]) {
|
|
250
|
+
const svelteName = SVELTE_ATTRS[base] ?? 'HTMLAttributes';
|
|
251
|
+
need('svelte/elements', svelteName);
|
|
252
|
+
return SVELTE_GENERIC.has(svelteName) ? ref(svelteName, [first && !t.isTSLiteralType(first) ? first : ref('HTMLElement')]) : ref(svelteName);
|
|
253
|
+
}
|
|
254
|
+
// Angular has no attribute types: an object of attributes, whose named keys `Pick` and `Omit` keep
|
|
255
|
+
if (target === 'angular' && (VUE_ATTRS.has(base) || base in SVELTE_ATTRS))
|
|
256
|
+
return attributeObject();
|
|
257
|
+
// the value of one attribute (`HTMLInputTypeAttribute`, `HTMLAttributeAnchorTarget`, `AriaRole`): React spells
|
|
258
|
+
// each as its known words or any other string, which is what every target's attribute takes
|
|
259
|
+
if (/^HTML\w*Attribute(\w+)?$|^AriaRole$/.test(base) && !base.endsWith('Attributes'))
|
|
260
|
+
return t.tsStringKeyword();
|
|
261
|
+
return t.tsUnknownKeyword();
|
|
262
|
+
};
|
|
263
|
+
// React's ChangeEvent on a field (`ChangeEvent<HTMLTextAreaElement>`) types `target` as the field. Svelte's handler
|
|
264
|
+
// types give the field as `currentTarget` only, and a change or input event is dispatched on the field itself, so a
|
|
265
|
+
// function that takes one reads `event.currentTarget`: the same element, typed as Svelte's handler types say
|
|
266
|
+
const fieldEvents = new WeakSet();
|
|
267
|
+
if (target === 'svelte') {
|
|
268
|
+
t.traverseFast(node, (fn) => {
|
|
269
|
+
if (!t.isFunction(fn))
|
|
270
|
+
return;
|
|
271
|
+
for (const p of fn.params) {
|
|
272
|
+
const type = t.isIdentifier(p) && t.isTSTypeAnnotation(p.typeAnnotation) ? p.typeAnnotation.typeAnnotation : null;
|
|
273
|
+
if (!t.isIdentifier(p) || !t.isTSTypeReference(type) || !isFieldChangeEvent(type, reactNames))
|
|
274
|
+
continue;
|
|
275
|
+
fieldEvents.add(type);
|
|
276
|
+
readTargetAsCurrent(fn, p.name);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
// React's node types that sit beside a function type in a union (see the Vue case above), found before mapping
|
|
281
|
+
const besideFunction = new WeakSet();
|
|
282
|
+
t.traverseFast(node, (u) => {
|
|
283
|
+
if (!t.isTSUnionType(u))
|
|
284
|
+
return;
|
|
285
|
+
const members = u.types.map((m) => (t.isTSParenthesizedType(m) ? m.typeAnnotation : m));
|
|
286
|
+
if (members.some((m) => t.isTSFunctionType(m)))
|
|
287
|
+
for (const m of members)
|
|
288
|
+
if (t.isTSTypeReference(m))
|
|
289
|
+
besideFunction.add(m);
|
|
290
|
+
});
|
|
291
|
+
return transform(node, (n) => {
|
|
292
|
+
if (t.isTSTypeReference(n))
|
|
293
|
+
return mapRef(n);
|
|
294
|
+
if (t.isTSInterfaceDeclaration(n) && n.extends?.length) {
|
|
295
|
+
// `interface P extends React.ButtonHTMLAttributes<HTMLButtonElement>`: the heritage maps like a type reference
|
|
296
|
+
n.extends = n.extends.flatMap((h) => {
|
|
297
|
+
if (!t.isTSEntityName(h.expression))
|
|
298
|
+
return [h];
|
|
299
|
+
const mapped = mapRef(t.tsTypeReference(h.expression, h.typeParameters ?? null));
|
|
300
|
+
if (mapped === null)
|
|
301
|
+
return [h];
|
|
302
|
+
if (t.isTSTypeReference(mapped))
|
|
303
|
+
return [t.tsExpressionWithTypeArguments(mapped.typeName, mapped.typeParameters ?? null)];
|
|
304
|
+
return [];
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
const FIELD_ELEMENTS = new Set(['HTMLInputElement', 'HTMLTextAreaElement', 'HTMLSelectElement']);
|
|
311
|
+
/** `ChangeEvent<HTMLInputElement>` (or `React.ChangeEvent<…>`) of a form field. */
|
|
312
|
+
function isFieldChangeEvent(n, reactNames) {
|
|
313
|
+
const name = n.typeName;
|
|
314
|
+
const react = (t.isTSQualifiedName(name) && t.isIdentifier(name.left, { name: 'React' })) || (t.isIdentifier(name) && reactNames.has(name.name));
|
|
315
|
+
const base = t.isIdentifier(name) ? (ALIASES.get(reactNames)?.get(name.name) ?? name.name) : typeRefName(n);
|
|
316
|
+
const first = n.typeParameters?.params[0];
|
|
317
|
+
return react && base === 'ChangeEvent' && t.isTSTypeReference(first) && t.isIdentifier(first.typeName) && FIELD_ELEMENTS.has(first.typeName.name);
|
|
318
|
+
}
|
|
319
|
+
/** `event.target` → `event.currentTarget` in a function's body, where `name` is its own parameter (not shadowed). */
|
|
320
|
+
function readTargetAsCurrent(fn, name) {
|
|
321
|
+
t.traverse(fn.body, (n, ancestors) => {
|
|
322
|
+
if (!t.isMemberExpression(n) || n.computed || !t.isIdentifier(n.object, { name }) || !t.isIdentifier(n.property, { name: 'target' }))
|
|
323
|
+
return;
|
|
324
|
+
const shadowed = ancestors.some(({ node }) => t.isFunction(node) && node.params.some((p) => name in t.getBindingIdentifiers(p)));
|
|
325
|
+
if (!shadowed)
|
|
326
|
+
n.property = t.identifier('currentTarget');
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
/** The DOM event type a React event prop receives, by its name (onPointerDown → PointerEvent). */
|
|
330
|
+
function eventTypeFor(prop) {
|
|
331
|
+
const e = prop.slice(2);
|
|
332
|
+
if (/^(Click|DoubleClick|Mouse|ContextMenu|AuxClick)/.test(e))
|
|
333
|
+
return 'MouseEvent';
|
|
334
|
+
if (/^(Pointer|GotPointer|LostPointer)/.test(e))
|
|
335
|
+
return 'PointerEvent';
|
|
336
|
+
if (/^Key/.test(e))
|
|
337
|
+
return 'KeyboardEvent';
|
|
338
|
+
if (/^(Focus|Blur)/.test(e))
|
|
339
|
+
return 'FocusEvent';
|
|
340
|
+
if (/^Wheel/.test(e))
|
|
341
|
+
return 'WheelEvent';
|
|
342
|
+
if (/^Touch/.test(e))
|
|
343
|
+
return 'TouchEvent';
|
|
344
|
+
if (/^(Drag|Drop)/.test(e))
|
|
345
|
+
return 'DragEvent';
|
|
346
|
+
if (/^Animation/.test(e))
|
|
347
|
+
return 'AnimationEvent';
|
|
348
|
+
if (/^Transition/.test(e))
|
|
349
|
+
return 'TransitionEvent';
|
|
350
|
+
return 'Event';
|
|
351
|
+
}
|
|
352
|
+
/** A type for an inherited HTML attribute the component destructures without declaring it (from its default, if any). */
|
|
353
|
+
export function inheritedAttrType(name, defaultValue = null) {
|
|
354
|
+
if (t.isNumericLiteral(defaultValue) || (t.isUnaryExpression(defaultValue) && t.isNumericLiteral(defaultValue.argument)))
|
|
355
|
+
return t.tsNumberKeyword();
|
|
356
|
+
if (t.isBooleanLiteral(defaultValue))
|
|
357
|
+
return t.tsBooleanKeyword();
|
|
358
|
+
if (t.isStringLiteral(defaultValue) || t.isTemplateLiteral(defaultValue))
|
|
359
|
+
return t.tsStringKeyword();
|
|
360
|
+
if (defaultValue && !t.isIdentifier(defaultValue, { name: 'undefined' }) && !/^on[A-Z]/.test(name))
|
|
361
|
+
return t.tsUnknownKeyword();
|
|
362
|
+
if (/^on[A-Z]/.test(name)) {
|
|
363
|
+
return t.tsFunctionType(null, [Object.assign(t.identifier('event'), { typeAnnotation: t.tsTypeAnnotation(ref(eventTypeFor(name))) })], t.tsTypeAnnotation(t.tsVoidKeyword()));
|
|
364
|
+
}
|
|
365
|
+
if (name === 'type')
|
|
366
|
+
return union(...['button', 'submit', 'reset'].map((v) => t.tsLiteralType(t.stringLiteral(v))));
|
|
367
|
+
if (/^(disabled|hidden|checked|readOnly|required|autoFocus|multiple|open)$/.test(name))
|
|
368
|
+
return t.tsBooleanKeyword();
|
|
369
|
+
if (/^(tabIndex|rows|cols|min|max|step|maxLength|minLength)$/.test(name))
|
|
370
|
+
return t.tsNumberKeyword();
|
|
371
|
+
if (name === 'className' || name === 'class')
|
|
372
|
+
return t.tsStringKeyword();
|
|
373
|
+
return t.tsStringKeyword();
|
|
374
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { FunctionIR, ModuleIR } from '../../ir/model.js';
|
|
3
|
+
import type { WebContext } from './module.js';
|
|
4
|
+
/** The values a file imports from React: named ones by local name (to the name React exports), and namespaces (`React`). */
|
|
5
|
+
export interface ReactValues {
|
|
6
|
+
named: Map<string, string>;
|
|
7
|
+
namespaces: Set<string>;
|
|
8
|
+
}
|
|
9
|
+
export declare function reactValues(mod: ModuleIR): ReactValues;
|
|
10
|
+
/** Whether a callee is React's element test (`isValidElement`, `React.isValidElement`). */
|
|
11
|
+
export declare function isElementTest(callee: t.Node, rv: ReactValues): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* React's element test, `isValidElement(x)`, as the target tells an element value apart: the target gives the
|
|
14
|
+
* expression. It has no React to call; the name is never left in the output.
|
|
15
|
+
*/
|
|
16
|
+
export declare function replaceElementTests(ir: FunctionIR, rv: ReactValues, make: (arg: t.Expression) => t.Expression): number;
|
|
17
|
+
/** The React runtime values (other than hooks) the function's code still reads, with the line of the first read. */
|
|
18
|
+
export declare function reactRuntimeReads(ir: FunctionIR, rv: ReactValues): Map<string, number | undefined>;
|
|
19
|
+
/** Reports each React runtime value (`cloneElement`, `Children`, `createElement`) a component or hook still reads. */
|
|
20
|
+
export declare function reportReactRuntime(ir: FunctionIR, rv: ReactValues, ctx: WebContext): void;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { transform } from '../../ir/rewrite.js';
|
|
3
|
+
export function reactValues(mod) {
|
|
4
|
+
const out = { named: new Map(), namespaces: new Set() };
|
|
5
|
+
for (const decl of mod.imports) {
|
|
6
|
+
if (decl.source.value !== 'react' || decl.importKind === 'type')
|
|
7
|
+
continue;
|
|
8
|
+
for (const s of decl.specifiers) {
|
|
9
|
+
if (t.isImportSpecifier(s)) {
|
|
10
|
+
if (s.importKind === 'type')
|
|
11
|
+
continue;
|
|
12
|
+
out.named.set(s.local.name, t.isIdentifier(s.imported) ? s.imported.name : s.imported.value);
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
out.namespaces.add(s.local.name);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** The React export a callee names (`isValidElement`, `React.isValidElement`, `Children.map` → `Children`), if any. */
|
|
21
|
+
function reactExport(callee, rv) {
|
|
22
|
+
if (t.isIdentifier(callee))
|
|
23
|
+
return rv.named.get(callee.name) ?? null;
|
|
24
|
+
if ((t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)) && !callee.computed && t.isIdentifier(callee.object)) {
|
|
25
|
+
if (rv.namespaces.has(callee.object.name) && t.isIdentifier(callee.property))
|
|
26
|
+
return callee.property.name;
|
|
27
|
+
return rv.named.get(callee.object.name) ?? null;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/** Whether a callee is React's element test (`isValidElement`, `React.isValidElement`). */
|
|
32
|
+
export function isElementTest(callee, rv) {
|
|
33
|
+
return reactExport(callee, rv) === 'isValidElement';
|
|
34
|
+
}
|
|
35
|
+
/** Whether a value is a Babel node (TNode and AttrNode kinds are lower case, Babel's are PascalCase). */
|
|
36
|
+
function isBabelNode(value) {
|
|
37
|
+
return !!value && typeof value === 'object' && 'type' in value && typeof value.type === 'string' && value.type in t.VISITOR_KEYS;
|
|
38
|
+
}
|
|
39
|
+
/** The parts of a lowered function that hold its code: script items, template, render helpers, a hook's result. */
|
|
40
|
+
function codeOf(ir) {
|
|
41
|
+
return [ir.items, Reflect.get(ir, 'template'), Reflect.get(ir, 'fragments'), Reflect.get(ir, 'returns'), Reflect.get(ir, 'props')];
|
|
42
|
+
}
|
|
43
|
+
/** Replaces, in place, every node of the function's code for which `visit` returns a replacement. */
|
|
44
|
+
function replaceIn(root, visit, seen) {
|
|
45
|
+
if (Array.isArray(root)) {
|
|
46
|
+
for (let i = 0; i < root.length; i++) {
|
|
47
|
+
const v = root[i];
|
|
48
|
+
if (isBabelNode(v))
|
|
49
|
+
root[i] = transform(v, visit);
|
|
50
|
+
else
|
|
51
|
+
replaceIn(v, visit, seen);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!root || typeof root !== 'object' || seen.has(root))
|
|
56
|
+
return;
|
|
57
|
+
seen.add(root);
|
|
58
|
+
for (const [key, v] of Object.entries(root)) {
|
|
59
|
+
if (isBabelNode(v))
|
|
60
|
+
Reflect.set(root, key, transform(v, visit));
|
|
61
|
+
else
|
|
62
|
+
replaceIn(v, visit, seen);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* React's element test, `isValidElement(x)`, as the target tells an element value apart: the target gives the
|
|
67
|
+
* expression. It has no React to call; the name is never left in the output.
|
|
68
|
+
*/
|
|
69
|
+
export function replaceElementTests(ir, rv, make) {
|
|
70
|
+
let count = 0;
|
|
71
|
+
const seen = new WeakSet();
|
|
72
|
+
for (const part of codeOf(ir)) {
|
|
73
|
+
replaceIn(part, (n) => {
|
|
74
|
+
if (!t.isCallExpression(n) || reactExport(n.callee, rv) !== 'isValidElement')
|
|
75
|
+
return null;
|
|
76
|
+
const arg = n.arguments[0];
|
|
77
|
+
if (n.arguments.length !== 1 || !arg || !t.isExpression(arg))
|
|
78
|
+
return null;
|
|
79
|
+
count++;
|
|
80
|
+
return make(arg);
|
|
81
|
+
}, seen);
|
|
82
|
+
}
|
|
83
|
+
return count;
|
|
84
|
+
}
|
|
85
|
+
/** React hooks (and `use`, read as a context or reported) are lowered; the rest of React's values used only as JSX tags have no value use either. */
|
|
86
|
+
const LOWERED = /^(use|use[A-Z]\w*|Fragment|StrictMode|Suspense|Profiler|forwardRef|memo)$/;
|
|
87
|
+
/** The React runtime values (other than hooks) the function's code still reads, with the line of the first read. */
|
|
88
|
+
export function reactRuntimeReads(ir, rv) {
|
|
89
|
+
const out = new Map();
|
|
90
|
+
const seen = new WeakSet();
|
|
91
|
+
const visitNode = (n, parent) => {
|
|
92
|
+
if (t.isTSType(n) || t.isTSTypeAnnotation(n) || t.isTSTypeParameterInstantiation(n))
|
|
93
|
+
return;
|
|
94
|
+
let name = null;
|
|
95
|
+
if (t.isIdentifier(n) && rv.named.has(n.name) && !(parent && (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.property === n && !parent.computed))
|
|
96
|
+
name = rv.named.get(n.name) ?? null;
|
|
97
|
+
if ((t.isMemberExpression(n) || t.isOptionalMemberExpression(n)) && !n.computed && t.isIdentifier(n.object) && rv.namespaces.has(n.object.name) && t.isIdentifier(n.property))
|
|
98
|
+
name = n.property.name;
|
|
99
|
+
if (name && !LOWERED.test(name) && !out.has(name))
|
|
100
|
+
out.set(name, n.loc?.start.line);
|
|
101
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
102
|
+
const value = Reflect.get(n, key);
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
for (const c of value)
|
|
105
|
+
if (isBabelNode(c))
|
|
106
|
+
visitNode(c, n);
|
|
107
|
+
}
|
|
108
|
+
else if (isBabelNode(value))
|
|
109
|
+
visitNode(value, n);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const walk = (value) => {
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
for (const v of value)
|
|
115
|
+
walk(v);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
119
|
+
return;
|
|
120
|
+
seen.add(value);
|
|
121
|
+
if (isBabelNode(value)) {
|
|
122
|
+
visitNode(value, null);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
for (const v of Object.values(value))
|
|
126
|
+
walk(v);
|
|
127
|
+
};
|
|
128
|
+
for (const part of codeOf(ir))
|
|
129
|
+
walk(part);
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
const TARGET_NAMES = { vue: 'Vue', svelte: 'Svelte', angular: 'Angular' };
|
|
133
|
+
/** Reports each React runtime value (`cloneElement`, `Children`, `createElement`) a component or hook still reads. */
|
|
134
|
+
export function reportReactRuntime(ir, rv, ctx) {
|
|
135
|
+
for (const [name, line] of reactRuntimeReads(ir, rv)) {
|
|
136
|
+
ctx.diagnostics.push({
|
|
137
|
+
code: 'react-runtime',
|
|
138
|
+
severity: 'error',
|
|
139
|
+
message: `${ir.name} calls React's ${name}, which works on React elements and has no ${TARGET_NAMES[ctx.target]} counterpart: the code that uses it is not converted.`,
|
|
140
|
+
file: ctx.sourceRel,
|
|
141
|
+
target: ctx.target,
|
|
142
|
+
...(line ? { line } : {}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* React calls a callback ref written inline (a new function every render) again after every render of its component:
|
|
4
|
+
* with null for the old function, then with the element for the new one. A target that runs the converted callback
|
|
5
|
+
* once when the element mounts (and again only when something it read changes, or with null when the element goes)
|
|
6
|
+
* ends in the same state as React when a null call followed by an element call leaves everything as the element call
|
|
7
|
+
* alone does. That holds for the forms below, and is not claimed for any other body (a counter, a write in the null
|
|
8
|
+
* branch the element branch does not undo, a call):
|
|
9
|
+
*
|
|
10
|
+
* - `target = el`, `holder.current = el`, `list[i] = el` (the element, or null, stored in one place);
|
|
11
|
+
* - `if (el) map.set(key, el); else map.delete(key)` (the same map and key), with or without the else;
|
|
12
|
+
* - `if (el) el.prop = value` (writes to the element itself, read again from current values).
|
|
13
|
+
*
|
|
14
|
+
* Shared by the targets (moved from the Svelte target, where it began).
|
|
15
|
+
*/
|
|
16
|
+
export declare function settlesLikeReact(fn: t.ArrowFunctionExpression | t.FunctionExpression): boolean;
|