@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,217 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* A running index across nested loops (`let index = -1;` then `index += 1; const i = index;` first thing in each inner
|
|
4
|
+
* row): React renders the rows in order, so each row reads its position in the flattened list. That position is a
|
|
5
|
+
* pure function of the data: the rows of the earlier outer items plus the row's own position. Written that way
|
|
6
|
+
* (`const index = -1 + 1 + indexStarts[gi]! + ri`, with `indexStarts` the sums of the earlier items' row counts
|
|
7
|
+
* computed where `index` was declared), each row computes it on its own, as a template renders rows. Rewrites the
|
|
8
|
+
* component's source before lowering; anything but that exact shape is left alone (and reported by lowering).
|
|
9
|
+
*/
|
|
10
|
+
export function precomputeRunningIndex(fnPath) {
|
|
11
|
+
const body = fnPath.node.body;
|
|
12
|
+
if (!t.isBlockStatement(body))
|
|
13
|
+
return;
|
|
14
|
+
let changed = false;
|
|
15
|
+
for (const stmt of [...body.body]) {
|
|
16
|
+
if (!t.isVariableDeclaration(stmt, { kind: 'let' }) || stmt.declarations.length !== 1)
|
|
17
|
+
continue;
|
|
18
|
+
const d = stmt.declarations[0];
|
|
19
|
+
// where it starts: a number, or a value made of names and numbers that stays put while the component renders
|
|
20
|
+
const init = d?.init ?? null;
|
|
21
|
+
if (!d || !t.isIdentifier(d.id) || !init || !plainValue(init))
|
|
22
|
+
continue;
|
|
23
|
+
const binding = fnPath.scope.getBinding(d.id.name);
|
|
24
|
+
const declared = binding?.path;
|
|
25
|
+
const initPath = declared?.isVariableDeclarator() ? declared.get('init') : null;
|
|
26
|
+
if (!initPath || !initPath.isExpression() || !readsOnlyBefore(initPath, fnPath, stmt))
|
|
27
|
+
continue;
|
|
28
|
+
const write = binding?.constantViolations.length === 1 ? binding.constantViolations[0] : undefined;
|
|
29
|
+
if (!binding || !write || !isIncrement(write.node))
|
|
30
|
+
continue;
|
|
31
|
+
// the increment is the first statement of a `.map()` row: `index += 1;`, or `const i = ++n;` (`n++` reads the
|
|
32
|
+
// value before)
|
|
33
|
+
const declarator = write.parentPath?.isVariableDeclarator() && write.parentPath.node.init === write.node && t.isIdentifier(write.parentPath.node.id) ? write.parentPath.node : null;
|
|
34
|
+
const statement = declarator ? write.parentPath?.parentPath : write.parentPath;
|
|
35
|
+
const block = statement?.parentPath;
|
|
36
|
+
const row = block?.parentPath;
|
|
37
|
+
if (!statement || !(statement.isExpressionStatement() || (declarator && statement.isVariableDeclaration() && statement.node.declarations.length === 1)) || !block?.isBlockStatement() || block.node.body[0] !== statement.node)
|
|
38
|
+
continue;
|
|
39
|
+
const before = t.isUpdateExpression(write.node) && !write.node.prefix;
|
|
40
|
+
if (!row || !(row.isArrowFunctionExpression() || row.isFunctionExpression()))
|
|
41
|
+
continue;
|
|
42
|
+
const innerCall = row.parentPath;
|
|
43
|
+
if (!innerCall?.isCallExpression() || innerCall.node.arguments[0] !== row.node || !isMapCall(innerCall.node))
|
|
44
|
+
continue;
|
|
45
|
+
// every read is inside that row, after the increment
|
|
46
|
+
if (!binding.referencePaths.every((r) => r.node === write.node || r.parentPath?.node === write.node || (r.findParent((p) => p === row) && (r.node.start ?? 0) > (statement.node.end ?? 0))))
|
|
47
|
+
continue;
|
|
48
|
+
const innerCallee = innerCall.get('callee');
|
|
49
|
+
if (!innerCallee.isMemberExpression())
|
|
50
|
+
continue;
|
|
51
|
+
const inner = innerCallee.node;
|
|
52
|
+
// the row's own position, and the outer row's when the loop is nested in another `.map()`
|
|
53
|
+
const outerRow = innerCall.getFunctionParent();
|
|
54
|
+
if (!outerRow)
|
|
55
|
+
continue;
|
|
56
|
+
let offset = null;
|
|
57
|
+
let starts = null;
|
|
58
|
+
if (outerRow !== fnPath) {
|
|
59
|
+
const outerCall = outerRow.parentPath;
|
|
60
|
+
if (!(outerRow.isArrowFunctionExpression() || outerRow.isFunctionExpression()) || !outerCall?.isCallExpression() || outerCall.node.arguments[0] !== outerRow.node || !isMapCall(outerCall.node))
|
|
61
|
+
continue;
|
|
62
|
+
if (outerCall.getFunctionParent() !== fnPath)
|
|
63
|
+
continue;
|
|
64
|
+
const item = outerRow.node.params[0];
|
|
65
|
+
if (!t.isIdentifier(item))
|
|
66
|
+
continue;
|
|
67
|
+
const outerCallee = outerCall.get('callee');
|
|
68
|
+
if (!outerCallee.isMemberExpression())
|
|
69
|
+
continue;
|
|
70
|
+
const outerIterable = outerCallee.node.object;
|
|
71
|
+
// the outer list is there where the counter was declared
|
|
72
|
+
if (!readsOnlyBefore(outerCallee.get('object'), fnPath, stmt))
|
|
73
|
+
continue;
|
|
74
|
+
// the inner list is read from the outer item only (`g.rows`)
|
|
75
|
+
if (!readsOnly(innerCallee.get('object'), outerRow, item.name))
|
|
76
|
+
continue;
|
|
77
|
+
const outerIndex = indexParam(outerRow.node, fnPath, 'groupIndex');
|
|
78
|
+
const name = fresh(fnPath, `${d.id.name}Starts`);
|
|
79
|
+
const each = t.identifier('each');
|
|
80
|
+
const at = Object.assign(t.identifier('at'), { typeAnnotation: t.tsTypeAnnotation(t.tsNumberKeyword()) });
|
|
81
|
+
const sum = Object.assign(t.identifier('sum'), { typeAnnotation: t.tsTypeAnnotation(t.tsNumberKeyword()) });
|
|
82
|
+
const rowsOf = renameIn(inner.object, item.name, each);
|
|
83
|
+
// indexStarts[k]: how many inner rows the outer items before k render
|
|
84
|
+
const init = t.callExpression(t.memberExpression(t.cloneNode(outerIterable, true), t.identifier('map')), [
|
|
85
|
+
t.arrowFunctionExpression([Object.assign(t.identifier('_'), { typeAnnotation: t.tsTypeAnnotation(t.tsUnknownKeyword()) }), at], t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.cloneNode(outerIterable, true), t.identifier('slice')), [t.numericLiteral(0), t.identifier('at')]), t.identifier('reduce')), [
|
|
86
|
+
t.arrowFunctionExpression([sum, each], t.binaryExpression('+', t.identifier('sum'), t.memberExpression(rowsOf, t.identifier('length')))),
|
|
87
|
+
t.numericLiteral(0),
|
|
88
|
+
])),
|
|
89
|
+
]);
|
|
90
|
+
starts = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(name), init)]);
|
|
91
|
+
offset = t.tsNonNullExpression(t.memberExpression(t.identifier(name), t.identifier(outerIndex), true));
|
|
92
|
+
}
|
|
93
|
+
const rowIndex = indexParam(row.node, fnPath, 'rowIndex');
|
|
94
|
+
const parts = [...(offset ? [offset] : []), t.identifier(rowIndex)];
|
|
95
|
+
const value = numberValue(init);
|
|
96
|
+
const first = value !== null ? t.numericLiteral(value + 1) : t.binaryExpression('+', t.parenthesizedExpression(t.cloneNode(init, true)), t.numericLiteral(1));
|
|
97
|
+
const position = parts.reduce((a, b) => t.binaryExpression('+', a, b), first);
|
|
98
|
+
const counter = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(d.id.name), position)]);
|
|
99
|
+
if (declarator && t.isIdentifier(declarator.id)) {
|
|
100
|
+
const value = before ? t.binaryExpression('-', t.identifier(d.id.name), t.numericLiteral(1)) : t.identifier(d.id.name);
|
|
101
|
+
statement.replaceWithMultiple([counter, t.variableDeclaration('const', [t.variableDeclarator(t.cloneNode(declarator.id), value)])]);
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
statement.replaceWith(counter);
|
|
105
|
+
const at = body.body.indexOf(stmt);
|
|
106
|
+
body.body.splice(at, 1, ...(starts ? [starts] : []));
|
|
107
|
+
changed = true;
|
|
108
|
+
}
|
|
109
|
+
if (changed)
|
|
110
|
+
fnPath.scope.crawl();
|
|
111
|
+
}
|
|
112
|
+
function numberValue(e) {
|
|
113
|
+
if (t.isNumericLiteral(e))
|
|
114
|
+
return e.value;
|
|
115
|
+
if (t.isUnaryExpression(e, { operator: '-' }) && t.isNumericLiteral(e.argument))
|
|
116
|
+
return -e.argument.value;
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
/** Names, numbers and arithmetic on them (`lead - 1`, `props.start`): nothing that calls or writes. */
|
|
120
|
+
function plainValue(e) {
|
|
121
|
+
if (t.isNumericLiteral(e) || t.isIdentifier(e))
|
|
122
|
+
return true;
|
|
123
|
+
if (t.isUnaryExpression(e) && (e.operator === '-' || e.operator === '+'))
|
|
124
|
+
return plainValue(e.argument);
|
|
125
|
+
if (t.isBinaryExpression(e) && /^[-+*/%]$/.test(e.operator))
|
|
126
|
+
return plainValue(e.left) && plainValue(e.right);
|
|
127
|
+
if (t.isMemberExpression(e) && !e.computed)
|
|
128
|
+
return plainValue(e.object);
|
|
129
|
+
if (t.isParenthesizedExpression(e))
|
|
130
|
+
return plainValue(e.expression);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
/** `n += 1`, `n++`, `++n` */
|
|
134
|
+
function isIncrement(n) {
|
|
135
|
+
if (t.isUpdateExpression(n))
|
|
136
|
+
return n.operator === '++';
|
|
137
|
+
return t.isAssignmentExpression(n, { operator: '+=' }) && t.isNumericLiteral(n.right, { value: 1 });
|
|
138
|
+
}
|
|
139
|
+
function isMapCall(call) {
|
|
140
|
+
return t.isMemberExpression(call.callee) && !call.callee.computed && t.isIdentifier(call.callee.property, { name: 'map' });
|
|
141
|
+
}
|
|
142
|
+
/** A name nothing in the component declares. */
|
|
143
|
+
function fresh(fnPath, base) {
|
|
144
|
+
let name = base;
|
|
145
|
+
for (let i = 2; fnPath.scope.hasBinding(name) || hasInner(fnPath, name); i++)
|
|
146
|
+
name = `${base}${i}`;
|
|
147
|
+
return name;
|
|
148
|
+
}
|
|
149
|
+
function hasInner(fnPath, name) {
|
|
150
|
+
let found = false;
|
|
151
|
+
fnPath.traverse({
|
|
152
|
+
Scope(p) {
|
|
153
|
+
if (p.scope.hasOwnBinding(name))
|
|
154
|
+
found = true;
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return found;
|
|
158
|
+
}
|
|
159
|
+
/** The index parameter of a `.map()` row, added when the row does not take one. */
|
|
160
|
+
function indexParam(row, fnPath, base) {
|
|
161
|
+
const second = row.params[1];
|
|
162
|
+
if (t.isIdentifier(second))
|
|
163
|
+
return second.name;
|
|
164
|
+
const name = fresh(fnPath, base);
|
|
165
|
+
if (!row.params[0])
|
|
166
|
+
row.params.push(t.identifier('_item'));
|
|
167
|
+
row.params[1] = t.identifier(name);
|
|
168
|
+
return name;
|
|
169
|
+
}
|
|
170
|
+
/** Every name the expression reads is bound before `before` (or outside the component). */
|
|
171
|
+
function readsOnlyBefore(expr, fnPath, before) {
|
|
172
|
+
let ok = true;
|
|
173
|
+
const check = (p) => {
|
|
174
|
+
if (!p.isReferencedIdentifier())
|
|
175
|
+
return;
|
|
176
|
+
const b = p.scope.getBinding(p.node.name);
|
|
177
|
+
if (b && b.scope === fnPath.scope && (b.path.node.start ?? 0) > (before.start ?? 0))
|
|
178
|
+
ok = false;
|
|
179
|
+
};
|
|
180
|
+
if (expr.isIdentifier())
|
|
181
|
+
check(expr);
|
|
182
|
+
expr.traverse({ Identifier: check });
|
|
183
|
+
return ok;
|
|
184
|
+
}
|
|
185
|
+
/** The expression reads, of the outer row's names, only its item. */
|
|
186
|
+
function readsOnly(expr, outerRow, item) {
|
|
187
|
+
let ok = true;
|
|
188
|
+
const check = (p) => {
|
|
189
|
+
if (!p.isReferencedIdentifier())
|
|
190
|
+
return;
|
|
191
|
+
const b = p.scope.getBinding(p.node.name);
|
|
192
|
+
if (b && b.scope === outerRow.scope && p.node.name !== item)
|
|
193
|
+
ok = false;
|
|
194
|
+
};
|
|
195
|
+
if (expr.isIdentifier())
|
|
196
|
+
check(expr);
|
|
197
|
+
expr.traverse({ Identifier: check });
|
|
198
|
+
return ok;
|
|
199
|
+
}
|
|
200
|
+
/** A copy of an expression with one free name replaced. */
|
|
201
|
+
function renameIn(e, from, to) {
|
|
202
|
+
const copy = t.cloneNode(e, true);
|
|
203
|
+
const visit = (n, parent) => {
|
|
204
|
+
if (t.isIdentifier(n) && n.name === from && !(parent && t.isMemberExpression(parent) && parent.property === n && !parent.computed))
|
|
205
|
+
return t.cloneNode(to);
|
|
206
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
207
|
+
const v = Reflect.get(n, key);
|
|
208
|
+
if (Array.isArray(v))
|
|
209
|
+
v.forEach((c, i) => t.isNode(c) && (v[i] = visit(c, n)));
|
|
210
|
+
else if (t.isNode(v))
|
|
211
|
+
Reflect.set(n, key, visit(v, n));
|
|
212
|
+
}
|
|
213
|
+
return n;
|
|
214
|
+
};
|
|
215
|
+
const out = visit(copy, null);
|
|
216
|
+
return t.isExpression(out) ? out : copy;
|
|
217
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ModuleIR } from './model.js';
|
|
2
|
+
/**
|
|
3
|
+
* React's state is a `const`: a test on it (`if (!sort) return rows`, `const active = sort?.key === k`) narrows it for
|
|
4
|
+
* the rest of the code, inside callbacks too. Vue reads it as `sort.value` and Svelte as a `let`, and TypeScript forgets
|
|
5
|
+
* a test on either inside a callback or through a const that holds the test. So where a computation tests state that
|
|
6
|
+
* may be null and reads it again in a callback or after such a const, it reads the state once into a const of its own
|
|
7
|
+
* (`const sortValue = sort`) and uses that: the same value, since nothing writes the state while it computes.
|
|
8
|
+
*
|
|
9
|
+
* Covered: values built by statements (`useMemo(() => { … })`), effect bodies (their callbacks: a frame, a timer) and
|
|
10
|
+
* the values a list declares for each row.
|
|
11
|
+
*/
|
|
12
|
+
export declare function snapshotNullableState(mod: ModuleIR): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* React's state is a `const`: a test on it (`if (!sort) return rows`, `const active = sort?.key === k`) narrows it for
|
|
4
|
+
* the rest of the code, inside callbacks too. Vue reads it as `sort.value` and Svelte as a `let`, and TypeScript forgets
|
|
5
|
+
* a test on either inside a callback or through a const that holds the test. So where a computation tests state that
|
|
6
|
+
* may be null and reads it again in a callback or after such a const, it reads the state once into a const of its own
|
|
7
|
+
* (`const sortValue = sort`) and uses that: the same value, since nothing writes the state while it computes.
|
|
8
|
+
*
|
|
9
|
+
* Covered: values built by statements (`useMemo(() => { … })`), effect bodies (their callbacks: a frame, a timer) and
|
|
10
|
+
* the values a list declares for each row.
|
|
11
|
+
*/
|
|
12
|
+
export function snapshotNullableState(mod) {
|
|
13
|
+
for (const fn of [...mod.components, ...mod.hooks]) {
|
|
14
|
+
const nullable = nullableState(fn.items);
|
|
15
|
+
if (!nullable.size)
|
|
16
|
+
continue;
|
|
17
|
+
for (const item of fn.items) {
|
|
18
|
+
// an effect's body reads the state as the render that ran it saw it, as a callback it starts does
|
|
19
|
+
if (item.kind === 'effect' && !item.core) {
|
|
20
|
+
for (const name of nullable) {
|
|
21
|
+
const statements = item.body.body;
|
|
22
|
+
if (!needsSnapshot(fn, name, statements))
|
|
23
|
+
continue;
|
|
24
|
+
const local = snapshotName(fn, name, statements);
|
|
25
|
+
replaceReads(fn, name, local, statements);
|
|
26
|
+
statements.unshift(snapshotDecl(fn, name, local));
|
|
27
|
+
}
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (item.kind !== 'block')
|
|
31
|
+
continue;
|
|
32
|
+
for (const name of nullable) {
|
|
33
|
+
const local = snapshotName(fn, name, item.statements);
|
|
34
|
+
if (!needsSnapshot(fn, name, item.statements))
|
|
35
|
+
continue;
|
|
36
|
+
replaceReads(fn, name, local, item.statements);
|
|
37
|
+
item.statements.unshift(snapshotDecl(fn, name, local));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (fn.type === 'component') {
|
|
41
|
+
visit(fn.template, (locals) => {
|
|
42
|
+
for (const name of nullable) {
|
|
43
|
+
const local = snapshotName(fn, name, locals);
|
|
44
|
+
if (!needsSnapshot(fn, name, locals))
|
|
45
|
+
continue;
|
|
46
|
+
replaceReads(fn, name, local, locals);
|
|
47
|
+
locals.unshift(snapshotDecl(fn, name, local));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** State that may hold null or undefined: no initial value, a null one, or a type that says so. */
|
|
54
|
+
function nullableState(items) {
|
|
55
|
+
const out = new Set();
|
|
56
|
+
for (const item of items) {
|
|
57
|
+
if (item.kind !== 'state')
|
|
58
|
+
continue;
|
|
59
|
+
const init = item.init;
|
|
60
|
+
const emptyInit = !init || t.isNullLiteral(init) || t.isIdentifier(init, { name: 'undefined' });
|
|
61
|
+
const typed = !!item.type && t.isTSUnionType(item.type) && item.type.types.some((m) => t.isTSNullKeyword(m) || t.isTSUndefinedKeyword(m));
|
|
62
|
+
if (emptyInit || typed)
|
|
63
|
+
out.add(item.name);
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** The `locals` of every list in a template (a list's per-row values), deepest last. */
|
|
68
|
+
function visit(nodes, each) {
|
|
69
|
+
for (const n of Array.isArray(nodes) ? nodes : [nodes]) {
|
|
70
|
+
if (n.type === 'for' && n.locals.length)
|
|
71
|
+
each(n.locals);
|
|
72
|
+
if (n.type === 'if')
|
|
73
|
+
for (const b of n.branches)
|
|
74
|
+
visit(b.children, each);
|
|
75
|
+
else if (n.type === 'slot')
|
|
76
|
+
visit(n.fallback, each);
|
|
77
|
+
else if ('children' in n)
|
|
78
|
+
visit(n.children, each);
|
|
79
|
+
if (n.type === 'element')
|
|
80
|
+
for (const a of n.attrs)
|
|
81
|
+
if (a.kind === 'slotProp')
|
|
82
|
+
visit(a.children, each);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Reads of the binding `name` under `roots`, each with whether a function lies between the root and the read. */
|
|
86
|
+
function readsOf(fn, name, roots) {
|
|
87
|
+
const out = [];
|
|
88
|
+
roots.forEach((root, index) => {
|
|
89
|
+
const walk = (n, parent, nested) => {
|
|
90
|
+
if (t.isIdentifier(n) && fn.refs.get(n) === name) {
|
|
91
|
+
const written = !!parent && ((t.isAssignmentExpression(parent) && parent.left === n) || t.isUpdateExpression(parent));
|
|
92
|
+
out.push({ node: n, nested, written, root: index });
|
|
93
|
+
}
|
|
94
|
+
const inner = nested || t.isFunction(n);
|
|
95
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? []) {
|
|
96
|
+
const value = Reflect.get(n, key);
|
|
97
|
+
for (const c of Array.isArray(value) ? value : [value])
|
|
98
|
+
if (t.isNode(c))
|
|
99
|
+
walk(c, n, inner);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
walk(root, null, false);
|
|
103
|
+
});
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/** A test on the state is lost where it is read again: inside a callback, or in a later statement after a const. */
|
|
107
|
+
function needsSnapshot(fn, name, roots) {
|
|
108
|
+
const reads = readsOf(fn, name, roots);
|
|
109
|
+
if (reads.length < 2 || reads.some((r) => r.written))
|
|
110
|
+
return false;
|
|
111
|
+
if (reads.some((r) => r.nested))
|
|
112
|
+
return true;
|
|
113
|
+
return new Set(reads.map((r) => r.root)).size > 1;
|
|
114
|
+
}
|
|
115
|
+
/** A free name for the snapshot (`sortValue`). */
|
|
116
|
+
function snapshotName(fn, name, roots) {
|
|
117
|
+
const taken = new Set([...fn.bindings.keys()]);
|
|
118
|
+
for (const root of roots) {
|
|
119
|
+
t.traverseFast(root, (n) => {
|
|
120
|
+
if (t.isIdentifier(n))
|
|
121
|
+
taken.add(n.name);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
let local = `${name}Value`;
|
|
125
|
+
for (let i = 2; taken.has(local); i++)
|
|
126
|
+
local = `${name}Value${i}`;
|
|
127
|
+
return local;
|
|
128
|
+
}
|
|
129
|
+
function replaceReads(fn, name, local, roots) {
|
|
130
|
+
for (const r of readsOf(fn, name, roots)) {
|
|
131
|
+
fn.refs.delete(r.node);
|
|
132
|
+
r.node.name = local;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** `const sortValue = sort`, its read linked to the state so each target reads the state its own way. */
|
|
136
|
+
function snapshotDecl(fn, name, local) {
|
|
137
|
+
const read = t.identifier(name);
|
|
138
|
+
fn.refs.set(read, name);
|
|
139
|
+
return t.variableDeclaration('const', [t.variableDeclarator(t.identifier(local), read)]);
|
|
140
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* CSS properties React writes as bare numbers (no `px`), from react-dom's isUnitlessNumber list. Every other numeric
|
|
4
|
+
* style value gets `px` appended by React, which Vue and Svelte do not do, so the targets append it themselves.
|
|
5
|
+
*/
|
|
6
|
+
export declare const UNITLESS: Set<string>;
|
|
7
|
+
export declare function isUnitless(prop: string): boolean;
|
|
8
|
+
/** `backgroundColor` → `background-color`; `WebkitMask` → `-webkit-mask`; custom properties unchanged. */
|
|
9
|
+
export declare function kebabCase(prop: string): string;
|
|
10
|
+
/** The key of a style object property, when it is static. */
|
|
11
|
+
export declare function styleKey(prop: t.ObjectProperty): string | null;
|
|
12
|
+
/** A numeric literal (or -number) value, when the expression is one. */
|
|
13
|
+
export declare function numericLiteral(e: t.Node): number | null;
|
|
14
|
+
/** Whether an expression can only be a string (so it needs no px handling); a choice may also give nothing. */
|
|
15
|
+
export declare function isStringy(e: t.Node): boolean;
|
|
16
|
+
/** React's rule for one numeric style value: `px` unless unitless or zero. */
|
|
17
|
+
export declare function reactStyleValue(prop: string, value: number): string | number;
|
|
18
|
+
/** The unitless list as source, for the run-time style helpers emitted into components that need them. */
|
|
19
|
+
export declare function unitlessSource(): string;
|
package/dist/ir/style.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* CSS properties React writes as bare numbers (no `px`), from react-dom's isUnitlessNumber list. Every other numeric
|
|
4
|
+
* style value gets `px` appended by React, which Vue and Svelte do not do, so the targets append it themselves.
|
|
5
|
+
*/
|
|
6
|
+
export const UNITLESS = new Set([
|
|
7
|
+
'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'boxFlex', 'boxFlexGroup',
|
|
8
|
+
'boxOrdinalGroup', 'columnCount', 'columns', 'flex', 'flexGrow', 'flexPositive', 'flexShrink', 'flexNegative', 'flexOrder', 'gridArea',
|
|
9
|
+
'gridRow', 'gridRowEnd', 'gridRowSpan', 'gridRowStart', 'gridColumn', 'gridColumnEnd', 'gridColumnSpan', 'gridColumnStart',
|
|
10
|
+
'fontWeight', 'lineClamp', 'lineHeight', 'opacity', 'order', 'orphans', 'scale', 'tabSize', 'widows', 'zIndex', 'zoom',
|
|
11
|
+
'fillOpacity', 'floodOpacity', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth',
|
|
12
|
+
'WebkitLineClamp', 'MozAnimationIterationCount', 'msFlex', 'msFlexGrow', 'msFlexShrink', 'msZoom', 'WebkitFlex', 'WebkitFlexGrow',
|
|
13
|
+
'WebkitFlexShrink', 'WebkitBoxFlex', 'WebkitColumnCount', 'WebkitOrder',
|
|
14
|
+
]);
|
|
15
|
+
export function isUnitless(prop) {
|
|
16
|
+
return prop.startsWith('--') || UNITLESS.has(prop);
|
|
17
|
+
}
|
|
18
|
+
/** `backgroundColor` → `background-color`; `WebkitMask` → `-webkit-mask`; custom properties unchanged. */
|
|
19
|
+
export function kebabCase(prop) {
|
|
20
|
+
if (prop.startsWith('--'))
|
|
21
|
+
return prop;
|
|
22
|
+
const k = prop.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
23
|
+
return /^(webkit|moz|ms|o)-/.test(k) ? `-${k}` : k;
|
|
24
|
+
}
|
|
25
|
+
/** The key of a style object property, when it is static. */
|
|
26
|
+
export function styleKey(prop) {
|
|
27
|
+
if (prop.computed) {
|
|
28
|
+
const key = prop.key;
|
|
29
|
+
if (t.isStringLiteral(key))
|
|
30
|
+
return key.value;
|
|
31
|
+
if (t.isTSAsExpression(key) && t.isStringLiteral(key.expression))
|
|
32
|
+
return key.expression.value;
|
|
33
|
+
if (t.isTemplateLiteral(key) && key.expressions.length === 0)
|
|
34
|
+
return key.quasis[0]?.value.cooked ?? null;
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (t.isIdentifier(prop.key))
|
|
38
|
+
return prop.key.name;
|
|
39
|
+
if (t.isStringLiteral(prop.key))
|
|
40
|
+
return prop.key.value;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** A numeric literal (or -number) value, when the expression is one. */
|
|
44
|
+
export function numericLiteral(e) {
|
|
45
|
+
if (t.isNumericLiteral(e))
|
|
46
|
+
return e.value;
|
|
47
|
+
if (t.isUnaryExpression(e) && e.operator === '-' && t.isNumericLiteral(e.argument))
|
|
48
|
+
return -e.argument.value;
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** Whether an expression can only be a string (so it needs no px handling); a choice may also give nothing. */
|
|
52
|
+
export function isStringy(e) {
|
|
53
|
+
if (t.isStringLiteral(e) || t.isTemplateLiteral(e))
|
|
54
|
+
return true;
|
|
55
|
+
if (t.isBinaryExpression(e) && e.operator === '+')
|
|
56
|
+
return isStringy(e.left) || isStringy(e.right);
|
|
57
|
+
// `turn > 0 ? 'hidden' : undefined`: a string or no value, never a number
|
|
58
|
+
const nothing = (x) => t.isNullLiteral(x) || t.isIdentifier(x, { name: 'undefined' });
|
|
59
|
+
if (t.isConditionalExpression(e))
|
|
60
|
+
return (isStringy(e.consequent) || nothing(e.consequent)) && (isStringy(e.alternate) || nothing(e.alternate)) && !(nothing(e.consequent) && nothing(e.alternate));
|
|
61
|
+
if (t.isLogicalExpression(e))
|
|
62
|
+
return isStringy(e.right) && (e.operator !== '&&' ? isStringy(e.left) : true);
|
|
63
|
+
if (t.isCallExpression(e) && t.isMemberExpression(e.callee) && t.isIdentifier(e.callee.property) && /^(toFixed|join|toString|trim|replace|toUpperCase|toLowerCase|padStart|padEnd|slice)$/.test(e.callee.property.name))
|
|
64
|
+
return true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/** React's rule for one numeric style value: `px` unless unitless or zero. */
|
|
68
|
+
export function reactStyleValue(prop, value) {
|
|
69
|
+
if (isUnitless(prop) || value === 0)
|
|
70
|
+
return value;
|
|
71
|
+
return `${value}px`;
|
|
72
|
+
}
|
|
73
|
+
/** The unitless list as source, for the run-time style helpers emitted into components that need them. */
|
|
74
|
+
export function unitlessSource() {
|
|
75
|
+
return `const UNITLESS = new Set('${[...UNITLESS].join(' ')}'.split(' '));`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { type Project } from '../analyzer/deps.js';
|
|
3
|
+
import type { ModuleIR } from './model.js';
|
|
4
|
+
export interface TypeMember {
|
|
5
|
+
type: t.TSType | null;
|
|
6
|
+
optional: boolean;
|
|
7
|
+
/** the file that declares the member (its type's names resolve there) */
|
|
8
|
+
file: string;
|
|
9
|
+
}
|
|
10
|
+
export type Members = Map<string, TypeMember>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a props type to its members across the compiled files: local and imported interfaces (with their
|
|
13
|
+
* `extends`), type aliases, intersections, object literals and the Omit / Pick / Partial / Required utilities, with
|
|
14
|
+
* keys given as string literals or as `(typeof KEYS)[number]` over a const array. Returns null when any part cannot be
|
|
15
|
+
* seen into, so callers keep the type as it was.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TypeResolver {
|
|
18
|
+
private readonly modules;
|
|
19
|
+
private readonly project;
|
|
20
|
+
/** a file being lowered (not in `modules` yet): its imports, by local name (see membersWhileLowering) */
|
|
21
|
+
private lowering;
|
|
22
|
+
constructor(modules: Map<string, ModuleIR>, project: Project);
|
|
23
|
+
/**
|
|
24
|
+
* The members of a type a file being lowered names but does not declare: the file's own names resolve through its
|
|
25
|
+
* imports (it is not in `modules` yet); everything else resolves as `members` does. Null when any part cannot be
|
|
26
|
+
* seen into (a type the file itself declares among them included).
|
|
27
|
+
*/
|
|
28
|
+
membersWhileLowering(type: t.TSType, file: string, imports: ReadonlyMap<string, {
|
|
29
|
+
file: string;
|
|
30
|
+
name: string;
|
|
31
|
+
}>): Members | null;
|
|
32
|
+
members(type: t.TSType, file: string, depth?: number): Members | null;
|
|
33
|
+
/** Whether a props type extends React's HTML attributes somewhere (the component forwards DOM attributes). */
|
|
34
|
+
extendsHtml(type: t.TSType, file: string, depth?: number): boolean;
|
|
35
|
+
/** Whether a name a file exports (or imports and re-exports) is only a type: it must be imported with `import type`. */
|
|
36
|
+
isTypeOnly(name: string, file: string): boolean;
|
|
37
|
+
/** The string keys of `'a' | 'b'`, `keyof typeof X` or `(typeof X)[number]` over a const array of strings. */
|
|
38
|
+
private keys;
|
|
39
|
+
private constInit;
|
|
40
|
+
private importOf;
|
|
41
|
+
private declaration;
|
|
42
|
+
}
|