@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
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import prettier from 'prettier';
|
|
5
|
+
import { TARGETS } from './types.js';
|
|
6
|
+
import { isAliased, makeProject, reactTypesMajor, resolveLocal } from './analyzer/deps.js';
|
|
7
|
+
import { parseSource } from './analyzer/parse.js';
|
|
8
|
+
import { lowerModule, moduleDiagnostics } from './ir/lower.js';
|
|
9
|
+
import { liveHookArgs } from './ir/live-args.js';
|
|
10
|
+
import { emptyLayout, isExportedComponent, layoutFor } from './targets/shared/layout.js';
|
|
11
|
+
import { emitVue } from './targets/vue/emit.js';
|
|
12
|
+
import { emitSvelte } from './targets/svelte/emit.js';
|
|
13
|
+
import { VUE_SLOT_FILE, vueSlotFiles } from './targets/vue/slot.js';
|
|
14
|
+
import { MOTION_HELPER_FILE, motionHelperFiles } from './targets/svelte/motion.js';
|
|
15
|
+
// M2: the Svelte layout and drag actions, once per conversion that uses layout, layoutId or drag
|
|
16
|
+
import { LAYOUT_HELPER_FILE, layoutHelperFiles } from './targets/svelte/motion-layout.js';
|
|
17
|
+
import { VUE_LAYOUT_FILE, vueLayoutFiles } from './targets/vue/motion-layout.js';
|
|
18
|
+
import { MARKUP_MODULE_FILE, MARKUP_VIEW_FILE, markupHelperFiles } from './targets/svelte/markup-data/helper.js';
|
|
19
|
+
import { emitAngular } from './targets/angular/emit.js';
|
|
20
|
+
import { planBanks } from './targets/angular/bank/plan.js';
|
|
21
|
+
import { emitReactNative } from './targets/react-native/emit.js';
|
|
22
|
+
import { scoreFidelity } from './targets/react-native/fidelity.js';
|
|
23
|
+
import { styleInlinable, validateAngular, validateFiles } from './validate.js';
|
|
24
|
+
import { typecheckWeb } from './typecheck/index.js';
|
|
25
|
+
import { useProjectLib } from './typecheck/host.js';
|
|
26
|
+
import { annotateParams, assertReactEventFields } from './ir/annotate.js';
|
|
27
|
+
import { resolveFalsyRenders } from './ir/falsy.js';
|
|
28
|
+
import { markMarkupValues, pureModuleFunctions } from './ir/markup-values.js';
|
|
29
|
+
import { settleSnippetHelpers, useSnippetHelpers } from './ir/helper-snippets.js';
|
|
30
|
+
import { foldForwardingRefs } from './ir/forward-refs.js';
|
|
31
|
+
import { snapshotNullableState } from './ir/snapshots.js';
|
|
32
|
+
import { inlineLatestRefs } from './ir/latest-refs.js';
|
|
33
|
+
import { settleEffectReturns } from './ir/effect-returns.js';
|
|
34
|
+
import { slotAsChild } from './ir/as-child.js';
|
|
35
|
+
import { claimRadix, markRadix } from './ir/radix.js';
|
|
36
|
+
import { vueRadix } from './targets/vue/radix/index.js';
|
|
37
|
+
import { svelteRadix } from './targets/svelte/radix/index.js';
|
|
38
|
+
// M3 (headless Radix cores): the files of the Radix packages morph writes itself, once per conversion that uses one
|
|
39
|
+
import { SVELTE_CORES_FILE, svelteCoreFiles } from './targets/svelte/radix/index.js';
|
|
40
|
+
import { angularCoreFiles } from './targets/angular/radix/cores/index.js';
|
|
41
|
+
// R3 (Radix on Angular): radix-ng's map, and the IR step that prepares its parts before Angular emits
|
|
42
|
+
import { angularRadix, prepareAngularRadix } from './targets/angular/radix/index.js';
|
|
43
|
+
import { linkImportedCompounds } from './ir/compounds.js';
|
|
44
|
+
import { reportForeignComponents } from './targets/shared/foreign.js';
|
|
45
|
+
import { stubReactLibraries } from './targets/shared/react-libs.js';
|
|
46
|
+
import { sparesUnusedComponents } from './targets/shared/unused.js';
|
|
47
|
+
import { contextLookup } from './targets/shared/context.js';
|
|
48
|
+
import { TypeResolver } from './ir/types.js';
|
|
49
|
+
import { TypeOracle } from './ir/oracle.js';
|
|
50
|
+
import { readSourceFile, toPosix } from './utils/fs-safe.js';
|
|
51
|
+
import { MorphError, errorMessage } from './utils/errors.js';
|
|
52
|
+
import { buildAnalysis } from './analyzer/manifest.js';
|
|
53
|
+
import { bridgeResult, planBridge } from './bridge/index.js';
|
|
54
|
+
import { carriedFontFiles, prepareGoogleFonts } from './fonts/index.js';
|
|
55
|
+
// M6 (--extract-ui): the entry's reads of the app sliced into props before anything is lowered
|
|
56
|
+
import { extractUi } from './ir/extract-ui.js';
|
|
57
|
+
/** The targets that map Radix primitives to a library of their own (ir/radix); any other refuses every Radix import. */
|
|
58
|
+
const RADIX_MAPS = { vue: vueRadix, svelte: svelteRadix, angular: angularRadix };
|
|
59
|
+
/** The most files one entry may pull in through local imports. */
|
|
60
|
+
const MAX_GRAPH = 400;
|
|
61
|
+
/** Follows local imports from the entry; the result is in dependency order (dependencies first). */
|
|
62
|
+
export function buildGraph(entry, project) {
|
|
63
|
+
const diagnostics = [];
|
|
64
|
+
const seen = new Map();
|
|
65
|
+
const order = [];
|
|
66
|
+
const visiting = new Set();
|
|
67
|
+
let tooLarge = false;
|
|
68
|
+
const visit = (file) => {
|
|
69
|
+
if (seen.has(file) || visiting.has(file))
|
|
70
|
+
return;
|
|
71
|
+
const rel = toPosix(relative(project.root, file));
|
|
72
|
+
if (seen.size >= MAX_GRAPH) {
|
|
73
|
+
if (!tooLarge)
|
|
74
|
+
diagnostics.push({ code: 'graph-too-large', severity: 'error', message: `${toPosix(relative(project.root, entry))} pulls in more than ${MAX_GRAPH} local files; the rest are not converted.`, file: rel });
|
|
75
|
+
tooLarge = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
visiting.add(file);
|
|
79
|
+
// a file that cannot be read or parsed (too large, not code) is a located error; the files that import it convert
|
|
80
|
+
// without it
|
|
81
|
+
let code;
|
|
82
|
+
let ast = null;
|
|
83
|
+
try {
|
|
84
|
+
code = readSourceFile(project.root, file);
|
|
85
|
+
if (!file.endsWith('.css') && !file.endsWith('.json'))
|
|
86
|
+
ast = parseSource(code, file);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
visiting.delete(file);
|
|
90
|
+
if (!(error instanceof MorphError))
|
|
91
|
+
throw error;
|
|
92
|
+
diagnostics.push({ code: error.code, severity: 'error', message: errorMessage(error), file: rel });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const node = { file, rel, code, deps: [], css: file.endsWith('.css'), ...(file.endsWith('.json') ? { data: true } : {}) };
|
|
96
|
+
if (ast) {
|
|
97
|
+
const sources = [];
|
|
98
|
+
for (const stmt of ast.program.body) {
|
|
99
|
+
const source = t.isImportDeclaration(stmt) || t.isExportAllDeclaration(stmt) || (t.isExportNamedDeclaration(stmt) && stmt.source) ? stmt.source?.value : undefined;
|
|
100
|
+
if (source)
|
|
101
|
+
sources.push(source);
|
|
102
|
+
}
|
|
103
|
+
// import('./designs/moon-cat') with a literal path: the file is part of the output too (a lazy loader map)
|
|
104
|
+
t.traverseFast(ast.program, (n) => {
|
|
105
|
+
if (t.isCallExpression(n) && t.isImport(n.callee) && t.isStringLiteral(n.arguments[0]))
|
|
106
|
+
sources.push(n.arguments[0].value);
|
|
107
|
+
// a type named inline: `import('./types').Size`
|
|
108
|
+
if (t.isTSImportType(n) && t.isStringLiteral(n.argument))
|
|
109
|
+
sources.push(n.argument.value);
|
|
110
|
+
});
|
|
111
|
+
for (const source of sources) {
|
|
112
|
+
const resolved = resolveLocal(file, source, project);
|
|
113
|
+
if (resolved) {
|
|
114
|
+
node.deps.push(resolved);
|
|
115
|
+
visit(resolved);
|
|
116
|
+
}
|
|
117
|
+
else if (source.startsWith('.') || isAliased(source, project)) {
|
|
118
|
+
diagnostics.push({ code: 'unresolved-import', severity: 'error', message: `Could not resolve ${source}.`, file: rel });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
visiting.delete(file);
|
|
123
|
+
seen.set(file, node);
|
|
124
|
+
order.push(node);
|
|
125
|
+
};
|
|
126
|
+
visit(resolve(entry));
|
|
127
|
+
return { nodes: order, diagnostics };
|
|
128
|
+
}
|
|
129
|
+
/** The module that declares an export (`name` in `file`), following `export … from` barrels, with its own name there. */
|
|
130
|
+
function declaringModule(modules, file, name, project, depth = 0) {
|
|
131
|
+
const mod = modules.get(file);
|
|
132
|
+
if (!mod || depth > 8)
|
|
133
|
+
return null;
|
|
134
|
+
const own = name === 'default' ? mod.defaultExport !== null : mod.components.some((c) => c.name === name) || mod.aliases.has(name) || mod.exportedNames.has(name);
|
|
135
|
+
if (own)
|
|
136
|
+
return { mod, file, name };
|
|
137
|
+
for (const re of mod.reexports) {
|
|
138
|
+
const source = re.source ? resolveLocal(file, re.source.value, project) : null;
|
|
139
|
+
if (!source)
|
|
140
|
+
continue;
|
|
141
|
+
if (t.isExportAllDeclaration(re)) {
|
|
142
|
+
const found = name === 'default' ? null : declaringModule(modules, source, name, project, depth + 1);
|
|
143
|
+
if (found)
|
|
144
|
+
return found;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
for (const s of re.specifiers) {
|
|
148
|
+
if (!t.isExportSpecifier(s) || (t.isIdentifier(s.exported) ? s.exported.name : s.exported.value) !== name)
|
|
149
|
+
continue;
|
|
150
|
+
return declaringModule(modules, source, s.local.name, project, depth + 1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Each module's pure functions kept as code (ModuleIR.pureFunctions), dependencies first so a call of an imported one
|
|
157
|
+
* counts; returned per file with the pure functions it imports under their local names: the calls a template may read
|
|
158
|
+
* as many times as it needs.
|
|
159
|
+
*/
|
|
160
|
+
function settlePureFunctions(modules, project) {
|
|
161
|
+
const out = new Map();
|
|
162
|
+
for (const [file, mod] of modules) {
|
|
163
|
+
const imported = new Set();
|
|
164
|
+
for (const decl of mod.imports) {
|
|
165
|
+
const source = decl.importKind === 'type' ? null : resolveLocal(file, decl.source.value, project);
|
|
166
|
+
if (!source)
|
|
167
|
+
continue;
|
|
168
|
+
for (const s of decl.specifiers) {
|
|
169
|
+
if (!t.isImportSpecifier(s) || s.importKind === 'type')
|
|
170
|
+
continue;
|
|
171
|
+
const found = declaringModule(modules, source, t.isIdentifier(s.imported) ? s.imported.name : s.imported.value, project);
|
|
172
|
+
if (found?.mod.pureFunctions?.has(found.name))
|
|
173
|
+
imported.add(s.local.name);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
mod.pureFunctions = pureModuleFunctions(mod, imported);
|
|
177
|
+
out.set(file, new Set([...mod.pureFunctions, ...imported]));
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Svelte: each module's render helpers kept as code become snippets with predicates (ir/helper-snippets
|
|
183
|
+
* settleSnippetHelpers), dependencies first; then each module's components use them, its own and the ones it imports
|
|
184
|
+
* straight from the declaring file, which it then imports the predicates of. Every other read of one is reported.
|
|
185
|
+
*/
|
|
186
|
+
function snippetHelpers(modules, project) {
|
|
187
|
+
for (const mod of modules.values())
|
|
188
|
+
settleSnippetHelpers(mod);
|
|
189
|
+
const out = [];
|
|
190
|
+
for (const [file, mod] of modules) {
|
|
191
|
+
const uses = new Map();
|
|
192
|
+
for (const [name, s] of mod.snippetHelpers?.shows ?? [])
|
|
193
|
+
uses.set(name, { shows: s.name, arity: s.arity });
|
|
194
|
+
const taken = new Set([...mod.moduleJsx.moduleNames, ...mod.imports.flatMap((d) => d.specifiers.map((s) => s.local.name))]);
|
|
195
|
+
const from = new Map();
|
|
196
|
+
for (const decl of mod.imports) {
|
|
197
|
+
const source = decl.importKind === 'type' ? null : resolveLocal(file, decl.source.value, project);
|
|
198
|
+
if (!source)
|
|
199
|
+
continue;
|
|
200
|
+
for (const s of decl.specifiers) {
|
|
201
|
+
if (!t.isImportSpecifier(s) || s.importKind === 'type')
|
|
202
|
+
continue;
|
|
203
|
+
const found = declaringModule(modules, source, t.isIdentifier(s.imported) ? s.imported.name : s.imported.value, project);
|
|
204
|
+
// a helper re-exported through another file: that file exports no predicate
|
|
205
|
+
const shows = found && found.file === source ? found.mod.snippetHelpers?.shows.get(found.name) : undefined;
|
|
206
|
+
if (!shows)
|
|
207
|
+
continue;
|
|
208
|
+
let local = shows.name;
|
|
209
|
+
for (let i = 2; taken.has(local); i++)
|
|
210
|
+
local = `${shows.name}${i}`;
|
|
211
|
+
taken.add(local);
|
|
212
|
+
uses.set(s.local.name, { shows: local, arity: shows.arity });
|
|
213
|
+
from.set(s.local.name, { decl, imported: shows.name, local });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const r = useSnippetHelpers(mod, uses);
|
|
217
|
+
for (const name of r.used) {
|
|
218
|
+
const f = from.get(name);
|
|
219
|
+
if (f && !f.decl.specifiers.some((sp) => sp.local.name === f.local))
|
|
220
|
+
f.decl.specifiers.push(t.importSpecifier(t.identifier(f.local), t.identifier(f.imported)));
|
|
221
|
+
}
|
|
222
|
+
for (const l of r.leftover) {
|
|
223
|
+
out.push({
|
|
224
|
+
code: 'module-jsx',
|
|
225
|
+
severity: 'error',
|
|
226
|
+
message: `${l.comp} reads the render helper ${l.name} outside markup (in script code, an element's attribute or an argument): Svelte declares it as a snippet, which markup renders or passes as a component's prop but no function returns as a value, so this read is not converted.`,
|
|
227
|
+
file: toPosix(relative(project.root, mod.file)),
|
|
228
|
+
target: 'svelte',
|
|
229
|
+
...(l.line ? { line: l.line } : {}),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/** Lowers every module of a graph in dependency order, so each sees the hooks it imports. */
|
|
236
|
+
export function lowerGraph(nodes, project, target) {
|
|
237
|
+
const modules = new Map();
|
|
238
|
+
const signatures = new Map();
|
|
239
|
+
// VS6: props types declared in files already lowered (lowerModule's heritageMembers)
|
|
240
|
+
const heritageTypes = new TypeResolver(modules, project);
|
|
241
|
+
for (const node of nodes) {
|
|
242
|
+
if (node.css || node.data)
|
|
243
|
+
continue;
|
|
244
|
+
const importsByLocal = new Map();
|
|
245
|
+
const ast = parseSource(node.code, node.file);
|
|
246
|
+
for (const stmt of ast.program.body) {
|
|
247
|
+
if (!t.isImportDeclaration(stmt))
|
|
248
|
+
continue;
|
|
249
|
+
const resolved = resolveLocal(node.file, stmt.source.value, project);
|
|
250
|
+
if (!resolved)
|
|
251
|
+
continue;
|
|
252
|
+
for (const s of stmt.specifiers) {
|
|
253
|
+
const name = t.isImportSpecifier(s) ? (t.isIdentifier(s.imported) ? s.imported.name : s.imported.value) : 'default';
|
|
254
|
+
importsByLocal.set(s.local.name, { file: resolved, name });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const mod = lowerModule(node.code, {
|
|
258
|
+
file: node.file,
|
|
259
|
+
importedHook: (local) => {
|
|
260
|
+
const imp = importsByLocal.get(local);
|
|
261
|
+
return imp ? (signatures.get(`${imp.file}#${imp.name}`) ?? null) : null;
|
|
262
|
+
},
|
|
263
|
+
// VS6: a props type imported from a file lowered before this one (the graph lists dependencies first)
|
|
264
|
+
heritageMembers: (type) => heritageTypes.membersWhileLowering(type, node.file, importsByLocal),
|
|
265
|
+
// VS6: on Svelte a markup prop that code reads too is a snippet (a value that code can test)
|
|
266
|
+
...(target === 'svelte' ? { heritageNodesReadByCode: true } : {}),
|
|
267
|
+
// M4: Vue and Svelte draw a block's one read value of markup on its own (ir/lower soleMarkupMember)
|
|
268
|
+
...(target === 'vue' || target === 'svelte' ? { soleMarkupMembers: true } : {}),
|
|
269
|
+
});
|
|
270
|
+
if ((reactTypesMajor(project.root) ?? 0) >= 19)
|
|
271
|
+
mod.reactTypes19 = true;
|
|
272
|
+
// `<Card.Header>` with `Card` imported from a module that declares the compound: the part, imported by name
|
|
273
|
+
linkImportedCompounds(mod, (local) => {
|
|
274
|
+
const imp = importsByLocal.get(local);
|
|
275
|
+
const found = imp ? declaringModule(modules, imp.file, imp.name, project) : null;
|
|
276
|
+
if (!found)
|
|
277
|
+
return null;
|
|
278
|
+
let source = toPosix(relative(dirname(node.file), found.file)).replace(/\.(tsx|ts|jsx|js|mts)$/, '');
|
|
279
|
+
if (!source.startsWith('.'))
|
|
280
|
+
source = `./${source}`;
|
|
281
|
+
return { mod: found.mod, name: found.name, source };
|
|
282
|
+
});
|
|
283
|
+
// arguments stay live: the module's hooks read them where used, and its calls of live hooks pass them so
|
|
284
|
+
const live = liveHookArgs(mod, (local) => {
|
|
285
|
+
const imp = importsByLocal.get(local);
|
|
286
|
+
return imp ? (signatures.get(`${imp.file}#${imp.name}`)?.params ?? null) : null;
|
|
287
|
+
});
|
|
288
|
+
for (const hook of mod.hooks)
|
|
289
|
+
signatures.set(`${node.file}#${hook.name}`, { name: hook.name, returnShape: hook.returnShape, file: node.file, params: live.get(hook.name) ?? [], ...(hook.markupMembers ? { markup: hook.markupMembers } : {}) });
|
|
290
|
+
// hooks re-exported through barrels keep their signature under the barrel's name
|
|
291
|
+
for (const re of mod.reexports) {
|
|
292
|
+
const resolved = re.source ? resolveLocal(node.file, re.source.value, project) : null;
|
|
293
|
+
if (!resolved)
|
|
294
|
+
continue;
|
|
295
|
+
if (t.isExportAllDeclaration(re)) {
|
|
296
|
+
for (const [key, sig] of signatures)
|
|
297
|
+
if (key.startsWith(`${resolved}#`))
|
|
298
|
+
signatures.set(`${node.file}#${key.slice(resolved.length + 1)}`, sig);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
for (const s of re.specifiers) {
|
|
302
|
+
if (!t.isExportSpecifier(s))
|
|
303
|
+
continue;
|
|
304
|
+
const sig = signatures.get(`${resolved}#${s.local.name}`);
|
|
305
|
+
const exported = t.isIdentifier(s.exported) ? s.exported.name : s.exported.value;
|
|
306
|
+
if (sig)
|
|
307
|
+
signatures.set(`${node.file}#${exported}`, sig);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
modules.set(node.file, mod);
|
|
312
|
+
}
|
|
313
|
+
return modules;
|
|
314
|
+
}
|
|
315
|
+
function relDiag(d, root) {
|
|
316
|
+
if (!d.file)
|
|
317
|
+
return d;
|
|
318
|
+
const file = d.file.includes(':') || d.file.startsWith('/') ? toPosix(relative(root, d.file)) : d.file;
|
|
319
|
+
return { ...d, file };
|
|
320
|
+
}
|
|
321
|
+
function dedupe(list) {
|
|
322
|
+
const seen = new Set();
|
|
323
|
+
return list.filter((d) => {
|
|
324
|
+
const key = `${d.code}|${d.severity}|${d.file ?? ''}|${d.line ?? ''}|${d.target ?? ''}|${d.message}`;
|
|
325
|
+
if (seen.has(key))
|
|
326
|
+
return false;
|
|
327
|
+
seen.add(key);
|
|
328
|
+
return true;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function statusOf(diagnostics) {
|
|
332
|
+
if (diagnostics.some((d) => d.severity === 'error'))
|
|
333
|
+
return 'unsupported';
|
|
334
|
+
if (diagnostics.some((d) => d.severity === 'warning'))
|
|
335
|
+
return 'partial';
|
|
336
|
+
return 'clean';
|
|
337
|
+
}
|
|
338
|
+
/** A file's status from its targets' statuses: the worst of them. */
|
|
339
|
+
export function worst(statuses) {
|
|
340
|
+
if (statuses.includes('unsupported'))
|
|
341
|
+
return 'unsupported';
|
|
342
|
+
// bridge mode: a wrapper around the React original is not a conversion, and ranks below any
|
|
343
|
+
if (statuses.includes('bridged'))
|
|
344
|
+
return 'bridged';
|
|
345
|
+
// assisted mode (X6): a model wrote it and it passed every gate; not the compiler's conversion, so below partial
|
|
346
|
+
if (statuses.includes('assisted'))
|
|
347
|
+
return 'assisted';
|
|
348
|
+
if (statuses.includes('partial'))
|
|
349
|
+
return 'partial';
|
|
350
|
+
return 'clean';
|
|
351
|
+
}
|
|
352
|
+
/** A line comment that only disables React hook lint rules: the whole line, or the end of a line of code. */
|
|
353
|
+
const REACT_HOOKS_LINT = /^[ \t]*\/\/ eslint-disable(?:-next-line|-line)? react-hooks\/[\w-]+(?:, ?react-hooks\/[\w-]+)*[ \t]*\r?\n|[ \t]*\/\/ eslint-disable-line react-hooks\/[\w-]+(?:, ?react-hooks\/[\w-]+)*[ \t]*$/gm;
|
|
354
|
+
const PRETTIER_PARSER = { '.vue': 'vue', '.ts': 'typescript', '.tsx': 'typescript' };
|
|
355
|
+
/** Svelte has no Prettier parser built in: format each <script> block as TypeScript, leave the markup as printed. */
|
|
356
|
+
async function formatSvelte(file) {
|
|
357
|
+
let contents = file.contents;
|
|
358
|
+
const blocks = [...contents.matchAll(/(<script[^>]*>)([\s\S]*?)(<\/script>)/g)];
|
|
359
|
+
for (const block of blocks.reverse()) {
|
|
360
|
+
const [whole, open, body, close] = block;
|
|
361
|
+
if (body === undefined || open === undefined || close === undefined || block.index === undefined)
|
|
362
|
+
continue;
|
|
363
|
+
try {
|
|
364
|
+
const formatted = await prettier.format(body, { parser: 'typescript', singleQuote: true, printWidth: 120, trailingComma: 'all' });
|
|
365
|
+
contents = contents.slice(0, block.index) + open + '\n' + formatted + close + contents.slice(block.index + whole.length);
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
// left as printed; svelte/compiler reports the real problem in validateFiles
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return { ...file, contents };
|
|
373
|
+
}
|
|
374
|
+
/** Shared modules are emitted again for every entry that imports them: format each distinct output once. */
|
|
375
|
+
const formatCache = new Map();
|
|
376
|
+
function format(file) {
|
|
377
|
+
const key = `${file.path}\0${file.contents}`;
|
|
378
|
+
let hit = formatCache.get(key);
|
|
379
|
+
if (!hit) {
|
|
380
|
+
hit = formatOnce(file);
|
|
381
|
+
if (formatCache.size > 20000)
|
|
382
|
+
formatCache.clear();
|
|
383
|
+
formatCache.set(key, hit);
|
|
384
|
+
}
|
|
385
|
+
return hit;
|
|
386
|
+
}
|
|
387
|
+
async function formatOnce(file) {
|
|
388
|
+
if (file.path.endsWith('.svelte'))
|
|
389
|
+
return formatSvelte(file);
|
|
390
|
+
const ext = file.path.endsWith('.svelte.ts') ? '.ts' : (file.path.match(/\.[a-z]+$/)?.[0] ?? '');
|
|
391
|
+
const parser = PRETTIER_PARSER[ext];
|
|
392
|
+
if (!parser)
|
|
393
|
+
return file;
|
|
394
|
+
try {
|
|
395
|
+
// (A6) Prettier would format an Angular component's inline template too, and Angular keeps one space of any white
|
|
396
|
+
// space inside a text node: the line breaks it adds around text, in an @if or @for body as well (`@if (x) {\n
|
|
397
|
+
// {{ word() }}\n}`), even with strict white space, put spaces into the DOM's text that React's has not. So each
|
|
398
|
+
// `template:` literal stays as the emitter printed it (one line per child only where no text is beside them, which
|
|
399
|
+
// Angular drops): it is set aside while the file is formatted, its `styles` and code included, and put back.
|
|
400
|
+
const held = [];
|
|
401
|
+
const source = parser === 'typescript' && file.contents.includes('@Component(')
|
|
402
|
+
? file.contents.replace(/template: `((?:\\[\s\S]|[^`\\])*)`/g, (_whole, body) => {
|
|
403
|
+
held.push(body);
|
|
404
|
+
return `template: \`__morphTemplate${held.length - 1}__\``;
|
|
405
|
+
})
|
|
406
|
+
: file.contents;
|
|
407
|
+
let contents = await prettier.format(source, { parser, singleQuote: true, printWidth: 120, trailingComma: 'all', vueIndentScriptAndStyle: false });
|
|
408
|
+
if (held.length)
|
|
409
|
+
contents = contents.replace(/__morphTemplate(\d+)__/g, (_whole, i) => held[Number(i)] ?? '');
|
|
410
|
+
return { ...file, contents };
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
// unformattable output is caught, with the real reason, by the target compiler in validateFiles
|
|
414
|
+
return file;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** Whether a source file other than `except` in the stylesheet's folder imports it. */
|
|
418
|
+
function importedElsewhere(cssFile, except) {
|
|
419
|
+
const dir = dirname(cssFile);
|
|
420
|
+
const name = basename(cssFile);
|
|
421
|
+
let entries;
|
|
422
|
+
try {
|
|
423
|
+
entries = readdirSync(dir);
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
for (const entry of entries) {
|
|
429
|
+
const file = join(dir, entry);
|
|
430
|
+
if (file === except || !/\.(tsx|ts|jsx|js|mjs)$/.test(entry))
|
|
431
|
+
continue;
|
|
432
|
+
try {
|
|
433
|
+
if (readFileSync(file, 'utf8').includes(name))
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* A stylesheet that belongs to one component file (imported by that file alone, here and in its folder, with one
|
|
444
|
+
* exported component that brings it everywhere) moves into that file's `<style>`, when the target's compiler takes it.
|
|
445
|
+
*/
|
|
446
|
+
function foldStyles(nodes, modules, layouts, target) {
|
|
447
|
+
for (const css of nodes) {
|
|
448
|
+
if (!css.css)
|
|
449
|
+
continue;
|
|
450
|
+
const importers = nodes.filter((n) => !n.css && n.deps.includes(css.file));
|
|
451
|
+
const host = importers.length === 1 ? importers[0] : undefined;
|
|
452
|
+
const layout = host ? layouts.get(host.file) : undefined;
|
|
453
|
+
const mod = host ? modules.get(host.file) : undefined;
|
|
454
|
+
const own = layouts.get(css.file);
|
|
455
|
+
if (!host || !layout || !mod || !own || layout.kind !== 'sfc')
|
|
456
|
+
continue;
|
|
457
|
+
if (mod.components.filter((c) => isExportedComponent(mod, c)).length > 1)
|
|
458
|
+
continue;
|
|
459
|
+
if (/@import\b/.test(css.code) || importedElsewhere(css.file, host.file) || !styleInlinable(target, css.code))
|
|
460
|
+
continue;
|
|
461
|
+
layout.styles.push({ file: css.rel, code: css.code });
|
|
462
|
+
layouts.set(css.file, { ...own, kind: 'inlined-style', modulePath: layout.modulePath });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/** Two source files must never write the same output file (a private component named like another file's, say). */
|
|
466
|
+
function separatePaths(layouts) {
|
|
467
|
+
const owner = new Map();
|
|
468
|
+
for (const layout of layouts.values()) {
|
|
469
|
+
if (layout.kind !== 'sfc')
|
|
470
|
+
continue;
|
|
471
|
+
for (const [name, path] of layout.components) {
|
|
472
|
+
let free = path;
|
|
473
|
+
for (let i = 2; owner.has(free) && owner.get(free) !== layout.source; i++)
|
|
474
|
+
free = path.replace(/(\.[a-z]+)$/, `${i}$1`);
|
|
475
|
+
owner.set(free, layout.source);
|
|
476
|
+
if (free === path)
|
|
477
|
+
continue;
|
|
478
|
+
layout.components.set(name, free);
|
|
479
|
+
if (layout.modulePath === path)
|
|
480
|
+
layout.modulePath = free;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/** Emits one target for an already lowered graph. */
|
|
485
|
+
export async function emitTarget(target, nodes, project, validate, typecheck = true, signal) {
|
|
486
|
+
const modules = lowerGraph(nodes, project, target);
|
|
487
|
+
// asks TypeScript on the React source; the program is built on the first question
|
|
488
|
+
const oracle = new TypeOracle(project, nodes.filter((n) => !n.css).map((n) => n.file));
|
|
489
|
+
// an effect written as an expression returns its value only when React's types say it may be a cleanup function
|
|
490
|
+
for (const mod of modules.values())
|
|
491
|
+
settleEffectReturns(mod, oracle);
|
|
492
|
+
// Radix's Slot picked by `asChild` (`asChild ? Slot.Root : 'button'`): the element holds the test (ir/as-child)
|
|
493
|
+
if (target !== 'react-native')
|
|
494
|
+
for (const mod of modules.values())
|
|
495
|
+
slotAsChild(mod);
|
|
496
|
+
// Radix primitives, recognised by their import; a target with a map of them converts each part (ir/radix)
|
|
497
|
+
const radixMap = RADIX_MAPS[target];
|
|
498
|
+
const radixDiagnostics = [];
|
|
499
|
+
if (target !== 'react-native') {
|
|
500
|
+
for (const mod of modules.values()) {
|
|
501
|
+
markRadix(mod);
|
|
502
|
+
if (radixMap)
|
|
503
|
+
claimRadix(mod, radixMap, radixDiagnostics, target);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// R3: each claimed part becomes the element Radix renders, for every module before any is emitted (targets/angular/radix)
|
|
507
|
+
if (target === 'angular')
|
|
508
|
+
for (const mod of modules.values())
|
|
509
|
+
prepareAngularRadix(mod, angularRadix.packages, radixDiagnostics);
|
|
510
|
+
// a ref that only mirrors a prop for callbacks (`latest.current = onChange`): Vue, Svelte and Angular callbacks read the
|
|
511
|
+
// prop (or the live argument) as it is now
|
|
512
|
+
if (target !== 'react-native')
|
|
513
|
+
for (const mod of modules.values())
|
|
514
|
+
inlineLatestRefs(mod);
|
|
515
|
+
const diagnostics = [...radixDiagnostics];
|
|
516
|
+
for (const mod of modules.values())
|
|
517
|
+
diagnostics.push(...moduleDiagnostics(mod));
|
|
518
|
+
// `{count && <Badge/>}` renders a falsy number in React: each web target gets the branch that renders it
|
|
519
|
+
if (target !== 'react-native')
|
|
520
|
+
for (const mod of modules.values())
|
|
521
|
+
resolveFalsyRenders(mod, oracle);
|
|
522
|
+
// markup held in a module's data (ModuleIR.markupValues) is printed by Vue and Svelte; Angular holds it in a template
|
|
523
|
+
// bank where every receiver renders it as markup, and refuses it, located, otherwise (targets/angular/bank/plan)
|
|
524
|
+
if (target === 'angular')
|
|
525
|
+
planBanks(modules, project, oracle, diagnostics);
|
|
526
|
+
if (target === 'react-native') {
|
|
527
|
+
for (const mod of modules.values()) {
|
|
528
|
+
if (!mod.markupValues?.length)
|
|
529
|
+
continue;
|
|
530
|
+
const names = mod.markupValues.map((v) => v.name).join(', ');
|
|
531
|
+
const message = `The file's data holds markup (${names}), which React Native output does not print yet: not converted; each value is declared null.`;
|
|
532
|
+
diagnostics.push({ code: 'module-jsx', severity: 'error', message, file: toPosix(relative(project.root, mod.file)), target });
|
|
533
|
+
// the data still names each value: each is declared, empty, so the file compiles and renders nothing there
|
|
534
|
+
const placeholders = mod.markupValues.map((v) => {
|
|
535
|
+
const decl = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(v.name), t.nullLiteral())]);
|
|
536
|
+
t.addComment(decl, 'trailing', ' markup not converted (see the module-jsx error)', true);
|
|
537
|
+
return decl;
|
|
538
|
+
});
|
|
539
|
+
mod.moduleBody.unshift(...placeholders);
|
|
540
|
+
mod.markupValues = [];
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
// markup a prop's data holds in a component's markup (ComponentIR.markupValues): Vue and Svelte print it; the Angular
|
|
544
|
+
// emitter prints it as templates of the component where the receiver tells markup apart, and reports it otherwise
|
|
545
|
+
// (targets/angular/markup-values)
|
|
546
|
+
// a value React's types say may be an element (`{tab.icon}`) renders as markup: Vue and Svelte print it (ir/markup-values)
|
|
547
|
+
// Vue also renders as markup what a pure module function kept as code returns (vue/render-fn renderHelperValue),
|
|
548
|
+
// called in the file that declares it or in one that imports it from the conversion
|
|
549
|
+
// Svelte declares them as exported snippets, each with a predicate of whether it renders anything (ir/helper-snippets)
|
|
550
|
+
if (target === 'svelte')
|
|
551
|
+
diagnostics.push(...snippetHelpers(modules, project));
|
|
552
|
+
const pureCalls = target === 'vue' ? settlePureFunctions(modules, project) : new Map();
|
|
553
|
+
if (target === 'vue' || target === 'svelte')
|
|
554
|
+
for (const [file, mod] of modules)
|
|
555
|
+
markMarkupValues(mod, oracle, pureCalls.get(file) ?? new Set());
|
|
556
|
+
// a callback ref that fills an element ref and hands the element to the parent's ref: that element is forwarded
|
|
557
|
+
if (target === 'vue' || target === 'svelte')
|
|
558
|
+
for (const mod of modules.values())
|
|
559
|
+
foldForwardingRefs(mod);
|
|
560
|
+
// state that may be null, tested and read again in a callback: read once into a const, so the test still narrows it
|
|
561
|
+
if (target === 'vue' || target === 'svelte')
|
|
562
|
+
for (const mod of modules.values())
|
|
563
|
+
snapshotNullableState(mod);
|
|
564
|
+
// state read from a store (`useSyncExternalStore(sub, () => dir)`) has the type React's checker gave the read
|
|
565
|
+
for (const mod of modules.values()) {
|
|
566
|
+
for (const fn of [...mod.components, ...mod.hooks]) {
|
|
567
|
+
for (const item of fn.items)
|
|
568
|
+
if (item.kind === 'state' && !item.type && item.typeFrom)
|
|
569
|
+
item.type = oracle.typeOfExpression(mod.file, item.typeFrom.loc);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
// a component from a package morph does not map (`<Swiper>` from a binding it cannot see) never converts
|
|
573
|
+
if (target !== 'react-native')
|
|
574
|
+
for (const mod of modules.values())
|
|
575
|
+
diagnostics.push(...reportForeignComponents(mod, project, target));
|
|
576
|
+
// a React-only library's bindings become placeholders of the same names; a file imported only for values that do
|
|
577
|
+
// not read the library is not refused for it
|
|
578
|
+
if (target !== 'react-native') {
|
|
579
|
+
const entry = nodes[nodes.length - 1]?.file ?? '';
|
|
580
|
+
stubReactLibraries(modules, nodes.map((n) => ({ file: n.file, code: n.code, isCode: !n.css && !n.data })), entry, project, target, diagnostics);
|
|
581
|
+
}
|
|
582
|
+
const layouts = new Map();
|
|
583
|
+
for (const node of nodes) {
|
|
584
|
+
const mod = modules.get(node.file);
|
|
585
|
+
if (node.css || !mod) {
|
|
586
|
+
layouts.set(node.file, emptyLayout(node.file, node.rel, 'copy'));
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
// a provider of a context another file declares is known before any file is emitted
|
|
590
|
+
const contexts = contextLookup(mod, { moduleOf: (f) => modules.get(f) ?? null, sourceFile: node.file, project });
|
|
591
|
+
layouts.set(node.file, layoutFor(mod, node.rel, target, node.file, (name) => contexts(name) !== null));
|
|
592
|
+
}
|
|
593
|
+
if (target === 'vue' || target === 'svelte')
|
|
594
|
+
foldStyles(nodes, modules, layouts, target);
|
|
595
|
+
separatePaths(layouts);
|
|
596
|
+
// a helper file written once per conversion takes its own name unless a file of the output already has it
|
|
597
|
+
const taken = new Set();
|
|
598
|
+
for (const layout of layouts.values()) {
|
|
599
|
+
taken.add(layout.kind === 'copy' ? layout.sourceRel : layout.modulePath);
|
|
600
|
+
for (const path of layout.components.values())
|
|
601
|
+
taken.add(path);
|
|
602
|
+
}
|
|
603
|
+
const helperPath = (name) => {
|
|
604
|
+
let free = name;
|
|
605
|
+
for (let i = 2; taken.has(free); i++)
|
|
606
|
+
free = name.replace(/(\.[a-z]+)$/, `${i}$1`);
|
|
607
|
+
return free;
|
|
608
|
+
};
|
|
609
|
+
const types = new TypeResolver(modules, project);
|
|
610
|
+
let files = [];
|
|
611
|
+
for (const node of nodes) {
|
|
612
|
+
const mod = modules.get(node.file);
|
|
613
|
+
const layout = layouts.get(node.file);
|
|
614
|
+
if (!layout)
|
|
615
|
+
continue;
|
|
616
|
+
if (node.css || !mod) {
|
|
617
|
+
// a JSON file is data the output imports as it is (every web target's bundler and TypeScript read it)
|
|
618
|
+
if (layout.kind !== 'inlined-style')
|
|
619
|
+
files.push({ path: node.rel, contents: node.code, kind: node.data ? 'module' : 'style' });
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
try {
|
|
623
|
+
if (target === 'react-native') {
|
|
624
|
+
files.push(...emitReactNative(mod, node, { project, diagnostics, layouts }));
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
// parameters React typed from their context keep that type once moved into script code
|
|
628
|
+
if (target === 'vue' || target === 'svelte') {
|
|
629
|
+
annotateParams(mod, node.file, oracle);
|
|
630
|
+
assertReactEventFields(mod);
|
|
631
|
+
}
|
|
632
|
+
const ctx = { target, project, sourceFile: node.file, sourceRel: node.rel, layoutOf: (f) => layouts.get(f) ?? null, moduleOf: (f) => modules.get(f) ?? null, diagnostics, types, oracle, helperPath };
|
|
633
|
+
files.push(...(target === 'vue' ? emitVue(mod, layout, ctx) : target === 'svelte' ? emitSvelte(mod, layout, ctx) : emitAngular(mod, layout, ctx)));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
diagnostics.push({ code: 'emit-failed', severity: 'error', message: `The ${target} emitter failed on this file: ${errorMessage(error)}`, file: node.rel, target });
|
|
638
|
+
if (process.env.MORPH_DEBUG && error instanceof Error)
|
|
639
|
+
console.error(error.stack);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
// an error in a declaration of an imported file that nothing the converted file uses reaches does not refuse it
|
|
643
|
+
if (target !== 'react-native') {
|
|
644
|
+
const byName = new Map();
|
|
645
|
+
for (const n of nodes) {
|
|
646
|
+
byName.set(n.rel, n.file);
|
|
647
|
+
byName.set(n.file, n.file);
|
|
648
|
+
}
|
|
649
|
+
sparesUnusedComponents(diagnostics, nodes.map((n) => ({ file: n.file, code: n.code, isCode: !n.css && !n.data })), nodes[nodes.length - 1]?.file ?? '', project, (f) => byName.get(f) ?? null);
|
|
650
|
+
}
|
|
651
|
+
// the Svelte motion action, once for every component of the conversion that animates
|
|
652
|
+
if (target === 'svelte')
|
|
653
|
+
files.push(...motionHelperFiles(diagnostics, helperPath(MOTION_HELPER_FILE)));
|
|
654
|
+
// M2: the Svelte layout and drag actions (motion's animateLayout and drag), once for every component that uses them
|
|
655
|
+
if (target === 'svelte')
|
|
656
|
+
files.push(...layoutHelperFiles(diagnostics, helperPath(LAYOUT_HELPER_FILE)));
|
|
657
|
+
// M2: the Vue layout and drag directives (motion's animateLayout and drag), once for every component that uses them
|
|
658
|
+
if (target === 'vue')
|
|
659
|
+
files.push(...vueLayoutFiles(diagnostics, helperPath(VUE_LAYOUT_FILE)));
|
|
660
|
+
// the Svelte types and renderer of elements held as data, once for every component of the conversion that holds them
|
|
661
|
+
if (target === 'svelte')
|
|
662
|
+
files.push(...markupHelperFiles(diagnostics, helperPath(MARKUP_MODULE_FILE), helperPath(MARKUP_VIEW_FILE)));
|
|
663
|
+
// Radix's Slot for Vue, once for every component of the conversion that renders one
|
|
664
|
+
if (target === 'vue')
|
|
665
|
+
files.push(...vueSlotFiles(diagnostics, helperPath(VUE_SLOT_FILE)));
|
|
666
|
+
// M3: the Svelte and Angular cores of the Radix packages a converted file uses (targets/*/radix/cores)
|
|
667
|
+
if (target === 'svelte')
|
|
668
|
+
files.push(...svelteCoreFiles(diagnostics, helperPath(SVELTE_CORES_FILE)));
|
|
669
|
+
if (target === 'angular')
|
|
670
|
+
files.push(...angularCoreFiles(diagnostics, helperPath));
|
|
671
|
+
// F5: the font module of each next/font call whose files the output carries (src/fonts)
|
|
672
|
+
if (target !== 'react-native')
|
|
673
|
+
files.push(...carriedFontFiles(diagnostics));
|
|
674
|
+
// a lint directive for React's hook rules (`// eslint-disable-next-line react-hooks/exhaustive-deps`) has no rule to
|
|
675
|
+
// silence in Vue or Svelte code
|
|
676
|
+
if (target === 'vue' || target === 'svelte')
|
|
677
|
+
files = files.map((f) => ({ ...f, contents: f.contents.replace(REACT_HOOKS_LINT, '') }));
|
|
678
|
+
files = await Promise.all(files.map(format));
|
|
679
|
+
signal?.throwIfAborted();
|
|
680
|
+
// JSON data is checked as JSON; the target's compiler reads it through the import of the file that uses it
|
|
681
|
+
const isData = (f) => f.path.endsWith('.json');
|
|
682
|
+
const dataProblems = () => files.filter(isData).flatMap((f) => {
|
|
683
|
+
try {
|
|
684
|
+
JSON.parse(f.contents);
|
|
685
|
+
return [];
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
return [{ code: 'validation-failed', severity: 'error', message: `${f.path} is not valid JSON: ${errorMessage(error)}`, file: f.path, target }];
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
// a file already refused for this target is not run through Angular's compiler (seconds per file, and the status is
|
|
692
|
+
// unsupported either way); its result is then not validated
|
|
693
|
+
const refused = target === 'angular' && diagnostics.some((d) => d.severity === 'error' && (d.target === undefined || d.target === target));
|
|
694
|
+
const validation = validate && !refused ? (target === 'angular' ? await validateAngular(files, project.root) : [...validateFiles(files.filter((f) => !isData(f)), target), ...dataProblems()]) : [];
|
|
695
|
+
signal?.throwIfAborted();
|
|
696
|
+
// output its compiler accepts is then type-checked as vue-tsc / svelte-check would (Angular's check is already strict)
|
|
697
|
+
const typed = [];
|
|
698
|
+
if (typecheck && validate && !validation.length && (target === 'vue' || target === 'svelte')) {
|
|
699
|
+
// the check knows the libraries the source project compiles with
|
|
700
|
+
useProjectLib(project.root);
|
|
701
|
+
for (const p of await typecheckWeb(files, target, project.root)) {
|
|
702
|
+
typed.push({ code: 'type-error', severity: 'warning', message: `${p.path}${p.line ? `: line ${p.line}` : ''}: ${p.message.split('\n')[0]}`, file: p.path, target });
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
const all = dedupe([...diagnostics, ...validation, ...typed].map((d) => relDiag({ ...d, target }, project.root)));
|
|
706
|
+
const result = { target, status: statusOf(all), files, diagnostics: all, validated: validate && !refused && validation.length === 0 };
|
|
707
|
+
if (target === 'react-native')
|
|
708
|
+
result.fidelity = scoreFidelity(nodes, modules, all);
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
/** Analyzes and compiles one component file (and the local files it imports) to every requested target. */
|
|
712
|
+
export async function compileFile(file, options = {}) {
|
|
713
|
+
const entry = resolve(file);
|
|
714
|
+
const project = makeProject(entry, options);
|
|
715
|
+
const { nodes, diagnostics: graphDiagnostics } = buildGraph(entry, project);
|
|
716
|
+
const analysis = buildAnalysis(entry, nodes, project, graphDiagnostics);
|
|
717
|
+
const targets = [];
|
|
718
|
+
// the file itself could not be read or parsed: nothing to convert, and the diagnostics say why
|
|
719
|
+
if (!nodes.some((n) => n.file === entry)) {
|
|
720
|
+
for (const target of options.targets ?? TARGETS)
|
|
721
|
+
targets.push({ target, status: 'unsupported', files: [], diagnostics: graphDiagnostics.map((d) => ({ ...d, target })), validated: false });
|
|
722
|
+
return { file: toPosix(relative(project.root, entry)), status: 'unsupported', analysis, targets };
|
|
723
|
+
}
|
|
724
|
+
// X6: next/font/google behind the fonts option only, fetched before any file is emitted (src/fonts/google.ts)
|
|
725
|
+
if (options.fonts)
|
|
726
|
+
await prepareGoogleFonts(nodes.map((n) => ({ file: n.file, code: n.code })), project, options.fonts === true ? {} : options.fonts);
|
|
727
|
+
// M6 (--extract-ui, opt-in): the entry's component sliced from its app (router, store, server) before it is lowered
|
|
728
|
+
const extracted = options.extractUi ? extractUi(entry, nodes, project) : null;
|
|
729
|
+
let bridge;
|
|
730
|
+
for (const target of options.targets ?? TARGETS) {
|
|
731
|
+
options.signal?.throwIfAborted();
|
|
732
|
+
const result = await emitTarget(target, nodes, project, options.validate ?? true, options.typecheck ?? true, options.signal);
|
|
733
|
+
result.diagnostics = dedupe([...graphDiagnostics.map((d) => ({ ...d, target })), ...result.diagnostics]);
|
|
734
|
+
// M6: the slice's warning (or why it did not slice) and its contract file, in every target
|
|
735
|
+
if (extracted) {
|
|
736
|
+
result.diagnostics = dedupe([...extracted.diagnostics.map((d) => ({ ...d, target })), ...result.diagnostics]);
|
|
737
|
+
if (extracted.contract)
|
|
738
|
+
result.files.push(extracted.contract);
|
|
739
|
+
}
|
|
740
|
+
result.status = statusOf(result.diagnostics);
|
|
741
|
+
// bridge mode (opt-in): a refused web target gets a wrapper that mounts the React original (src/bridge)
|
|
742
|
+
if (options.bridge && result.status === 'unsupported' && target !== 'react-native') {
|
|
743
|
+
bridge ??= planBridge(entry, project, analysis);
|
|
744
|
+
targets.push(await bridgeResult(result, bridge, toPosix(relative(project.root, entry)), project, options.validate ?? true, options.typecheck ?? true));
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
targets.push(result);
|
|
748
|
+
}
|
|
749
|
+
return { file: toPosix(relative(project.root, entry)), status: worst(targets.map((r) => r.status)), analysis, targets };
|
|
750
|
+
}
|