@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,239 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { templateExpressions } from '../targets/shared/inline.js';
|
|
3
|
+
import { unwrap } from './lower.js';
|
|
4
|
+
/**
|
|
5
|
+
* Radix's Slot without Radix. shadcn's components switch their element for a Slot when given `asChild`:
|
|
6
|
+
*
|
|
7
|
+
* const Comp = asChild ? Slot.Root : 'button';
|
|
8
|
+
* return <Comp data-slot="button" className={…} {...props} />;
|
|
9
|
+
*
|
|
10
|
+
* The Slot renders the one element it is given as children, with the Slot's props merged onto it (Radix's mergeProps:
|
|
11
|
+
* the child's own props win, class names are joined, styles merged with the child's winning, a handler both have runs
|
|
12
|
+
* the child's first, refs composed). This pass recognises the Slot by its import (`Slot` from 'radix-ui', read as
|
|
13
|
+
* `Slot.Root` or `Slot.Slot`; `Slot` or `Root` from '@radix-ui/react-slot') and by that one use: a value of the
|
|
14
|
+
* component that picks it or a tag name by a test, read only as an element's tag. The element keeps the tag and holds
|
|
15
|
+
* the test (ElementNode.asChild); the value goes, and the import with it when nothing else reads the Slot. Any other
|
|
16
|
+
* use stays as it was (the React-library placeholder and its diagnostic).
|
|
17
|
+
*/
|
|
18
|
+
export function slotAsChild(mod) {
|
|
19
|
+
const slots = slotBindings(mod);
|
|
20
|
+
if (!slots.length)
|
|
21
|
+
return;
|
|
22
|
+
const isSlot = (e) => {
|
|
23
|
+
const x = t.isExpression(e) ? unwrap(e) : e;
|
|
24
|
+
for (const s of slots) {
|
|
25
|
+
if (s.member === null && t.isIdentifier(x, { name: s.local }))
|
|
26
|
+
return true;
|
|
27
|
+
if (s.member !== null && t.isMemberExpression(x) && !x.computed && t.isIdentifier(x.object, { name: s.local }) && t.isIdentifier(x.property) && s.member.has(x.property.name))
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
let converted = false;
|
|
33
|
+
for (const comp of mod.components) {
|
|
34
|
+
for (const item of [...comp.items]) {
|
|
35
|
+
if (item.kind !== 'derived' || !t.isIdentifier(item.id) || item.declKind !== 'const')
|
|
36
|
+
continue;
|
|
37
|
+
const name = item.id.name;
|
|
38
|
+
const init = unwrap(item.init);
|
|
39
|
+
if (!t.isConditionalExpression(init))
|
|
40
|
+
continue;
|
|
41
|
+
const slotFirst = isSlot(init.consequent) && t.isStringLiteral(unwrap(init.alternate));
|
|
42
|
+
const slotLast = isSlot(init.alternate) && t.isStringLiteral(unwrap(init.consequent));
|
|
43
|
+
if (!slotFirst && !slotLast)
|
|
44
|
+
continue;
|
|
45
|
+
const tagValue = unwrap(slotFirst ? init.alternate : init.consequent);
|
|
46
|
+
if (!t.isStringLiteral(tagValue) || !/^[a-z][a-z0-9-]*$/.test(tagValue.value))
|
|
47
|
+
continue;
|
|
48
|
+
const elements = tagged(comp, name);
|
|
49
|
+
// read only as a tag, and on elements whose ref (if any) would reach the element itself
|
|
50
|
+
if (!elements.length || readsName(comp, name, item) || elements.some((el) => el.attrs.some((a) => a.kind === 'ref')))
|
|
51
|
+
continue;
|
|
52
|
+
for (const el of elements) {
|
|
53
|
+
el.tag = tagValue.value;
|
|
54
|
+
el.component = false;
|
|
55
|
+
// the test's names keep their binding links (the targets rewrite props and state through them)
|
|
56
|
+
const test = t.cloneNode(init.test, true);
|
|
57
|
+
linkCopy(comp, init.test, test);
|
|
58
|
+
el.asChild = slotFirst ? test : t.unaryExpression('!', test);
|
|
59
|
+
}
|
|
60
|
+
comp.items = comp.items.filter((i) => i !== item);
|
|
61
|
+
comp.bindings.delete(name);
|
|
62
|
+
const prop = slotFirst && t.isIdentifier(init.test) ? comp.props.find((p) => p.local === comp.refs.get(init.test)) : undefined;
|
|
63
|
+
if (prop)
|
|
64
|
+
comp.asChildProp = prop.key;
|
|
65
|
+
converted = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!converted)
|
|
69
|
+
return;
|
|
70
|
+
// the Slot's import goes once nothing else of the module reads it
|
|
71
|
+
for (const s of slots) {
|
|
72
|
+
if (mentions(mod, s.local))
|
|
73
|
+
continue;
|
|
74
|
+
s.decl.specifiers = s.decl.specifiers.filter((x) => x !== s.specifier);
|
|
75
|
+
if (!s.decl.specifiers.length)
|
|
76
|
+
mod.imports = mod.imports.filter((d) => d !== s.decl);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function slotBindings(mod) {
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const decl of mod.imports) {
|
|
82
|
+
if (decl.importKind === 'type')
|
|
83
|
+
continue;
|
|
84
|
+
const source = decl.source.value;
|
|
85
|
+
for (const s of decl.specifiers) {
|
|
86
|
+
if (t.isImportSpecifier(s) && s.importKind === 'type')
|
|
87
|
+
continue;
|
|
88
|
+
const imported = t.isImportSpecifier(s) ? (t.isIdentifier(s.imported) ? s.imported.name : s.imported.value) : null;
|
|
89
|
+
if (source === 'radix-ui' && imported === 'Slot')
|
|
90
|
+
out.push({ local: s.local.name, member: new Set(['Root', 'Slot']), decl, specifier: s });
|
|
91
|
+
if (source === '@radix-ui/react-slot') {
|
|
92
|
+
if (imported === 'Slot' || imported === 'Root')
|
|
93
|
+
out.push({ local: s.local.name, member: null, decl, specifier: s });
|
|
94
|
+
else if (t.isImportNamespaceSpecifier(s))
|
|
95
|
+
out.push({ local: s.local.name, member: new Set(['Root', 'Slot']), decl, specifier: s });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
/** The elements of a component's markup that become a Radix Slot under a test (ElementNode.asChild). */
|
|
102
|
+
export function asChildElements(comp) {
|
|
103
|
+
return elementsWhere(comp, (n) => !!n.asChild);
|
|
104
|
+
}
|
|
105
|
+
/** Every element of the component's markup (its fragments too) whose tag is `name`. */
|
|
106
|
+
function tagged(comp, name) {
|
|
107
|
+
return elementsWhere(comp, (n) => n.component && n.tag === name);
|
|
108
|
+
}
|
|
109
|
+
function elementsWhere(comp, keep) {
|
|
110
|
+
const out = [];
|
|
111
|
+
const visit = (n) => {
|
|
112
|
+
switch (n.type) {
|
|
113
|
+
case 'element':
|
|
114
|
+
if (keep(n))
|
|
115
|
+
out.push(n);
|
|
116
|
+
for (const a of n.attrs)
|
|
117
|
+
if (a.kind === 'slotProp')
|
|
118
|
+
a.children.forEach(visit);
|
|
119
|
+
n.children.forEach(visit);
|
|
120
|
+
return;
|
|
121
|
+
case 'if':
|
|
122
|
+
for (const b of n.branches)
|
|
123
|
+
b.children.forEach(visit);
|
|
124
|
+
return;
|
|
125
|
+
case 'slot':
|
|
126
|
+
n.fallback.forEach(visit);
|
|
127
|
+
return;
|
|
128
|
+
case 'for':
|
|
129
|
+
case 'fragment':
|
|
130
|
+
case 'keyed':
|
|
131
|
+
case 'presence':
|
|
132
|
+
n.children.forEach(visit);
|
|
133
|
+
return;
|
|
134
|
+
default:
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
visit(comp.template);
|
|
139
|
+
for (const f of comp.fragments)
|
|
140
|
+
visit(f.template);
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/** Whether anything but a tag reads the value: script items (other than its own declaration) or markup expressions. */
|
|
144
|
+
function readsName(comp, name, own) {
|
|
145
|
+
const roots = [];
|
|
146
|
+
for (const item of comp.items) {
|
|
147
|
+
if (item === own)
|
|
148
|
+
continue;
|
|
149
|
+
for (const value of Object.values(item)) {
|
|
150
|
+
if (Array.isArray(value))
|
|
151
|
+
for (const v of value)
|
|
152
|
+
if (t.isNode(v))
|
|
153
|
+
roots.push(v);
|
|
154
|
+
if (t.isNode(value))
|
|
155
|
+
roots.push(value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
roots.push(...templateExpressions(comp.template));
|
|
159
|
+
for (const f of comp.fragments)
|
|
160
|
+
roots.push(...templateExpressions(f.template));
|
|
161
|
+
let found = false;
|
|
162
|
+
for (const root of roots) {
|
|
163
|
+
t.traverseFast(root, (n) => {
|
|
164
|
+
if (t.isIdentifier(n) && (comp.refs.get(n) === name || n.name === name))
|
|
165
|
+
found = true;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return found;
|
|
169
|
+
}
|
|
170
|
+
/** Copies the binding links of `from`'s identifiers onto the same identifiers of its copy `to` (same shape, in order). */
|
|
171
|
+
function linkCopy(comp, from, to) {
|
|
172
|
+
const a = [];
|
|
173
|
+
const b = [];
|
|
174
|
+
t.traverseFast(from, (n) => {
|
|
175
|
+
if (t.isIdentifier(n))
|
|
176
|
+
a.push(n);
|
|
177
|
+
});
|
|
178
|
+
t.traverseFast(to, (n) => {
|
|
179
|
+
if (t.isIdentifier(n))
|
|
180
|
+
b.push(n);
|
|
181
|
+
});
|
|
182
|
+
a.forEach((id, i) => {
|
|
183
|
+
const name = comp.refs.get(id);
|
|
184
|
+
const copy = b[i];
|
|
185
|
+
if (name && copy)
|
|
186
|
+
comp.refs.set(copy, name);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** Whether the module still reads a name: its statements, its functions' code and markup (tags included). */
|
|
190
|
+
function mentions(mod, name) {
|
|
191
|
+
let found = false;
|
|
192
|
+
const look = (root) => {
|
|
193
|
+
t.traverseFast(root, (n) => {
|
|
194
|
+
if (t.isIdentifier(n, { name }) || t.isJSXIdentifier(n, { name }))
|
|
195
|
+
found = true;
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
for (const stmt of mod.moduleBody)
|
|
199
|
+
look(stmt);
|
|
200
|
+
for (const fn of [...mod.components, ...mod.hooks]) {
|
|
201
|
+
for (const item of fn.items) {
|
|
202
|
+
for (const value of Object.values(item)) {
|
|
203
|
+
if (Array.isArray(value))
|
|
204
|
+
for (const v of value)
|
|
205
|
+
if (t.isNode(v))
|
|
206
|
+
look(v);
|
|
207
|
+
if (t.isNode(value))
|
|
208
|
+
look(value);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const comp of mod.components) {
|
|
213
|
+
for (const root of [comp.template, ...comp.fragments.map((f) => f.template)]) {
|
|
214
|
+
for (const e of templateExpressions(root))
|
|
215
|
+
look(e);
|
|
216
|
+
if (hasTagRoot(root, name))
|
|
217
|
+
found = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return found;
|
|
221
|
+
}
|
|
222
|
+
/** Whether an element's tag is `name` or a member of it (`Slot.Root`). */
|
|
223
|
+
function hasTagRoot(n, name) {
|
|
224
|
+
switch (n.type) {
|
|
225
|
+
case 'element':
|
|
226
|
+
return n.tag === name || n.tag.startsWith(`${name}.`) || n.children.some((c) => hasTagRoot(c, name)) || n.attrs.some((a) => a.kind === 'slotProp' && a.children.some((c) => hasTagRoot(c, name)));
|
|
227
|
+
case 'if':
|
|
228
|
+
return n.branches.some((b) => b.children.some((c) => hasTagRoot(c, name)));
|
|
229
|
+
case 'slot':
|
|
230
|
+
return n.fallback.some((c) => hasTagRoot(c, name));
|
|
231
|
+
case 'for':
|
|
232
|
+
case 'fragment':
|
|
233
|
+
case 'keyed':
|
|
234
|
+
case 'presence':
|
|
235
|
+
return n.children.some((c) => hasTagRoot(c, name));
|
|
236
|
+
default:
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModuleIR } from './model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Takes the compound declarations out of the module body into `module.compounds` (root → member → part) and
|
|
4
|
+
* `module.aliases`; `componentNames` are the module's components. Parts of an exported root are exported too, so
|
|
5
|
+
* other files reach them.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectCompounds(module: ModuleIR, componentNames: ReadonlySet<string>): void;
|
|
8
|
+
/** The part a member tag names (`Card.Header`), through the module's compounds, or null. */
|
|
9
|
+
export declare function compoundPart(module: ModuleIR, owner: string, member: string): string | null;
|
|
10
|
+
/** Whether a component is the root or a part of a compound: it stands alone (its own file), as its callers name it. */
|
|
11
|
+
export declare function inCompound(module: ModuleIR, name: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* `<Card.Header>` where the module declares `Card`: the part's own tag. `<Card>` where `Card` is another name for a
|
|
14
|
+
* component of the module (a compound's root, `memo(ChipView)`): that component's tag.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveCompoundTags(module: ModuleIR): void;
|
|
17
|
+
/**
|
|
18
|
+
* `<Card.Header>` where `Card` is imported from a module that declares it as a compound: the part is imported under a
|
|
19
|
+
* name of its own (`import { Header as CardHeader } from './card'`), which each target resolves to the part's file.
|
|
20
|
+
* `imported` gives the module that declares what a local import binds (through barrels), the name it declares it by,
|
|
21
|
+
* and the specifier that reaches that module from this one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function linkImportedCompounds(module: ModuleIR, imported: (local: string) => {
|
|
24
|
+
mod: ModuleIR;
|
|
25
|
+
name: string;
|
|
26
|
+
source: string;
|
|
27
|
+
} | null): void;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { unwrap } from './lower.js';
|
|
3
|
+
/**
|
|
4
|
+
* Compound components: a root component that carries its parts as members, so callers write `<Card.Header>`. React
|
|
5
|
+
* builds them two ways, `const Card = Object.assign(CardRoot, { Header, Body })` and `Card.Header = Header`. A target
|
|
6
|
+
* component is a file, not an object to hang members on, so each target gets one form: the root and every part are
|
|
7
|
+
* components of their own (a file each in Vue and Svelte, a class each in Angular), `Card` is another name for the
|
|
8
|
+
* root, and `<Card.Header>` is the part itself, in the same file and in every file that imports `Card`.
|
|
9
|
+
*/
|
|
10
|
+
/** `Object.assign(…)` */
|
|
11
|
+
function isObjectAssign(call) {
|
|
12
|
+
return t.isMemberExpression(call.callee) && !call.callee.computed && t.isIdentifier(call.callee.object, { name: 'Object' }) && t.isIdentifier(call.callee.property, { name: 'assign' });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Takes the compound declarations out of the module body into `module.compounds` (root → member → part) and
|
|
16
|
+
* `module.aliases`; `componentNames` are the module's components. Parts of an exported root are exported too, so
|
|
17
|
+
* other files reach them.
|
|
18
|
+
*/
|
|
19
|
+
export function collectCompounds(module, componentNames) {
|
|
20
|
+
const compounds = new Map();
|
|
21
|
+
const rootOf = (name) => (componentNames.has(name) ? name : (module.aliases.get(name) ?? null));
|
|
22
|
+
const add = (root, member, part) => {
|
|
23
|
+
let parts = compounds.get(root);
|
|
24
|
+
if (!parts)
|
|
25
|
+
compounds.set(root, (parts = new Map()));
|
|
26
|
+
parts.set(member, part);
|
|
27
|
+
};
|
|
28
|
+
module.moduleBody = module.moduleBody.filter((stmt) => {
|
|
29
|
+
const decl = t.isExportNamedDeclaration(stmt) ? stmt.declaration : stmt;
|
|
30
|
+
// const Card = Object.assign(CardRoot, { Header, Body: CardBody })
|
|
31
|
+
const d = t.isVariableDeclaration(decl) && decl.kind === 'const' && decl.declarations.length === 1 ? decl.declarations[0] : undefined;
|
|
32
|
+
const init = d?.init ? unwrap(d.init) : null;
|
|
33
|
+
if (d && t.isIdentifier(d.id) && t.isCallExpression(init) && isObjectAssign(init) && init.arguments.length === 2) {
|
|
34
|
+
const [first, second] = init.arguments;
|
|
35
|
+
const root = t.isIdentifier(first) ? rootOf(first.name) : null;
|
|
36
|
+
const members = t.isObjectExpression(second)
|
|
37
|
+
? second.properties.map((p) => {
|
|
38
|
+
if (!t.isObjectProperty(p) || p.computed || !t.isIdentifier(p.value))
|
|
39
|
+
return null;
|
|
40
|
+
const key = t.isIdentifier(p.key) ? p.key.name : t.isStringLiteral(p.key) ? p.key.value : null;
|
|
41
|
+
const part = rootOf(p.value.name);
|
|
42
|
+
return key && part ? { key, part } : null;
|
|
43
|
+
})
|
|
44
|
+
: [];
|
|
45
|
+
if (root && members.length && members.every((m) => m !== null)) {
|
|
46
|
+
for (const m of members)
|
|
47
|
+
if (m)
|
|
48
|
+
add(root, m.key, m.part);
|
|
49
|
+
module.aliases.set(d.id.name, root);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Card.Header = Header
|
|
54
|
+
if (t.isExpressionStatement(stmt) && t.isAssignmentExpression(stmt.expression, { operator: '=' })) {
|
|
55
|
+
const { left, right } = stmt.expression;
|
|
56
|
+
if (t.isMemberExpression(left) && !left.computed && t.isIdentifier(left.object) && t.isIdentifier(left.property) && t.isIdentifier(right)) {
|
|
57
|
+
const root = rootOf(left.object.name);
|
|
58
|
+
const part = rootOf(right.name);
|
|
59
|
+
if (root && part) {
|
|
60
|
+
add(root, left.property.name, part);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
});
|
|
67
|
+
if (!compounds.size)
|
|
68
|
+
return;
|
|
69
|
+
module.compounds = compounds;
|
|
70
|
+
const exported = (name) => module.exportedNames.has(name) || module.defaultExport === name || [...module.aliases].some(([alias, real]) => real === name && (module.exportedNames.has(alias) || module.defaultExport === alias));
|
|
71
|
+
for (const [root, parts] of compounds)
|
|
72
|
+
if (exported(root))
|
|
73
|
+
for (const part of parts.values())
|
|
74
|
+
module.exportedNames.add(part);
|
|
75
|
+
}
|
|
76
|
+
/** The part a member tag names (`Card.Header`), through the module's compounds, or null. */
|
|
77
|
+
export function compoundPart(module, owner, member) {
|
|
78
|
+
const root = module.components.some((c) => c.name === owner) ? owner : (module.aliases.get(owner) ?? owner);
|
|
79
|
+
return module.compounds?.get(root)?.get(member) ?? null;
|
|
80
|
+
}
|
|
81
|
+
/** Whether a component is the root or a part of a compound: it stands alone (its own file), as its callers name it. */
|
|
82
|
+
export function inCompound(module, name) {
|
|
83
|
+
for (const [root, parts] of module.compounds ?? [])
|
|
84
|
+
if (root === name || [...parts.values()].includes(name))
|
|
85
|
+
return true;
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
/** Every element of a component's markup (its template and its render helpers), for a tag rewrite. */
|
|
89
|
+
function eachElement(module, visit) {
|
|
90
|
+
const walk = (n) => {
|
|
91
|
+
switch (n.type) {
|
|
92
|
+
case 'element':
|
|
93
|
+
visit(n);
|
|
94
|
+
for (const a of n.attrs)
|
|
95
|
+
if (a.kind === 'slotProp')
|
|
96
|
+
a.children.forEach(walk);
|
|
97
|
+
n.children.forEach(walk);
|
|
98
|
+
return;
|
|
99
|
+
case 'if':
|
|
100
|
+
for (const b of n.branches)
|
|
101
|
+
b.children.forEach(walk);
|
|
102
|
+
return;
|
|
103
|
+
case 'slot':
|
|
104
|
+
n.fallback.forEach(walk);
|
|
105
|
+
return;
|
|
106
|
+
case 'for':
|
|
107
|
+
case 'fragment':
|
|
108
|
+
case 'keyed':
|
|
109
|
+
case 'presence':
|
|
110
|
+
n.children.forEach(walk);
|
|
111
|
+
return;
|
|
112
|
+
default:
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
for (const c of module.components) {
|
|
117
|
+
walk(c.template);
|
|
118
|
+
for (const f of c.fragments)
|
|
119
|
+
walk(f.template);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* `<Card.Header>` where the module declares `Card`: the part's own tag. `<Card>` where `Card` is another name for a
|
|
124
|
+
* component of the module (a compound's root, `memo(ChipView)`): that component's tag.
|
|
125
|
+
*/
|
|
126
|
+
export function resolveCompoundTags(module) {
|
|
127
|
+
if (!module.compounds && !module.aliases.size)
|
|
128
|
+
return;
|
|
129
|
+
const names = new Set(module.components.map((c) => c.name));
|
|
130
|
+
eachElement(module, (n) => {
|
|
131
|
+
if (!n.component)
|
|
132
|
+
return;
|
|
133
|
+
const dot = n.tag.indexOf('.');
|
|
134
|
+
if (dot < 0) {
|
|
135
|
+
const real = module.aliases.get(n.tag);
|
|
136
|
+
if (real && names.has(real))
|
|
137
|
+
n.tag = real;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (n.tag.indexOf('.', dot + 1) >= 0)
|
|
141
|
+
return;
|
|
142
|
+
const part = compoundPart(module, n.tag.slice(0, dot), n.tag.slice(dot + 1));
|
|
143
|
+
if (part)
|
|
144
|
+
n.tag = part;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* `<Card.Header>` where `Card` is imported from a module that declares it as a compound: the part is imported under a
|
|
149
|
+
* name of its own (`import { Header as CardHeader } from './card'`), which each target resolves to the part's file.
|
|
150
|
+
* `imported` gives the module that declares what a local import binds (through barrels), the name it declares it by,
|
|
151
|
+
* and the specifier that reaches that module from this one.
|
|
152
|
+
*/
|
|
153
|
+
export function linkImportedCompounds(module, imported) {
|
|
154
|
+
const taken = new Set([...module.moduleJsx.moduleNames, ...module.imports.flatMap((d) => d.specifiers.map((s) => s.local.name))]);
|
|
155
|
+
const linked = new Map();
|
|
156
|
+
eachElement(module, (n) => {
|
|
157
|
+
const dot = n.tag.indexOf('.');
|
|
158
|
+
if (!n.component || dot < 0 || n.tag.indexOf('.', dot + 1) >= 0)
|
|
159
|
+
return;
|
|
160
|
+
const already = linked.get(n.tag);
|
|
161
|
+
if (already) {
|
|
162
|
+
n.tag = already;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const owner = n.tag.slice(0, dot);
|
|
166
|
+
const member = n.tag.slice(dot + 1);
|
|
167
|
+
const imp = imported(owner);
|
|
168
|
+
if (!imp)
|
|
169
|
+
return;
|
|
170
|
+
const exportName = imp.name === 'default' ? imp.mod.defaultExport : imp.name;
|
|
171
|
+
const part = exportName ? compoundPart(imp.mod, exportName, member) : null;
|
|
172
|
+
if (!part)
|
|
173
|
+
return;
|
|
174
|
+
let local = `${owner}${member}`;
|
|
175
|
+
for (let i = 2; taken.has(local); i++)
|
|
176
|
+
local = `${owner}${member}${i}`;
|
|
177
|
+
taken.add(local);
|
|
178
|
+
// from the module that declares the part (a barrel in between exports the compound, not its parts)
|
|
179
|
+
module.imports.push(t.importDeclaration([t.importSpecifier(t.identifier(local), t.identifier(part))], t.stringLiteral(imp.source)));
|
|
180
|
+
linked.set(n.tag, local);
|
|
181
|
+
n.tag = local;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Diagnostic } from '../types.js';
|
|
2
|
+
import type { ContextRef, ModuleIR, ScriptItem } from './model.js';
|
|
3
|
+
/** One problem with a context read or provider, said where it is. */
|
|
4
|
+
export interface ContextProblem {
|
|
5
|
+
code: string;
|
|
6
|
+
severity: Diagnostic['severity'];
|
|
7
|
+
message: string;
|
|
8
|
+
line?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Links a module's context reads and providers to their `createContext` declarations, once the graph is known:
|
|
12
|
+
*
|
|
13
|
+
* - `useContext(Ctx)` / `use(Ctx)` reads get their context;
|
|
14
|
+
* - `<Ctx.Provider value={v}>` (React 19: `<Ctx value={v}>`) leaves the markup, its children rendering in place, and
|
|
15
|
+
* becomes one of the component's `provides`: a component provides from its own instance (Vue's provide, Svelte's
|
|
16
|
+
* context, Angular's providers), for everything it renders.
|
|
17
|
+
*
|
|
18
|
+
* What has no faithful form is reported and left out: a read of something that is not a context of the compiled files,
|
|
19
|
+
* a provider inside a loop or a condition (it comes and goes, or repeats, where a component instance provides once), a
|
|
20
|
+
* context provided twice by one component. A component it renders outside the provider also sees the value (a warning).
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveContexts(mod: ModuleIR, lookup: (local: string) => ContextRef | null, options?: {
|
|
23
|
+
conditional?: boolean;
|
|
24
|
+
}): ContextProblem[];
|
|
25
|
+
/** The context a read was linked to by resolveContexts, or null. */
|
|
26
|
+
export declare function contextOfRead(item: ScriptItem): ContextRef | null;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { cloneWithRefs } from './rewrite.js';
|
|
3
|
+
/**
|
|
4
|
+
* Links a module's context reads and providers to their `createContext` declarations, once the graph is known:
|
|
5
|
+
*
|
|
6
|
+
* - `useContext(Ctx)` / `use(Ctx)` reads get their context;
|
|
7
|
+
* - `<Ctx.Provider value={v}>` (React 19: `<Ctx value={v}>`) leaves the markup, its children rendering in place, and
|
|
8
|
+
* becomes one of the component's `provides`: a component provides from its own instance (Vue's provide, Svelte's
|
|
9
|
+
* context, Angular's providers), for everything it renders.
|
|
10
|
+
*
|
|
11
|
+
* What has no faithful form is reported and left out: a read of something that is not a context of the compiled files,
|
|
12
|
+
* a provider inside a loop or a condition (it comes and goes, or repeats, where a component instance provides once), a
|
|
13
|
+
* context provided twice by one component. A component it renders outside the provider also sees the value (a warning).
|
|
14
|
+
*/
|
|
15
|
+
export function resolveContexts(mod, lookup, options = {}) {
|
|
16
|
+
const problems = [];
|
|
17
|
+
for (const fn of [...mod.components, ...mod.hooks])
|
|
18
|
+
resolveReads(fn, lookup, problems);
|
|
19
|
+
for (const comp of mod.components)
|
|
20
|
+
resolveProviders(comp, lookup, problems, options.conditional ?? false);
|
|
21
|
+
return problems;
|
|
22
|
+
}
|
|
23
|
+
/** The declaration each linked context read reads (kept beside the IR, so passes that walk it never walk declarations). */
|
|
24
|
+
const linked = new WeakMap();
|
|
25
|
+
/** The context a read was linked to by resolveContexts, or null. */
|
|
26
|
+
export function contextOfRead(item) {
|
|
27
|
+
return linked.get(item) ?? null;
|
|
28
|
+
}
|
|
29
|
+
function resolveReads(fn, lookup, problems) {
|
|
30
|
+
fn.items = fn.items.map((item) => {
|
|
31
|
+
if (item.kind !== 'context')
|
|
32
|
+
return item;
|
|
33
|
+
const ref = lookup(item.context);
|
|
34
|
+
if (ref) {
|
|
35
|
+
linked.set(item, ref);
|
|
36
|
+
return item;
|
|
37
|
+
}
|
|
38
|
+
const line = item.call.loc?.start.line;
|
|
39
|
+
problems.push({
|
|
40
|
+
code: item.hook === 'use' ? 'react-use' : 'context',
|
|
41
|
+
severity: 'error',
|
|
42
|
+
message: item.hook === 'use'
|
|
43
|
+
? `use(${item.context}) reads something other than a context created with createContext in the compiled files (a promise, or a library's context): not converted.`
|
|
44
|
+
: `${item.context} is not a context created with createContext in the compiled files (a library's context, say): useContext(${item.context}) is not converted.`,
|
|
45
|
+
...(line ? { line } : {}),
|
|
46
|
+
});
|
|
47
|
+
// kept as written, so the code that reads it still compiles; the error says it does not work
|
|
48
|
+
const binding = fn.bindings.get(item.name);
|
|
49
|
+
if (binding)
|
|
50
|
+
binding.reactive = false;
|
|
51
|
+
return { kind: 'derived', id: t.identifier(item.name), names: [item.name], init: item.call, memo: false, type: null, declKind: 'const' };
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Whether two places sit in different branches of one `if`, so they never render together. */
|
|
55
|
+
function exclusive(a, b) {
|
|
56
|
+
return a.some(([node, i]) => b.some(([other, j]) => other === node && j !== i));
|
|
57
|
+
}
|
|
58
|
+
function providerName(n) {
|
|
59
|
+
// a Radix part, known by its import (ir/radix), is a component, never a React context's provider, even when the
|
|
60
|
+
// part is named Provider (`<TooltipPrimitive.Provider>`)
|
|
61
|
+
if (!n.component || n.radix)
|
|
62
|
+
return null;
|
|
63
|
+
const name = n.tag.endsWith('.Provider') ? n.tag.slice(0, -'.Provider'.length) : n.tag;
|
|
64
|
+
return name.includes('.') ? null : name;
|
|
65
|
+
}
|
|
66
|
+
function resolveProviders(comp, lookup, problems, conditional) {
|
|
67
|
+
/** components, slots and helper calls rendered outside every provider, with where they sit */
|
|
68
|
+
const outside = [];
|
|
69
|
+
/** where each provider under a condition sits */
|
|
70
|
+
const placed = [];
|
|
71
|
+
const valueOf = (n) => {
|
|
72
|
+
for (const a of n.attrs) {
|
|
73
|
+
if (a.kind === 'expr' && a.name === 'value')
|
|
74
|
+
return a.expr;
|
|
75
|
+
if (a.kind === 'static' && a.name === 'value')
|
|
76
|
+
return t.stringLiteral(a.value);
|
|
77
|
+
if (a.kind === 'bool' && a.name === 'value')
|
|
78
|
+
return t.booleanLiteral(true);
|
|
79
|
+
}
|
|
80
|
+
return t.identifier('undefined');
|
|
81
|
+
};
|
|
82
|
+
const walk = (nodes, where) => nodes.flatMap((n) => {
|
|
83
|
+
switch (n.type) {
|
|
84
|
+
case 'element': {
|
|
85
|
+
const name = providerName(n);
|
|
86
|
+
const ref = name ? lookup(name) : null;
|
|
87
|
+
if (!name || (!ref && !n.tag.endsWith('.Provider'))) {
|
|
88
|
+
if (!where.provided && (n.component || n.tag === 'slot'))
|
|
89
|
+
outside.push({ what: `<${n.tag}>`, path: where.path });
|
|
90
|
+
for (const a of n.attrs)
|
|
91
|
+
if (a.kind === 'slotProp')
|
|
92
|
+
a.children = walk(a.children, where);
|
|
93
|
+
n.children = walk(n.children, where);
|
|
94
|
+
return [n];
|
|
95
|
+
}
|
|
96
|
+
const value = valueOf(n);
|
|
97
|
+
const line = value.loc?.start.line;
|
|
98
|
+
const at = line ? { line } : {};
|
|
99
|
+
const inner = () => walk(n.children, { ...where, provided: true });
|
|
100
|
+
if (!ref) {
|
|
101
|
+
problems.push({ code: 'context', severity: 'error', message: `<${n.tag}>: ${name} is not a context created with createContext in the compiled files; its children render without it.`, ...at });
|
|
102
|
+
return inner();
|
|
103
|
+
}
|
|
104
|
+
if (n.attrs.some((a) => a.kind === 'spread')) {
|
|
105
|
+
problems.push({ code: 'context-provider', severity: 'error', message: `<${n.tag}> takes its props from a spread: the value it provides is not known, so it is not provided.`, ...at });
|
|
106
|
+
return inner();
|
|
107
|
+
}
|
|
108
|
+
if (comp.provides.some((p) => p.context.decl === ref.decl)) {
|
|
109
|
+
problems.push({ code: 'context-provider', severity: 'error', message: `${comp.name} provides ${name} twice: a component provides one value per context, so the inner provider is not converted. Move it into a component of its own.`, ...at });
|
|
110
|
+
return inner();
|
|
111
|
+
}
|
|
112
|
+
// under conditions only: the component provides `value` while they hold and passes on the value from above
|
|
113
|
+
// otherwise, which is what everything the branch renders reads either way
|
|
114
|
+
const when = where.when;
|
|
115
|
+
if (conditional && !where.loop && where.branch && when?.length) {
|
|
116
|
+
comp.provides.push({ context: ref, value, when: when.map((c) => cloneWithRefs(c, comp)).reduce((a, b) => t.logicalExpression('&&', a, b)) });
|
|
117
|
+
placed.push(where.path);
|
|
118
|
+
return inner();
|
|
119
|
+
}
|
|
120
|
+
if (where.loop || where.branch) {
|
|
121
|
+
problems.push({
|
|
122
|
+
code: 'context-provider',
|
|
123
|
+
severity: 'error',
|
|
124
|
+
message: `<${n.tag}> sits ${where.loop ? 'inside a loop' : 'inside a condition'}: a component provides one value for everything it renders, from setup on, so a provider that ${where.loop ? 'repeats' : 'comes and goes'} has no direct form. Move it into a component of its own.`,
|
|
125
|
+
...at,
|
|
126
|
+
});
|
|
127
|
+
return inner();
|
|
128
|
+
}
|
|
129
|
+
comp.provides.push({ context: ref, value });
|
|
130
|
+
return inner();
|
|
131
|
+
}
|
|
132
|
+
case 'if': {
|
|
133
|
+
// a branch renders when every earlier test fails and its own holds
|
|
134
|
+
const failed = [];
|
|
135
|
+
n.branches.forEach((b, i) => {
|
|
136
|
+
const own = b.test ? [...failed, b.test] : [...failed];
|
|
137
|
+
const when = where.when ? [...where.when, ...own] : null;
|
|
138
|
+
b.children = walk(b.children, { ...where, branch: true, when, path: [...where.path, [n, i]] });
|
|
139
|
+
if (b.test)
|
|
140
|
+
failed.push(t.unaryExpression('!', t.isIdentifier(b.test) || t.isMemberExpression(b.test) || t.isCallExpression(b.test) ? b.test : t.parenthesizedExpression(b.test)));
|
|
141
|
+
});
|
|
142
|
+
return [n];
|
|
143
|
+
}
|
|
144
|
+
case 'for':
|
|
145
|
+
n.children = walk(n.children, { ...where, loop: true });
|
|
146
|
+
return [n];
|
|
147
|
+
case 'slot':
|
|
148
|
+
if (!where.provided)
|
|
149
|
+
outside.push({ what: 'a slot', path: where.path });
|
|
150
|
+
n.fallback = walk(n.fallback, { ...where, branch: true, when: null });
|
|
151
|
+
return [n];
|
|
152
|
+
case 'presence':
|
|
153
|
+
n.children = walk(n.children, { ...where, branch: true, when: null });
|
|
154
|
+
return [n];
|
|
155
|
+
case 'fragment':
|
|
156
|
+
case 'keyed':
|
|
157
|
+
n.children = walk(n.children, where);
|
|
158
|
+
return [n];
|
|
159
|
+
case 'render':
|
|
160
|
+
if (!where.provided)
|
|
161
|
+
outside.push({ what: `${n.name}()`, path: where.path });
|
|
162
|
+
return [n];
|
|
163
|
+
default:
|
|
164
|
+
return [n];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
const [root] = walk([comp.template], { loop: false, branch: false, provided: false, when: [], path: [] });
|
|
168
|
+
comp.template = root ?? { type: 'fragment', children: [] };
|
|
169
|
+
for (const f of comp.fragments) {
|
|
170
|
+
// a helper's markup renders where it is called: a call outside the providers is counted there
|
|
171
|
+
const [template] = walk([f.template], { loop: false, branch: true, provided: true, when: null, path: [] });
|
|
172
|
+
f.template = template ?? { type: 'fragment', children: [] };
|
|
173
|
+
}
|
|
174
|
+
// what renders only where every provider under a condition does not (another branch of its `if`) reads the value
|
|
175
|
+
// from above, as in React
|
|
176
|
+
const seen = comp.provides.some((p) => !p.when) ? outside : outside.filter((o) => !placed.every((at) => exclusive(at, o.path)));
|
|
177
|
+
if (comp.provides.length && seen.length) {
|
|
178
|
+
const names = comp.provides.map((p) => p.context.local).join(', ');
|
|
179
|
+
problems.push({
|
|
180
|
+
code: 'context-provider-scope',
|
|
181
|
+
severity: 'warning',
|
|
182
|
+
message: `${comp.name} renders ${[...new Set(seen.map((o) => o.what))].slice(0, 3).join(', ')} outside its ${names} provider: the component provides for everything it renders, so ${seen.length > 1 ? 'those' : 'that'} would read the provided value where React gives the value from above.`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
package/dist/ir/dom.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/** The React names domAttributeName maps (for targets that rename the keys of a spread object at run time). */
|
|
3
|
+
export declare const REACT_ATTRIBUTE_NAMES: readonly string[];
|
|
4
|
+
export declare function domAttributeName(react: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* The DOM event a React handler listens to. React's onChange on text inputs fires on every keystroke (the DOM `input`
|
|
7
|
+
* event); on checkboxes, radios and selects it is the DOM `change` event.
|
|
8
|
+
*/
|
|
9
|
+
export declare function domEventName(react: string, tag: string, attributes: (t.JSXAttribute | t.JSXSpreadAttribute)[]): string;
|
|
10
|
+
/** Standard DOM event props, which Svelte 5 spells in lower case (`onclick`). */
|
|
11
|
+
export declare function isDomEventProp(name: string): boolean;
|