@buaa_smat/hometrans 26.0.5 → 26.0.6
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/README.md +249 -279
- package/agents/code-reviewer.md +1 -1
- package/dist/cli/editors.json +20 -0
- package/dist/platform/registry.js +1 -0
- package/dist/platform/validate.js +2 -1
- package/i18n/agents/code-reviewer.md +1 -1
- package/i18n/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/i18n/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
- package/i18n/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/i18n/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/i18n/skills/a2h-app-migrate/SKILL.md +32 -15
- package/i18n/skills/a2h-app-migrate/references/stage-map.md +4 -2
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +148 -89
- package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
- package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
- package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +9 -3
- package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
- package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
- package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +14 -12
- package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
- package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
- package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
- package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
- package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
- package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
- package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
- package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
- package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
- package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
- package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
- package/i18n/skills/a2h-module-semantic-docs/SKILL.md +3 -2
- package/i18n/skills/a2h-page-specgen/SKILL.md +36 -5
- package/i18n/skills/a2h-page-specgen/references/behavior-ledger.md +89 -21
- package/i18n/skills/a2h-page-specgen/references/gates.md +33 -7
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
- package/i18n/skills/a2h-page-specgen/references/spec-example.md +166 -32
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +8 -5
- package/i18n/skills/a2h-page-specgen/scripts/behavior-audit.mjs +37 -1
- package/i18n/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
- package/i18n/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
- package/i18n/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +32 -0
- package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
- package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
- package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +19 -10
- package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +62 -3
- package/i18n/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
- package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +116 -6
- package/i18n/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
- package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +26 -14
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +216 -216
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +100 -15
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +118 -25
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +104 -19
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +155 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
- package/i18n/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +75 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +124 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
- package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +106 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +12 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +11 -3
- package/i18n/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
- package/i18n/skills/a2h-resource-convert/SKILL.md +1 -1
- package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
- package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
- package/i18n/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
- package/i18n/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
- package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +15 -12
- package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
- package/i18n/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
- package/i18n/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
- package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +5 -3
- package/i18n/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
- package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
- package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
- package/i18n/skills/a2h-spec-generate/references/input-formats.md +1 -1
- package/i18n/skills/a2h-utg-explorer/SKILL.md +11 -5
- package/i18n/skills/a2h-utg-explorer/references/architecture.md +37 -19
- package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +48 -3
- package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
- package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
- package/i18n/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
- package/i18n/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +143 -14
- package/i18n/skills/a2h-utg-static/SKILL.md +3 -3
- package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
- package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
- package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
- package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
- package/package.json +2 -1
- package/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/codebuddy/agents/build-fixer.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/model-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +5 -0
- package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/deveco/agents/build-fixer.frontmatter.md +2 -0
- package/platforms/deveco/agents/code-reviewer.frontmatter.md +2 -0
- package/platforms/deveco/agents/model-render-worker.frontmatter.md +2 -0
- package/platforms/deveco/agents/model-worker.frontmatter.md +2 -0
- package/platforms/deveco/agents/specgen-worker.frontmatter.md +2 -0
- package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/opencode/agents/build-fixer.frontmatter.md +2 -0
- package/platforms/opencode/agents/code-reviewer.frontmatter.md +2 -0
- package/platforms/opencode/agents/model-render-worker.frontmatter.md +2 -0
- package/platforms/opencode/agents/model-worker.frontmatter.md +2 -0
- package/platforms/opencode/agents/specgen-worker.frontmatter.md +2 -0
- package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
- package/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
- package/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
- package/skills/a2h-app-migrate/SKILL.md +31 -14
- package/skills/a2h-app-migrate/references/stage-map.md +4 -2
- package/skills/a2h-app-migrate/references/workflow.yaml +152 -89
- package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +1 -1
- package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +28 -11
- package/skills/a2h-app-migrate/scripts/dag_action_catalog.mjs +76 -0
- package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +60 -5
- package/skills/a2h-app-migrate/scripts/dag_runner.mjs +184 -4
- package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
- package/skills/a2h-app-migrate/scripts/ledger.mjs +2 -2
- package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -3
- package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
- package/skills/a2h-app-migrate/test/test_dag_blocked_guard.mjs +291 -0
- package/skills/a2h-app-migrate/test/test_dag_production.mjs +40 -0
- package/skills/a2h-app-migrate/test/test_dag_runner.mjs +4 -3
- package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
- package/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +36 -0
- package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +19 -6
- package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
- package/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
- package/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
- package/skills/a2h-batch-ui-align/SKILL.md +14 -12
- package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
- package/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
- package/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
- package/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
- package/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
- package/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
- package/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
- package/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
- package/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
- package/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
- package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
- package/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
- package/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
- package/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
- package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
- package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +6 -1
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
- package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +270 -0
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +134 -16
- package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +39 -8
- package/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
- package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
- package/skills/a2h-batch-ui-align/scripts/module_placement.mjs +189 -0
- package/skills/a2h-batch-ui-align/scripts/overlay_effects.mjs +205 -0
- package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +28 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +28 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_chrome_defaults.test.mjs +328 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_click_handler.test.mjs +127 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_compose_semantics.test.mjs +150 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +117 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +413 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_runtime_api.test.mjs +159 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_sheet_builder.test.mjs +192 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +4 -2
- package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
- package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_compose.test.mjs +106 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +15 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_pass.test.mjs +150 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +125 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +56 -0
- package/skills/a2h-batch-ui-align/scripts/tests/measure_pack_icon_leaf.test.mjs +143 -0
- package/skills/a2h-batch-ui-align/scripts/tests/module_placement.test.mjs +248 -0
- package/skills/a2h-batch-ui-align/scripts/tests/overlay_effects.test.mjs +214 -0
- package/skills/a2h-fix-build-errors/references/known-patterns.md +5 -5
- package/skills/a2h-module-semantic-docs/SKILL.md +3 -2
- package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +10 -0
- package/skills/a2h-module-semantic-docs/scripts/design_baseline.mjs +158 -0
- package/skills/a2h-module-semantic-docs/test/test_design_baseline.mjs +128 -0
- package/skills/a2h-page-specgen/SKILL.md +36 -5
- package/skills/a2h-page-specgen/references/behavior-ledger.md +88 -21
- package/skills/a2h-page-specgen/references/evidence.md +2 -1
- package/skills/a2h-page-specgen/references/execution-model.md +13 -5
- package/skills/a2h-page-specgen/references/gates.md +33 -7
- package/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
- package/skills/a2h-page-specgen/references/spec-example.md +166 -32
- package/skills/a2h-page-specgen/references/spec-template.md +8 -5
- package/skills/a2h-page-specgen/scripts/behavior-audit.mjs +40 -2
- package/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
- package/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
- package/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +35 -2
- package/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
- package/skills/a2h-page-specgen/scripts/finalize.mjs +55 -2
- package/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
- package/skills/a2h-page-specgen/scripts/gate.mjs +20 -11
- package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +56 -3
- package/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
- package/skills/a2h-page-specgen/scripts/lib/hg.mjs +114 -5
- package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +20 -3
- package/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
- package/skills/a2h-page-specgen/scripts/prepare.mjs +25 -14
- package/skills/a2h-page-specgen/scripts/report.mjs +26 -5
- package/skills/a2h-page-specgen/scripts/submission.mjs +69 -2
- package/skills/a2h-page-specgen/scripts/submit.mjs +105 -4
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +224 -224
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +110 -18
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +97 -12
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +153 -3
- package/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
- package/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
- package/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
- package/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
- package/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
- package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
- package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +82 -3
- package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
- package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +11 -0
- package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
- package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +94 -1
- package/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
- package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +14 -0
- package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +49 -1
- package/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
- package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +12 -4
- package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
- package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
- package/skills/a2h-page-specgen/scripts/test/report.test.mjs +80 -1
- package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
- package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +23 -0
- package/skills/a2h-page-specgen/scripts/waker.mjs +8 -1
- package/skills/a2h-resource-convert/SKILL.md +1 -1
- package/skills/a2h-resource-convert/data/framework-strings/NOTICE +10 -0
- package/skills/a2h-resource-convert/data/framework-strings/manifest.json +90 -0
- package/skills/a2h-resource-convert/data/framework-strings/strings.json +382 -0
- package/skills/a2h-resource-convert/references/conversion-rules.md +7 -1
- package/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
- package/skills/a2h-resource-convert/references/step5-reference-resolution.md +16 -0
- package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
- package/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
- package/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
- package/skills/a2h-spec-design-pipeline/SKILL.md +14 -11
- package/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
- package/skills/a2h-spec-design-pipeline/references/execution-model.md +3 -0
- package/skills/a2h-spec-design-pipeline/references/final-report-template.md +6 -3
- package/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
- package/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/scripts.md +4 -3
- package/skills/a2h-spec-design-pipeline/references/shared-layer.md +24 -19
- package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
- package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +12 -5
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/README.md +27 -3
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-param-contract.json +46 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-permission-map.json +2511 -295
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-cn.md +27 -72
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-en.md +39 -83
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +132 -101
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +158 -115
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-cn.md +60 -93
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-en.md +73 -100
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-cn.md +52 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-en.md +59 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ApiPermissionDeclaredCheck.js +57 -8
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +475 -18
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/PlatformApiContractCheck.js +472 -4
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/RoutePageSideEffectImportCheck.js +570 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/arkui/RouteParamCarrierSubCheck.js +1053 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/sql/SqlIdentifierAnalysis.js +427 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +7 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/settle.ts +785 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_api_permission_declared.ts +286 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_arkui_runtime_pitfall.ts +166 -2
- package/skills/a2h-spec-design-pipeline/scripts/test_docs_refresh_contract.ts +40 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_platform_api_contract.ts +350 -7
- package/skills/a2h-spec-design-pipeline/scripts/test_route_page_side_effect_import.ts +185 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_route_param_carrier.ts +341 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_settle.ts +593 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +92 -1
- package/skills/a2h-spec-design-pipeline/scripts/test_sql_identifier_analysis.ts +137 -0
- package/skills/a2h-spec-generate/references/input-formats.md +1 -1
- package/skills/a2h-utg-explorer/SKILL.md +11 -5
- package/skills/a2h-utg-explorer/references/architecture.md +37 -19
- package/skills/a2h-utg-explorer/scripts/audit.mjs +6 -2
- package/skills/a2h-utg-explorer/scripts/close_phases.mjs +8 -5
- package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +95 -19
- package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +192 -4
- package/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
- package/skills/a2h-utg-explorer/scripts/panel_routes.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/plan.mjs +16 -1
- package/skills/a2h-utg-explorer/scripts/predicates.mjs +270 -0
- package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +2 -0
- package/skills/a2h-utg-explorer/scripts/recover.mjs +4 -3
- package/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
- package/skills/a2h-utg-explorer/scripts/rejudge.mjs +4 -3
- package/skills/a2h-utg-explorer/scripts/report.mjs +32 -2
- package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +103 -36
- package/skills/a2h-utg-explorer/scripts/run_device.mjs +3 -8
- package/skills/a2h-utg-explorer/scripts/schedule_states.mjs +189 -0
- package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +9 -0
- package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +11 -0
- package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +31 -2
- package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
- package/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
- package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +4 -1
- package/skills/a2h-utg-explorer/scripts/tests/hybrid_route.test.mjs +6 -28
- package/skills/a2h-utg-explorer/scripts/tests/in_route_surface.test.mjs +125 -0
- package/skills/a2h-utg-explorer/scripts/tests/list_probe_target_wait.test.mjs +86 -0
- package/skills/a2h-utg-explorer/scripts/tests/multi_host.test.mjs +167 -0
- package/skills/a2h-utg-explorer/scripts/tests/nested_list.test.mjs +58 -0
- package/skills/a2h-utg-explorer/scripts/tests/overlay_opener.test.mjs +100 -0
- package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +8 -1
- package/skills/a2h-utg-explorer/scripts/tests/pr169_review_fixes.test.mjs +1 -0
- package/skills/a2h-utg-explorer/scripts/tests/pr191_review_fixes.test.mjs +2 -31
- package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +1 -1
- package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +56 -7
- package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +117 -6
- package/skills/a2h-utg-explorer/scripts/tests/state_inventory.test.mjs +414 -0
- package/skills/a2h-utg-explorer/scripts/tests/tree_unreliable.test.mjs +197 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +196 -30
- package/skills/a2h-utg-explorer/scripts/utg_explorer/hosts.mjs +146 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
- package/skills/a2h-utg-explorer/scripts/utg_explorer/states.mjs +286 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +197 -19
- package/skills/a2h-utg-static/SKILL.md +3 -3
- package/skills/a2h-utg-static/references/extractors.md +7 -0
- package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
- package/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
- package/skills/a2h-utg-static/scripts/compose_overlay.mjs +642 -22
- package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
- package/skills/a2h-utg-static/scripts/tests/test_in_route_surface.mjs +123 -0
- package/skills/a2h-utg-static/scripts/tests/test_overlay_host_effects.mjs +239 -0
- package/skills/a2h-utg-static/scripts/tests/test_shared_host_depths.mjs +48 -0
- package/skills/a2h-utg-static/scripts/utg_html.mjs +2 -0
- package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
- package/i18n/skills/a2h-app-migrate/references/specs.example.json +0 -19
- package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
- package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
- package/resource/convert_pipeline_process.svg +0 -114
- package/resource/project_architecture.svg +0 -120
- package/resource/set_environment.png +0 -0
- package/resource/set_multimodel.png +0 -0
- package/skills/a2h-app-migrate/references/specs.example.json +0 -19
- package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
- package/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Route-param carrier sub-checks (part of @hometrans/arkui-runtime-pitfall).
|
|
5
|
+
*
|
|
6
|
+
* Four sub-codes — the cross-page result-carrier defects that compile 100% clean and
|
|
7
|
+
* break when the receiving page renders the value:
|
|
8
|
+
*
|
|
9
|
+
* [route-param-v2-instance] router params carry an @ObservedV2/@Observed class instance
|
|
10
|
+
* (directly, through a local object literal, or through an
|
|
11
|
+
* interface/type alias whose field is typed as that class).
|
|
12
|
+
* ArkUI serializes router params at the page boundary; a V2
|
|
13
|
+
* instance's fields arrive as __ob_* keys or undefined. (ERROR)
|
|
14
|
+
* [route-param-v2-new] `new Xxx(...)` built inline inside router params — same boundary,
|
|
15
|
+
* same loss. (ERROR)
|
|
16
|
+
* [route-param-v2-stringify] `JSON.stringify(v)` where v is an @ObservedV2/@Observed instance —
|
|
17
|
+
* the decorated fields serialize as __ob_* keys, so the result is
|
|
18
|
+
* not the DTO the caller expects. (ERROR)
|
|
19
|
+
* [route-param-unrebuilt-receive]
|
|
20
|
+
* `getParams()` cast to a contract whose field is still typed as the
|
|
21
|
+
* decorated class, and the receiving method neither validates the
|
|
22
|
+
* key fields (typeof) nor rebuilds the entity (new Xxx(...)).
|
|
23
|
+
* The runtime value is a plain object, so @Trace observation is gone;
|
|
24
|
+
* routed to review because reading plain fields can be enough for a
|
|
25
|
+
* read-only card. (WARN)
|
|
26
|
+
*
|
|
27
|
+
* The check is text-based on purpose (same approach as the rest of the owning rule): it needs
|
|
28
|
+
* no CFG, and decides cross-file relations inside one scene pass. Type resolution is
|
|
29
|
+
* import-aware — a name is resolved through the file's relative imports, `import * as ns`,
|
|
30
|
+
* namespace-qualified names and the declaring file's own declarations; a bare name is trusted only
|
|
31
|
+
* when exactly one declaration with that name exists in the whole scene. Anything unresolved stays
|
|
32
|
+
* silent (the same bar the other migration rules use).
|
|
33
|
+
*
|
|
34
|
+
* Deliberate silences (documented in the rule doc): `any`/`Object` casts, helper-returned values,
|
|
35
|
+
* object spread, `Object.assign`, computed keys and types imported from a package (oh_modules) are
|
|
36
|
+
* not graded. Flagging them would trade a hard false positive for an unbounded guess.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const fs = require('fs');
|
|
40
|
+
const path = require('path');
|
|
41
|
+
|
|
42
|
+
const hc = require(process.env.HOMECHECK_MODULE_PATH || 'homecheck');
|
|
43
|
+
const { AlertLevel } = hc;
|
|
44
|
+
|
|
45
|
+
const ROUTER_CALLS = ['back', 'pushUrl', 'replaceUrl', 'pushNamedRoute', 'replaceNamedRoute'];
|
|
46
|
+
|
|
47
|
+
function safe(fn, fallback) {
|
|
48
|
+
try {
|
|
49
|
+
return fn();
|
|
50
|
+
} catch (_err) {
|
|
51
|
+
return fallback;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* ------------------------------------------------------------------ */
|
|
56
|
+
/* Lexical helpers (same shape as ArkUIRuntimePitfallCheck) */
|
|
57
|
+
/* ------------------------------------------------------------------ */
|
|
58
|
+
|
|
59
|
+
/** Replace string/template contents with equal-length whitespace (quotes kept). */
|
|
60
|
+
function maskStrings(code) {
|
|
61
|
+
let out = '';
|
|
62
|
+
let q = '';
|
|
63
|
+
for (let i = 0; i < code.length; i++) {
|
|
64
|
+
const c = code[i];
|
|
65
|
+
if (q === '') {
|
|
66
|
+
if (c === '"' || c === "'" || c === '`') { q = c; }
|
|
67
|
+
out += c;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (c === '\\') { out += ' '; i++; continue; }
|
|
71
|
+
if (c === q) { q = ''; out += c; continue; }
|
|
72
|
+
out += (c === '\n' ? '\n' : ' ');
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** When code[open] is ( / { / [, return the balancing close position; brackets in strings do not count. */
|
|
78
|
+
function matchBracket(code, open) {
|
|
79
|
+
const pairs = { '(': ')', '{': '}', '[': ']' };
|
|
80
|
+
const close = pairs[code[open]];
|
|
81
|
+
if (!close) { return -1; }
|
|
82
|
+
let depth = 0;
|
|
83
|
+
let q = '';
|
|
84
|
+
for (let i = open; i < code.length; i++) {
|
|
85
|
+
const c = code[i];
|
|
86
|
+
if (q !== '') {
|
|
87
|
+
if (c === '\\') { i++; continue; }
|
|
88
|
+
if (c === q) { q = ''; }
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (c === '"' || c === "'" || c === '`') { q = c; continue; }
|
|
92
|
+
if (c === '(' || c === '{' || c === '[') { depth++; continue; }
|
|
93
|
+
if (c === ')' || c === '}' || c === ']') {
|
|
94
|
+
depth--;
|
|
95
|
+
if (depth === 0) { return i; }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function lineOf(code, index) {
|
|
102
|
+
let line = 1;
|
|
103
|
+
const end = Math.min(index, code.length);
|
|
104
|
+
for (let i = 0; i < end; i++) {
|
|
105
|
+
if (code[i] === '\n') { line++; }
|
|
106
|
+
}
|
|
107
|
+
return line;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Every `{...}` range in the file: [{ open, close }]. Braces inside strings/comments do not count. */
|
|
111
|
+
function braceRanges(code) {
|
|
112
|
+
const masked = maskStrings(code);
|
|
113
|
+
const stack = [];
|
|
114
|
+
const ranges = [];
|
|
115
|
+
for (let i = 0; i < masked.length; i++) {
|
|
116
|
+
const c = masked[i];
|
|
117
|
+
if (c === '{') { stack.push(i); continue; }
|
|
118
|
+
if (c === '}') {
|
|
119
|
+
const open = stack.pop();
|
|
120
|
+
if (open !== undefined) { ranges.push({ open, close: i }); }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return ranges;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Split [start, end) on a top-level separator, respecting (), {}, [] and string literals. */
|
|
127
|
+
function splitTopLevel(code, start, end, sep) {
|
|
128
|
+
const parts = [];
|
|
129
|
+
let depth = 0;
|
|
130
|
+
let q = '';
|
|
131
|
+
let segStart = start;
|
|
132
|
+
for (let i = start; i < end; i++) {
|
|
133
|
+
const c = code[i];
|
|
134
|
+
if (q !== '') {
|
|
135
|
+
if (c === '\\') { i++; continue; }
|
|
136
|
+
if (c === q) { q = ''; }
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (c === '"' || c === "'" || c === '`') { q = c; continue; }
|
|
140
|
+
if (c === '(' || c === '{' || c === '[') { depth++; continue; }
|
|
141
|
+
if (c === ')' || c === '}' || c === ']') { depth--; continue; }
|
|
142
|
+
if (c === sep && depth === 0) {
|
|
143
|
+
parts.push({ start: segStart, end: i });
|
|
144
|
+
segStart = i + 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
parts.push({ start: segStart, end });
|
|
148
|
+
return parts;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Index of `needle` at depth 0 inside text, or -1. */
|
|
152
|
+
function topLevelIndexOf(text, needle) {
|
|
153
|
+
let depth = 0;
|
|
154
|
+
let q = '';
|
|
155
|
+
for (let i = 0; i < text.length; i++) {
|
|
156
|
+
const c = text[i];
|
|
157
|
+
if (q !== '') {
|
|
158
|
+
if (c === '\\') { i++; continue; }
|
|
159
|
+
if (c === q) { q = ''; }
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (c === '"' || c === "'" || c === '`') { q = c; continue; }
|
|
163
|
+
if (c === '(' || c === '{' || c === '[') { depth++; continue; }
|
|
164
|
+
if (c === ')' || c === '}' || c === ']') { depth--; continue; }
|
|
165
|
+
if (depth === 0 && text.startsWith(needle, i)) { return i; }
|
|
166
|
+
}
|
|
167
|
+
return -1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Top-level `key: value`, shorthand `key`, and `...spread` entries of an object literal body. */
|
|
171
|
+
function objectProps(code, bodyStart, bodyEnd) {
|
|
172
|
+
const props = [];
|
|
173
|
+
const parts = splitTopLevel(code, bodyStart + 1, bodyEnd, ',');
|
|
174
|
+
for (const part of parts) {
|
|
175
|
+
const raw = code.slice(part.start, part.end);
|
|
176
|
+
const leading = raw.length - raw.replace(/^\s+/, '').length;
|
|
177
|
+
const text = raw.trim();
|
|
178
|
+
if (text === '') { continue; }
|
|
179
|
+
if (text.startsWith('...')) {
|
|
180
|
+
continue; // spreading a V2 instance is not graded (see the header)
|
|
181
|
+
}
|
|
182
|
+
const colon = topLevelIndexOf(text, ':');
|
|
183
|
+
if (colon < 0) {
|
|
184
|
+
const shorthand = /^([A-Za-z_$][\w$]*)$/.exec(text);
|
|
185
|
+
if (shorthand) {
|
|
186
|
+
props.push({ key: shorthand[1], value: shorthand[1], index: part.start + leading });
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const keyText = text.slice(0, colon).trim();
|
|
191
|
+
const valueText = text.slice(colon + 1);
|
|
192
|
+
const value = valueText.trim();
|
|
193
|
+
const key = /^([A-Za-z_$][\w$]*)$/.exec(keyText);
|
|
194
|
+
if (key === null || value === '') { continue; }
|
|
195
|
+
const valueLeading = valueText.length - valueText.replace(/^\s+/, '').length;
|
|
196
|
+
props.push({
|
|
197
|
+
key: key[1],
|
|
198
|
+
value,
|
|
199
|
+
index: part.start + leading + colon + 1 + valueLeading,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return props;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function stripOuter(expr) {
|
|
206
|
+
let t = String(expr || '').trim();
|
|
207
|
+
let changed = true;
|
|
208
|
+
while (changed && t.length > 0) {
|
|
209
|
+
changed = false;
|
|
210
|
+
if (t.endsWith(';')) { t = t.slice(0, -1).trim(); changed = true; }
|
|
211
|
+
if (t.endsWith('!')) { t = t.slice(0, -1).trim(); changed = true; }
|
|
212
|
+
if (t.startsWith('(') && matchBracket(t, 0) === t.length - 1) {
|
|
213
|
+
t = t.slice(1, -1).trim();
|
|
214
|
+
changed = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return t;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Split `expr as Type` at depth 0: { expr, type } (type is null when there is no cast). */
|
|
221
|
+
function splitCast(expr) {
|
|
222
|
+
const t = String(expr || '').trim();
|
|
223
|
+
let depth = 0;
|
|
224
|
+
let q = '';
|
|
225
|
+
for (let i = 0; i < t.length; i++) {
|
|
226
|
+
const c = t[i];
|
|
227
|
+
if (q !== '') {
|
|
228
|
+
if (c === '\\') { i++; continue; }
|
|
229
|
+
if (c === q) { q = ''; }
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (c === '"' || c === "'" || c === '`') { q = c; continue; }
|
|
233
|
+
if (c === '(' || c === '{' || c === '[') { depth++; continue; }
|
|
234
|
+
if (c === ')' || c === '}' || c === ']') { depth--; continue; }
|
|
235
|
+
if (depth !== 0) { continue; }
|
|
236
|
+
if (t.startsWith('as', i) && /\s/.test(t[i - 1] || '') && /\s/.test(t[i + 2] || '')) {
|
|
237
|
+
return { expr: t.slice(0, i).trim(), type: t.slice(i + 2).trim() };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { expr: t, type: null };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Type candidates of a syntactic type: array wrappers and union members unwrapped. */
|
|
244
|
+
function typeCandidates(type) {
|
|
245
|
+
const out = [];
|
|
246
|
+
const seen = new Set();
|
|
247
|
+
const visit = (raw) => {
|
|
248
|
+
let t = String(raw || '').trim();
|
|
249
|
+
if (t === '') { return; }
|
|
250
|
+
if (seen.has(t)) { return; }
|
|
251
|
+
seen.add(t);
|
|
252
|
+
t = t.replace(/^readonly\s+/, '');
|
|
253
|
+
if (t.startsWith('(') && matchBracket(t, 0) === t.length - 1) {
|
|
254
|
+
visit(t.slice(1, -1));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const union = splitTopLevel(t, 0, t.length, '|').map((p) => t.slice(p.start, p.end).trim());
|
|
258
|
+
if (union.length > 1) {
|
|
259
|
+
for (const part of union) { visit(part); }
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (t.endsWith('[]')) { visit(t.slice(0, -2)); return; }
|
|
263
|
+
const arr = /^Array\s*<([\s\S]+)>$/.exec(t);
|
|
264
|
+
if (arr) { visit(arr[1]); return; }
|
|
265
|
+
const set = /^(?:ReadonlyArray|Readonly)\s*<([\s\S]+)>$/.exec(t);
|
|
266
|
+
if (set) { visit(set[1]); return; }
|
|
267
|
+
const name = /^([A-Za-z_$][\w$]*)(?:\.[A-Za-z_$][\w$]*)?$/.exec(t);
|
|
268
|
+
if (name) { out.push(t); }
|
|
269
|
+
};
|
|
270
|
+
visit(type);
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* ------------------------------------------------------------------ */
|
|
275
|
+
/* Per-file model */
|
|
276
|
+
/* ------------------------------------------------------------------ */
|
|
277
|
+
|
|
278
|
+
function resolveRelativeImport(fromFile, spec) {
|
|
279
|
+
if (typeof spec !== 'string' || !spec.startsWith('.')) { return null; }
|
|
280
|
+
const base = path.resolve(path.dirname(fromFile), spec);
|
|
281
|
+
const candidates = [
|
|
282
|
+
base,
|
|
283
|
+
`${base}.ets`,
|
|
284
|
+
`${base}.ts`,
|
|
285
|
+
path.join(base, 'index.ets'),
|
|
286
|
+
path.join(base, 'index.ts'),
|
|
287
|
+
];
|
|
288
|
+
for (const candidate of candidates) {
|
|
289
|
+
if (safe(() => fs.statSync(candidate).isFile(), false)) { return path.normalize(candidate); }
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Fields declared at the top level of an object/interface/class body. */
|
|
295
|
+
function fieldsOf(code, open, close) {
|
|
296
|
+
const fields = [];
|
|
297
|
+
const body = code.slice(open + 1, close);
|
|
298
|
+
// Depth of every position in `body`, so nested object literals / method bodies do not look
|
|
299
|
+
// like fields (a method's `key: value,` line must never become a class field).
|
|
300
|
+
const depth = new Int32Array(body.length + 1);
|
|
301
|
+
let d = 0;
|
|
302
|
+
let q = '';
|
|
303
|
+
for (let i = 0; i < body.length; i++) {
|
|
304
|
+
depth[i] = d;
|
|
305
|
+
const c = body[i];
|
|
306
|
+
if (q !== '') {
|
|
307
|
+
if (c === '\\') { i++; continue; }
|
|
308
|
+
if (c === q) { q = ''; }
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (c === '"' || c === "'" || c === '`') { q = c; continue; }
|
|
312
|
+
if (c === '{') { d++; continue; }
|
|
313
|
+
if (c === '}') { d--; continue; }
|
|
314
|
+
}
|
|
315
|
+
depth[body.length] = d;
|
|
316
|
+
const re = /^[ \t]*(?:@[A-Za-z_$][\w$]*(?:\([^)\n]*\))?[ \t]*)*(?:(?:private|public|protected|readonly|static|declare|abstract)\s+)*([A-Za-z_$][\w$]*)\s*\??\s*:\s*([^;=\n]+)/gm;
|
|
317
|
+
let m;
|
|
318
|
+
while ((m = re.exec(body)) !== null) {
|
|
319
|
+
if (depth[m.index] !== 0) { continue; }
|
|
320
|
+
fields.push({ name: m[1], type: m[2].trim() });
|
|
321
|
+
}
|
|
322
|
+
return fields;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function parseImports(filePath, code) {
|
|
326
|
+
const imports = new Map(); // local name -> { name, file }
|
|
327
|
+
const namespaces = new Map(); // local ns -> file
|
|
328
|
+
let m;
|
|
329
|
+
const named = /import\s+(?:type\s+)?\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
330
|
+
while ((m = named.exec(code)) !== null) {
|
|
331
|
+
const target = resolveRelativeImport(filePath, m[2]);
|
|
332
|
+
if (target === null) { continue; }
|
|
333
|
+
for (const part of m[1].split(',')) {
|
|
334
|
+
const spec = part.trim();
|
|
335
|
+
if (spec === '') { continue; }
|
|
336
|
+
const alias = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(spec);
|
|
337
|
+
if (alias) { imports.set(alias[2], { name: alias[1], file: target }); }
|
|
338
|
+
else if (/^[A-Za-z_$][\w$]*$/.test(spec)) { imports.set(spec, { name: spec, file: target }); }
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const def = /import\s+([A-Za-z_$][\w$]*)\s*(?:,\s*\{[\s\S]*?\}\s*)?from\s*['"]([^'"]+)['"]/g;
|
|
342
|
+
while ((m = def.exec(code)) !== null) {
|
|
343
|
+
const target = resolveRelativeImport(filePath, m[2]);
|
|
344
|
+
if (target !== null) { imports.set(m[1], { name: m[1], file: target }); }
|
|
345
|
+
}
|
|
346
|
+
const ns = /import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s*['"]([^'"]+)['"]/g;
|
|
347
|
+
while ((m = ns.exec(code)) !== null) {
|
|
348
|
+
const target = resolveRelativeImport(filePath, m[2]);
|
|
349
|
+
if (target !== null) { namespaces.set(m[1], target); }
|
|
350
|
+
}
|
|
351
|
+
return { imports, namespaces };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function parseFile(filePath, code, raw) {
|
|
355
|
+
const { imports, namespaces } = parseImports(filePath, code);
|
|
356
|
+
const classes = new Map(); // class name -> { open, close, fields: Map }
|
|
357
|
+
const declarations = []; // [{ name, kind: 'class'|'interface'|'type', decorated, open, close, fields }]
|
|
358
|
+
let m;
|
|
359
|
+
|
|
360
|
+
const classRe = /((?:export\s+)?(?:@[A-Za-z_$][\w$]*(?:\([^)]*\))?\s*)*)(?:export\s+)?(?:default\s+)?class\s+([A-Za-z_$][\w$]*)[^{]*\{/g;
|
|
361
|
+
while ((m = classRe.exec(code)) !== null) {
|
|
362
|
+
const open = m.index + m[0].length - 1;
|
|
363
|
+
const close = matchBracket(code, open);
|
|
364
|
+
if (close < 0) { continue; }
|
|
365
|
+
const isDecorated = /@(?:ObservedV2|Observed)\b/.test(m[1]);
|
|
366
|
+
const fields = new Map(fieldsOf(code, open, close).map((f) => [f.name, f.type]));
|
|
367
|
+
classes.set(m[2], { open, close, fields });
|
|
368
|
+
declarations.push({ name: m[2], kind: 'class', decorated: isDecorated, open, close, fields });
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const ifaceRe = /\binterface\s+([A-Za-z_$][\w$]*)(?:\s+extends\s+[^{]+)?\s*\{/g;
|
|
372
|
+
while ((m = ifaceRe.exec(code)) !== null) {
|
|
373
|
+
const open = m.index + m[0].length - 1;
|
|
374
|
+
const close = matchBracket(code, open);
|
|
375
|
+
if (close < 0) { continue; }
|
|
376
|
+
const fields = fieldsOf(code, open, close);
|
|
377
|
+
declarations.push({ name: m[1], kind: 'interface', decorated: false, open, close, fields });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const typeRe = /\btype\s+([A-Za-z_$][\w$]*)\s*=\s*\{/g;
|
|
381
|
+
while ((m = typeRe.exec(code)) !== null) {
|
|
382
|
+
const open = m.index + m[0].length - 1;
|
|
383
|
+
const close = matchBracket(code, open);
|
|
384
|
+
if (close < 0) { continue; }
|
|
385
|
+
const fields = fieldsOf(code, open, close);
|
|
386
|
+
declarations.push({ name: m[1], kind: 'type', decorated: false, open, close, fields });
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const ranges = braceRanges(code);
|
|
390
|
+
const scopeOf = (index) => {
|
|
391
|
+
let best = null;
|
|
392
|
+
for (const r of ranges) {
|
|
393
|
+
if (r.open <= index && index <= r.close) {
|
|
394
|
+
if (best === null || (r.close - r.open) < (best.close - best.open)) { best = r; }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return best;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const locals = [];
|
|
401
|
+
const localRe = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::\s*([A-Za-z_$][\w$.<>\[\]| ]*))?\s*=\s*/g;
|
|
402
|
+
while ((m = localRe.exec(code)) !== null) {
|
|
403
|
+
const initStart = m.index + m[0].length;
|
|
404
|
+
let initEnd = initStart;
|
|
405
|
+
while (initEnd < code.length && code[initEnd] !== ';' && code[initEnd] !== '\n') { initEnd++; }
|
|
406
|
+
const init = code.slice(initStart, initEnd).trim();
|
|
407
|
+
let type = m[2] ? m[2].trim() : null;
|
|
408
|
+
if (type === null) {
|
|
409
|
+
const created = /^new\s+([A-Za-z_$][\w$]*)\s*\(/.exec(init);
|
|
410
|
+
if (created) { type = created[1]; }
|
|
411
|
+
}
|
|
412
|
+
locals.push({
|
|
413
|
+
name: m[1],
|
|
414
|
+
type,
|
|
415
|
+
init,
|
|
416
|
+
initStart,
|
|
417
|
+
index: m.index,
|
|
418
|
+
scope: scopeOf(m.index),
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const paramScopes = [];
|
|
423
|
+
const masked = maskStrings(code);
|
|
424
|
+
for (let i = 0; i < masked.length; i++) {
|
|
425
|
+
if (masked[i] !== '(') { continue; }
|
|
426
|
+
const close = matchBracket(masked, i);
|
|
427
|
+
if (close < 0) { continue; }
|
|
428
|
+
let p = i - 1;
|
|
429
|
+
while (p >= 0 && /\s/.test(masked[p])) { p--; }
|
|
430
|
+
let a = close + 1;
|
|
431
|
+
while (a < masked.length && /\s/.test(masked[a])) { a++; }
|
|
432
|
+
const before = p >= 0 ? masked[p] : '';
|
|
433
|
+
const after = masked.slice(a, a + 2);
|
|
434
|
+
const word = /([A-Za-z_$][\w$]*)\s*$/.exec(masked.slice(Math.max(0, p - 30), p + 1));
|
|
435
|
+
if (word && /^(?:if|for|while|switch|catch|with)$/.test(word[1])) { continue; }
|
|
436
|
+
const afterOk = after.startsWith('=>') || after.startsWith(':') || after.startsWith('{') ||
|
|
437
|
+
after.startsWith(';');
|
|
438
|
+
if (!afterOk) { continue; }
|
|
439
|
+
const beforeOk = /[\w$>)\]]/.test(before) || after.startsWith('=>');
|
|
440
|
+
if (!beforeOk) { continue; }
|
|
441
|
+
const types = new Map();
|
|
442
|
+
for (const part of splitTopLevel(masked, i + 1, close, ',')) {
|
|
443
|
+
const seg = masked.slice(part.start, part.end).trim();
|
|
444
|
+
const pm = /^(?:\.\.\.)?\s*([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(seg);
|
|
445
|
+
if (pm) { types.set(pm[1], pm[2].trim()); }
|
|
446
|
+
}
|
|
447
|
+
if (types.size === 0) { continue; }
|
|
448
|
+
let bodyOpen = a;
|
|
449
|
+
while (bodyOpen < masked.length && masked[bodyOpen] !== '{' && masked[bodyOpen] !== ';' &&
|
|
450
|
+
!masked.startsWith('=>', bodyOpen)) { bodyOpen++; }
|
|
451
|
+
let scope = null;
|
|
452
|
+
if (masked[bodyOpen] === '{') {
|
|
453
|
+
const bodyClose = matchBracket(masked, bodyOpen);
|
|
454
|
+
if (bodyClose > bodyOpen) { scope = { open: bodyOpen, close: bodyClose }; }
|
|
455
|
+
}
|
|
456
|
+
if (scope === null) { scope = scopeOf(i); }
|
|
457
|
+
paramScopes.push({ open: i, close, scope, types });
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
filePath,
|
|
462
|
+
code,
|
|
463
|
+
raw: typeof raw === 'string' ? raw : code,
|
|
464
|
+
imports,
|
|
465
|
+
namespaces,
|
|
466
|
+
classes,
|
|
467
|
+
declarations,
|
|
468
|
+
locals,
|
|
469
|
+
paramScopes,
|
|
470
|
+
scopeOf,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/* ------------------------------------------------------------------ */
|
|
475
|
+
/* Project-wide type resolution */
|
|
476
|
+
/* ------------------------------------------------------------------ */
|
|
477
|
+
|
|
478
|
+
function buildProject(scans) {
|
|
479
|
+
const byFile = new Map();
|
|
480
|
+
const declCount = new Map(); // type name -> declaration count in the whole scene
|
|
481
|
+
const decoratedDecl = new Set(); // names with at least one @ObservedV2/@Observed class
|
|
482
|
+
for (const file of scans) {
|
|
483
|
+
byFile.set(file.filePath, file);
|
|
484
|
+
for (const decl of file.declarations) {
|
|
485
|
+
declCount.set(decl.name, (declCount.get(decl.name) || 0) + 1);
|
|
486
|
+
if (decl.decorated) { decoratedDecl.add(decl.name); }
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return { byFile, declCount, decoratedDecl };
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function importTarget(project, file, name) {
|
|
493
|
+
if (name.indexOf('.') >= 0) {
|
|
494
|
+
const [ns, member] = name.split('.');
|
|
495
|
+
const target = file.namespaces.get(ns);
|
|
496
|
+
if (target === undefined) { return null; }
|
|
497
|
+
const targetFile = project.byFile.get(path.normalize(target));
|
|
498
|
+
if (targetFile === undefined) { return null; }
|
|
499
|
+
return { file: targetFile, name: member };
|
|
500
|
+
}
|
|
501
|
+
const imported = file.imports.get(name);
|
|
502
|
+
if (imported !== undefined) {
|
|
503
|
+
const targetFile = project.byFile.get(path.normalize(imported.file));
|
|
504
|
+
if (targetFile !== undefined) { return { file: targetFile, name: imported.name }; }
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
return { file, name };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** Resolve a type name to { kind, decorated, fields, file } (or null when not gradable). */
|
|
511
|
+
function resolveType(project, file, name) {
|
|
512
|
+
const target = importTarget(project, file, name);
|
|
513
|
+
if (target !== null) {
|
|
514
|
+
const decl = target.file.declarations.find((d) => d.name === target.name);
|
|
515
|
+
if (decl !== undefined) {
|
|
516
|
+
return {
|
|
517
|
+
kind: decl.kind,
|
|
518
|
+
decorated: decl.decorated,
|
|
519
|
+
fields: decl.fields,
|
|
520
|
+
file: target.file,
|
|
521
|
+
name: target.name,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
// No import and no local declaration: only trust a name declared exactly once in the scene.
|
|
527
|
+
if (project.declCount.get(name) === 1 && project.decoratedDecl.has(name)) {
|
|
528
|
+
return { kind: 'class', decorated: true, fields: new Map(), file: null, name };
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function decoratedType(project, file, type) {
|
|
534
|
+
for (const candidate of typeCandidates(type)) {
|
|
535
|
+
const decl = resolveType(project, file, candidate);
|
|
536
|
+
if (decl !== null && decl.kind === 'class' && decl.decorated) {
|
|
537
|
+
return { className: candidate };
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function contractWithDecoratedField(project, file, type) {
|
|
544
|
+
for (const candidate of typeCandidates(type)) {
|
|
545
|
+
const decl = resolveType(project, file, candidate);
|
|
546
|
+
if (decl === null || decl.kind === 'class') { continue; }
|
|
547
|
+
const fields = Array.isArray(decl.fields) ? decl.fields : [];
|
|
548
|
+
for (const field of fields) {
|
|
549
|
+
const hit = decoratedType(project, decl.file || file, field.type);
|
|
550
|
+
if (hit !== null) {
|
|
551
|
+
return { contract: candidate, field: field.name, fieldType: field.type, className: hit.className };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/* ------------------------------------------------------------------ */
|
|
559
|
+
/* Expression typing */
|
|
560
|
+
/* ------------------------------------------------------------------ */
|
|
561
|
+
|
|
562
|
+
function scopeContains(scope, index) {
|
|
563
|
+
return scope === null || scope === undefined ||
|
|
564
|
+
(scope.open <= index && index <= scope.close);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function visibleLocal(file, name, at) {
|
|
568
|
+
let best = null;
|
|
569
|
+
for (const local of file.locals) {
|
|
570
|
+
if (local.name !== name || local.index > at) { continue; }
|
|
571
|
+
if (!scopeContains(local.scope, at)) { continue; }
|
|
572
|
+
if (best === null || local.index > best.index) { best = local; }
|
|
573
|
+
}
|
|
574
|
+
return best;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** Index of the opening bracket matching `code[close]` (`)`, `]` or `}`), or -1. */
|
|
578
|
+
function matchBracketBackward(code, close) {
|
|
579
|
+
let depth = 0;
|
|
580
|
+
for (let i = close; i >= 0; i--) {
|
|
581
|
+
const c = code[i];
|
|
582
|
+
if (c === ')' || c === ']' || c === '}') { depth++; continue; }
|
|
583
|
+
if (c === '(' || c === '[' || c === '{') {
|
|
584
|
+
depth--;
|
|
585
|
+
if (depth === 0) { return i; }
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return -1;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Member-chain text immediately left of `end` (the dot of `.back`), e.g.
|
|
593
|
+
* `this.getUIContext().getRouter`, `uiContext?.getRouter`, `routing`. Calls are walked
|
|
594
|
+
* backwards with bracket matching so `X.getRouter().back(...)` resolves to `X.getRouter`.
|
|
595
|
+
* Pass string-masked code.
|
|
596
|
+
*/
|
|
597
|
+
function receiverChain(code, end) {
|
|
598
|
+
let pos = end;
|
|
599
|
+
while (pos > 0 && /\s/.test(code[pos - 1])) { pos--; }
|
|
600
|
+
// `router?.back(...)` / `router!.back(...)`: the `?` / `!` belongs to the receiver.
|
|
601
|
+
while (pos > 0 && (code[pos - 1] === '?' || code[pos - 1] === '!')) { pos--; }
|
|
602
|
+
while (pos > 0 && /\s/.test(code[pos - 1])) { pos--; }
|
|
603
|
+
let text = '';
|
|
604
|
+
for (;;) {
|
|
605
|
+
if (code[pos - 1] === ')') {
|
|
606
|
+
const open = matchBracketBackward(code, pos - 1);
|
|
607
|
+
if (open < 0) { break; }
|
|
608
|
+
text = code.slice(open, pos) + text;
|
|
609
|
+
pos = open;
|
|
610
|
+
while (pos > 0 && /\s/.test(code[pos - 1])) { pos--; }
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
const m = /[A-Za-z_$][\w$]*$/.exec(code.slice(Math.max(0, pos - 120), pos));
|
|
614
|
+
if (m === null) { break; }
|
|
615
|
+
text = m[0] + text;
|
|
616
|
+
pos -= m[0].length;
|
|
617
|
+
while (pos > 0 && /\s/.test(code[pos - 1])) { pos--; }
|
|
618
|
+
if (pos >= 2 && code.slice(pos - 2, pos) === '?.') {
|
|
619
|
+
text = '?.' + text;
|
|
620
|
+
pos -= 2;
|
|
621
|
+
} else if (pos >= 1 && code[pos - 1] === '.') {
|
|
622
|
+
text = '.' + text;
|
|
623
|
+
pos -= 1;
|
|
624
|
+
} else {
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
while (pos > 0 && /\s/.test(code[pos - 1])) { pos--; }
|
|
628
|
+
}
|
|
629
|
+
return text;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Is `chain` (the receiver of a `.back(` call) a router expression?
|
|
634
|
+
* Accepted: `router`, a lowercase `*router` member (`this.router`, `appRouter`), any
|
|
635
|
+
* `X.getRouter()` result, and a local alias of either (`const routing = ui.getRouter()`,
|
|
636
|
+
* `const r = router`) resolved through the visible local declarations. Everything else —
|
|
637
|
+
* `history.back`, `this.queue.back`, `this.vm.back`, the static helper `OrderRouter.back(ctx)` —
|
|
638
|
+
* is not a router call and stays out of the rule.
|
|
639
|
+
*/
|
|
640
|
+
function isRouterReceiver(file, chain, at, seen) {
|
|
641
|
+
const c = chain.trim();
|
|
642
|
+
if (c === '') { return false; }
|
|
643
|
+
if (/getRouter\s*\(\s*\)\s*$/.test(c)) { return true; }
|
|
644
|
+
const last = /(?:^|[.?])([A-Za-z_$][\w$]*)$/.exec(c);
|
|
645
|
+
// `router` / `this.router` / `appRouter` — a lowercase member name. An uppercase class
|
|
646
|
+
// (`OrderRouter.back(uiContext)`) is a custom helper, not the router API.
|
|
647
|
+
if (last !== null && /^[a-z][A-Za-z0-9_$]*$/.test(last[1]) && /[Rr]outer$/.test(last[1])) { return true; }
|
|
648
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(c)) { return false; }
|
|
649
|
+
const visited = seen || new Set();
|
|
650
|
+
if (visited.has(c)) { return false; }
|
|
651
|
+
visited.add(c);
|
|
652
|
+
const local = visibleLocal(file, c, at);
|
|
653
|
+
if (local === null || typeof local.init !== 'string' || local.init === '') { return false; }
|
|
654
|
+
return isRouterReceiver(file, local.init, local.index, visited);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** Is the back() index computed from router.getState().index (directly or via a local alias)? */
|
|
658
|
+
function isRouterStateIndex(file, expr, at, seen) {
|
|
659
|
+
if (/getState\s*\(\s*\)\s*\.\s*index/.test(expr)) { return true; }
|
|
660
|
+
const field = /^([A-Za-z_$][\w$]*)\s*\.\s*index(?:\s*[-+]\s*[\s\S]+)?$/.exec(expr);
|
|
661
|
+
if (field !== null) {
|
|
662
|
+
// `const state = router.getState(); … back(state.index - N)`
|
|
663
|
+
const holder = visibleLocal(file, field[1], at);
|
|
664
|
+
return holder !== null && typeof holder.init === 'string' && /getState\s*\(\s*\)\s*$/.test(holder.init);
|
|
665
|
+
}
|
|
666
|
+
const base = /^([A-Za-z_$][\w$]*)(?:\s*[-+]\s*[\s\S]+)?$/.exec(expr);
|
|
667
|
+
if (base === null) { return false; }
|
|
668
|
+
const visited = seen || new Set();
|
|
669
|
+
if (visited.has(base[1])) { return false; }
|
|
670
|
+
visited.add(base[1]);
|
|
671
|
+
const local = visibleLocal(file, base[1], at);
|
|
672
|
+
if (local === null || typeof local.init !== 'string') { return false; }
|
|
673
|
+
// Aliases can chain (`targetIndex = currentIndex - 2`, `currentIndex = routing.getState().index`).
|
|
674
|
+
return isRouterStateIndex(file, local.init, local.index, visited);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function enclosingClassField(file, index, fieldName) {
|
|
678
|
+
let best = null;
|
|
679
|
+
for (const cls of file.classes.values()) {
|
|
680
|
+
if (cls.open <= index && index <= cls.close) {
|
|
681
|
+
if (best === null || (cls.close - cls.open) < (best.close - best.open)) { best = cls; }
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (best === null) { return null; }
|
|
685
|
+
return best.fields.get(fieldName) || null;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function identifierType(file, name, at) {
|
|
689
|
+
const thisField = /^this\.([A-Za-z_$][\w$]*)$/.exec(name);
|
|
690
|
+
if (thisField !== null) { return enclosingClassField(file, at, thisField[1]); }
|
|
691
|
+
|
|
692
|
+
let best = null;
|
|
693
|
+
for (const ps of file.paramScopes) {
|
|
694
|
+
if (!scopeContains(ps.scope, at)) { continue; }
|
|
695
|
+
if (!ps.types.has(name)) { continue; }
|
|
696
|
+
if (best === null || (ps.scope.close - ps.scope.open) < (best.scope.close - best.scope.open)) {
|
|
697
|
+
best = ps;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (best !== null) { return best.types.get(name); }
|
|
701
|
+
|
|
702
|
+
const local = visibleLocal(file, name, at);
|
|
703
|
+
if (local !== null) { return local.type; }
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** Best-effort type of an expression; null means "cannot be graded". */
|
|
708
|
+
function expressionType(file, expr, at) {
|
|
709
|
+
const t = stripOuter(expr);
|
|
710
|
+
let m;
|
|
711
|
+
if ((m = /^new\s+([A-Za-z_$][\w$]*)\s*\(/.exec(t)) !== null) { return m[1]; }
|
|
712
|
+
const cast = splitCast(t);
|
|
713
|
+
if (cast.type !== null) { return cast.type; }
|
|
714
|
+
if (t.startsWith('[')) {
|
|
715
|
+
const close = matchBracket(t, 0);
|
|
716
|
+
if (close < 0) { return null; }
|
|
717
|
+
const elems = splitTopLevel(t, 1, close, ',');
|
|
718
|
+
let elementType = null;
|
|
719
|
+
for (const part of elems) {
|
|
720
|
+
const sub = t.slice(part.start, part.end).trim();
|
|
721
|
+
if (sub === '') { continue; }
|
|
722
|
+
const subType = expressionType(file, sub, at);
|
|
723
|
+
if (subType === null) { return null; }
|
|
724
|
+
if (elementType === null) { elementType = subType; }
|
|
725
|
+
else if (elementType !== subType) { return null; }
|
|
726
|
+
}
|
|
727
|
+
return elementType === null ? null : `Array<${elementType}>`;
|
|
728
|
+
}
|
|
729
|
+
if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?$/.test(t)) {
|
|
730
|
+
return identifierType(file, t, at);
|
|
731
|
+
}
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/* ------------------------------------------------------------------ */
|
|
736
|
+
/* Checker */
|
|
737
|
+
/* ------------------------------------------------------------------ */
|
|
738
|
+
|
|
739
|
+
class RouteParamCarrierSubCheck {
|
|
740
|
+
/** @param {{ addIssue: Function }} host the owning rule (every issue is reported through it). */
|
|
741
|
+
constructor(host) {
|
|
742
|
+
this.host = host;
|
|
743
|
+
this.reported = new Set();
|
|
744
|
+
this.messages = {
|
|
745
|
+
v2Value: {
|
|
746
|
+
en: '[route-param-v2-instance] %s sends the @ObservedV2/@Observed class instance `%s` through router params (`%s`) — router params are serialized at the page boundary, so the instance arrives with __ob_* keys or undefined fields. Send a flat DTO (toXxxDto) and rebuild the entity on the receiving page.',
|
|
747
|
+
cn: '[route-param-v2-instance] %s 把 @ObservedV2/@Observed 类实例 `%s` 通过路由 params 传递(`%s`)——params 在页面边界会被序列化,实例到达对端时字段会变成 __ob_* 或 undefined。请改传扁平 DTO(toXxxDto),由接收页重建实体。',
|
|
748
|
+
},
|
|
749
|
+
v2New: {
|
|
750
|
+
en: '[route-param-v2-new] %s passes `new %s(...)` through router params — a class instance is serialized at the page boundary and loses its decorated fields (`__ob_*` / undefined). Build a flat DTO literal (toXxxDto) instead.',
|
|
751
|
+
cn: '[route-param-v2-new] %s 把 `new %s(...)` 通过路由 params 传递——类实例在页面边界被序列化后,被装饰的字段会丢失(`__ob_*` / undefined)。请改用扁平 DTO 字面量(toXxxDto)。',
|
|
752
|
+
},
|
|
753
|
+
v2Stringify: {
|
|
754
|
+
en: '[route-param-v2-stringify] `JSON.stringify(%s)` where `%s` is an @ObservedV2/@Observed class instance — decorated fields serialize as `__ob_*` keys, so the result is not the DTO the caller expects. Project the fields explicitly (toXxxDto).',
|
|
755
|
+
cn: '[route-param-v2-stringify] 对 `%s` 调用 `JSON.stringify`,而它是 @ObservedV2/@Observed 类实例——被装饰的字段会序列化成 `__ob_*` 键,结果不是调用方期望的 DTO。请显式写 toXxxDto 投影。',
|
|
756
|
+
},
|
|
757
|
+
receive: {
|
|
758
|
+
en: '[route-param-unrebuilt-receive] %s casts the router result to `%s`, whose field `%s` is still typed as the @ObservedV2/@Observed class `%s` — the arriving value is a serialized plain object, not a live instance, so `new %s(...)` is never called and @Trace observation is gone. Validate the key fields and rebuild the entity, or carry the result through a one-shot store.',
|
|
759
|
+
cn: '[route-param-unrebuilt-receive] %s 把路由返回值断言成 `%s`,其中字段 `%s` 仍然是 @ObservedV2/@Observed 类 `%s`——到达的值是序列化后的普通对象,不是活实例,因此没有 `new %s(...)` 重建实体,@Trace 观测也已丢失。请校验关键字段并重建实体,或改用一次性 Store 传递结果。',
|
|
760
|
+
},
|
|
761
|
+
backIndex: {
|
|
762
|
+
en: '[route-back-index-base] back(%s) targets a page by index while the index base is inconsistent: the docs say [0,+∞), the runtime counts from 1 and rejects 0. Compute the target with router.getState().index - N and fall back to back() when it would be < 1.',
|
|
763
|
+
cn: '[route-back-index-base] back(%s) 用索引回退到指定页,但索引起点存在文档冲突:文档写 [0,+∞),运行期按 1 起计数并拒绝 0。请用 router.getState().index - N 计算目标,目标 < 1 时退回 back()。',
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
reset() {
|
|
769
|
+
this.reported = new Set();
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
issue(filePath, line, messageKey, values, severity) {
|
|
773
|
+
const key = `${messageKey}|${filePath}|${line}|${values.join('§')}`;
|
|
774
|
+
if (this.reported.has(key)) { return; }
|
|
775
|
+
this.reported.add(key);
|
|
776
|
+
const template = this.messages[messageKey];
|
|
777
|
+
const build = (text) => {
|
|
778
|
+
let result = text;
|
|
779
|
+
for (const value of values) { result = result.replace('%s', String(value)); }
|
|
780
|
+
return result;
|
|
781
|
+
};
|
|
782
|
+
this.host.addIssue({
|
|
783
|
+
filePath,
|
|
784
|
+
line,
|
|
785
|
+
colStart: 0,
|
|
786
|
+
colEnd: 0,
|
|
787
|
+
message: { en: build(template.en), cn: build(template.cn) },
|
|
788
|
+
severity,
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
check(scans) {
|
|
793
|
+
if (!Array.isArray(scans) || scans.length === 0) { return; }
|
|
794
|
+
const parsed = scans.map((scan) => parseFile(path.normalize(scan.filePath), scan.code, scan.raw));
|
|
795
|
+
const project = buildProject(parsed);
|
|
796
|
+
for (const file of parsed) {
|
|
797
|
+
this.checkRouterCalls(project, file);
|
|
798
|
+
this.checkBackIndex(project, file);
|
|
799
|
+
this.checkStringify(project, file);
|
|
800
|
+
this.checkReceiver(project, file);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/* ---------------------------------------------------------------- */
|
|
805
|
+
|
|
806
|
+
checkRouterCalls(project, file) {
|
|
807
|
+
const callRe = new RegExp(`\\.(${ROUTER_CALLS.join('|')})\\s*\\(`, 'g');
|
|
808
|
+
let m;
|
|
809
|
+
while ((m = callRe.exec(file.code)) !== null) {
|
|
810
|
+
const open = file.code.indexOf('(', m.index);
|
|
811
|
+
const close = matchBracket(file.code, open);
|
|
812
|
+
if (close < 0) { continue; }
|
|
813
|
+
let argStart = open + 1;
|
|
814
|
+
while (argStart < close && /\s/.test(file.code[argStart])) { argStart++; }
|
|
815
|
+
if (file.code[argStart] !== '{') { continue; }
|
|
816
|
+
const argEnd = matchBracket(file.code, argStart);
|
|
817
|
+
if (argEnd < 0) { continue; }
|
|
818
|
+
const params = objectProps(file.code, argStart, argEnd).find((p) => p.key === 'params');
|
|
819
|
+
if (params === undefined) { continue; }
|
|
820
|
+
const line = lineOf(file.code, m.index);
|
|
821
|
+
const boundary = `router.${m[1]}`;
|
|
822
|
+
this.judgeParams(project, file, params.value, params.index, boundary, line);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* `back(index)` — an indexed back call. The index base is ambiguous across the platform's own
|
|
828
|
+
* declarations (and its docs): `[0,+∞)` in UIContext.Router vs 1-based in @ohos.router /
|
|
829
|
+
* getState().index / getStateByIndex, and the runtime rejects 0. Only the
|
|
830
|
+
* `getState().index - N` form (directly or through local aliases) is portable; every other
|
|
831
|
+
* index source is reported so the caller computes the target explicitly and guards `< 1`.
|
|
832
|
+
* Only router receivers are graded; `// BACK-INDEX: <reason>` closes one site.
|
|
833
|
+
*/
|
|
834
|
+
checkBackIndex(project, file) {
|
|
835
|
+
// Strings are masked before locating the call so a log/message literal such as
|
|
836
|
+
// 'router.back(2) failed' is not mistaken for a call; the argument is still read from
|
|
837
|
+
// the original text (positions are preserved by maskStrings).
|
|
838
|
+
const masked = maskStrings(file.code);
|
|
839
|
+
const callRe = /\.back\s*\(/g;
|
|
840
|
+
const rawLines = file.raw.split(/\r?\n/);
|
|
841
|
+
let m;
|
|
842
|
+
while ((m = callRe.exec(masked)) !== null) {
|
|
843
|
+
const open = masked.indexOf('(', m.index);
|
|
844
|
+
const close = matchBracket(masked, open);
|
|
845
|
+
if (close < 0) { continue; }
|
|
846
|
+
const arg = file.code.slice(open + 1, close).trim();
|
|
847
|
+
if (arg === '' || arg.startsWith('{')) { continue; } // back() / back({url}) — no index
|
|
848
|
+
// Router calls only: a custom stack/queue/cursor `.back(n)` is not this rule's subject.
|
|
849
|
+
if (!isRouterReceiver(file, receiverChain(masked, m.index), m.index)) { continue; }
|
|
850
|
+
// `back(index, params)` — only the first argument is the index.
|
|
851
|
+
const first = splitTopLevel(file.code, open + 1, close, ',')[0];
|
|
852
|
+
const indexArg = file.code.slice(first.start, first.end).trim();
|
|
853
|
+
const line = lineOf(file.code, m.index);
|
|
854
|
+
// `// BACK-INDEX: <reason>` closes this site — on the call line, or on a comment-only
|
|
855
|
+
// line directly above (a trailing marker on the previous statement must not leak here).
|
|
856
|
+
const sameLine = rawLines[line - 1] !== undefined && /\/\/\s*BACK-INDEX\s*[::]/.test(rawLines[line - 1]);
|
|
857
|
+
const above = rawLines[line - 2] !== undefined && /^\s*\/\/\s*BACK-INDEX\s*[::]/.test(rawLines[line - 2]);
|
|
858
|
+
if (sameLine || above) { continue; }
|
|
859
|
+
const expr = stripOuter(indexArg);
|
|
860
|
+
if (isRouterStateIndex(file, expr, open)) { continue; }
|
|
861
|
+
this.issue(file.filePath, line, 'backIndex',
|
|
862
|
+
[expr.slice(0, 60)], AlertLevel.WARN);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
judgeParams(project, file, expr, at, boundary, line) {
|
|
867
|
+
const v = stripOuter(expr);
|
|
868
|
+
const cast = splitCast(v);
|
|
869
|
+
if (cast.type !== null) {
|
|
870
|
+
this.judgeType(project, file, cast.type, cast.expr, at, boundary, line);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
if (v.startsWith('{')) {
|
|
874
|
+
const open = file.code.indexOf('{', at);
|
|
875
|
+
const close = matchBracket(file.code, open);
|
|
876
|
+
if (close < 0) { return; }
|
|
877
|
+
for (const prop of objectProps(file.code, open, close)) {
|
|
878
|
+
if (prop.key === null) { continue; }
|
|
879
|
+
this.judgeExpression(project, file, prop.value, prop.index, boundary, line, prop.key);
|
|
880
|
+
}
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
if (v.startsWith('[')) {
|
|
884
|
+
const close = matchBracket(v, 0);
|
|
885
|
+
if (close < 0) { return; }
|
|
886
|
+
for (const part of splitTopLevel(v, 1, close, ',')) {
|
|
887
|
+
const sub = v.slice(part.start, part.end).trim();
|
|
888
|
+
if (sub !== '') { this.judgeExpression(project, file, sub, at, boundary, line, 'params[]'); }
|
|
889
|
+
}
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
const id = /^([A-Za-z_$][\w$]*)$/.exec(v);
|
|
893
|
+
if (id !== null) {
|
|
894
|
+
const local = visibleLocal(file, id[1], at);
|
|
895
|
+
if (local !== null) {
|
|
896
|
+
const init = stripOuter(local.init);
|
|
897
|
+
if (init.startsWith('{')) {
|
|
898
|
+
const open = file.code.indexOf('{', local.initStart);
|
|
899
|
+
const close = matchBracket(file.code, open);
|
|
900
|
+
if (close > 0) {
|
|
901
|
+
for (const prop of objectProps(file.code, open, close)) {
|
|
902
|
+
if (prop.key === null) { continue; }
|
|
903
|
+
this.judgeExpression(project, file, prop.value, prop.index, boundary, line, prop.key);
|
|
904
|
+
}
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (local.type !== null) {
|
|
909
|
+
this.judgeType(project, file, local.type, id[1], at, boundary, line);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
const type = identifierType(file, id[1], at);
|
|
914
|
+
if (type !== null) { this.judgeType(project, file, type, id[1], at, boundary, line); }
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
this.judgeExpression(project, file, v, at, boundary, line, 'params');
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
judgeExpression(project, file, expr, at, boundary, line, label) {
|
|
921
|
+
const v = stripOuter(expr);
|
|
922
|
+
const cast = splitCast(v);
|
|
923
|
+
if (cast.type !== null) {
|
|
924
|
+
this.judgeType(project, file, cast.type, cast.expr, at, boundary, line, label);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
if (v.startsWith('{')) {
|
|
928
|
+
const open = file.code.indexOf('{', at);
|
|
929
|
+
const close = matchBracket(file.code, open);
|
|
930
|
+
if (close < 0) { return; }
|
|
931
|
+
for (const prop of objectProps(file.code, open, close)) {
|
|
932
|
+
if (prop.key === null) { continue; }
|
|
933
|
+
this.judgeExpression(project, file, prop.value, prop.index, boundary, line, `${label}.${prop.key}`);
|
|
934
|
+
}
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (v.startsWith('[')) {
|
|
938
|
+
const close = matchBracket(v, 0);
|
|
939
|
+
if (close < 0) { return; }
|
|
940
|
+
for (const part of splitTopLevel(v, 1, close, ',')) {
|
|
941
|
+
const sub = v.slice(part.start, part.end).trim();
|
|
942
|
+
if (sub !== '') {
|
|
943
|
+
this.judgeExpression(project, file, sub, at, boundary, line, `${label}[]`);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
const type = expressionType(file, v, at);
|
|
949
|
+
if (type !== null) { this.judgeType(project, file, type, v, at, boundary, line, label); }
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
judgeType(project, file, type, expr, at, boundary, line, label) {
|
|
953
|
+
const decorated = decoratedType(project, file, type);
|
|
954
|
+
if (decorated !== null) {
|
|
955
|
+
const shown = label || expr;
|
|
956
|
+
if (/^new\s+/.test(stripOuter(expr))) {
|
|
957
|
+
this.issue(file.filePath, line, 'v2New', [boundary, decorated.className], AlertLevel.ERROR);
|
|
958
|
+
} else {
|
|
959
|
+
this.issue(file.filePath, line, 'v2Value', [boundary, decorated.className, shown], AlertLevel.ERROR);
|
|
960
|
+
}
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const contract = contractWithDecoratedField(project, file, type);
|
|
964
|
+
if (contract !== null) {
|
|
965
|
+
const shown = label || expr;
|
|
966
|
+
this.issue(file.filePath, line, 'v2Value',
|
|
967
|
+
[boundary, contract.fieldType, `${shown}.${contract.field}`], AlertLevel.ERROR);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
checkStringify(project, file) {
|
|
972
|
+
const re = /JSON\.stringify\s*\(/g;
|
|
973
|
+
let m;
|
|
974
|
+
while ((m = re.exec(file.code)) !== null) {
|
|
975
|
+
const open = file.code.indexOf('(', m.index);
|
|
976
|
+
const close = matchBracket(file.code, open);
|
|
977
|
+
if (close < 0) { continue; }
|
|
978
|
+
const args = splitTopLevel(file.code, open + 1, close, ',');
|
|
979
|
+
if (args.length === 0) { continue; }
|
|
980
|
+
const arg = file.code.slice(args[0].start, args[0].end).trim();
|
|
981
|
+
if (arg === '') { continue; }
|
|
982
|
+
const type = expressionType(file, arg, m.index);
|
|
983
|
+
if (type === null) { continue; }
|
|
984
|
+
const decorated = decoratedType(project, file, type);
|
|
985
|
+
if (decorated === null) { continue; }
|
|
986
|
+
this.issue(file.filePath, lineOf(file.code, m.index), 'v2Stringify',
|
|
987
|
+
[arg, decorated.className], AlertLevel.ERROR);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
checkReceiver(project, file) {
|
|
992
|
+
const getRe = /\.getParams\s*\(\s*\)/g;
|
|
993
|
+
let m;
|
|
994
|
+
while ((m = getRe.exec(file.code)) !== null) {
|
|
995
|
+
const body = this.enclosingBody(file, m.index);
|
|
996
|
+
if (body === null) { continue; }
|
|
997
|
+
const rawVars = new Set();
|
|
998
|
+
const rawRe = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=;\n]+)?=\s*[^;\n]*getParams\s*\(/g;
|
|
999
|
+
let r;
|
|
1000
|
+
while ((r = rawRe.exec(file.code)) !== null) {
|
|
1001
|
+
if (body.open <= r.index && r.index <= body.close) { rawVars.add(r[1]); }
|
|
1002
|
+
}
|
|
1003
|
+
const castRe = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::\s*([A-Za-z_$][\w$.<>\[\]| ]*))?\s*=\s*([^;\n]+)/g;
|
|
1004
|
+
let c;
|
|
1005
|
+
while ((c = castRe.exec(file.code)) !== null) {
|
|
1006
|
+
if (c.index < m.index || c.index > body.close) { continue; }
|
|
1007
|
+
const rhs = c[3].trim();
|
|
1008
|
+
const annotated = c[2] === undefined ? null : c[2].trim();
|
|
1009
|
+
const asCast = / as\s+([A-Za-z_$][\w$.<>\[\]|]+)\s*$/.exec(rhs);
|
|
1010
|
+
if (asCast !== null) {
|
|
1011
|
+
this.judgeReceiverContract(project, file, c.index, asCast[1], body);
|
|
1012
|
+
} else if (/getParams\s*\(/.test(rhs)) {
|
|
1013
|
+
if (annotated !== null) { this.judgeReceiverContract(project, file, c.index, annotated, body); }
|
|
1014
|
+
} else {
|
|
1015
|
+
const source = /^([A-Za-z_$][\w$]*)$/.exec(rhs);
|
|
1016
|
+
if (source !== null && rawVars.has(source[1]) && annotated !== null) {
|
|
1017
|
+
this.judgeReceiverContract(project, file, c.index, annotated, body);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
enclosingBody(file, index) {
|
|
1025
|
+
let best = null;
|
|
1026
|
+
for (const ps of file.paramScopes) {
|
|
1027
|
+
if (ps.scope !== null && ps.scope.open <= index && index <= ps.scope.close) {
|
|
1028
|
+
if (best === null || (ps.scope.close - ps.scope.open) < (best.close - best.open)) {
|
|
1029
|
+
best = ps.scope;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
if (best !== null) { return best; }
|
|
1034
|
+
const scope = file.scopeOf(index);
|
|
1035
|
+
return scope === null ? null : { open: scope.open, close: scope.close };
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
judgeReceiverContract(project, file, index, type, body) {
|
|
1039
|
+
const contract = contractWithDecoratedField(project, file, type);
|
|
1040
|
+
if (contract === null) { return; }
|
|
1041
|
+
const tail = file.code.slice(index, body.close);
|
|
1042
|
+
if (/\btypeof\b/.test(tail)) { return; }
|
|
1043
|
+
const escaped = contract.className.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1044
|
+
if (new RegExp(`\\bnew\\s+${escaped}\\s*\\(`).test(tail)) { return; }
|
|
1045
|
+
this.issue(file.filePath, lineOf(file.code, index), 'receive',
|
|
1046
|
+
['router.getParams()', contract.contract, contract.field, contract.fieldType, contract.className],
|
|
1047
|
+
AlertLevel.WARN);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// Sub-check module: no Rule(...) decorator and no ruleDocPath of its own; the owning
|
|
1052
|
+
// @hometrans/arkui-runtime-pitfall rule reports every issue through its own doc.
|
|
1053
|
+
module.exports = { RouteParamCarrierSubCheck };
|