@superblocksteam/vite-plugin-file-sync 2.0.55 → 2.0.56-next.1
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/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +394 -2303
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/examples.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/examples.js +34 -35
- package/dist/ai-service/agent/subagents/apis/examples.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts +2 -8
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js +17 -46
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts +0 -1
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js +4 -25
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/state.js +1 -1
- package/dist/ai-service/agent/subagents/apis/state.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts +1 -1
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/system-prompt.js +134 -173
- package/dist/ai-service/agent/subagents/apis/system-prompt.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/types.d.ts +1 -4
- package/dist/ai-service/agent/subagents/apis/types.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.js +14 -31
- package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/build-api.d.ts +1 -6
- package/dist/ai-service/agent/tools/apis/build-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/build-api.js +12 -21
- package/dist/ai-service/agent/tools/apis/build-api.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/finalize-api.d.ts +2 -6
- package/dist/ai-service/agent/tools/apis/finalize-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/finalize-api.js +29 -20
- package/dist/ai-service/agent/tools/apis/finalize-api.js.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.js +4 -9
- package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.d.ts +7 -1
- package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.js +43 -8
- package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.js +7 -9
- package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.d.ts +2 -0
- package/dist/ai-service/agent/tools/build-read-files.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.js +18 -18
- package/dist/ai-service/agent/tools/build-read-files.js.map +1 -1
- package/dist/ai-service/agent/tools/build-rename-file.d.ts +11 -0
- package/dist/ai-service/agent/tools/build-rename-file.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/build-rename-file.js +103 -0
- package/dist/ai-service/agent/tools/build-rename-file.js.map +1 -0
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts +0 -1
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-validate-icons.js +0 -6
- package/dist/ai-service/agent/tools/build-validate-icons.js.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.js +5 -6
- package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
- package/dist/ai-service/agent/tools/index.d.ts +0 -10
- package/dist/ai-service/agent/tools/index.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/index.js +0 -10
- package/dist/ai-service/agent/tools/index.js.map +1 -1
- package/dist/ai-service/agent/tools/shared-helpers.d.ts +1 -7
- package/dist/ai-service/agent/tools/shared-helpers.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/shared-helpers.js +9 -29
- package/dist/ai-service/agent/tools/shared-helpers.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +5 -11
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts +1 -2
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js +89 -67
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/explain-code-finalize.d.ts +4 -0
- package/dist/ai-service/agent/tools2/tools/explain-code-finalize.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/explain-code-finalize.js +19 -0
- package/dist/ai-service/agent/tools2/tools/explain-code-finalize.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/glob.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/glob.js +15 -6
- package/dist/ai-service/agent/tools2/tools/glob.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +13 -0
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js +21 -0
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/index.d.ts +1 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/index.js +1 -0
- package/dist/ai-service/agent/tools2/tools/index.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/ls.d.ts +10 -0
- package/dist/ai-service/agent/tools2/tools/ls.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/ls.js +71 -0
- package/dist/ai-service/agent/tools2/tools/ls.js.map +1 -0
- package/dist/ai-service/agent/utils.d.ts +0 -35
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +0 -132
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/app-interface/file-system-interface.d.ts +1 -1
- package/dist/ai-service/app-interface/file-system-interface.d.ts.map +1 -1
- package/dist/ai-service/app-interface/file-system-interface.js +2 -2
- package/dist/ai-service/app-interface/file-system-interface.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +5 -0
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +60 -0
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +8 -1
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/clark-provider/clark-chat-settings.d.ts +2 -1
- package/dist/ai-service/clark-provider/clark-chat-settings.d.ts.map +1 -1
- package/dist/ai-service/clark-provider/clark-chat-settings.js +1 -0
- package/dist/ai-service/clark-provider/clark-chat-settings.js.map +1 -1
- package/dist/ai-service/const.d.ts +3 -7
- package/dist/ai-service/const.d.ts.map +1 -1
- package/dist/ai-service/const.js +2 -6
- package/dist/ai-service/const.js.map +1 -1
- package/dist/ai-service/context/app-context.d.ts +2 -1
- package/dist/ai-service/context/app-context.d.ts.map +1 -1
- package/dist/ai-service/context/app-context.js +9 -15
- package/dist/ai-service/context/app-context.js.map +1 -1
- package/dist/ai-service/index.d.ts +4 -4
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +168 -16
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/llm/impl/anthropic.d.ts.map +1 -1
- package/dist/ai-service/llm/impl/anthropic.js +1 -0
- package/dist/ai-service/llm/impl/anthropic.js.map +1 -1
- package/dist/ai-service/llm/impl/clark.d.ts.map +1 -1
- package/dist/ai-service/llm/impl/clark.js +1 -0
- package/dist/ai-service/llm/impl/clark.js.map +1 -1
- package/dist/ai-service/llm/provider.d.ts.map +1 -1
- package/dist/ai-service/llm/provider.js +1 -0
- package/dist/ai-service/llm/provider.js.map +1 -1
- package/dist/ai-service/llm/types.d.ts +1 -1
- package/dist/ai-service/llm/types.d.ts.map +1 -1
- package/dist/ai-service/prompt-builder-service/types.d.ts +0 -2
- package/dist/ai-service/prompt-builder-service/types.d.ts.map +1 -1
- package/dist/ai-service/prompt-builder-service/types.js.map +1 -1
- package/dist/ai-service/prompts/explain-code.d.ts +7 -0
- package/dist/ai-service/prompts/explain-code.d.ts.map +1 -0
- package/dist/ai-service/prompts/explain-code.js +23 -0
- package/dist/ai-service/prompts/explain-code.js.map +1 -0
- package/dist/ai-service/state-machine/clark-fsm.d.ts +0 -2
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +16 -16
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +39 -4
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/mocks.d.ts.map +1 -1
- package/dist/ai-service/state-machine/mocks.js +1 -0
- package/dist/ai-service/state-machine/mocks.js.map +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/orders-app.d.ts +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/orders-app.d.ts.map +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/orders-app.js +0 -7
- package/dist/ai-service/test-utils/app-generation-mocks/orders-app.js.map +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/smoketest.d.ts +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/smoketest.d.ts.map +1 -1
- package/dist/ai-service/test-utils/app-generation-mocks/smoketest.js +0 -8
- package/dist/ai-service/test-utils/app-generation-mocks/smoketest.js.map +1 -1
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.d.ts.map +1 -1
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.js +0 -15
- package/dist/ai-service/transform/api-builder/to-sdk-transformer.js.map +1 -1
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.d.ts.map +1 -1
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.js +0 -13
- package/dist/ai-service/transform/api-builder/to-yaml-transformer.js.map +1 -1
- package/dist/ai-service/types.d.ts +2 -2
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/util/json-stream-parser.d.ts +20 -0
- package/dist/ai-service/util/json-stream-parser.d.ts.map +1 -0
- package/dist/ai-service/util/json-stream-parser.js +139 -0
- package/dist/ai-service/util/json-stream-parser.js.map +1 -0
- package/dist/binding-extraction/extract-identifiers.d.ts +1 -5
- package/dist/binding-extraction/extract-identifiers.d.ts.map +1 -1
- package/dist/binding-extraction/extract-identifiers.js +78 -15
- package/dist/binding-extraction/extract-identifiers.js.map +1 -1
- package/dist/binding-extraction/index.d.ts +1 -1
- package/dist/binding-extraction/index.d.ts.map +1 -1
- package/dist/binding-extraction/index.js +1 -1
- package/dist/binding-extraction/index.js.map +1 -1
- package/dist/binding-extraction/{extract-js-identifiers.d.ts → js-identifiers.d.ts} +2 -1
- package/dist/binding-extraction/js-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/{extract-js-identifiers.js → js-identifiers.js} +81 -1
- package/dist/binding-extraction/js-identifiers.js.map +1 -0
- package/dist/binding-extraction/python-identifiers.d.ts +13 -0
- package/dist/binding-extraction/python-identifiers.d.ts.map +1 -0
- package/dist/binding-extraction/{extract-py-identifiers.js → python-identifiers.js} +155 -1
- package/dist/binding-extraction/python-identifiers.js.map +1 -0
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +9 -15
- package/dist/codegen.js.map +1 -1
- package/dist/components-manager.d.ts +12 -13
- package/dist/components-manager.d.ts.map +1 -1
- package/dist/components-manager.js +78 -139
- package/dist/components-manager.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +140 -361
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-helpers.d.ts +2 -2
- package/dist/file-system-helpers.d.ts.map +1 -1
- package/dist/file-system-helpers.js +6 -4
- package/dist/file-system-helpers.js.map +1 -1
- package/dist/file-system-manager.d.ts +8 -33
- package/dist/file-system-manager.d.ts.map +1 -1
- package/dist/file-system-manager.js +217 -600
- package/dist/file-system-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/inject-no-select.d.ts +15 -0
- package/dist/inject-no-select.d.ts.map +1 -0
- package/dist/inject-no-select.js +173 -0
- package/dist/inject-no-select.js.map +1 -0
- package/dist/injected-index.d.ts +0 -1
- package/dist/injected-index.d.ts.map +1 -1
- package/dist/injected-index.js +0 -1
- package/dist/injected-index.js.map +1 -1
- package/dist/lock-service/activity-tracker.d.ts.map +1 -1
- package/dist/lock-service/activity-tracker.js +4 -1
- package/dist/lock-service/activity-tracker.js.map +1 -1
- package/dist/parsing/entity/to-code-entity.d.ts.map +1 -1
- package/dist/parsing/entity/to-code-entity.js +3 -4
- package/dist/parsing/entity/to-code-entity.js.map +1 -1
- package/dist/parsing/entity/to-value-entity.d.ts.map +1 -1
- package/dist/parsing/entity/to-value-entity.js +19 -13
- package/dist/parsing/entity/to-value-entity.js.map +1 -1
- package/dist/parsing/ids.d.ts +0 -1
- package/dist/parsing/ids.d.ts.map +1 -1
- package/dist/parsing/ids.js +3 -4
- package/dist/parsing/ids.js.map +1 -1
- package/dist/parsing/imports.d.ts.map +1 -1
- package/dist/parsing/imports.js +0 -10
- package/dist/parsing/imports.js.map +1 -1
- package/dist/parsing/index.d.ts +0 -1
- package/dist/parsing/index.d.ts.map +1 -1
- package/dist/parsing/index.js +0 -1
- package/dist/parsing/index.js.map +1 -1
- package/dist/parsing/jsx.d.ts.map +1 -1
- package/dist/parsing/jsx.js +50 -22
- package/dist/parsing/jsx.js.map +1 -1
- package/dist/parsing/page.d.ts +0 -1
- package/dist/parsing/page.d.ts.map +1 -1
- package/dist/parsing/page.js +55 -32
- package/dist/parsing/page.js.map +1 -1
- package/dist/parsing/properties.d.ts.map +1 -1
- package/dist/parsing/properties.js +45 -15
- package/dist/parsing/properties.js.map +1 -1
- package/dist/parsing/template/index.js +1 -1
- package/dist/parsing/template/index.js.map +1 -1
- package/dist/parsing/template/to-code-template.d.ts +1 -2
- package/dist/parsing/template/to-code-template.d.ts.map +1 -1
- package/dist/parsing/template/to-code-template.js +2 -3
- package/dist/parsing/template/to-code-template.js.map +1 -1
- package/dist/parsing/type-parsing-registry.d.ts +0 -1
- package/dist/parsing/type-parsing-registry.d.ts.map +1 -1
- package/dist/parsing/type-parsing-registry.js +0 -2
- package/dist/parsing/type-parsing-registry.js.map +1 -1
- package/dist/parsing/util.d.ts.map +1 -1
- package/dist/parsing/util.js +22 -5
- package/dist/parsing/util.js.map +1 -1
- package/dist/plugin-options.d.ts +8 -1
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/plugin-options.js.map +1 -1
- package/dist/refactor/javascript.js +1 -1
- package/dist/refactor/javascript.js.map +1 -1
- package/dist/rename-manager.d.ts.map +1 -1
- package/dist/rename-manager.js +1 -2
- package/dist/rename-manager.js.map +1 -1
- package/dist/router-parser.d.ts +35 -0
- package/dist/router-parser.d.ts.map +1 -0
- package/dist/router-parser.js +490 -0
- package/dist/router-parser.js.map +1 -0
- package/dist/socket-manager.d.ts +3 -3
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +14 -15
- package/dist/socket-manager.js.map +1 -1
- package/dist/source-tracker.d.ts +9 -77
- package/dist/source-tracker.d.ts.map +1 -1
- package/dist/source-tracker.js +84 -375
- package/dist/source-tracker.js.map +1 -1
- package/dist/util/operation-queue.d.ts +3 -0
- package/dist/util/operation-queue.d.ts.map +1 -1
- package/dist/util/operation-queue.js +5 -0
- package/dist/util/operation-queue.js.map +1 -1
- package/dist/util.d.ts +13 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +49 -28
- package/dist/util.js.map +1 -1
- package/dist/vite-plugin-yaml-types.d.ts +9 -0
- package/dist/vite-plugin-yaml-types.d.ts.map +1 -0
- package/dist/vite-plugin-yaml-types.js +114 -0
- package/dist/vite-plugin-yaml-types.js.map +1 -0
- package/package.json +8 -7
- package/dist/ai-service/agent/tools/build-add-event.d.ts +0 -14
- package/dist/ai-service/agent/tools/build-add-event.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-add-event.js +0 -44
- package/dist/ai-service/agent/tools/build-add-event.js.map +0 -1
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts +0 -16
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-add-state-var.js +0 -62
- package/dist/ai-service/agent/tools/build-add-state-var.js.map +0 -1
- package/dist/ai-service/agent/tools/build-add-timer.d.ts +0 -16
- package/dist/ai-service/agent/tools/build-add-timer.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-add-timer.js +0 -46
- package/dist/ai-service/agent/tools/build-add-timer.js.map +0 -1
- package/dist/ai-service/agent/tools/build-create-page.d.ts +0 -10
- package/dist/ai-service/agent/tools/build-create-page.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-create-page.js +0 -57
- package/dist/ai-service/agent/tools/build-create-page.js.map +0 -1
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts +0 -9
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-list-available-components.js +0 -55
- package/dist/ai-service/agent/tools/build-list-available-components.js.map +0 -1
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts +0 -9
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-register-component-name.js +0 -53
- package/dist/ai-service/agent/tools/build-register-component-name.js.map +0 -1
- package/dist/ai-service/agent/tools/build-rename-page.d.ts +0 -9
- package/dist/ai-service/agent/tools/build-rename-page.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-rename-page.js +0 -50
- package/dist/ai-service/agent/tools/build-rename-page.js.map +0 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts +0 -25
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.js +0 -266
- package/dist/ai-service/agent/tools/build-set-api-triggers.js.map +0 -1
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts +0 -16
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/build-update-state-var.js +0 -67
- package/dist/ai-service/agent/tools/build-update-state-var.js.map +0 -1
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts +0 -20
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/study-current-app-state.js +0 -20
- package/dist/ai-service/agent/tools/study-current-app-state.js.map +0 -1
- package/dist/binding-extraction/extract-js-identifiers.d.ts.map +0 -1
- package/dist/binding-extraction/extract-js-identifiers.js.map +0 -1
- package/dist/binding-extraction/extract-py-identifiers.d.ts +0 -4
- package/dist/binding-extraction/extract-py-identifiers.d.ts.map +0 -1
- package/dist/binding-extraction/extract-py-identifiers.js.map +0 -1
- package/dist/component-docs-service/index.d.ts +0 -37
- package/dist/component-docs-service/index.d.ts.map +0 -1
- package/dist/component-docs-service/index.js +0 -118
- package/dist/component-docs-service/index.js.map +0 -1
- package/dist/parsing/events/index.d.ts +0 -5
- package/dist/parsing/events/index.d.ts.map +0 -1
- package/dist/parsing/events/index.js +0 -7
- package/dist/parsing/events/index.js.map +0 -1
- package/dist/parsing/events/to-code-events.d.ts +0 -3
- package/dist/parsing/events/to-code-events.d.ts.map +0 -1
- package/dist/parsing/events/to-code-events.js +0 -147
- package/dist/parsing/events/to-code-events.js.map +0 -1
- package/dist/parsing/events/to-value-events.d.ts +0 -10
- package/dist/parsing/events/to-value-events.d.ts.map +0 -1
- package/dist/parsing/events/to-value-events.js +0 -473
- package/dist/parsing/events/to-value-events.js.map +0 -1
- package/dist/parsing/scope.d.ts +0 -103
- package/dist/parsing/scope.d.ts.map +0 -1
- package/dist/parsing/scope.js +0 -902
- package/dist/parsing/scope.js.map +0 -1
- package/dist/routing.d.ts +0 -6
- package/dist/routing.d.ts.map +0 -1
- package/dist/routing.js +0 -169
- package/dist/routing.js.map +0 -1
- package/dist/sb-scope-manager.d.ts +0 -121
- package/dist/sb-scope-manager.d.ts.map +0 -1
- package/dist/sb-scope-manager.js +0 -678
- package/dist/sb-scope-manager.js.map +0 -1
package/dist/parsing/scope.js
DELETED
|
@@ -1,902 +0,0 @@
|
|
|
1
|
-
import { parse } from "@babel/parser";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
import { getStableEntityId, getStableScopeId, } from "@superblocksteam/library-shared";
|
|
4
|
-
import { SbEntityType } from "@superblocksteam/library-shared/types";
|
|
5
|
-
import { getPropertyExpression } from "../codegen.js";
|
|
6
|
-
import { renameEntityInJavascript } from "../refactor/javascript.js";
|
|
7
|
-
import { traverse } from "../traverse.js";
|
|
8
|
-
import { parser as entityParser } from "./entity/index.js";
|
|
9
|
-
import { getSbElementId, setSbElementId, supplementElementIds } from "./ids.js";
|
|
10
|
-
import { REQUIRED_IMPORTS_BY_PROPERTY_TYPE } from "./imports.js";
|
|
11
|
-
import { getIdentiferName, isSbScopeFunction, nodeToValue, extractNameFromBindAttribute, } from "./util.js";
|
|
12
|
-
const importsByEntityType = {
|
|
13
|
-
[SbEntityType.VARIABLE]: [
|
|
14
|
-
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
15
|
-
{ importName: "StateVar", importPath: "@superblocksteam/library" },
|
|
16
|
-
{
|
|
17
|
-
importName: "StateVarPersistence",
|
|
18
|
-
importPath: "@superblocksteam/library",
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
[SbEntityType.TIMER]: [
|
|
22
|
-
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
23
|
-
{ importName: "Timer", importPath: "@superblocksteam/library" },
|
|
24
|
-
{ importName: "EventFlow", importPath: "@superblocksteam/library" },
|
|
25
|
-
],
|
|
26
|
-
[SbEntityType.EVENT]: [
|
|
27
|
-
{ importName: "SbEvent", importPath: "@superblocksteam/library" },
|
|
28
|
-
],
|
|
29
|
-
[SbEntityType.API]: [
|
|
30
|
-
{ importName: "SB", importPath: "@superblocksteam/library" },
|
|
31
|
-
{ importName: "SbApi", importPath: "@superblocksteam/library" },
|
|
32
|
-
{ importName: "EventFlow", importPath: "@superblocksteam/library" },
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Given an object property from a scope entry, like:
|
|
37
|
-
* pageSize: StateVar({
|
|
38
|
-
* defaultValue: "test ${Math.random()}",
|
|
39
|
-
* persistence: StateVarPersistence.TEMPORARY
|
|
40
|
-
* })
|
|
41
|
-
*
|
|
42
|
-
* Returns a reference to the object expression node
|
|
43
|
-
*/
|
|
44
|
-
function getConfigObject(node) {
|
|
45
|
-
const config = node.get("value");
|
|
46
|
-
if (!config.isCallExpression()) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const args = config.get("arguments");
|
|
50
|
-
if (args.length !== 1) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
const configObject = args[0];
|
|
54
|
-
if (!configObject?.isObjectExpression()) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return configObject;
|
|
58
|
-
}
|
|
59
|
-
export function updateEntityNode(node, updates, entityId) {
|
|
60
|
-
const entity = fromNodeToEntity(node, entityId);
|
|
61
|
-
if (!entity) {
|
|
62
|
-
throw new Error("Entity could not be created from node: " +
|
|
63
|
-
getIdentiferName(node.node.key));
|
|
64
|
-
}
|
|
65
|
-
const configObject = getConfigObject(node);
|
|
66
|
-
if (!configObject) {
|
|
67
|
-
return {
|
|
68
|
-
imports: [],
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
let imports = importsByEntityType[entity.type] ?? [];
|
|
72
|
-
for (const [key, info] of Object.entries(updates ?? {})) {
|
|
73
|
-
const property = configObject.get("properties").find((property) => {
|
|
74
|
-
return (property.isObjectProperty() &&
|
|
75
|
-
property.get("key").isIdentifier() &&
|
|
76
|
-
getIdentiferName(property.node.key) === key);
|
|
77
|
-
});
|
|
78
|
-
if (!property) {
|
|
79
|
-
configObject.pushContainer("properties", t.objectProperty(t.identifier(key), getPropertyExpression(info)));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
property.replaceWith(t.objectProperty(t.identifier(key), getPropertyExpression(info)));
|
|
83
|
-
}
|
|
84
|
-
if (info.type in REQUIRED_IMPORTS_BY_PROPERTY_TYPE) {
|
|
85
|
-
const requiredImports = REQUIRED_IMPORTS_BY_PROPERTY_TYPE[info.type];
|
|
86
|
-
if (requiredImports) {
|
|
87
|
-
imports = [...imports, ...requiredImports];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return { imports };
|
|
92
|
-
}
|
|
93
|
-
export function fromEntityToNode(entity) {
|
|
94
|
-
const imports = importsByEntityType[entity.type] ?? [];
|
|
95
|
-
const code = entityParser.toCode(entity);
|
|
96
|
-
const parsedEntity = parse(code, {
|
|
97
|
-
sourceType: "module",
|
|
98
|
-
plugins: ["typescript", "jsx"],
|
|
99
|
-
});
|
|
100
|
-
if (parsedEntity.program.body[0]?.type !== "ExpressionStatement") {
|
|
101
|
-
throw new Error("Invalid entity ast definition");
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
entity: t.objectProperty(t.identifier(entity.name), parsedEntity.program.body[0].expression),
|
|
105
|
-
imports,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
export function fromNodeToEntity(property, entityId) {
|
|
109
|
-
const entityName = nodeToValue(property.get("key").node);
|
|
110
|
-
const expression = property.get("value");
|
|
111
|
-
const id = entityId ?? getSbElementId(property.node);
|
|
112
|
-
return entityParser.toValue(expression, {
|
|
113
|
-
key: entityName,
|
|
114
|
-
id,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export function getScope(fileName, file) {
|
|
118
|
-
if (!file || !file.ast) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const ast = t.cloneNode(file.ast, true, false);
|
|
122
|
-
if (!ast) {
|
|
123
|
-
throw new Error("Failed to clone AST for file " + fileName);
|
|
124
|
-
}
|
|
125
|
-
try {
|
|
126
|
-
const scope = parseSbScopeDefinition(ast);
|
|
127
|
-
if (!scope) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const scopeId = scope.id;
|
|
131
|
-
supplementElementIds({ fileName, ast, shouldModifyAst: true, scopeId });
|
|
132
|
-
const entities = scope.scopeEntities?.get("properties").reduce((acc, property) => {
|
|
133
|
-
if (property.isObjectProperty()) {
|
|
134
|
-
const entity = fromNodeToEntity(property);
|
|
135
|
-
if (entity) {
|
|
136
|
-
acc[entity.name] = entity;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return acc;
|
|
140
|
-
}, {}) ?? {};
|
|
141
|
-
return {
|
|
142
|
-
entities: entities,
|
|
143
|
-
scopeName: scope.name,
|
|
144
|
-
scopeId: scope.id,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
catch (_e) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// sb scope utils
|
|
152
|
-
/**
|
|
153
|
-
* Builds a map of scope usages within files
|
|
154
|
-
* @param ast The AST to analyze
|
|
155
|
-
* @param filePath The path of the file being analyzed
|
|
156
|
-
* @param scopeDefinitions List of scope definitions (name and entities)
|
|
157
|
-
* @param scopeNameToScopeUsage Existing map to update (optional)
|
|
158
|
-
* @returns Updated map of scope usages
|
|
159
|
-
*/
|
|
160
|
-
export function buildScopeDestructuredUsageMap(ast, filePath, scopeNames, scopeNameToScopeUsage = {}) {
|
|
161
|
-
traverse(ast, {
|
|
162
|
-
// Look for variable declarations like: const { Entity1 } = ScopeName;
|
|
163
|
-
VariableDeclaration(path) {
|
|
164
|
-
const declarations = path.get("declarations");
|
|
165
|
-
for (const declaration of declarations) {
|
|
166
|
-
if (!declaration.isVariableDeclarator())
|
|
167
|
-
continue;
|
|
168
|
-
const id = declaration.get("id");
|
|
169
|
-
const init = declaration.get("init");
|
|
170
|
-
// Check if this is a destructuring assignment
|
|
171
|
-
if (id.isObjectPattern() && init.isIdentifier()) {
|
|
172
|
-
const scopeName = init.node.name;
|
|
173
|
-
// Check if the identifier is a known scope
|
|
174
|
-
if (scopeNames.has(scopeName)) {
|
|
175
|
-
// Initialize the nested structure if it doesn't exist
|
|
176
|
-
if (!scopeNameToScopeUsage[scopeName]) {
|
|
177
|
-
scopeNameToScopeUsage[scopeName] = {};
|
|
178
|
-
}
|
|
179
|
-
if (!scopeNameToScopeUsage[scopeName][filePath]) {
|
|
180
|
-
scopeNameToScopeUsage[scopeName][filePath] = [];
|
|
181
|
-
}
|
|
182
|
-
// Add this usage to the map
|
|
183
|
-
scopeNameToScopeUsage[scopeName][filePath].push(path);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
return scopeNameToScopeUsage;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Updates all scope usages to include the complete list of entity names
|
|
193
|
-
* @param scopeUsages Map of file paths to NodePaths where the scope is used
|
|
194
|
-
* @param entityNames Complete list of entity names to include in all usages
|
|
195
|
-
*/
|
|
196
|
-
export function updateScopeUsages(scopeUsages, entityNames) {
|
|
197
|
-
// Process each file's usages
|
|
198
|
-
Object.values(scopeUsages).forEach((usages) => {
|
|
199
|
-
usages.forEach((usage) => {
|
|
200
|
-
if (usage.isVariableDeclaration()) {
|
|
201
|
-
// Handle variable declarations: const { Entity1 } = Scope;
|
|
202
|
-
const declarations = usage.get("declarations");
|
|
203
|
-
for (const declaration of declarations) {
|
|
204
|
-
if (!declaration.isVariableDeclarator())
|
|
205
|
-
continue;
|
|
206
|
-
const id = declaration.get("id");
|
|
207
|
-
if (id.isObjectPattern()) {
|
|
208
|
-
// Preserve existing aliases when updating destructuring
|
|
209
|
-
const existingAliases = new Map();
|
|
210
|
-
id.node.properties.forEach((prop) => {
|
|
211
|
-
if (prop.type === "ObjectProperty" &&
|
|
212
|
-
!prop.computed &&
|
|
213
|
-
prop.key.type === "Identifier" &&
|
|
214
|
-
prop.value.type === "Identifier" &&
|
|
215
|
-
!prop.shorthand) {
|
|
216
|
-
existingAliases.set(prop.key.name, prop.value.name);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
const newProperties = entityNames.map((name) => {
|
|
220
|
-
const aliasName = existingAliases.get(name);
|
|
221
|
-
return aliasName
|
|
222
|
-
? t.objectProperty(t.identifier(name), t.identifier(aliasName), false, false)
|
|
223
|
-
: t.objectProperty(t.identifier(name), t.identifier(name), false, true);
|
|
224
|
-
});
|
|
225
|
-
id.node.properties = newProperties;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Adds scope destructuring and imports to a component based on a JSX element locator
|
|
234
|
-
* @param elementPath Path to the JSX element that serves as the locator
|
|
235
|
-
* @param scopeDef Scope definition containing name, entities, and file path
|
|
236
|
-
* @param componentFilePath Path to the component file (for relative import calculation)
|
|
237
|
-
* @returns The newly created destructuring node path or null if failed
|
|
238
|
-
*/
|
|
239
|
-
export function addScopeToComponent({ elementLocation, scopeDefinition, }) {
|
|
240
|
-
// Find the function component or class that contains this JSX element
|
|
241
|
-
const componentPath = findEnclosingComponent(elementLocation);
|
|
242
|
-
if (!componentPath) {
|
|
243
|
-
throw new Error("Could not find enclosing component for the JSX element");
|
|
244
|
-
}
|
|
245
|
-
return addScopeDestructuring(componentPath, scopeDefinition);
|
|
246
|
-
}
|
|
247
|
-
function findEnclosingComponent(elementPath) {
|
|
248
|
-
let currentPath = elementPath;
|
|
249
|
-
while (currentPath) {
|
|
250
|
-
// Check for component types
|
|
251
|
-
if (currentPath.isFunctionDeclaration() ||
|
|
252
|
-
currentPath.isArrowFunctionExpression() ||
|
|
253
|
-
currentPath.isFunctionExpression() ||
|
|
254
|
-
currentPath.isClassDeclaration()) {
|
|
255
|
-
return currentPath;
|
|
256
|
-
}
|
|
257
|
-
// Move up the tree
|
|
258
|
-
currentPath = currentPath.parentPath;
|
|
259
|
-
}
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Adds scope destructuring to the component body
|
|
264
|
-
* @param componentPath Path to the component declaration
|
|
265
|
-
* @param scopeDef Scope definition containing name and entities
|
|
266
|
-
* @returns The newly created destructuring node path or null if failed
|
|
267
|
-
*/
|
|
268
|
-
function addScopeDestructuring(componentPath, scopeDefinition) {
|
|
269
|
-
// Create the destructuring variable declaration
|
|
270
|
-
// const { Entity1, Entity2 } = ScopeName;
|
|
271
|
-
const uniqueEntityNames = [...new Set(scopeDefinition.entityNames)];
|
|
272
|
-
const destructuringDeclaration = t.variableDeclaration("const", [
|
|
273
|
-
t.variableDeclarator(t.objectPattern(uniqueEntityNames.map((name) => t.objectProperty(t.identifier(name), t.identifier(name), false, // computed
|
|
274
|
-
true))), t.identifier(scopeDefinition.name)),
|
|
275
|
-
]);
|
|
276
|
-
let addedNodePath = null;
|
|
277
|
-
if (componentPath.isFunctionDeclaration() ||
|
|
278
|
-
componentPath.isFunctionExpression() ||
|
|
279
|
-
componentPath.isArrowFunctionExpression()) {
|
|
280
|
-
// For function components, add at the start of the function body
|
|
281
|
-
let body = componentPath.get("body");
|
|
282
|
-
if (Array.isArray(body)) {
|
|
283
|
-
body = body[0];
|
|
284
|
-
if (!body)
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
body = body;
|
|
288
|
-
if (body.isBlockStatement()) {
|
|
289
|
-
// Function with block body: function Component() { ... }
|
|
290
|
-
const [newPath] = body.unshiftContainer("body", destructuringDeclaration);
|
|
291
|
-
addedNodePath = newPath;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
// Arrow function with expression body: () => <div />
|
|
295
|
-
// Need to convert to block body first
|
|
296
|
-
const retStatement = t.returnStatement(body.node);
|
|
297
|
-
componentPath.node.body = t.blockStatement([
|
|
298
|
-
destructuringDeclaration,
|
|
299
|
-
retStatement,
|
|
300
|
-
]);
|
|
301
|
-
// Get the path to the newly added node
|
|
302
|
-
const blockBody = componentPath.get("body");
|
|
303
|
-
addedNodePath = blockBody.get("body")[0];
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
else if (componentPath.isClassDeclaration()) {
|
|
307
|
-
// For class components, add to the render method
|
|
308
|
-
const renderMethod = findRenderMethod(componentPath);
|
|
309
|
-
if (renderMethod) {
|
|
310
|
-
const renderBody = renderMethod.get("body");
|
|
311
|
-
const [newPath] = renderBody.unshiftContainer("body", destructuringDeclaration);
|
|
312
|
-
addedNodePath = newPath;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return addedNodePath;
|
|
316
|
-
}
|
|
317
|
-
function findRenderMethod(classPath) {
|
|
318
|
-
const body = classPath.get("body");
|
|
319
|
-
const methods = body.get("body");
|
|
320
|
-
for (const method of methods) {
|
|
321
|
-
if (method.isClassMethod() &&
|
|
322
|
-
method.node.kind === "method" &&
|
|
323
|
-
method.get("key").isIdentifier() &&
|
|
324
|
-
method.get("key").node.name === "render") {
|
|
325
|
-
return method;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
export function isComponentAlreadyUsingScope(elementLocation, usagesInFile) {
|
|
331
|
-
// Check if we have usage data for this scope and file
|
|
332
|
-
if (!usagesInFile?.length) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
// Find the component that contains this JSX element
|
|
336
|
-
const componentPath = findEnclosingComponent(elementLocation);
|
|
337
|
-
if (!componentPath) {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
// Check if any of the usages are within the same component
|
|
341
|
-
for (const usage of usagesInFile) {
|
|
342
|
-
// Find the component containing this usage
|
|
343
|
-
let currentPath = usage;
|
|
344
|
-
let usageComponentPath = null;
|
|
345
|
-
// Traverse up the tree to find the containing component
|
|
346
|
-
while (currentPath) {
|
|
347
|
-
if (currentPath.isFunctionDeclaration() ||
|
|
348
|
-
currentPath.isArrowFunctionExpression() ||
|
|
349
|
-
currentPath.isFunctionExpression() ||
|
|
350
|
-
currentPath.isClassDeclaration()) {
|
|
351
|
-
usageComponentPath = currentPath;
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
currentPath = currentPath.parentPath;
|
|
355
|
-
}
|
|
356
|
-
// If the usage is in the same component, return true
|
|
357
|
-
if (usageComponentPath && usageComponentPath === componentPath) {
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
/*
|
|
364
|
-
Example code:
|
|
365
|
-
export const Page1Scope = createScope<
|
|
366
|
-
{component: any}
|
|
367
|
-
>( ({ entities: { component, count } }: { entities: { component, count } }) => ({
|
|
368
|
-
count: StateVar({ defaultValue: 0 }),
|
|
369
|
-
}),
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
export const Page1 = Page1Scope.entities;
|
|
373
|
-
|
|
374
|
-
SBDefintiion:
|
|
375
|
-
- name: Page1
|
|
376
|
-
- entityNames: ["count", "component"]
|
|
377
|
-
- scopeEntities: {count: SBVariable({defaultValue: 0})} (nodepath)
|
|
378
|
-
- scopeComponents: { component: any} (nodePath)
|
|
379
|
-
- destructuredEntitiesParam: { component, count } (nodePath)
|
|
380
|
-
- scopeFunction: ({ entities }: { component, count }) => {
|
|
381
|
-
count: StateVar({ defaultValue: 0 }),
|
|
382
|
-
} (nodePath)
|
|
383
|
-
*/
|
|
384
|
-
export function parseSbScopeDefinition(ast) {
|
|
385
|
-
let scopeName = null;
|
|
386
|
-
let scopeScopeName = null; // e.g., "Page1Scope"
|
|
387
|
-
const entityNames = [];
|
|
388
|
-
let mainNode = null;
|
|
389
|
-
let scopeEntities = null;
|
|
390
|
-
let scopeComponents = null;
|
|
391
|
-
let destructuredEntitiesParam = null;
|
|
392
|
-
let scopeFunction = null;
|
|
393
|
-
const scopeNameToEntityId = {};
|
|
394
|
-
let scopeId = null;
|
|
395
|
-
// Helper function to extract entity names and IDs from object expression
|
|
396
|
-
function extractEntityNamesFromObject(objExpr) {
|
|
397
|
-
const properties = objExpr.get("properties");
|
|
398
|
-
properties.forEach((prop) => {
|
|
399
|
-
if (prop.isObjectProperty() && prop.node.key.type === "Identifier") {
|
|
400
|
-
const name = getIdentiferName(prop.node.key);
|
|
401
|
-
if (!name) {
|
|
402
|
-
console.warn("Could not find name for entity");
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
// Add to entityNames if not already present
|
|
406
|
-
if (!entityNames.includes(name)) {
|
|
407
|
-
entityNames.push(name);
|
|
408
|
-
}
|
|
409
|
-
let entityId = getSbElementId(prop.node);
|
|
410
|
-
if (!entityId) {
|
|
411
|
-
entityId = getStableEntityId(scopeId, name);
|
|
412
|
-
setSbElementId(prop.node, entityId);
|
|
413
|
-
}
|
|
414
|
-
if (entityId) {
|
|
415
|
-
scopeNameToEntityId[name] = entityId;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
// Helper function to find and process the returned object expression
|
|
421
|
-
function findReturnedObject(functionPath) {
|
|
422
|
-
const body = functionPath.get("body");
|
|
423
|
-
if (body.isObjectExpression()) {
|
|
424
|
-
// Arrow function with expression body: () => ({})
|
|
425
|
-
scopeEntities = body;
|
|
426
|
-
extractEntityNamesFromObject(body);
|
|
427
|
-
}
|
|
428
|
-
else if (body.isBlockStatement()) {
|
|
429
|
-
// Function with block body: () => { return {}; } or function() { return {}; }
|
|
430
|
-
body.traverse({
|
|
431
|
-
ReturnStatement(returnPath) {
|
|
432
|
-
const argument = returnPath.get("argument");
|
|
433
|
-
if (argument.isObjectExpression()) {
|
|
434
|
-
scopeEntities = argument;
|
|
435
|
-
extractEntityNamesFromObject(argument);
|
|
436
|
-
}
|
|
437
|
-
},
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
// First pass: Find scope definition and extract name from options, plus export declaration
|
|
442
|
-
traverse(ast, {
|
|
443
|
-
ExportNamedDeclaration(path) {
|
|
444
|
-
const declaration = path.get("declaration");
|
|
445
|
-
if (!declaration.isVariableDeclaration())
|
|
446
|
-
return;
|
|
447
|
-
const declarations = declaration.get("declarations");
|
|
448
|
-
for (const varDeclarator of declarations) {
|
|
449
|
-
if (!varDeclarator.isVariableDeclarator())
|
|
450
|
-
continue;
|
|
451
|
-
const id = varDeclarator.get("id");
|
|
452
|
-
const init = varDeclarator.get("init");
|
|
453
|
-
// Check if this is the entities export (e.g., export const Page1 = Page1Scope.entities)
|
|
454
|
-
if (id.isIdentifier() &&
|
|
455
|
-
init.isMemberExpression() &&
|
|
456
|
-
init.get("property").isIdentifier()) {
|
|
457
|
-
const property = init.get("property");
|
|
458
|
-
if (property.isIdentifier() && property.node.name === "entities") {
|
|
459
|
-
const object = init.get("object");
|
|
460
|
-
if (object.isIdentifier()) {
|
|
461
|
-
// Found the entities export, extract the page name from the left side of the assignment
|
|
462
|
-
scopeName = id.node.name;
|
|
463
|
-
scopeScopeName = object.node.name;
|
|
464
|
-
scopeId = getStableScopeId(scopeName);
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
VariableDeclaration(path) {
|
|
472
|
-
// Look for createScope calls to extract name from options
|
|
473
|
-
const declarations = path.get("declarations");
|
|
474
|
-
for (const varDeclarator of declarations) {
|
|
475
|
-
if (!varDeclarator.isVariableDeclarator())
|
|
476
|
-
continue;
|
|
477
|
-
const id = varDeclarator.get("id");
|
|
478
|
-
const init = varDeclarator.get("init");
|
|
479
|
-
if (!id.isIdentifier() ||
|
|
480
|
-
!init.isCallExpression() ||
|
|
481
|
-
!init.get("callee").isIdentifier()) {
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
const callee = init.get("callee");
|
|
485
|
-
if (!callee.isIdentifier() || !isSbScopeFunction(callee.node.name)) {
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
// Check if this matches our scope name (if we found one)
|
|
489
|
-
if (scopeScopeName && id.node.name !== scopeScopeName) {
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
// Extract name from options object (second argument)
|
|
493
|
-
if (init.node.arguments.length <= 1) {
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
const args = init.get("arguments");
|
|
497
|
-
const optionsArg = args[1];
|
|
498
|
-
if (!optionsArg || !optionsArg.isObjectExpression()) {
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
const properties = optionsArg.get("properties");
|
|
502
|
-
const nameProperty = properties.find((prop) => {
|
|
503
|
-
if (prop.isObjectProperty() && prop.get("key").isIdentifier()) {
|
|
504
|
-
return prop.get("key").node.name === "name";
|
|
505
|
-
}
|
|
506
|
-
return false;
|
|
507
|
-
});
|
|
508
|
-
if (!nameProperty || !nameProperty.isObjectProperty()) {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
const value = nameProperty.get("value");
|
|
512
|
-
if (!value.isStringLiteral()) {
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
scopeName = value.node.value;
|
|
516
|
-
scopeId = getStableScopeId(scopeName);
|
|
517
|
-
// If we haven't found the scope name yet, use this one
|
|
518
|
-
if (!scopeScopeName) {
|
|
519
|
-
scopeScopeName = id.node.name;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
});
|
|
524
|
-
// Second pass: Find the scope definition and extract entity names
|
|
525
|
-
if (scopeName && scopeScopeName && scopeId) {
|
|
526
|
-
traverse(ast, {
|
|
527
|
-
VariableDeclaration(path) {
|
|
528
|
-
const declarations = path.get("declarations");
|
|
529
|
-
for (const varDeclarator of declarations) {
|
|
530
|
-
if (!varDeclarator.isVariableDeclarator())
|
|
531
|
-
continue;
|
|
532
|
-
const id = varDeclarator.get("id");
|
|
533
|
-
const init = varDeclarator.get("init");
|
|
534
|
-
if (id.isIdentifier() && id.node.name === scopeScopeName) {
|
|
535
|
-
if (init.isCallExpression() && init.get("callee").isIdentifier()) {
|
|
536
|
-
const callee = init.get("callee");
|
|
537
|
-
if (callee.isIdentifier() &&
|
|
538
|
-
isSbScopeFunction(callee.node.name)) {
|
|
539
|
-
// Extract entity names from the type parameters
|
|
540
|
-
if (init.node.typeParameters) {
|
|
541
|
-
const typeParameters = init.get("typeParameters");
|
|
542
|
-
if (typeParameters.isTSTypeParameterInstantiation() &&
|
|
543
|
-
typeParameters.node.params.length > 0) {
|
|
544
|
-
const typeParams = typeParameters.get("params");
|
|
545
|
-
if (typeParams.length > 0) {
|
|
546
|
-
const typeParam = typeParams[0];
|
|
547
|
-
if (typeParam && typeParam.isTSTypeLiteral()) {
|
|
548
|
-
const members = typeParam.get("members");
|
|
549
|
-
members.forEach((member) => {
|
|
550
|
-
if (member.isTSPropertySignature() &&
|
|
551
|
-
member.get("key").isIdentifier()) {
|
|
552
|
-
const key = member.get("key");
|
|
553
|
-
if (key.isIdentifier()) {
|
|
554
|
-
entityNames.push(key.node.name);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
// Store reference to the type literal node for components
|
|
559
|
-
scopeComponents = typeParam;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
// Extract entity names from the function argument
|
|
565
|
-
if (init.node.arguments.length > 0) {
|
|
566
|
-
const args = init.get("arguments");
|
|
567
|
-
if (args.length > 0) {
|
|
568
|
-
const funcArg = args[0];
|
|
569
|
-
// Handle both arrow functions and regular functions
|
|
570
|
-
if (funcArg &&
|
|
571
|
-
(funcArg.isArrowFunctionExpression() ||
|
|
572
|
-
funcArg.isFunctionExpression())) {
|
|
573
|
-
scopeFunction = funcArg;
|
|
574
|
-
// Handle parameters
|
|
575
|
-
const params = funcArg.get("params");
|
|
576
|
-
if (params &&
|
|
577
|
-
Array.isArray(params) &&
|
|
578
|
-
params.length > 0) {
|
|
579
|
-
const param = params[0];
|
|
580
|
-
if (param && param.isObjectPattern()) {
|
|
581
|
-
destructuredEntitiesParam = param;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
// Find and process the returned object
|
|
585
|
-
findReturnedObject(funcArg);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
// Set mainNode to the createScope call expression
|
|
590
|
-
mainNode = init;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
},
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
if (!scopeName || !mainNode || !scopeId || !scopeFunction || !scopeEntities) {
|
|
599
|
-
console.error("Failed to parse scope definition: missing required elements for scope creation", { scopeName, mainNode, scopeId, scopeFunction, scopeEntities });
|
|
600
|
-
throw new Error("Failed to parse scope definition: missing required elements for scope creation");
|
|
601
|
-
}
|
|
602
|
-
// Remove duplicates from entityNames if any
|
|
603
|
-
const uniqueEntityNames = [...new Set(entityNames)];
|
|
604
|
-
return {
|
|
605
|
-
name: scopeName,
|
|
606
|
-
entityNames: uniqueEntityNames,
|
|
607
|
-
mainNode,
|
|
608
|
-
scopeEntities,
|
|
609
|
-
scopeComponents,
|
|
610
|
-
id: scopeId,
|
|
611
|
-
scopeNameToEntityId,
|
|
612
|
-
destructuredEntitiesParam,
|
|
613
|
-
scopeFunction,
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* This will rename a scope variable declaration in a scope file and the entities export that
|
|
618
|
-
* references it.
|
|
619
|
-
*/
|
|
620
|
-
export function renameScopeVariableDeclaration(oldName, newName, ast) {
|
|
621
|
-
traverse(ast, {
|
|
622
|
-
ExportNamedDeclaration(path) {
|
|
623
|
-
const declaration = path.get("declaration");
|
|
624
|
-
if (!declaration.isVariableDeclaration()) {
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
const declarations = declaration.get("declarations");
|
|
628
|
-
for (const varDeclarator of declarations) {
|
|
629
|
-
if (!varDeclarator.isVariableDeclarator()) {
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
const id = varDeclarator.get("id");
|
|
633
|
-
if (!id.isIdentifier()) {
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
const name = getIdentiferName(id.node);
|
|
637
|
-
if (name === oldName) {
|
|
638
|
-
id.replaceWith(t.identifier(newName));
|
|
639
|
-
}
|
|
640
|
-
if (name === `${oldName}Scope`) {
|
|
641
|
-
id.replaceWith(t.identifier(`${newName}Scope`));
|
|
642
|
-
}
|
|
643
|
-
renameEntityInJavascript({
|
|
644
|
-
oldName: `${oldName}Scope`,
|
|
645
|
-
newName: `${newName}Scope`,
|
|
646
|
-
nodePath: path,
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* This will update the "name" in our scope options object, but will fall back
|
|
654
|
-
* to creating one if it doesn't exist (unnamed scopes)
|
|
655
|
-
*/
|
|
656
|
-
export function updateScopeNameInOptions(scopeDefinition, newName) {
|
|
657
|
-
const mainNode = scopeDefinition.mainNode;
|
|
658
|
-
const args = mainNode.get("arguments");
|
|
659
|
-
if (args.length >= 2) {
|
|
660
|
-
const optionsArg = args[1];
|
|
661
|
-
if (optionsArg?.isObjectExpression()) {
|
|
662
|
-
const properties = optionsArg.get("properties");
|
|
663
|
-
const nameProperty = properties.find((prop) => {
|
|
664
|
-
if (prop.isObjectProperty() && prop.get("key").isIdentifier()) {
|
|
665
|
-
const key = prop.get("key");
|
|
666
|
-
return key.isIdentifier() && key.node.name === "name";
|
|
667
|
-
}
|
|
668
|
-
return false;
|
|
669
|
-
});
|
|
670
|
-
if (nameProperty && nameProperty.isObjectProperty()) {
|
|
671
|
-
nameProperty.get("value").replaceWith(t.stringLiteral(newName));
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
const newNameProperty = t.objectProperty(t.identifier("name"), t.stringLiteral(newName));
|
|
675
|
-
optionsArg.pushContainer("properties", newNameProperty);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
else if (args.length === 1) {
|
|
680
|
-
const optionsObject = t.objectExpression([
|
|
681
|
-
t.objectProperty(t.identifier("name"), t.stringLiteral(newName)),
|
|
682
|
-
]);
|
|
683
|
-
mainNode.pushContainer("arguments", optionsObject);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
function toPascalCase(name) {
|
|
687
|
-
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
688
|
-
}
|
|
689
|
-
// Find the registerPage call and rename the component if it contains the old page name
|
|
690
|
-
function renamePageComponent(oldName, newName, nodePath) {
|
|
691
|
-
traverse(nodePath.node, {
|
|
692
|
-
CallExpression(path) {
|
|
693
|
-
if (path.node.callee.type === "Identifier" &&
|
|
694
|
-
path.node.callee.name === "registerPage") {
|
|
695
|
-
const args = path.node.arguments;
|
|
696
|
-
if (args.length > 0 && args[0]?.type === "Identifier") {
|
|
697
|
-
const componentName = args[0].name;
|
|
698
|
-
const oldNameLower = oldName.toLowerCase();
|
|
699
|
-
const componentNameLower = componentName.toLowerCase();
|
|
700
|
-
if (componentNameLower.includes(oldNameLower)) {
|
|
701
|
-
const newComponentName = componentName.replace(new RegExp(escapeRegExp(oldName), "gi"), (match) => {
|
|
702
|
-
if (match.charAt(0) === match.charAt(0).toUpperCase()) {
|
|
703
|
-
return toPascalCase(newName);
|
|
704
|
-
}
|
|
705
|
-
else {
|
|
706
|
-
return newName.toLowerCase();
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
renameEntityInJavascript({
|
|
710
|
-
oldName: componentName,
|
|
711
|
-
newName: newComponentName,
|
|
712
|
-
nodePath,
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
path.stop();
|
|
717
|
-
}
|
|
718
|
-
},
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
// Escape special regex characters in a string
|
|
722
|
-
function escapeRegExp(string) {
|
|
723
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* This will update the imports in the page file to use the new scope name
|
|
727
|
-
*/
|
|
728
|
-
export function updateScopeImports(oldName, newName, ast) {
|
|
729
|
-
// its so much easier to just delete and re-add the import
|
|
730
|
-
traverse(ast, {
|
|
731
|
-
ImportDeclaration(path) {
|
|
732
|
-
const source = path.get("source");
|
|
733
|
-
if (source.isStringLiteral() &&
|
|
734
|
-
/^\.\/scope(\.ts)?$/.test(source.node.value)) {
|
|
735
|
-
path.replaceWith(t.importDeclaration([
|
|
736
|
-
t.importSpecifier(t.identifier(newName), t.identifier(newName)),
|
|
737
|
-
t.importSpecifier(t.identifier(`${newName}Scope`), t.identifier(`${newName}Scope`)),
|
|
738
|
-
], t.stringLiteral(`./scope`)));
|
|
739
|
-
path.stop();
|
|
740
|
-
}
|
|
741
|
-
},
|
|
742
|
-
Program: {
|
|
743
|
-
exit(path) {
|
|
744
|
-
renameEntityInJavascript({
|
|
745
|
-
oldName: oldName,
|
|
746
|
-
newName: newName,
|
|
747
|
-
nodePath: path,
|
|
748
|
-
});
|
|
749
|
-
renameEntityInJavascript({
|
|
750
|
-
oldName: `${oldName}Scope`,
|
|
751
|
-
newName: `${newName}Scope`,
|
|
752
|
-
nodePath: path,
|
|
753
|
-
});
|
|
754
|
-
renamePageComponent(oldName, newName, path);
|
|
755
|
-
},
|
|
756
|
-
},
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
export function findBindComponentsInScopeUsage(usage) {
|
|
760
|
-
const componentPath = findEnclosingComponent(usage);
|
|
761
|
-
if (!componentPath) {
|
|
762
|
-
return [];
|
|
763
|
-
}
|
|
764
|
-
const allBindNames = findBindNamesInComponentPath(componentPath);
|
|
765
|
-
return allBindNames;
|
|
766
|
-
}
|
|
767
|
-
function findBindNamesInComponentPath(componentPath) {
|
|
768
|
-
const bindNames = [];
|
|
769
|
-
componentPath.traverse({
|
|
770
|
-
JSXElement(path) {
|
|
771
|
-
const bindAttribute = path
|
|
772
|
-
.get("openingElement")
|
|
773
|
-
.get("attributes")
|
|
774
|
-
.find((n) => n.isJSXAttribute() && getIdentiferName(n.node.name) === "bind");
|
|
775
|
-
if (bindAttribute) {
|
|
776
|
-
const bindName = extractNameFromBindAttribute(bindAttribute.node, true);
|
|
777
|
-
if (bindName) {
|
|
778
|
-
bindNames.push(bindName);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
},
|
|
782
|
-
});
|
|
783
|
-
return bindNames;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Creates an empty scope definition with the given scope name.
|
|
787
|
-
* This generates a minimal scope with no entities or components and returns the parsed definition.
|
|
788
|
-
* Useful as a fallback when components are missing and need to be initialized.
|
|
789
|
-
*
|
|
790
|
-
* @param scopeName - The name of the scope (e.g., "Page1")
|
|
791
|
-
* @returns A parsed SbScopeDefinition with empty entities and components
|
|
792
|
-
*/
|
|
793
|
-
export function createEmptyScopeDefinition(scopeName) {
|
|
794
|
-
const code = `const ${scopeName}Scope = createScope<{}>(() => ({}));
|
|
795
|
-
export const ${scopeName} = ${scopeName}Scope.entities;`;
|
|
796
|
-
const ast = parse(code, {
|
|
797
|
-
sourceType: "module",
|
|
798
|
-
plugins: ["typescript", "jsx"],
|
|
799
|
-
});
|
|
800
|
-
return parseSbScopeDefinition(ast);
|
|
801
|
-
}
|
|
802
|
-
/**
|
|
803
|
-
* Adds type parameters to an existing createScope call if they don't exist.
|
|
804
|
-
* This function modifies the AST directly by adding a TypeScript type parameter
|
|
805
|
-
* to the createScope call expression.
|
|
806
|
-
*
|
|
807
|
-
* @param scopeDefinition - The scope definition containing the AST nodes
|
|
808
|
-
* @returns The scope definition with type parameters added (modifies the scope definition in place)
|
|
809
|
-
*/
|
|
810
|
-
export function addTypeParametersToScope(scopeDefinition) {
|
|
811
|
-
// Get the createScope call expression
|
|
812
|
-
const mainPath = scopeDefinition.mainNode;
|
|
813
|
-
// Check if type parameters already exist
|
|
814
|
-
if (mainPath.node.typeParameters) {
|
|
815
|
-
const typeParams = mainPath.node.typeParameters.params;
|
|
816
|
-
if (typeParams.length > 0 && t.isTSTypeLiteral(typeParams[0])) {
|
|
817
|
-
return scopeDefinition;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
const emptyScope = createEmptyScopeDefinition(scopeDefinition.name);
|
|
821
|
-
const typeParameterInstantiation = emptyScope.mainNode.node.typeParameters;
|
|
822
|
-
// Add type parameters to the AST
|
|
823
|
-
mainPath.node.typeParameters = typeParameterInstantiation;
|
|
824
|
-
// Add the type literal to the scope definition
|
|
825
|
-
scopeDefinition.scopeComponents = emptyScope.scopeComponents;
|
|
826
|
-
return scopeDefinition;
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Utility to update the destructured entities parameter in function-based scopes
|
|
830
|
-
* Handles both cases:
|
|
831
|
-
* 1. ({ entities }) => ... (needs to add destructuring)
|
|
832
|
-
* 2. () => ... (needs to add entire parameter)
|
|
833
|
-
*/
|
|
834
|
-
export function updateDestructuredEntitiesParam(scopeDef) {
|
|
835
|
-
const uniqueEntityNames = [...new Set(scopeDef.entityNames)];
|
|
836
|
-
// If no entities, just ensure we have a basic parameter structure
|
|
837
|
-
if (uniqueEntityNames.length === 0) {
|
|
838
|
-
// For empty scopes, we can use either ({ entities }) or () format
|
|
839
|
-
// We'll standardize on () for empty scopes
|
|
840
|
-
if (scopeDef.scopeFunction.node.params.length > 0) {
|
|
841
|
-
scopeDef.scopeFunction.node.params = [];
|
|
842
|
-
scopeDef.destructuredEntitiesParam = null; // Clear the reference
|
|
843
|
-
}
|
|
844
|
-
return;
|
|
845
|
-
}
|
|
846
|
-
// Analyze existing destructuring to preserve aliases
|
|
847
|
-
const existingAliases = new Map();
|
|
848
|
-
if (scopeDef.destructuredEntitiesParam &&
|
|
849
|
-
scopeDef.destructuredEntitiesParam.isObjectPattern()) {
|
|
850
|
-
const entitiesParam = scopeDef.destructuredEntitiesParam;
|
|
851
|
-
const entitiesProperty = entitiesParam.node.properties.find((prop) => prop.type === "ObjectProperty" &&
|
|
852
|
-
!prop.computed &&
|
|
853
|
-
prop.key.type === "Identifier" &&
|
|
854
|
-
prop.key.name === "entities");
|
|
855
|
-
if (entitiesProperty &&
|
|
856
|
-
entitiesProperty.type === "ObjectProperty" &&
|
|
857
|
-
entitiesProperty.value.type === "ObjectPattern") {
|
|
858
|
-
entitiesProperty.value.properties.forEach((prop) => {
|
|
859
|
-
if (prop.type === "ObjectProperty" &&
|
|
860
|
-
!prop.computed &&
|
|
861
|
-
prop.key.type === "Identifier" &&
|
|
862
|
-
prop.value.type === "Identifier") {
|
|
863
|
-
if (!prop.shorthand) {
|
|
864
|
-
existingAliases.set(prop.key.name, prop.value.name);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
// Create the entities destructuring pattern, preserving aliases
|
|
871
|
-
const entitiesDestructuring = t.objectPattern(uniqueEntityNames.map((name) => {
|
|
872
|
-
const aliasName = existingAliases.get(name);
|
|
873
|
-
if (aliasName) {
|
|
874
|
-
return t.objectProperty(t.identifier(name), t.identifier(aliasName), false, false);
|
|
875
|
-
}
|
|
876
|
-
else {
|
|
877
|
-
return t.objectProperty(t.identifier(name), t.identifier(name), false, true);
|
|
878
|
-
}
|
|
879
|
-
}));
|
|
880
|
-
const entitiesProperty = t.objectProperty(t.identifier("entities"), entitiesDestructuring);
|
|
881
|
-
const mainDestructuringPattern = t.objectPattern([entitiesProperty]);
|
|
882
|
-
// Case 1: Function already has parameters
|
|
883
|
-
if (scopeDef.scopeFunction.node.params.length > 0) {
|
|
884
|
-
const firstParam = scopeDef.scopeFunction.get("params")[0];
|
|
885
|
-
if (firstParam && firstParam.isObjectPattern()) {
|
|
886
|
-
// Update existing object pattern
|
|
887
|
-
firstParam.node.properties = [entitiesProperty];
|
|
888
|
-
scopeDef.destructuredEntitiesParam = firstParam;
|
|
889
|
-
}
|
|
890
|
-
else if (firstParam) {
|
|
891
|
-
// Replace non-object parameter with object pattern
|
|
892
|
-
firstParam.replaceWith(mainDestructuringPattern);
|
|
893
|
-
scopeDef.destructuredEntitiesParam = scopeDef.scopeFunction.get("params")[0];
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
else {
|
|
897
|
-
// Case 2: Function has no parameters - add the destructuring parameter
|
|
898
|
-
scopeDef.scopeFunction.node.params = [mainDestructuringPattern];
|
|
899
|
-
scopeDef.destructuredEntitiesParam = scopeDef.scopeFunction.get("params")[0];
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
//# sourceMappingURL=scope.js.map
|