@superblocksteam/vite-plugin-file-sync 1.99.99-next.2
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.txt +87 -0
- package/dist/ai-service/app-interface/shell.d.ts +15 -0
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -0
- package/dist/ai-service/app-interface/shell.js +81 -0
- package/dist/ai-service/app-interface/shell.js.map +1 -0
- package/dist/ai-service/artifacts/bolt.d.ts +8 -0
- package/dist/ai-service/artifacts/bolt.d.ts.map +1 -0
- package/dist/ai-service/artifacts/bolt.js +34 -0
- package/dist/ai-service/artifacts/bolt.js.map +1 -0
- package/dist/ai-service/const.d.ts +9 -0
- package/dist/ai-service/const.d.ts.map +1 -0
- package/dist/ai-service/const.js +10 -0
- package/dist/ai-service/const.js.map +1 -0
- package/dist/ai-service/eval/template-renderer.d.ts +13 -0
- package/dist/ai-service/eval/template-renderer.d.ts.map +1 -0
- package/dist/ai-service/eval/template-renderer.js +67 -0
- package/dist/ai-service/eval/template-renderer.js.map +1 -0
- package/dist/ai-service/index.d.ts +21 -0
- package/dist/ai-service/index.d.ts.map +1 -0
- package/dist/ai-service/index.js +153 -0
- package/dist/ai-service/index.js.map +1 -0
- package/dist/ai-service/integrations/const.d.ts +41 -0
- package/dist/ai-service/integrations/const.d.ts.map +1 -0
- package/dist/ai-service/integrations/const.js +76 -0
- package/dist/ai-service/integrations/const.js.map +1 -0
- package/dist/ai-service/integrations/from-prompt-context.d.ts +4 -0
- package/dist/ai-service/integrations/from-prompt-context.d.ts.map +1 -0
- package/dist/ai-service/integrations/from-prompt-context.js +56 -0
- package/dist/ai-service/integrations/from-prompt-context.js.map +1 -0
- package/dist/ai-service/integrations/to-sdk-prompt.d.ts +3 -0
- package/dist/ai-service/integrations/to-sdk-prompt.d.ts.map +1 -0
- package/dist/ai-service/integrations/to-sdk-prompt.js +45 -0
- package/dist/ai-service/integrations/to-sdk-prompt.js.map +1 -0
- package/dist/ai-service/integrations/types.d.ts +31 -0
- package/dist/ai-service/integrations/types.d.ts.map +1 -0
- package/dist/ai-service/integrations/types.js +2 -0
- package/dist/ai-service/integrations/types.js.map +1 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.d.ts +2 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.d.ts.map +1 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.js +386 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-api-draft.js.map +1 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.d.ts +2 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.d.ts.map +1 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.js +219 -0
- package/dist/ai-service/prompts/draft-subprompts/superblocks-layouts-with-grid-examples.js.map +1 -0
- package/dist/ai-service/prompts/generated/index.d.ts +4 -0
- package/dist/ai-service/prompts/generated/index.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/index.js +6 -0
- package/dist/ai-service/prompts/generated/index.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbButtonPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbCheckboxPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbColumnPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbContainerPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbDatePickerPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbDropdownPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbIconPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbImagePropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbInputPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbModalPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbPagePropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbSectionPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbSlideoutPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbSwitchPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbTablePropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.js +6 -0
- package/dist/ai-service/prompts/generated/library-components/SbTextPropsDocs.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/index.d.ts +17 -0
- package/dist/ai-service/prompts/generated/library-components/index.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-components/index.js +19 -0
- package/dist/ai-service/prompts/generated/library-components/index.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/Dim.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-typedefs/Dim.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/Dim.js +6 -0
- package/dist/ai-service/prompts/generated/library-typedefs/Dim.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.d.ts +2 -0
- package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.js +6 -0
- package/dist/ai-service/prompts/generated/library-typedefs/SbEventFlow.js.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/index.d.ts +3 -0
- package/dist/ai-service/prompts/generated/library-typedefs/index.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/library-typedefs/index.js +5 -0
- package/dist/ai-service/prompts/generated/library-typedefs/index.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/index.d.ts +11 -0
- package/dist/ai-service/prompts/generated/subprompts/index.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/index.js +13 -0
- package/dist/ai-service/prompts/generated/subprompts/index.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-api.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-api.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-api.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-api.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-custom-components.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-event-flow.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-layouts.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-page.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-page.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-page.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-page.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-routes.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-state.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-state.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-state.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-state.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/superblocks-theming.js.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/system.d.ts +2 -0
- package/dist/ai-service/prompts/generated/subprompts/system.d.ts.map +1 -0
- package/dist/ai-service/prompts/generated/subprompts/system.js +6 -0
- package/dist/ai-service/prompts/generated/subprompts/system.js.map +1 -0
- package/dist/ai-service/prompts/markdown-loader.d.ts +10 -0
- package/dist/ai-service/prompts/markdown-loader.d.ts.map +1 -0
- package/dist/ai-service/prompts/markdown-loader.js +71 -0
- package/dist/ai-service/prompts/markdown-loader.js.map +1 -0
- package/dist/ai-service/prompts/system.d.ts +2 -0
- package/dist/ai-service/prompts/system.d.ts.map +1 -0
- package/dist/ai-service/prompts/system.js +152 -0
- package/dist/ai-service/prompts/system.js.map +1 -0
- package/dist/ai-service/result-buffer/bolt.d.ts +15 -0
- package/dist/ai-service/result-buffer/bolt.d.ts.map +1 -0
- package/dist/ai-service/result-buffer/bolt.js +73 -0
- package/dist/ai-service/result-buffer/bolt.js.map +1 -0
- package/dist/ai-service/result-buffer/shared.d.ts +13 -0
- package/dist/ai-service/result-buffer/shared.d.ts.map +1 -0
- package/dist/ai-service/result-buffer/shared.js +7 -0
- package/dist/ai-service/result-buffer/shared.js.map +1 -0
- package/dist/ai-service/state-machine/clark-fsm.d.ts +177 -0
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -0
- package/dist/ai-service/state-machine/clark-fsm.js +70 -0
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -0
- package/dist/ai-service/state-machine/fsm.d.ts +42 -0
- package/dist/ai-service/state-machine/fsm.d.ts.map +1 -0
- package/dist/ai-service/state-machine/fsm.js +64 -0
- package/dist/ai-service/state-machine/fsm.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/agent-planning.js +263 -0
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/awaiting-user.js +36 -0
- package/dist/ai-service/state-machine/handlers/awaiting-user.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/idle.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/idle.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/idle.js +24 -0
- package/dist/ai-service/state-machine/handlers/idle.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.js +160 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/play-dead.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/play-dead.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/play-dead.js +11 -0
- package/dist/ai-service/state-machine/handlers/play-dead.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/post-processing.d.ts +3 -0
- package/dist/ai-service/state-machine/handlers/post-processing.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/post-processing.js +85 -0
- package/dist/ai-service/state-machine/handlers/post-processing.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.d.ts +4 -0
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.d.ts.map +1 -0
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.js +40 -0
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.js.map +1 -0
- package/dist/ai-service/state-machine/helpers/metadata.d.ts +6 -0
- package/dist/ai-service/state-machine/helpers/metadata.d.ts.map +1 -0
- package/dist/ai-service/state-machine/helpers/metadata.js +11 -0
- package/dist/ai-service/state-machine/helpers/metadata.js.map +1 -0
- package/dist/ai-service/state-machine/helpers/peer.d.ts +5 -0
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -0
- package/dist/ai-service/state-machine/helpers/peer.js +7 -0
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -0
- package/dist/ai-service/state-machine/helpers/transition.d.ts +12 -0
- package/dist/ai-service/state-machine/helpers/transition.d.ts.map +1 -0
- package/dist/ai-service/state-machine/helpers/transition.js +12 -0
- package/dist/ai-service/state-machine/helpers/transition.js.map +1 -0
- package/dist/ai-service/state-machine/mocks.d.ts +7 -0
- package/dist/ai-service/state-machine/mocks.d.ts.map +1 -0
- package/dist/ai-service/state-machine/mocks.js +72 -0
- package/dist/ai-service/state-machine/mocks.js.map +1 -0
- package/dist/ai-service/state-machine/test-util.d.ts +5 -0
- package/dist/ai-service/state-machine/test-util.d.ts.map +1 -0
- package/dist/ai-service/state-machine/test-util.js +29 -0
- package/dist/ai-service/state-machine/test-util.js.map +1 -0
- package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.d.ts +21 -0
- package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.d.ts.map +1 -0
- package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.js +48 -0
- package/dist/ai-service/transform/add-metadata-to-api-yaml/transformer.js.map +1 -0
- package/dist/ai-service/transform/api-builder/shared.d.ts +11 -0
- package/dist/ai-service/transform/api-builder/shared.d.ts.map +1 -0
- package/dist/ai-service/transform/api-builder/shared.js +55 -0
- package/dist/ai-service/transform/api-builder/shared.js.map +1 -0
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.d.ts +27 -0
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.d.ts.map +1 -0
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.js +67 -0
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.js.map +1 -0
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.d.ts +23 -0
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.d.ts.map +1 -0
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.js +59 -0
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.js.map +1 -0
- package/dist/ai-service/transform/remove-api-builder-imports/transformer.d.ts +19 -0
- package/dist/ai-service/transform/remove-api-builder-imports/transformer.d.ts.map +1 -0
- package/dist/ai-service/transform/remove-api-builder-imports/transformer.js +45 -0
- package/dist/ai-service/transform/remove-api-builder-imports/transformer.js.map +1 -0
- package/dist/ai-service/transform/shared.d.ts +20 -0
- package/dist/ai-service/transform/shared.d.ts.map +1 -0
- package/dist/ai-service/transform/shared.js +134 -0
- package/dist/ai-service/transform/shared.js.map +1 -0
- package/dist/ai-service/transform/workaround-missing-sbapi/transformer.d.ts +17 -0
- package/dist/ai-service/transform/workaround-missing-sbapi/transformer.d.ts.map +1 -0
- package/dist/ai-service/transform/workaround-missing-sbapi/transformer.js +33 -0
- package/dist/ai-service/transform/workaround-missing-sbapi/transformer.js.map +1 -0
- package/dist/ai-service/types.d.ts +71 -0
- package/dist/ai-service/types.d.ts.map +1 -0
- package/dist/ai-service/types.js +8 -0
- package/dist/ai-service/types.js.map +1 -0
- package/dist/binding-extraction/extract-control-block-identifiers.d.ts +4 -0
- package/dist/binding-extraction/extract-control-block-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/extract-control-block-identifiers.js +86 -0
- package/dist/binding-extraction/extract-control-block-identifiers.js.map +1 -0
- package/dist/binding-extraction/extract-embedded-identifiers.d.ts +16 -0
- package/dist/binding-extraction/extract-embedded-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/extract-embedded-identifiers.js +100 -0
- package/dist/binding-extraction/extract-embedded-identifiers.js.map +1 -0
- package/dist/binding-extraction/extract-identifiers.d.ts +8 -0
- package/dist/binding-extraction/extract-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/extract-identifiers.js +150 -0
- package/dist/binding-extraction/extract-identifiers.js.map +1 -0
- package/dist/binding-extraction/extract-js-identifiers.d.ts +19 -0
- package/dist/binding-extraction/extract-js-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/extract-js-identifiers.js +161 -0
- package/dist/binding-extraction/extract-js-identifiers.js.map +1 -0
- package/dist/binding-extraction/extract-py-identifiers.d.ts +4 -0
- package/dist/binding-extraction/extract-py-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/extract-py-identifiers.js +161 -0
- package/dist/binding-extraction/extract-py-identifiers.js.map +1 -0
- package/dist/binding-extraction/shared.d.ts +225 -0
- package/dist/binding-extraction/shared.d.ts.map +1 -0
- package/dist/binding-extraction/shared.js +43 -0
- package/dist/binding-extraction/shared.js.map +1 -0
- package/dist/binding-extraction/template-strings.d.ts +9 -0
- package/dist/binding-extraction/template-strings.d.ts.map +1 -0
- package/dist/binding-extraction/template-strings.js +45 -0
- package/dist/binding-extraction/template-strings.js.map +1 -0
- package/dist/codegen.d.ts +26 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +222 -0
- package/dist/codegen.js.map +1 -0
- package/dist/components-manager.d.ts +38 -0
- package/dist/components-manager.d.ts.map +1 -0
- package/dist/components-manager.js +177 -0
- package/dist/components-manager.js.map +1 -0
- package/dist/custom-components.d.ts +6 -0
- package/dist/custom-components.d.ts.map +1 -0
- package/dist/custom-components.js +51 -0
- package/dist/custom-components.js.map +1 -0
- package/dist/draft-interface.d.ts +12 -0
- package/dist/draft-interface.d.ts.map +1 -0
- package/dist/draft-interface.js +2 -0
- package/dist/draft-interface.js.map +1 -0
- package/dist/errors/error-handler.d.ts +35 -0
- package/dist/errors/error-handler.d.ts.map +1 -0
- package/dist/errors/error-handler.js +65 -0
- package/dist/errors/error-handler.js.map +1 -0
- package/dist/errors/make-server-error.d.ts +5 -0
- package/dist/errors/make-server-error.d.ts.map +1 -0
- package/dist/errors/make-server-error.js +21 -0
- package/dist/errors/make-server-error.js.map +1 -0
- package/dist/file-sync-vite-plugin.d.ts +4 -0
- package/dist/file-sync-vite-plugin.d.ts.map +1 -0
- package/dist/file-sync-vite-plugin.js +691 -0
- package/dist/file-sync-vite-plugin.js.map +1 -0
- package/dist/file-system-helpers.d.ts +7 -0
- package/dist/file-system-helpers.d.ts.map +1 -0
- package/dist/file-system-helpers.js +12 -0
- package/dist/file-system-helpers.js.map +1 -0
- package/dist/file-system-manager.d.ts +133 -0
- package/dist/file-system-manager.d.ts.map +1 -0
- package/dist/file-system-manager.js +1205 -0
- package/dist/file-system-manager.js.map +1 -0
- package/dist/generate.d.ts +8 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +7 -0
- package/dist/generate.js.map +1 -0
- package/dist/ids.d.ts +2 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +21 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/injected-index.d.ts +12 -0
- package/dist/injected-index.d.ts.map +1 -0
- package/dist/injected-index.js +38 -0
- package/dist/injected-index.js.map +1 -0
- package/dist/lock-service/index.d.ts +108 -0
- package/dist/lock-service/index.d.ts.map +1 -0
- package/dist/lock-service/index.js +324 -0
- package/dist/lock-service/index.js.map +1 -0
- package/dist/parsing/bindings.d.ts +4 -0
- package/dist/parsing/bindings.d.ts.map +1 -0
- package/dist/parsing/bindings.js +17 -0
- package/dist/parsing/bindings.js.map +1 -0
- package/dist/parsing/computed/index.d.ts +4 -0
- package/dist/parsing/computed/index.d.ts.map +1 -0
- package/dist/parsing/computed/index.js +7 -0
- package/dist/parsing/computed/index.js.map +1 -0
- package/dist/parsing/computed/to-code-computed.d.ts +2 -0
- package/dist/parsing/computed/to-code-computed.d.ts.map +1 -0
- package/dist/parsing/computed/to-code-computed.js +43 -0
- package/dist/parsing/computed/to-code-computed.js.map +1 -0
- package/dist/parsing/computed/to-value-computed.d.ts +4 -0
- package/dist/parsing/computed/to-value-computed.d.ts.map +1 -0
- package/dist/parsing/computed/to-value-computed.js +13 -0
- package/dist/parsing/computed/to-value-computed.js.map +1 -0
- package/dist/parsing/dim/index.d.ts +5 -0
- package/dist/parsing/dim/index.d.ts.map +1 -0
- package/dist/parsing/dim/index.js +7 -0
- package/dist/parsing/dim/index.js.map +1 -0
- package/dist/parsing/dim/to-code-dimensions.d.ts +3 -0
- package/dist/parsing/dim/to-code-dimensions.d.ts.map +1 -0
- package/dist/parsing/dim/to-code-dimensions.js +22 -0
- package/dist/parsing/dim/to-code-dimensions.js.map +1 -0
- package/dist/parsing/dim/to-value-dimensions.d.ts +4 -0
- package/dist/parsing/dim/to-value-dimensions.d.ts.map +1 -0
- package/dist/parsing/dim/to-value-dimensions.js +39 -0
- package/dist/parsing/dim/to-value-dimensions.js.map +1 -0
- package/dist/parsing/entity/index.d.ts +7 -0
- package/dist/parsing/entity/index.d.ts.map +1 -0
- package/dist/parsing/entity/index.js +7 -0
- package/dist/parsing/entity/index.js.map +1 -0
- package/dist/parsing/entity/to-code-entity.d.ts +3 -0
- package/dist/parsing/entity/to-code-entity.d.ts.map +1 -0
- package/dist/parsing/entity/to-code-entity.js +41 -0
- package/dist/parsing/entity/to-code-entity.js.map +1 -0
- package/dist/parsing/entity/to-value-entity.d.ts +8 -0
- package/dist/parsing/entity/to-value-entity.d.ts.map +1 -0
- package/dist/parsing/entity/to-value-entity.js +120 -0
- package/dist/parsing/entity/to-value-entity.js.map +1 -0
- package/dist/parsing/events/index.d.ts +5 -0
- package/dist/parsing/events/index.d.ts.map +1 -0
- package/dist/parsing/events/index.js +7 -0
- package/dist/parsing/events/index.js.map +1 -0
- package/dist/parsing/events/to-code-events.d.ts +3 -0
- package/dist/parsing/events/to-code-events.d.ts.map +1 -0
- package/dist/parsing/events/to-code-events.js +100 -0
- package/dist/parsing/events/to-code-events.js.map +1 -0
- package/dist/parsing/events/to-value-events.d.ts +6 -0
- package/dist/parsing/events/to-value-events.d.ts.map +1 -0
- package/dist/parsing/events/to-value-events.js +194 -0
- package/dist/parsing/events/to-value-events.js.map +1 -0
- package/dist/parsing/ids.d.ts +17 -0
- package/dist/parsing/ids.d.ts.map +1 -0
- package/dist/parsing/ids.js +143 -0
- package/dist/parsing/ids.js.map +1 -0
- package/dist/parsing/imports.d.ts +6 -0
- package/dist/parsing/imports.d.ts.map +1 -0
- package/dist/parsing/imports.js +31 -0
- package/dist/parsing/imports.js.map +1 -0
- package/dist/parsing/jsx-utils.d.ts +9 -0
- package/dist/parsing/jsx-utils.d.ts.map +1 -0
- package/dist/parsing/jsx-utils.js +48 -0
- package/dist/parsing/jsx-utils.js.map +1 -0
- package/dist/parsing/jsx.d.ts +23 -0
- package/dist/parsing/jsx.d.ts.map +1 -0
- package/dist/parsing/jsx.js +330 -0
- package/dist/parsing/jsx.js.map +1 -0
- package/dist/parsing/page.d.ts +9 -0
- package/dist/parsing/page.d.ts.map +1 -0
- package/dist/parsing/page.js +156 -0
- package/dist/parsing/page.js.map +1 -0
- package/dist/parsing/properties.d.ts +5 -0
- package/dist/parsing/properties.d.ts.map +1 -0
- package/dist/parsing/properties.js +89 -0
- package/dist/parsing/properties.js.map +1 -0
- package/dist/parsing/scope.d.ts +90 -0
- package/dist/parsing/scope.d.ts.map +1 -0
- package/dist/parsing/scope.js +669 -0
- package/dist/parsing/scope.js.map +1 -0
- package/dist/parsing/template/index.d.ts +5 -0
- package/dist/parsing/template/index.d.ts.map +1 -0
- package/dist/parsing/template/index.js +7 -0
- package/dist/parsing/template/index.js.map +1 -0
- package/dist/parsing/template/to-code-template.d.ts +2 -0
- package/dist/parsing/template/to-code-template.d.ts.map +1 -0
- package/dist/parsing/template/to-code-template.js +5 -0
- package/dist/parsing/template/to-code-template.js.map +1 -0
- package/dist/parsing/template/to-value-template.d.ts +4 -0
- package/dist/parsing/template/to-value-template.d.ts.map +1 -0
- package/dist/parsing/template/to-value-template.js +30 -0
- package/dist/parsing/template/to-value-template.js.map +1 -0
- package/dist/parsing/theme.d.ts +3 -0
- package/dist/parsing/theme.d.ts.map +1 -0
- package/dist/parsing/theme.js +87 -0
- package/dist/parsing/theme.js.map +1 -0
- package/dist/parsing/type-parsing-registry.d.ts +8 -0
- package/dist/parsing/type-parsing-registry.d.ts.map +1 -0
- package/dist/parsing/type-parsing-registry.js +11 -0
- package/dist/parsing/type-parsing-registry.js.map +1 -0
- package/dist/parsing/types.d.ts +9 -0
- package/dist/parsing/types.d.ts.map +1 -0
- package/dist/parsing/types.js +2 -0
- package/dist/parsing/types.js.map +1 -0
- package/dist/parsing/util.d.ts +34 -0
- package/dist/parsing/util.d.ts.map +1 -0
- package/dist/parsing/util.js +338 -0
- package/dist/parsing/util.js.map +1 -0
- package/dist/plugin-options.d.ts +25 -0
- package/dist/plugin-options.d.ts.map +1 -0
- package/dist/plugin-options.js +14 -0
- package/dist/plugin-options.js.map +1 -0
- package/dist/refactor/blocks.d.ts +10 -0
- package/dist/refactor/blocks.d.ts.map +1 -0
- package/dist/refactor/blocks.js +214 -0
- package/dist/refactor/blocks.js.map +1 -0
- package/dist/refactor/javascript.d.ts +15 -0
- package/dist/refactor/javascript.d.ts.map +1 -0
- package/dist/refactor/javascript.js +182 -0
- package/dist/refactor/javascript.js.map +1 -0
- package/dist/refactor-jsx.d.ts +28 -0
- package/dist/refactor-jsx.d.ts.map +1 -0
- package/dist/refactor-jsx.js +77 -0
- package/dist/refactor-jsx.js.map +1 -0
- package/dist/rename-manager.d.ts +27 -0
- package/dist/rename-manager.d.ts.map +1 -0
- package/dist/rename-manager.js +140 -0
- package/dist/rename-manager.js.map +1 -0
- package/dist/routing.d.ts +6 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +76 -0
- package/dist/routing.js.map +1 -0
- package/dist/sb-scope-manager.d.ts +102 -0
- package/dist/sb-scope-manager.d.ts.map +1 -0
- package/dist/sb-scope-manager.js +507 -0
- package/dist/sb-scope-manager.js.map +1 -0
- package/dist/socket-manager.d.ts +39 -0
- package/dist/socket-manager.d.ts.map +1 -0
- package/dist/socket-manager.js +184 -0
- package/dist/socket-manager.js.map +1 -0
- package/dist/source-tracker.d.ts +190 -0
- package/dist/source-tracker.d.ts.map +1 -0
- package/dist/source-tracker.js +962 -0
- package/dist/source-tracker.js.map +1 -0
- package/dist/sync-service/download.d.ts +15 -0
- package/dist/sync-service/download.d.ts.map +1 -0
- package/dist/sync-service/download.js +116 -0
- package/dist/sync-service/download.js.map +1 -0
- package/dist/sync-service/draft-helpers.d.ts +77 -0
- package/dist/sync-service/draft-helpers.d.ts.map +1 -0
- package/dist/sync-service/draft-helpers.js +512 -0
- package/dist/sync-service/draft-helpers.js.map +1 -0
- package/dist/sync-service/hash-cache.d.ts +15 -0
- package/dist/sync-service/hash-cache.d.ts.map +1 -0
- package/dist/sync-service/hash-cache.js +58 -0
- package/dist/sync-service/hash-cache.js.map +1 -0
- package/dist/sync-service/hash-dir-tree.d.ts +10 -0
- package/dist/sync-service/hash-dir-tree.d.ts.map +1 -0
- package/dist/sync-service/hash-dir-tree.js +53 -0
- package/dist/sync-service/hash-dir-tree.js.map +1 -0
- package/dist/sync-service/index.d.ts +143 -0
- package/dist/sync-service/index.d.ts.map +1 -0
- package/dist/sync-service/index.js +351 -0
- package/dist/sync-service/index.js.map +1 -0
- package/dist/sync-service/list-dir.d.ts +29 -0
- package/dist/sync-service/list-dir.d.ts.map +1 -0
- package/dist/sync-service/list-dir.js +66 -0
- package/dist/sync-service/list-dir.js.map +1 -0
- package/dist/sync-service/server-rpc/client.d.ts +13 -0
- package/dist/sync-service/server-rpc/client.d.ts.map +1 -0
- package/dist/sync-service/server-rpc/client.js +65 -0
- package/dist/sync-service/server-rpc/client.js.map +1 -0
- package/dist/sync-service/server-rpc/handlers.d.ts +3 -0
- package/dist/sync-service/server-rpc/handlers.d.ts.map +1 -0
- package/dist/sync-service/server-rpc/handlers.js +18 -0
- package/dist/sync-service/server-rpc/handlers.js.map +1 -0
- package/dist/sync-service/snapshot/take-snapshot.d.ts +35 -0
- package/dist/sync-service/snapshot/take-snapshot.d.ts.map +1 -0
- package/dist/sync-service/snapshot/take-snapshot.js +227 -0
- package/dist/sync-service/snapshot/take-snapshot.js.map +1 -0
- package/dist/sync-service/snapshot/types.d.ts +24 -0
- package/dist/sync-service/snapshot/types.d.ts.map +1 -0
- package/dist/sync-service/snapshot/types.js +3 -0
- package/dist/sync-service/snapshot/types.js.map +1 -0
- package/dist/sync-service/snapshot/upload-snapshot.d.ts +5 -0
- package/dist/sync-service/snapshot/upload-snapshot.d.ts.map +1 -0
- package/dist/sync-service/snapshot/upload-snapshot.js +63 -0
- package/dist/sync-service/snapshot/upload-snapshot.js.map +1 -0
- package/dist/traverse.d.ts +6 -0
- package/dist/traverse.d.ts.map +1 -0
- package/dist/traverse.js +7 -0
- package/dist/traverse.js.map +1 -0
- package/dist/util/generation-number-sequence.d.ts +7 -0
- package/dist/util/generation-number-sequence.d.ts.map +1 -0
- package/dist/util/generation-number-sequence.js +13 -0
- package/dist/util/generation-number-sequence.js.map +1 -0
- package/dist/util/logger.d.ts +22 -0
- package/dist/util/logger.d.ts.map +1 -0
- package/dist/util/logger.js +64 -0
- package/dist/util/logger.js.map +1 -0
- package/dist/util/operation-queue.d.ts +17 -0
- package/dist/util/operation-queue.d.ts.map +1 -0
- package/dist/util/operation-queue.js +27 -0
- package/dist/util/operation-queue.js.map +1 -0
- package/dist/util/tracing.d.ts +4 -0
- package/dist/util/tracing.d.ts.map +1 -0
- package/dist/util/tracing.js +56 -0
- package/dist/util/tracing.js.map +1 -0
- package/dist/util/with-resolvers.d.ts +10 -0
- package/dist/util/with-resolvers.d.ts.map +1 -0
- package/dist/util/with-resolvers.js +14 -0
- package/dist/util/with-resolvers.js.map +1 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +123 -0
- package/dist/util.js.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import { transformFromAstSync } from "@babel/core";
|
|
2
|
+
import { parse } from "@babel/parser";
|
|
3
|
+
import { variableDeclarator, objectPattern, objectProperty, variableDeclaration, identifier, blockStatement, returnStatement, } from "@babel/types";
|
|
4
|
+
import * as t from "@babel/types";
|
|
5
|
+
import { getStableScopeId, } from "@superblocksteam/library-shared";
|
|
6
|
+
import { SbEntityType } from "@superblocksteam/library-shared/types";
|
|
7
|
+
import { generatePredictableId } from "@superblocksteam/shared/dist/utils/appDSL.js";
|
|
8
|
+
import { getPropertyExpression } from "../codegen.js";
|
|
9
|
+
import { traverse } from "../traverse.js";
|
|
10
|
+
import { parser as entityParser } from "./entity/index.js";
|
|
11
|
+
import { getSbElementId, setSbElementId, supplementElementIds } from "./ids.js";
|
|
12
|
+
import { REQUIRED_IMPORTS_BY_PROPERTY_TYPE } from "./imports.js";
|
|
13
|
+
import { getIdentiferName, isSbScopeFunction, nodeToValue, extractNameFromBindAttribute, } from "./util.js";
|
|
14
|
+
export function getScopeElementId(scopeId, name) {
|
|
15
|
+
return `SB-${generatePredictableId(scopeId + name)}-type`;
|
|
16
|
+
}
|
|
17
|
+
const importsByEntityType = {
|
|
18
|
+
[SbEntityType.VARIABLE]: [
|
|
19
|
+
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
20
|
+
{ importName: "SbVariable", importPath: "@superblocksteam/library" },
|
|
21
|
+
{
|
|
22
|
+
importName: "SbVariablePersistence",
|
|
23
|
+
importPath: "@superblocksteam/library",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
[SbEntityType.TIMER]: [
|
|
27
|
+
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
28
|
+
{ importName: "SbTimer", importPath: "@superblocksteam/library" },
|
|
29
|
+
{ importName: "SbEventFlow", importPath: "@superblocksteam/library" },
|
|
30
|
+
],
|
|
31
|
+
[SbEntityType.EVENT]: [
|
|
32
|
+
{ importName: "SbEvent", importPath: "@superblocksteam/library" },
|
|
33
|
+
],
|
|
34
|
+
[SbEntityType.API]: [
|
|
35
|
+
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
36
|
+
{ importName: "SbApi", importPath: "@superblocksteam/library" },
|
|
37
|
+
{ importName: "SbEventFlow", importPath: "@superblocksteam/library" },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Given an object property from a scope entry, like:
|
|
42
|
+
* pageSize: SbVariable({
|
|
43
|
+
* defaultValue: "test ${Math.random()}",
|
|
44
|
+
* persistence: SbVariablePersistence.TEMPORARY
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* Returns a reference to the object expression node
|
|
48
|
+
*/
|
|
49
|
+
function getConfigObject(node) {
|
|
50
|
+
const config = node.get("value");
|
|
51
|
+
if (!config.isCallExpression()) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const args = config.get("arguments");
|
|
55
|
+
if (args.length !== 1) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const configObject = args[0];
|
|
59
|
+
if (!configObject?.isObjectExpression()) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return configObject;
|
|
63
|
+
}
|
|
64
|
+
export function updateEntityNode(node, updates, entityId) {
|
|
65
|
+
const entity = fromNodeToEntity(node, entityId);
|
|
66
|
+
if (!entity) {
|
|
67
|
+
throw new Error("Entity could not be created from node: " +
|
|
68
|
+
getIdentiferName(node.node.key));
|
|
69
|
+
}
|
|
70
|
+
const configObject = getConfigObject(node);
|
|
71
|
+
if (!configObject) {
|
|
72
|
+
return {
|
|
73
|
+
imports: [],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
let imports = importsByEntityType[entity.type] ?? [];
|
|
77
|
+
for (const [key, info] of Object.entries(updates ?? {})) {
|
|
78
|
+
const property = configObject.get("properties").find((property) => {
|
|
79
|
+
return (property.isObjectProperty() &&
|
|
80
|
+
property.get("key").isIdentifier() &&
|
|
81
|
+
getIdentiferName(property.node.key) === key);
|
|
82
|
+
});
|
|
83
|
+
if (!property) {
|
|
84
|
+
configObject.pushContainer("properties", objectProperty(identifier(key), getPropertyExpression(info)));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
property.replaceWith(objectProperty(identifier(key), getPropertyExpression(info)));
|
|
88
|
+
}
|
|
89
|
+
if (info.type in REQUIRED_IMPORTS_BY_PROPERTY_TYPE) {
|
|
90
|
+
const requiredImports = REQUIRED_IMPORTS_BY_PROPERTY_TYPE[info.type];
|
|
91
|
+
if (requiredImports) {
|
|
92
|
+
imports = [...imports, ...requiredImports];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { imports };
|
|
97
|
+
}
|
|
98
|
+
export function fromEntityToNode(entity) {
|
|
99
|
+
const imports = importsByEntityType[entity.type] ?? [];
|
|
100
|
+
const code = entityParser.toCode(entity);
|
|
101
|
+
const parsedEntity = parse(code, {
|
|
102
|
+
sourceType: "module",
|
|
103
|
+
plugins: ["typescript", "jsx"],
|
|
104
|
+
});
|
|
105
|
+
if (parsedEntity.program.body[0]?.type !== "ExpressionStatement") {
|
|
106
|
+
throw new Error("Invalid entity ast definition");
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
entity: objectProperty(identifier(entity.name), parsedEntity.program.body[0].expression),
|
|
110
|
+
imports,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function fromNodeToEntity(property, entityId) {
|
|
114
|
+
const entityName = nodeToValue(property.get("key").node);
|
|
115
|
+
const expression = property.get("value");
|
|
116
|
+
const id = entityId ?? getSbElementId(property.node);
|
|
117
|
+
return entityParser.toValue(expression, {
|
|
118
|
+
key: entityName,
|
|
119
|
+
id,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export function getScope(fileName, file) {
|
|
123
|
+
if (!file || !file.ast) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const clonedAst = transformFromAstSync(file.ast, undefined, { ast: true });
|
|
127
|
+
if (!clonedAst?.ast) {
|
|
128
|
+
throw new Error("Failed to clone AST for file " + fileName);
|
|
129
|
+
}
|
|
130
|
+
const ast = clonedAst.ast;
|
|
131
|
+
if (!ast) {
|
|
132
|
+
throw new Error("Failed to parse AST for file " + fileName);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const scope = parseSbScopeDefinition(ast);
|
|
136
|
+
if (!scope) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const scopeId = scope.id;
|
|
140
|
+
supplementElementIds({ fileName, ast, shouldModifyAst: true, scopeId });
|
|
141
|
+
const entities = scope.scopeEntities?.get("properties").reduce((acc, property) => {
|
|
142
|
+
if (property.isObjectProperty()) {
|
|
143
|
+
const entity = fromNodeToEntity(property);
|
|
144
|
+
if (entity) {
|
|
145
|
+
acc[entity.name] = entity;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return acc;
|
|
149
|
+
}, {}) ?? {};
|
|
150
|
+
return {
|
|
151
|
+
entities: entities,
|
|
152
|
+
scopeName: scope.name,
|
|
153
|
+
scopeId: scope.id,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (_e) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// sb scope utils
|
|
161
|
+
/**
|
|
162
|
+
* Builds a map of scope usages within files
|
|
163
|
+
* @param ast The AST to analyze
|
|
164
|
+
* @param filePath The path of the file being analyzed
|
|
165
|
+
* @param scopeDefinitions List of scope definitions (name and entities)
|
|
166
|
+
* @param scopeNameToScopeUsage Existing map to update (optional)
|
|
167
|
+
* @returns Updated map of scope usages
|
|
168
|
+
*/
|
|
169
|
+
export function buildScopeDestructuredUsageMap(ast, filePath, scopeNames, scopeNameToScopeUsage = {}) {
|
|
170
|
+
traverse(ast, {
|
|
171
|
+
// Look for variable declarations like: const { Entity1 } = ScopeName;
|
|
172
|
+
VariableDeclaration(path) {
|
|
173
|
+
const declarations = path.get("declarations");
|
|
174
|
+
for (const declaration of declarations) {
|
|
175
|
+
if (!declaration.isVariableDeclarator())
|
|
176
|
+
continue;
|
|
177
|
+
const id = declaration.get("id");
|
|
178
|
+
const init = declaration.get("init");
|
|
179
|
+
// Check if this is a destructuring assignment
|
|
180
|
+
if (id.isObjectPattern() && init.isIdentifier()) {
|
|
181
|
+
const scopeName = init.node.name;
|
|
182
|
+
// Check if the identifier is a known scope
|
|
183
|
+
if (scopeNames.has(scopeName)) {
|
|
184
|
+
// Initialize the nested structure if it doesn't exist
|
|
185
|
+
if (!scopeNameToScopeUsage[scopeName]) {
|
|
186
|
+
scopeNameToScopeUsage[scopeName] = {};
|
|
187
|
+
}
|
|
188
|
+
if (!scopeNameToScopeUsage[scopeName][filePath]) {
|
|
189
|
+
scopeNameToScopeUsage[scopeName][filePath] = [];
|
|
190
|
+
}
|
|
191
|
+
// Add this usage to the map
|
|
192
|
+
scopeNameToScopeUsage[scopeName][filePath].push(path);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
return scopeNameToScopeUsage;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Updates all scope usages to include the complete list of entity names
|
|
202
|
+
* @param scopeUsages Map of file paths to NodePaths where the scope is used
|
|
203
|
+
* @param entityNames Complete list of entity names to include in all usages
|
|
204
|
+
*/
|
|
205
|
+
export function updateScopeUsages(scopeUsages, entityNames) {
|
|
206
|
+
// Process each file's usages
|
|
207
|
+
Object.values(scopeUsages).forEach((usages) => {
|
|
208
|
+
usages.forEach((usage) => {
|
|
209
|
+
if (usage.isVariableDeclaration()) {
|
|
210
|
+
// Handle variable declarations: const { Entity1 } = Scope;
|
|
211
|
+
const declarations = usage.get("declarations");
|
|
212
|
+
for (const declaration of declarations) {
|
|
213
|
+
if (!declaration.isVariableDeclarator())
|
|
214
|
+
continue;
|
|
215
|
+
const id = declaration.get("id");
|
|
216
|
+
if (id.isObjectPattern()) {
|
|
217
|
+
const newProperties = entityNames.map((name) => objectProperty(identifier(name), identifier(name), false, // computed
|
|
218
|
+
true));
|
|
219
|
+
id.node.properties = newProperties;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Adds scope destructuring and imports to a component based on a JSX element locator
|
|
228
|
+
* @param elementPath Path to the JSX element that serves as the locator
|
|
229
|
+
* @param scopeDef Scope definition containing name, entities, and file path
|
|
230
|
+
* @param componentFilePath Path to the component file (for relative import calculation)
|
|
231
|
+
* @returns The newly created destructuring node path or null if failed
|
|
232
|
+
*/
|
|
233
|
+
export function addScopeToComponent({ elementLocation, scopeDefinition, }) {
|
|
234
|
+
// Find the function component or class that contains this JSX element
|
|
235
|
+
const componentPath = findEnclosingComponent(elementLocation);
|
|
236
|
+
if (!componentPath) {
|
|
237
|
+
throw new Error("Could not find enclosing component for the JSX element");
|
|
238
|
+
}
|
|
239
|
+
return addScopeDestructuring(componentPath, scopeDefinition);
|
|
240
|
+
}
|
|
241
|
+
function findEnclosingComponent(elementPath) {
|
|
242
|
+
let currentPath = elementPath;
|
|
243
|
+
while (currentPath) {
|
|
244
|
+
// Check for component types
|
|
245
|
+
if (currentPath.isFunctionDeclaration() ||
|
|
246
|
+
currentPath.isArrowFunctionExpression() ||
|
|
247
|
+
currentPath.isFunctionExpression() ||
|
|
248
|
+
currentPath.isClassDeclaration()) {
|
|
249
|
+
return currentPath;
|
|
250
|
+
}
|
|
251
|
+
// Move up the tree
|
|
252
|
+
currentPath = currentPath.parentPath;
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Adds scope destructuring to the component body
|
|
258
|
+
* @param componentPath Path to the component declaration
|
|
259
|
+
* @param scopeDef Scope definition containing name and entities
|
|
260
|
+
* @returns The newly created destructuring node path or null if failed
|
|
261
|
+
*/
|
|
262
|
+
function addScopeDestructuring(componentPath, scopeDefinition) {
|
|
263
|
+
// Create the destructuring variable declaration
|
|
264
|
+
// const { Entity1, Entity2 } = ScopeName;
|
|
265
|
+
const uniqueEntityNames = [...new Set(scopeDefinition.entityNames)];
|
|
266
|
+
const destructuringDeclaration = variableDeclaration("const", [
|
|
267
|
+
variableDeclarator(objectPattern(uniqueEntityNames.map((name) => objectProperty(identifier(name), identifier(name), false, // computed
|
|
268
|
+
true))), identifier(scopeDefinition.name)),
|
|
269
|
+
]);
|
|
270
|
+
let addedNodePath = null;
|
|
271
|
+
if (componentPath.isFunctionDeclaration() ||
|
|
272
|
+
componentPath.isFunctionExpression() ||
|
|
273
|
+
componentPath.isArrowFunctionExpression()) {
|
|
274
|
+
// For function components, add at the start of the function body
|
|
275
|
+
let body = componentPath.get("body");
|
|
276
|
+
if (Array.isArray(body)) {
|
|
277
|
+
body = body[0];
|
|
278
|
+
if (!body)
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
body = body;
|
|
282
|
+
if (body.isBlockStatement()) {
|
|
283
|
+
// Function with block body: function Component() { ... }
|
|
284
|
+
const [newPath] = body.unshiftContainer("body", destructuringDeclaration);
|
|
285
|
+
addedNodePath = newPath;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
// Arrow function with expression body: () => <div />
|
|
289
|
+
// Need to convert to block body first
|
|
290
|
+
const retStatement = returnStatement(body.node);
|
|
291
|
+
componentPath.node.body = blockStatement([
|
|
292
|
+
destructuringDeclaration,
|
|
293
|
+
retStatement,
|
|
294
|
+
]);
|
|
295
|
+
// Get the path to the newly added node
|
|
296
|
+
const blockBody = componentPath.get("body");
|
|
297
|
+
addedNodePath = blockBody.get("body")[0];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else if (componentPath.isClassDeclaration()) {
|
|
301
|
+
// For class components, add to the render method
|
|
302
|
+
const renderMethod = findRenderMethod(componentPath);
|
|
303
|
+
if (renderMethod) {
|
|
304
|
+
const renderBody = renderMethod.get("body");
|
|
305
|
+
const [newPath] = renderBody.unshiftContainer("body", destructuringDeclaration);
|
|
306
|
+
addedNodePath = newPath;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return addedNodePath;
|
|
310
|
+
}
|
|
311
|
+
function findRenderMethod(classPath) {
|
|
312
|
+
const body = classPath.get("body");
|
|
313
|
+
const methods = body.get("body");
|
|
314
|
+
for (const method of methods) {
|
|
315
|
+
if (method.isClassMethod() &&
|
|
316
|
+
method.node.kind === "method" &&
|
|
317
|
+
method.get("key").isIdentifier() &&
|
|
318
|
+
method.get("key").node.name === "render") {
|
|
319
|
+
return method;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
export function isComponentAlreadyUsingScope(elementLocation, usagesInFile) {
|
|
325
|
+
// Check if we have usage data for this scope and file
|
|
326
|
+
if (!usagesInFile?.length) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
// Find the component that contains this JSX element
|
|
330
|
+
const componentPath = findEnclosingComponent(elementLocation);
|
|
331
|
+
if (!componentPath) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
// Check if any of the usages are within the same component
|
|
335
|
+
for (const usage of usagesInFile) {
|
|
336
|
+
// Find the component containing this usage
|
|
337
|
+
let currentPath = usage;
|
|
338
|
+
let usageComponentPath = null;
|
|
339
|
+
// Traverse up the tree to find the containing component
|
|
340
|
+
while (currentPath) {
|
|
341
|
+
if (currentPath.isFunctionDeclaration() ||
|
|
342
|
+
currentPath.isArrowFunctionExpression() ||
|
|
343
|
+
currentPath.isFunctionExpression() ||
|
|
344
|
+
currentPath.isClassDeclaration()) {
|
|
345
|
+
usageComponentPath = currentPath;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
currentPath = currentPath.parentPath;
|
|
349
|
+
}
|
|
350
|
+
// If the usage is in the same component, return true
|
|
351
|
+
if (usageComponentPath && usageComponentPath === componentPath) {
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
/*
|
|
358
|
+
Example code:
|
|
359
|
+
export const Page1Scope = createSbScope<
|
|
360
|
+
{component: any}
|
|
361
|
+
>( ({ entities: { component, count } }: { entities: { component, count } }) => ({
|
|
362
|
+
count: SbVariable({ defaultValue: 0 }),
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
export const Page1 = Page1Scope.entities;
|
|
367
|
+
|
|
368
|
+
SBDefintiion:
|
|
369
|
+
- name: Page1
|
|
370
|
+
- entityNames: ["count", "component"]
|
|
371
|
+
- scopeEntities: {count: SBVariable({defaultValue: 0})} (nodepath)
|
|
372
|
+
- scopeComponents: { component: any} (nodePath)
|
|
373
|
+
- destructuredEntitiesParam: { component, count } (nodePath)
|
|
374
|
+
- scopeFunction: ({ entities }: { component, count }) => {
|
|
375
|
+
count: SbVariable({ defaultValue: 0 }),
|
|
376
|
+
} (nodePath)
|
|
377
|
+
*/
|
|
378
|
+
export function parseSbScopeDefinition(ast) {
|
|
379
|
+
let scopeName = null;
|
|
380
|
+
let scopeScopeName = null; // e.g., "Page1Scope"
|
|
381
|
+
const entityNames = [];
|
|
382
|
+
let mainNode = null;
|
|
383
|
+
let scopeEntities = null;
|
|
384
|
+
let scopeComponents = null;
|
|
385
|
+
let destructuredEntitiesParam = null;
|
|
386
|
+
let scopeFunction = null;
|
|
387
|
+
const scopeNameToEntityId = {};
|
|
388
|
+
let scopeId = null;
|
|
389
|
+
// Helper function to extract entity names and IDs from object expression
|
|
390
|
+
function extractEntityNamesFromObject(objExpr) {
|
|
391
|
+
const properties = objExpr.get("properties");
|
|
392
|
+
properties.forEach((prop) => {
|
|
393
|
+
if (prop.isObjectProperty() && prop.node.key.type === "Identifier") {
|
|
394
|
+
const name = getIdentiferName(prop.node.key);
|
|
395
|
+
if (!name) {
|
|
396
|
+
console.warn("Could not find name for entity");
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
// Add to entityNames if not already present
|
|
400
|
+
if (!entityNames.includes(name)) {
|
|
401
|
+
entityNames.push(name);
|
|
402
|
+
}
|
|
403
|
+
let entityId = getSbElementId(prop.node);
|
|
404
|
+
if (!entityId) {
|
|
405
|
+
entityId = getScopeElementId(scopeId, name);
|
|
406
|
+
setSbElementId(prop.node, entityId);
|
|
407
|
+
}
|
|
408
|
+
if (entityId) {
|
|
409
|
+
scopeNameToEntityId[name] = entityId;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
// Helper function to find and process the returned object expression
|
|
415
|
+
function findReturnedObject(functionPath) {
|
|
416
|
+
const body = functionPath.get("body");
|
|
417
|
+
if (body.isObjectExpression()) {
|
|
418
|
+
// Arrow function with expression body: () => ({})
|
|
419
|
+
scopeEntities = body;
|
|
420
|
+
extractEntityNamesFromObject(body);
|
|
421
|
+
}
|
|
422
|
+
else if (body.isBlockStatement()) {
|
|
423
|
+
// Function with block body: () => { return {}; } or function() { return {}; }
|
|
424
|
+
body.traverse({
|
|
425
|
+
ReturnStatement(returnPath) {
|
|
426
|
+
const argument = returnPath.get("argument");
|
|
427
|
+
if (argument.isObjectExpression()) {
|
|
428
|
+
scopeEntities = argument;
|
|
429
|
+
extractEntityNamesFromObject(argument);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// First pass: Find the export const Page1 = Page1Scope.entities statement to get the page name
|
|
436
|
+
traverse(ast, {
|
|
437
|
+
ExportNamedDeclaration(path) {
|
|
438
|
+
const declaration = path.get("declaration");
|
|
439
|
+
if (!declaration.isVariableDeclaration())
|
|
440
|
+
return;
|
|
441
|
+
const declarations = declaration.get("declarations");
|
|
442
|
+
for (const varDeclarator of declarations) {
|
|
443
|
+
if (!varDeclarator.isVariableDeclarator())
|
|
444
|
+
continue;
|
|
445
|
+
const id = varDeclarator.get("id");
|
|
446
|
+
const init = varDeclarator.get("init");
|
|
447
|
+
// Check if this is the entities export (e.g., export const Page1 = Page1Scope.entities)
|
|
448
|
+
if (id.isIdentifier() &&
|
|
449
|
+
init.isMemberExpression() &&
|
|
450
|
+
init.get("property").isIdentifier()) {
|
|
451
|
+
const property = init.get("property");
|
|
452
|
+
if (property.isIdentifier() && property.node.name === "entities") {
|
|
453
|
+
const object = init.get("object");
|
|
454
|
+
if (object.isIdentifier()) {
|
|
455
|
+
// Found the entities export, extract the page name from the left side of the assignment
|
|
456
|
+
scopeName = id.node.name;
|
|
457
|
+
scopeScopeName = object.node.name;
|
|
458
|
+
scopeId = getStableScopeId(scopeName);
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
// Second pass: Find the scope definition and extract entity names
|
|
467
|
+
if (scopeName && scopeScopeName && scopeId) {
|
|
468
|
+
traverse(ast, {
|
|
469
|
+
VariableDeclaration(path) {
|
|
470
|
+
const declarations = path.get("declarations");
|
|
471
|
+
for (const varDeclarator of declarations) {
|
|
472
|
+
if (!varDeclarator.isVariableDeclarator())
|
|
473
|
+
continue;
|
|
474
|
+
const id = varDeclarator.get("id");
|
|
475
|
+
const init = varDeclarator.get("init");
|
|
476
|
+
if (id.isIdentifier() && id.node.name === scopeScopeName) {
|
|
477
|
+
if (init.isCallExpression() && init.get("callee").isIdentifier()) {
|
|
478
|
+
const callee = init.get("callee");
|
|
479
|
+
if (callee.isIdentifier() &&
|
|
480
|
+
isSbScopeFunction(callee.node.name)) {
|
|
481
|
+
// Extract entity names from the type parameters
|
|
482
|
+
if (init.node.typeParameters) {
|
|
483
|
+
const typeParameters = init.get("typeParameters");
|
|
484
|
+
if (typeParameters.isTSTypeParameterInstantiation() &&
|
|
485
|
+
typeParameters.node.params.length > 0) {
|
|
486
|
+
const typeParams = typeParameters.get("params");
|
|
487
|
+
if (typeParams.length > 0) {
|
|
488
|
+
const typeParam = typeParams[0];
|
|
489
|
+
if (typeParam && typeParam.isTSTypeLiteral()) {
|
|
490
|
+
const members = typeParam.get("members");
|
|
491
|
+
members.forEach((member) => {
|
|
492
|
+
if (member.isTSPropertySignature() &&
|
|
493
|
+
member.get("key").isIdentifier()) {
|
|
494
|
+
const key = member.get("key");
|
|
495
|
+
if (key.isIdentifier()) {
|
|
496
|
+
entityNames.push(key.node.name);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
// Store reference to the type literal node for components
|
|
501
|
+
scopeComponents = typeParam;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// Extract entity names from the function argument
|
|
507
|
+
if (init.node.arguments.length > 0) {
|
|
508
|
+
const args = init.get("arguments");
|
|
509
|
+
if (args.length > 0) {
|
|
510
|
+
const funcArg = args[0];
|
|
511
|
+
// Handle both arrow functions and regular functions
|
|
512
|
+
if (funcArg &&
|
|
513
|
+
(funcArg.isArrowFunctionExpression() ||
|
|
514
|
+
funcArg.isFunctionExpression())) {
|
|
515
|
+
scopeFunction = funcArg;
|
|
516
|
+
// Handle parameters
|
|
517
|
+
const params = funcArg.get("params");
|
|
518
|
+
if (params &&
|
|
519
|
+
Array.isArray(params) &&
|
|
520
|
+
params.length > 0) {
|
|
521
|
+
const param = params[0];
|
|
522
|
+
if (param && param.isObjectPattern()) {
|
|
523
|
+
destructuredEntitiesParam = param;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
// Find and process the returned object
|
|
527
|
+
findReturnedObject(funcArg);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
// Set mainNode to the createSbScope call expression
|
|
532
|
+
mainNode = init;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
if (!scopeName || !mainNode || !scopeId || !scopeFunction || !scopeEntities) {
|
|
541
|
+
throw new Error("Failed to parse scope definition: missing required elements for scope creation");
|
|
542
|
+
}
|
|
543
|
+
// Remove duplicates from entityNames if any
|
|
544
|
+
const uniqueEntityNames = [...new Set(entityNames)];
|
|
545
|
+
return {
|
|
546
|
+
name: scopeName,
|
|
547
|
+
entityNames: uniqueEntityNames,
|
|
548
|
+
mainNode,
|
|
549
|
+
scopeEntities,
|
|
550
|
+
scopeComponents,
|
|
551
|
+
id: scopeId,
|
|
552
|
+
scopeNameToEntityId,
|
|
553
|
+
destructuredEntitiesParam,
|
|
554
|
+
scopeFunction,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
export function findBindComponentsInScopeUsage(usage) {
|
|
558
|
+
const componentPath = findEnclosingComponent(usage);
|
|
559
|
+
if (!componentPath) {
|
|
560
|
+
return [];
|
|
561
|
+
}
|
|
562
|
+
const allBindNames = findBindNamesInComponentPath(componentPath);
|
|
563
|
+
return Array.from(new Set(allBindNames));
|
|
564
|
+
}
|
|
565
|
+
function findBindNamesInComponentPath(componentPath) {
|
|
566
|
+
const bindNames = [];
|
|
567
|
+
componentPath.traverse({
|
|
568
|
+
JSXElement(path) {
|
|
569
|
+
const bindAttribute = path
|
|
570
|
+
.get("openingElement")
|
|
571
|
+
.get("attributes")
|
|
572
|
+
.find((n) => n.isJSXAttribute() && getIdentiferName(n.node.name) === "bind");
|
|
573
|
+
if (bindAttribute) {
|
|
574
|
+
const bindName = extractNameFromBindAttribute(bindAttribute.node, true);
|
|
575
|
+
if (bindName) {
|
|
576
|
+
bindNames.push(bindName);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
return bindNames;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Creates an empty scope definition with the given scope name.
|
|
585
|
+
* This generates a minimal scope with no entities or components and returns the parsed definition.
|
|
586
|
+
* Useful as a fallback when components are missing and need to be initialized.
|
|
587
|
+
*
|
|
588
|
+
* @param scopeName - The name of the scope (e.g., "Page1")
|
|
589
|
+
* @returns A parsed SbScopeDefinition with empty entities and components
|
|
590
|
+
*/
|
|
591
|
+
export function createEmptyScopeDefinition(scopeName) {
|
|
592
|
+
const code = `const ${scopeName}Scope = createSbScope<{}>(() => ({}));
|
|
593
|
+
export const ${scopeName} = ${scopeName}Scope.entities;`;
|
|
594
|
+
const ast = parse(code, {
|
|
595
|
+
sourceType: "module",
|
|
596
|
+
plugins: ["typescript", "jsx"],
|
|
597
|
+
});
|
|
598
|
+
return parseSbScopeDefinition(ast);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Adds type parameters to an existing createSbScope call if they don't exist.
|
|
602
|
+
* This function modifies the AST directly by adding a TypeScript type parameter
|
|
603
|
+
* to the createSbScope call expression.
|
|
604
|
+
*
|
|
605
|
+
* @param scopeDefinition - The scope definition containing the AST nodes
|
|
606
|
+
* @returns The scope definition with type parameters added (modifies the scope definition in place)
|
|
607
|
+
*/
|
|
608
|
+
export function addTypeParametersToScope(scopeDefinition) {
|
|
609
|
+
// Get the createSbScope call expression
|
|
610
|
+
const mainPath = scopeDefinition.mainNode;
|
|
611
|
+
// Check if type parameters already exist
|
|
612
|
+
if (mainPath.node.typeParameters) {
|
|
613
|
+
const typeParams = mainPath.node.typeParameters.params;
|
|
614
|
+
if (typeParams.length > 0 && t.isTSTypeLiteral(typeParams[0])) {
|
|
615
|
+
return scopeDefinition;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const emptyScope = createEmptyScopeDefinition(scopeDefinition.name);
|
|
619
|
+
const typeParameterInstantiation = emptyScope.mainNode.node.typeParameters;
|
|
620
|
+
// Add type parameters to the AST
|
|
621
|
+
mainPath.node.typeParameters = typeParameterInstantiation;
|
|
622
|
+
// Add the type literal to the scope definition
|
|
623
|
+
scopeDefinition.scopeComponents = emptyScope.scopeComponents;
|
|
624
|
+
return scopeDefinition;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Utility to update the destructured entities parameter in function-based scopes
|
|
628
|
+
* Handles both cases:
|
|
629
|
+
* 1. ({ entities }) => ... (needs to add destructuring)
|
|
630
|
+
* 2. () => ... (needs to add entire parameter)
|
|
631
|
+
*/
|
|
632
|
+
export function updateDestructuredEntitiesParam(scopeDef) {
|
|
633
|
+
const uniqueEntityNames = [...new Set(scopeDef.entityNames)];
|
|
634
|
+
// If no entities, just ensure we have a basic parameter structure
|
|
635
|
+
if (uniqueEntityNames.length === 0) {
|
|
636
|
+
// For empty scopes, we can use either ({ entities }) or () format
|
|
637
|
+
// We'll standardize on () for empty scopes
|
|
638
|
+
if (scopeDef.scopeFunction.node.params.length > 0) {
|
|
639
|
+
scopeDef.scopeFunction.node.params = [];
|
|
640
|
+
scopeDef.destructuredEntitiesParam = null; // Clear the reference
|
|
641
|
+
}
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
// Create the entities destructuring pattern
|
|
645
|
+
const entitiesDestructuring = objectPattern(uniqueEntityNames.map((name) => objectProperty(identifier(name), identifier(name), false, // computed
|
|
646
|
+
true)));
|
|
647
|
+
const entitiesProperty = objectProperty(identifier("entities"), entitiesDestructuring);
|
|
648
|
+
const mainDestructuringPattern = objectPattern([entitiesProperty]);
|
|
649
|
+
// Case 1: Function already has parameters
|
|
650
|
+
if (scopeDef.scopeFunction.node.params.length > 0) {
|
|
651
|
+
const firstParam = scopeDef.scopeFunction.get("params")[0];
|
|
652
|
+
if (firstParam && firstParam.isObjectPattern()) {
|
|
653
|
+
// Update existing object pattern
|
|
654
|
+
firstParam.node.properties = [entitiesProperty];
|
|
655
|
+
scopeDef.destructuredEntitiesParam = firstParam;
|
|
656
|
+
}
|
|
657
|
+
else if (firstParam) {
|
|
658
|
+
// Replace non-object parameter with object pattern
|
|
659
|
+
firstParam.replaceWith(mainDestructuringPattern);
|
|
660
|
+
scopeDef.destructuredEntitiesParam = scopeDef.scopeFunction.get("params")[0];
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
// Case 2: Function has no parameters - add the destructuring parameter
|
|
665
|
+
scopeDef.scopeFunction.node.params = [mainDestructuringPattern];
|
|
666
|
+
scopeDef.destructuredEntitiesParam = scopeDef.scopeFunction.get("params")[0];
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
//# sourceMappingURL=scope.js.map
|