@codeyam/codeyam-cli 0.1.0-staging.8aea589 → 0.1.0-staging.bbe4da9
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/analyzer-template/.build-info.json +7 -7
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +8 -7
- package/analyzer-template/packages/ai/index.ts +6 -2
- package/analyzer-template/packages/ai/package.json +2 -2
- package/analyzer-template/packages/ai/scripts/ai-test-matrix.mjs +424 -0
- package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +24 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +6 -16
- package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +197 -0
- package/analyzer-template/packages/ai/src/lib/astScopes/paths.ts +28 -2
- package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +145 -4
- package/analyzer-template/packages/ai/src/lib/checkAllAttributes.ts +1 -3
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1877 -542
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/FunctionCallManager.ts +138 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.ts +1 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +139 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/DebugTracer.ts +224 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/PathManager.ts +203 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/README.md +294 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +161 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/VisitedTracker.ts +235 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +64 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +14 -6
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/selectBestValue.ts +70 -0
- package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/uniqueIdUtils.ts +113 -0
- package/analyzer-template/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.ts +36 -0
- package/analyzer-template/packages/ai/src/lib/generateChangesEntityDocumentation.ts +20 -2
- package/analyzer-template/packages/ai/src/lib/generateChangesEntityScenarioData.ts +56 -160
- package/analyzer-template/packages/ai/src/lib/generateChangesEntityScenarios.ts +79 -265
- package/analyzer-template/packages/ai/src/lib/generateEntityDocumentation.ts +16 -2
- package/analyzer-template/packages/ai/src/lib/generateEntityKeyAttributes.ts +32 -8
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +53 -154
- package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +84 -254
- package/analyzer-template/packages/ai/src/lib/generateStatementAnalysis.ts +48 -71
- package/analyzer-template/packages/ai/src/lib/getConditionalUsagesFromCode.ts +27 -6
- package/analyzer-template/packages/ai/src/lib/getLLMCallStats.ts +0 -14
- package/analyzer-template/packages/ai/src/lib/modelInfo.ts +15 -0
- package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +42 -4
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChangesEntityDocumentationGenerator.ts +8 -33
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.ts +54 -62
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.ts +93 -109
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityDocumentationGenerator.ts +8 -27
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +33 -38
- package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.ts +30 -30
- package/analyzer-template/packages/ai/src/lib/types/index.ts +2 -0
- package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +41 -0
- package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +47 -8
- package/analyzer-template/packages/analyze/src/lib/asts/nodes/getNodeType.ts +1 -1
- package/analyzer-template/packages/analyze/src/lib/asts/nodes/index.ts +2 -1
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExportedNodes.ts +4 -2
- package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +5 -3
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +8 -10
- package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +6 -1
- package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +8 -6
- package/analyzer-template/packages/analyze/src/lib/files/analyze/trackEntityCircularDependencies.ts +5 -13
- package/analyzer-template/packages/analyze/src/lib/files/analyzeChange.ts +34 -15
- package/analyzer-template/packages/analyze/src/lib/files/analyzeEntity.ts +17 -3
- package/analyzer-template/packages/analyze/src/lib/files/analyzeInitial.ts +35 -16
- package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +21 -33
- package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +75 -10
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +26 -0
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +7 -1
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.ts +9 -1
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateScenarioData.ts +6 -1
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateScenarios.ts +9 -1
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +15 -7
- package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.ts +12 -2
- package/analyzer-template/packages/aws/dist/src/lib/s3/getPresignedUrl.d.ts +23 -0
- package/analyzer-template/packages/aws/dist/src/lib/s3/getPresignedUrl.d.ts.map +1 -0
- package/analyzer-template/packages/aws/dist/src/lib/s3/getPresignedUrl.js +30 -0
- package/analyzer-template/packages/aws/dist/src/lib/s3/getPresignedUrl.js.map +1 -0
- package/analyzer-template/packages/aws/package.json +5 -4
- package/analyzer-template/packages/aws/s3/index.ts +4 -0
- package/analyzer-template/packages/aws/src/lib/s3/getPresignedUrl.ts +62 -0
- package/analyzer-template/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.ts +28 -21
- package/analyzer-template/packages/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.ts +18 -11
- package/analyzer-template/packages/generate/src/lib/scenarioComponent.ts +6 -3
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js +28 -21
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.js +18 -11
- package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.js.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponent.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponent.js +5 -3
- package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponent.js.map +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/db.d.ts +2 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/db.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/db.js +3 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/db.js.map +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tableRelations.d.ts +2 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tableRelations.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tables/debugReportsTable.d.ts +37 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tables/debugReportsTable.d.ts.map +1 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tables/debugReportsTable.js +27 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/kysely/tables/debugReportsTable.js.map +1 -0
- package/analyzer-template/packages/github/dist/supabase/src/lib/scenarioToDb.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/scenarioToDb.js +1 -1
- package/analyzer-template/packages/github/dist/supabase/src/lib/scenarioToDb.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/index.d.ts +2 -0
- package/analyzer-template/packages/github/dist/utils/index.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/index.js +2 -0
- package/analyzer-template/packages/github/dist/utils/index.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/Semaphore.d.ts +25 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/Semaphore.d.ts.map +1 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/Semaphore.js +40 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/Semaphore.js.map +1 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/applyUniversalMocks.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/applyUniversalMocks.js +39 -5
- package/analyzer-template/packages/github/dist/utils/src/lib/applyUniversalMocks.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getNextRoutePath.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getNextRoutePath.js +2 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getNextRoutePath.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getRemixRoutePath.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getRemixRoutePath.js +2 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/getRemixRoutePath.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.js +2 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.js +1 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.js.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.d.ts +12 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.d.ts.map +1 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.js +32 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.js.map +1 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.js +17 -0
- package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
- package/analyzer-template/packages/supabase/src/lib/kysely/db.ts +6 -0
- package/analyzer-template/packages/supabase/src/lib/kysely/tableRelations.ts +3 -0
- package/analyzer-template/packages/supabase/src/lib/kysely/tables/debugReportsTable.ts +61 -0
- package/analyzer-template/packages/supabase/src/lib/scenarioToDb.ts +1 -0
- package/analyzer-template/packages/ui-components/src/scenario-editor/components/DataItemEditor.tsx +1 -1
- package/analyzer-template/packages/utils/dist/utils/index.d.ts +2 -0
- package/analyzer-template/packages/utils/dist/utils/index.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/index.js +2 -0
- package/analyzer-template/packages/utils/dist/utils/index.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/Semaphore.d.ts +25 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/Semaphore.d.ts.map +1 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/Semaphore.js +40 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/Semaphore.js.map +1 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/applyUniversalMocks.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/applyUniversalMocks.js +39 -5
- package/analyzer-template/packages/utils/dist/utils/src/lib/applyUniversalMocks.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getNextRoutePath.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getNextRoutePath.js +2 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getNextRoutePath.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getRemixRoutePath.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getRemixRoutePath.js +2 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/getRemixRoutePath.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.js +2 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/nextRouteFileNameToRoute.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.js +1 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/remixRouteFileNameToRoute.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.d.ts +12 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.d.ts.map +1 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.js +32 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/frameworks/sanitizeNextRouteSegments.js.map +1 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.js +17 -0
- package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
- package/analyzer-template/packages/utils/index.ts +2 -0
- package/analyzer-template/packages/utils/src/lib/Semaphore.ts +42 -0
- package/analyzer-template/packages/utils/src/lib/applyUniversalMocks.ts +46 -7
- package/analyzer-template/packages/utils/src/lib/frameworks/getNextRoutePath.ts +2 -1
- package/analyzer-template/packages/utils/src/lib/frameworks/getRemixRoutePath.ts +2 -1
- package/analyzer-template/packages/utils/src/lib/frameworks/nextRouteFileNameToRoute.ts +2 -1
- package/analyzer-template/packages/utils/src/lib/frameworks/remixRouteFileNameToRoute.ts +1 -0
- package/analyzer-template/packages/utils/src/lib/frameworks/sanitizeNextRouteSegments.ts +33 -0
- package/analyzer-template/packages/utils/src/lib/lightweightEntityExtractor.ts +16 -0
- package/analyzer-template/project/constructMockCode.ts +199 -9
- package/analyzer-template/project/reconcileMockDataKeys.ts +13 -0
- package/analyzer-template/project/runMultiScenarioServer.ts +0 -4
- package/analyzer-template/project/runScenarioServer.ts +0 -4
- package/analyzer-template/project/start.ts +1 -11
- package/analyzer-template/project/startScenarioCapture.ts +24 -0
- package/analyzer-template/project/startServer.ts +50 -70
- package/analyzer-template/project/trackGeneratedFiles.ts +41 -0
- package/analyzer-template/project/writeMockDataTsx.ts +191 -7
- package/analyzer-template/project/writeScenarioComponents.ts +643 -63
- package/analyzer-template/project/writeUniversalMocks.ts +66 -8
- package/analyzer-template/scripts/postbuild.cjs +12 -1
- package/background/src/lib/virtualized/project/constructMockCode.js +183 -11
- package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +12 -0
- package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
- package/background/src/lib/virtualized/project/runMultiScenarioServer.js +0 -3
- package/background/src/lib/virtualized/project/runMultiScenarioServer.js.map +1 -1
- package/background/src/lib/virtualized/project/start.js +1 -8
- package/background/src/lib/virtualized/project/start.js.map +1 -1
- package/background/src/lib/virtualized/project/startScenarioCapture.js +18 -0
- package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
- package/background/src/lib/virtualized/project/startServer.js +40 -68
- package/background/src/lib/virtualized/project/startServer.js.map +1 -1
- package/background/src/lib/virtualized/project/trackGeneratedFiles.js +30 -0
- package/background/src/lib/virtualized/project/trackGeneratedFiles.js.map +1 -0
- package/background/src/lib/virtualized/project/writeMockDataTsx.js +156 -6
- package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
- package/background/src/lib/virtualized/project/writeScenarioComponents.js +433 -41
- package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
- package/background/src/lib/virtualized/project/writeUniversalMocks.js +56 -7
- package/background/src/lib/virtualized/project/writeUniversalMocks.js.map +1 -1
- package/codeyam-cli/src/cli.js +6 -0
- package/codeyam-cli/src/cli.js.map +1 -1
- package/codeyam-cli/src/codeyam-cli.js +0 -0
- package/codeyam-cli/src/commands/debug.js +222 -0
- package/codeyam-cli/src/commands/debug.js.map +1 -0
- package/codeyam-cli/src/commands/init.js +4 -23
- package/codeyam-cli/src/commands/init.js.map +1 -1
- package/codeyam-cli/src/commands/report.js +102 -0
- package/codeyam-cli/src/commands/report.js.map +1 -0
- package/codeyam-cli/src/commands/setup-sandbox.js +165 -0
- package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -0
- package/codeyam-cli/src/commands/test-startup.js +14 -5
- package/codeyam-cli/src/commands/test-startup.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/cleanupAnalysisFiles.test.js +6 -6
- package/codeyam-cli/src/utils/__tests__/cleanupAnalysisFiles.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +8 -0
- package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
- package/codeyam-cli/src/utils/analysisRunner.js +2 -1
- package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
- package/codeyam-cli/src/utils/analyzer.js +24 -2
- package/codeyam-cli/src/utils/analyzer.js.map +1 -1
- package/codeyam-cli/src/utils/cleanupAnalysisFiles.js +2 -2
- package/codeyam-cli/src/utils/cleanupAnalysisFiles.js.map +1 -1
- package/codeyam-cli/src/utils/generateReport.js +219 -0
- package/codeyam-cli/src/utils/generateReport.js.map +1 -0
- package/codeyam-cli/src/utils/install-skills.js +7 -0
- package/codeyam-cli/src/utils/install-skills.js.map +1 -1
- package/codeyam-cli/src/utils/queue/__tests__/job.pidTracking.test.js +1 -0
- package/codeyam-cli/src/utils/queue/__tests__/job.pidTracking.test.js.map +1 -1
- package/codeyam-cli/src/utils/queue/job.js +10 -5
- package/codeyam-cli/src/utils/queue/job.js.map +1 -1
- package/codeyam-cli/src/utils/sandbox.js +190 -0
- package/codeyam-cli/src/utils/sandbox.js.map +1 -0
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +4 -0
- package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
- package/codeyam-cli/src/utils/webappDetection.js +2 -1
- package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
- package/codeyam-cli/src/webserver/app/lib/database.js +50 -2
- package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeIcon-Dp_FTAs1.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-TlHocYno.js +26 -0
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-CVMmGuIc.js +3 -0
- package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-BKKG1s2B.js → LogViewer-JkfQ-VaI.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-Cqce0_KG.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-BrMAP1nP.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/ScenarioPreview-Bi-__7HT.js +6 -0
- package/codeyam-cli/src/webserver/build/client/assets/ScenarioViewer-XmIpHcLJ.js +5 -0
- package/codeyam-cli/src/webserver/build/client/assets/_index-BmfhU6CA.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-Dm8lM73z.js +10 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.generate-report-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/chart-column-kA4jn9if.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/chunk-WWGJGFF6-CgXbbZRx.js +26 -0
- package/codeyam-cli/src/webserver/build/client/assets/circle-check-B2oHQ-zo.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/clock-BAfbP_iK.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/codeyam-name-logo-CvKwUgHo.svg +9 -0
- package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-BBYuR56H.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BgPXZbm0.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-BHiWkb_W.js → entity._sha._-BkoAXaOa.js} +10 -10
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-Bj5GHkhb.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.edit._scenarioId-eW5z9AyZ.js +5 -0
- package/codeyam-cli/src/webserver/build/client/assets/entityStatus-C5Okl18j.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entityVersioning-Bk_YB1jM.js → entityVersioning-CU_Lchhc.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/entry.client-B9tSboXM.js +5 -0
- package/codeyam-cli/src/webserver/build/client/assets/file-text-18aYHZGd.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/files-Df79EyEb.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/git-CDEwTVH_.js +12 -0
- package/codeyam-cli/src/webserver/build/client/assets/globals-DXRB6jBc.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/html2canvas-pro.esm-XQCGvadH.js +5 -0
- package/codeyam-cli/src/webserver/build/client/assets/index-_LjBsTxX.js +8 -0
- package/codeyam-cli/src/webserver/build/client/assets/loader-circle-D_EGChhq.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/manifest-3e0ffbcc.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/root-CGyT4J4b.js +16 -0
- package/codeyam-cli/src/webserver/build/client/assets/settings-CEPbAsom.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/settings-R8QF_mHX.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/simulations-B_PXvFom.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/triangle-alert-BthANBVv.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-Lumm1t01.js → useLastLogLine-Blr5oZDE.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/useReportContext-CANr3QJ5.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/useToast-Bbf4Hokd.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/index-vf1FETCO.js +1 -0
- package/codeyam-cli/src/webserver/build/server/assets/server-build-B5s58TvB.js +169 -0
- package/codeyam-cli/src/webserver/build/server/index.js +1 -1
- package/codeyam-cli/src/webserver/build-info.json +5 -5
- package/codeyam-cli/src/webserver/server.js +1 -1
- package/codeyam-cli/src/webserver/server.js.map +1 -1
- package/codeyam-cli/templates/codeyam-setup-skill.md +70 -85
- package/codeyam-cli/templates/debug-command.md +125 -0
- package/package.json +9 -11
- package/packages/ai/index.js +2 -3
- package/packages/ai/index.js.map +1 -1
- package/packages/ai/src/lib/analyzeScope.js +13 -0
- package/packages/ai/src/lib/analyzeScope.js.map +1 -1
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +6 -15
- package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
- package/packages/ai/src/lib/astScopes/methodSemantics.js +134 -0
- package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
- package/packages/ai/src/lib/astScopes/paths.js +28 -3
- package/packages/ai/src/lib/astScopes/paths.js.map +1 -1
- package/packages/ai/src/lib/astScopes/processExpression.js +123 -3
- package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
- package/packages/ai/src/lib/checkAllAttributes.js +1 -3
- package/packages/ai/src/lib/checkAllAttributes.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +1358 -396
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/FunctionCallManager.js +137 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/FunctionCallManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js +1 -1
- package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +112 -0
- package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/DebugTracer.js +176 -0
- package/packages/ai/src/lib/dataStructure/helpers/DebugTracer.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/PathManager.js +178 -0
- package/packages/ai/src/lib/dataStructure/helpers/PathManager.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +138 -0
- package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/VisitedTracker.js +199 -0
- package/packages/ai/src/lib/dataStructure/helpers/VisitedTracker.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +55 -1
- package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +14 -6
- package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
- package/packages/ai/src/lib/dataStructure/helpers/selectBestValue.js +62 -0
- package/packages/ai/src/lib/dataStructure/helpers/selectBestValue.js.map +1 -0
- package/packages/ai/src/lib/dataStructure/helpers/uniqueIdUtils.js +90 -0
- package/packages/ai/src/lib/dataStructure/helpers/uniqueIdUtils.js.map +1 -0
- package/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.js +22 -0
- package/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.js.map +1 -1
- package/packages/ai/src/lib/generateChangesEntityDocumentation.js +19 -1
- package/packages/ai/src/lib/generateChangesEntityDocumentation.js.map +1 -1
- package/packages/ai/src/lib/generateChangesEntityScenarioData.js +55 -156
- package/packages/ai/src/lib/generateChangesEntityScenarioData.js.map +1 -1
- package/packages/ai/src/lib/generateChangesEntityScenarios.js +79 -262
- package/packages/ai/src/lib/generateChangesEntityScenarios.js.map +1 -1
- package/packages/ai/src/lib/generateEntityDocumentation.js +15 -1
- package/packages/ai/src/lib/generateEntityDocumentation.js.map +1 -1
- package/packages/ai/src/lib/generateEntityKeyAttributes.js +32 -8
- package/packages/ai/src/lib/generateEntityKeyAttributes.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarioData.js +52 -152
- package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
- package/packages/ai/src/lib/generateEntityScenarios.js +88 -258
- package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
- package/packages/ai/src/lib/generateStatementAnalysis.js +46 -71
- package/packages/ai/src/lib/generateStatementAnalysis.js.map +1 -1
- package/packages/ai/src/lib/getConditionalUsagesFromCode.js +13 -8
- package/packages/ai/src/lib/getConditionalUsagesFromCode.js.map +1 -1
- package/packages/ai/src/lib/getLLMCallStats.js +0 -14
- package/packages/ai/src/lib/getLLMCallStats.js.map +1 -1
- package/packages/ai/src/lib/modelInfo.js +15 -0
- package/packages/ai/src/lib/modelInfo.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +36 -3
- package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityDocumentationGenerator.js +8 -33
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityDocumentationGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.js +35 -41
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.js +59 -72
- package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateEntityDocumentationGenerator.js +8 -27
- package/packages/ai/src/lib/promptGenerators/generateEntityDocumentationGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +24 -27
- package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
- package/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.js +21 -22
- package/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.js.map +1 -1
- package/packages/ai/src/lib/types/index.js +2 -0
- package/packages/ai/src/lib/types/index.js.map +1 -1
- package/packages/ai/src/lib/worker/SerializableDataStructure.js +7 -0
- package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/FileAnalyzer.js +39 -7
- package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
- package/packages/analyze/src/lib/asts/nodes/getNodeType.js +1 -1
- package/packages/analyze/src/lib/asts/nodes/getNodeType.js.map +1 -1
- package/packages/analyze/src/lib/asts/nodes/index.js +2 -1
- package/packages/analyze/src/lib/asts/nodes/index.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExportedNodes.js +3 -2
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExportedNodes.js.map +1 -1
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +4 -3
- package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +6 -8
- package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +5 -1
- package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +8 -2
- package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/trackEntityCircularDependencies.js +5 -8
- package/packages/analyze/src/lib/files/analyze/trackEntityCircularDependencies.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeChange.js +21 -9
- package/packages/analyze/src/lib/files/analyzeChange.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeEntity.js +10 -4
- package/packages/analyze/src/lib/files/analyzeEntity.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeInitial.js +21 -9
- package/packages/analyze/src/lib/files/analyzeInitial.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeRemixRoute.js +18 -23
- package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
- package/packages/analyze/src/lib/files/getImportedExports.js +56 -4
- package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +24 -0
- package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +6 -1
- package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.js +9 -1
- package/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateScenarioData.js +5 -1
- package/packages/analyze/src/lib/files/scenarios/generateScenarioData.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/generateScenarios.js +9 -1
- package/packages/analyze/src/lib/files/scenarios/generateScenarios.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +16 -7
- package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js +8 -2
- package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js.map +1 -1
- package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js +28 -21
- package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js.map +1 -1
- package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.js +18 -11
- package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageRemix.js.map +1 -1
- package/packages/generate/src/lib/scenarioComponent.js +5 -3
- package/packages/generate/src/lib/scenarioComponent.js.map +1 -1
- package/packages/supabase/src/lib/kysely/db.js +3 -0
- package/packages/supabase/src/lib/kysely/db.js.map +1 -1
- package/packages/supabase/src/lib/kysely/tables/debugReportsTable.js +27 -0
- package/packages/supabase/src/lib/kysely/tables/debugReportsTable.js.map +1 -0
- package/packages/supabase/src/lib/scenarioToDb.js +1 -1
- package/packages/supabase/src/lib/scenarioToDb.js.map +1 -1
- package/packages/utils/index.js +2 -0
- package/packages/utils/index.js.map +1 -1
- package/packages/utils/src/lib/Semaphore.js +40 -0
- package/packages/utils/src/lib/Semaphore.js.map +1 -0
- package/packages/utils/src/lib/applyUniversalMocks.js +39 -5
- package/packages/utils/src/lib/applyUniversalMocks.js.map +1 -1
- package/packages/utils/src/lib/frameworks/getNextRoutePath.js +2 -1
- package/packages/utils/src/lib/frameworks/getNextRoutePath.js.map +1 -1
- package/packages/utils/src/lib/frameworks/getRemixRoutePath.js +2 -1
- package/packages/utils/src/lib/frameworks/getRemixRoutePath.js.map +1 -1
- package/packages/utils/src/lib/frameworks/nextRouteFileNameToRoute.js +2 -1
- package/packages/utils/src/lib/frameworks/nextRouteFileNameToRoute.js.map +1 -1
- package/packages/utils/src/lib/frameworks/remixRouteFileNameToRoute.js +1 -0
- package/packages/utils/src/lib/frameworks/remixRouteFileNameToRoute.js.map +1 -1
- package/packages/utils/src/lib/frameworks/sanitizeNextRouteSegments.js +32 -0
- package/packages/utils/src/lib/frameworks/sanitizeNextRouteSegments.js.map +1 -0
- package/packages/utils/src/lib/lightweightEntityExtractor.js +17 -0
- package/packages/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
- package/analyzer-template/packages/ai/src/lib/generateEntityDataMap.ts +0 -375
- package/codeyam-cli/src/webserver/build/client/assets/EntityTypeIcon-rqv54FUY.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-B0oiPem-.js +0 -26
- package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DqXXjAJ7.js +0 -3
- package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-DU_jxCPD.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/ScenarioPreview-5DY-YIxu.js +0 -6
- package/codeyam-cli/src/webserver/build/client/assets/ScenarioViewer-DmjXUj6m.js +0 -5
- package/codeyam-cli/src/webserver/build/client/assets/_index-DvSrcxsk.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-CsaMd9mb.js +0 -10
- package/codeyam-cli/src/webserver/build/client/assets/chart-column-VXBS6qOn.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/circle-alert-n5GUC2AS.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/clock-DKqtX8js.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/components-Dj-Ggnl2.js +0 -40
- package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BbR3FwNc.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-L7M9Vr5z.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.edit._scenarioId-C9w-q7P3.js +0 -5
- package/codeyam-cli/src/webserver/build/client/assets/entry.client-CdGoUs8A.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/file-text-B6Er7j5k.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/files-KcDVw1FY.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/git-B9uZ8eSJ.js +0 -12
- package/codeyam-cli/src/webserver/build/client/assets/globals-B0f88RTV.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/loader-circle-v3c6DFp4.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-fca08d7e.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/root-Cf8VBqIb.js +0 -16
- package/codeyam-cli/src/webserver/build/client/assets/search-DA14wXpu.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-COJUrwGu.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/settings-NU_ZquhK.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/simulations-CNaMJ-nR.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/useToast-BRShB17p.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/zap-BvukH0eN.js +0 -1
- package/codeyam-cli/src/webserver/build/client/cy-logo-cli.svg +0 -13
- package/codeyam-cli/src/webserver/build/client/favicon.svg +0 -13
- package/codeyam-cli/src/webserver/build/server/assets/index-DHr4rT4u.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-Bi1mj14J.js +0 -166
- package/codeyam-cli/src/webserver/public/cy-logo-cli.svg +0 -13
- package/codeyam-cli/src/webserver/public/favicon.svg +0 -13
- package/packages/ai/src/lib/generateEntityDataMap.js +0 -335
- package/packages/ai/src/lib/generateEntityDataMap.js.map +0 -1
- package/packages/ai/src/lib/promptGenerators/generateEntityDataMapGenerator.js +0 -17
- package/packages/ai/src/lib/promptGenerators/generateEntityDataMapGenerator.js.map +0 -1
|
@@ -1,71 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ScopeDataStructure
|
|
2
3
|
*
|
|
3
|
-
* The
|
|
4
|
-
*
|
|
4
|
+
* The core engine for CodeYam's static analysis. Takes AST analysis output and
|
|
5
|
+
* determines the complete data schema for a function by tracking how data flows
|
|
6
|
+
* through the code.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
8
|
+
* ## High-Level Architecture
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* ```
|
|
11
|
+
* ┌─────────────────┐ ┌─────────────────────────────────────────────┐
|
|
12
|
+
* │ AST Analyzer │────▶│ ScopeDataStructure │
|
|
13
|
+
* │ (per-scope) │ │ │
|
|
14
|
+
* └─────────────────┘ │ Phase 1: Discovery (onlyEquivalencies) │
|
|
15
|
+
* │ ├─ Process each scope's analysis │
|
|
16
|
+
* │ ├─ Build equivalency relationships │
|
|
17
|
+
* │ └─ Track nested scope hierarchy │
|
|
18
|
+
* │ │
|
|
19
|
+
* │ Phase 2: Schema Building │
|
|
20
|
+
* │ ├─ Follow all equivalencies │
|
|
21
|
+
* │ ├─ Build complete schemas at data sources │
|
|
22
|
+
* │ └─ Populate equivalencyDatabase │
|
|
23
|
+
* └─────────────────────────────────────────────┘
|
|
24
|
+
* │
|
|
25
|
+
* ▼
|
|
26
|
+
* ┌─────────────────────────────────────────────┐
|
|
27
|
+
* │ Output │
|
|
28
|
+
* │ • Function signature schemas │
|
|
29
|
+
* │ • Return value types │
|
|
30
|
+
* │ • External API call schemas │
|
|
31
|
+
* │ • Data flow (source → usage) mappings │
|
|
32
|
+
* └─────────────────────────────────────────────┘
|
|
33
|
+
* ```
|
|
10
34
|
*
|
|
11
|
-
*
|
|
12
|
-
* source of the data (either the function's signature arguments or an external
|
|
13
|
-
* API call made from within the function). While following the equivalencies the
|
|
14
|
-
* second pass populates the equivalencyDatabase which tracks all equivalent values
|
|
15
|
-
* and provides easy access to determine where data comes from and where it is used
|
|
16
|
-
* to call external functions. This makes it possible to combine schemas between
|
|
17
|
-
* functions to create a complete schema for a dependency tree.
|
|
35
|
+
* ## Key Concepts
|
|
18
36
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
37
|
+
* ### Equivalencies
|
|
38
|
+
* When code assigns one variable to another (`const user = props.user`), we create
|
|
39
|
+
* an "equivalency" linking the two paths. Following these links lets us trace data
|
|
40
|
+
* back to its source (function arguments or API returns).
|
|
41
|
+
*
|
|
42
|
+
* ### Schema Paths
|
|
43
|
+
* Dot-separated strings describing data structure:
|
|
44
|
+
* - `signature[0].user.id` - First arg's user.id property
|
|
45
|
+
* - `items[].name` - name property of array elements
|
|
46
|
+
* - `functionCallReturnValue(fetch).data` - Return from fetch() call
|
|
47
|
+
*
|
|
48
|
+
* ### Two-Phase Processing
|
|
49
|
+
* 1. **Phase 1 (Discovery)**: `onlyEquivalencies = true`
|
|
50
|
+
* - Processes scopes, builds equivalency graph
|
|
51
|
+
* - Does NOT populate schemas yet
|
|
52
|
+
*
|
|
53
|
+
* 2. **Phase 2 (Schema Building)**: `captureCompleteSchema()`
|
|
54
|
+
* - Follows equivalencies to build complete schemas
|
|
55
|
+
* - Populates `equivalencyDatabase` for source/usage queries
|
|
56
|
+
*
|
|
57
|
+
* ## Key Methods (Entry Points)
|
|
58
|
+
*
|
|
59
|
+
* - `constructor(scopeName, scopeText, managers, scopeAnalysis)` - Initialize with root scope
|
|
60
|
+
* - `addScopeAnalysis(scopeName, text, analysis)` - Add nested scope
|
|
61
|
+
* - `captureCompleteSchema()` - Trigger Phase 2 processing
|
|
62
|
+
* - `getSchema({scopeName})` - Get schema for a scope
|
|
63
|
+
* - `getFunctionSignature({functionName})` - Get function signature schema
|
|
64
|
+
* - `getSourceEquivalencies()` - Find where data comes from
|
|
65
|
+
* - `getUsageEquivalencies()` - Find where data is used
|
|
66
|
+
*
|
|
67
|
+
* ## Debugging Tips
|
|
68
|
+
*
|
|
69
|
+
* - Enable metrics: `addToSchemaCallCount`, `followEquivalenciesCallCount`
|
|
70
|
+
* - Check `scopeNode.equivalencies` for raw equivalency data
|
|
71
|
+
* - Use `getEquivalenciesDatabaseEntry(scope, path)` to trace a specific path
|
|
72
|
+
* - The `visitedTracker` prevents infinite loops - if data is missing, check if
|
|
73
|
+
* it was already visited with a different value
|
|
74
|
+
*
|
|
75
|
+
* ## Related Files
|
|
76
|
+
*
|
|
77
|
+
* - `helpers/` - Extracted utility modules (PathManager, VisitedTracker, etc.)
|
|
78
|
+
* - `equivalencyManagers/` - Plugins that create equivalencies from AST patterns
|
|
79
|
+
* - `helpers/README.md` - Overview of the helper module architecture
|
|
22
80
|
*/
|
|
23
|
-
import { joinParenthesesAndArrays, splitOutsideParenthesesAndArrays, } from "../splitOutsideParentheses.js";
|
|
24
81
|
import fillInSchemaGapsAndUnknowns from "./helpers/fillInSchemaGapsAndUnknowns.js";
|
|
25
82
|
import ensureSchemaConsistency from "./helpers/ensureSchemaConsistency.js";
|
|
26
|
-
import cleanOutBoundary from "../cleanOutBoundary.js";
|
|
27
83
|
import cleanPath from "./helpers/cleanPath.js";
|
|
84
|
+
import { PathManager } from "./helpers/PathManager.js";
|
|
85
|
+
import { uniqueId, uniqueScopeVariables, uniqueScopeAndPaths, } from "./helpers/uniqueIdUtils.js";
|
|
86
|
+
import selectBestValue from "./helpers/selectBestValue.js";
|
|
87
|
+
import { VisitedTracker } from "./helpers/VisitedTracker.js";
|
|
88
|
+
import { DebugTracer } from "./helpers/DebugTracer.js";
|
|
89
|
+
import { BatchSchemaProcessor } from "./helpers/BatchSchemaProcessor.js";
|
|
90
|
+
import { ScopeTreeManager, ROOT_SCOPE_NAME, } from "./helpers/ScopeTreeManager.js";
|
|
28
91
|
import cleanScopeNodeName from "./helpers/cleanScopeNodeName.js";
|
|
29
92
|
import getFunctionCallRoot from "./helpers/getFunctionCallRoot.js";
|
|
30
93
|
import cleanPathOfNonTransformingFunctions from "./helpers/cleanPathOfNonTransformingFunctions.js";
|
|
31
94
|
import { arrayMethodsSet } from "./helpers/cleanNonObjectFunctions.js";
|
|
32
|
-
const ROOT_SCOPE_NAME = 'root';
|
|
33
95
|
// DEBUG: Performance metrics
|
|
34
96
|
export let maxEquivalencyChainDepth = 0;
|
|
35
97
|
export let addToSchemaCallCount = 0;
|
|
36
98
|
export let followEquivalenciesCallCount = 0;
|
|
99
|
+
export let followEquivalenciesEarlyExitCount = 0;
|
|
100
|
+
export let followEquivalenciesEarlyExitPhase1Count = 0;
|
|
101
|
+
export let followEquivalenciesWithWorkCount = 0;
|
|
102
|
+
export let addEquivalencyCallCount = 0;
|
|
37
103
|
export function resetScopeDataStructureMetrics() {
|
|
38
104
|
maxEquivalencyChainDepth = 0;
|
|
39
105
|
addToSchemaCallCount = 0;
|
|
40
106
|
followEquivalenciesCallCount = 0;
|
|
107
|
+
followEquivalenciesEarlyExitCount = 0;
|
|
108
|
+
followEquivalenciesEarlyExitPhase1Count = 0;
|
|
109
|
+
followEquivalenciesWithWorkCount = 0;
|
|
110
|
+
addEquivalencyCallCount = 0;
|
|
41
111
|
}
|
|
112
|
+
// Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
|
|
113
|
+
const ALLOWED_EQUIVALENCY_REASONS = new Set([
|
|
114
|
+
'original equivalency',
|
|
115
|
+
'implicit parent equivalency',
|
|
116
|
+
'explicit parent equivalency',
|
|
117
|
+
'transformed non-object function equivalency - original equivalency',
|
|
118
|
+
'equivalency to external function call',
|
|
119
|
+
'functionCall to function signature equivalency',
|
|
120
|
+
'explicit parent signature',
|
|
121
|
+
'useState setter call equivalency',
|
|
122
|
+
'non-object function argument function signature equivalency1',
|
|
123
|
+
'non-object function argument function signature equivalency2',
|
|
124
|
+
'returnValue to functionCallReturnValue equivalency',
|
|
125
|
+
'.map() function deconstruction',
|
|
126
|
+
'useMemo return value equivalent to first argument return value',
|
|
127
|
+
'useState value equivalency',
|
|
128
|
+
'Node .then() equivalency',
|
|
129
|
+
'Explicit array deconstruction equivalency value',
|
|
130
|
+
'forwardRef equivalency',
|
|
131
|
+
'forwardRef signature to child signature equivalency',
|
|
132
|
+
'captured function call return value equivalency',
|
|
133
|
+
'original equivalency - rerouted via useCallback',
|
|
134
|
+
'non-object function argument function signature equivalency1 - rerouted via useCallback',
|
|
135
|
+
'non-object function argument function signature equivalency2 - rerouted via useCallback',
|
|
136
|
+
'implicit parent equivalency - rerouted via useCallback',
|
|
137
|
+
'Spread operator equivalency key update: implicit parent equivalency',
|
|
138
|
+
'Array.from() equivalency',
|
|
139
|
+
'propagated sub-property equivalency',
|
|
140
|
+
'propagated function call return sub-property equivalency',
|
|
141
|
+
'where was this function called from', // Added: tracks which scope called an external function
|
|
142
|
+
]);
|
|
143
|
+
const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
|
|
144
|
+
'signature of functionCall',
|
|
145
|
+
'transformed non-object function equivalency - implicit parent equivalency',
|
|
146
|
+
'transformed non-object function equivalency - non-object function argument function signature equivalency1',
|
|
147
|
+
'transformed non-object function equivalency - non-object function argument function signature equivalency2',
|
|
148
|
+
'transformed non-object function equivalency - equivalency to external function call',
|
|
149
|
+
'Explicit array deconstruction equivalency key',
|
|
150
|
+
'transformed non-object function equivalency - useState setter call equivalency',
|
|
151
|
+
'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
|
|
152
|
+
'transformed non-object function equivalency - Array.from() equivalency',
|
|
153
|
+
'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
|
|
154
|
+
]);
|
|
42
155
|
export class ScopeDataStructure {
|
|
156
|
+
// Getter for backward compatibility - returns the tree structure
|
|
157
|
+
get scopeTree() {
|
|
158
|
+
return this.scopeTreeManager.getTree();
|
|
159
|
+
}
|
|
43
160
|
constructor(managers, scopeName = ROOT_SCOPE_NAME, scopeText, scopeAnalysis) {
|
|
44
161
|
this.debugCount = 0;
|
|
45
162
|
this.onlyEquivalencies = true;
|
|
46
163
|
this.equivalencyManagers = [];
|
|
47
164
|
this.scopeNodes = {};
|
|
48
|
-
this.
|
|
165
|
+
this.scopeTreeManager = new ScopeTreeManager();
|
|
49
166
|
this.externalFunctionCalls = [];
|
|
50
167
|
this.environmentVariables = [];
|
|
51
168
|
this.equivalencyDatabase = [];
|
|
169
|
+
/**
|
|
170
|
+
* Conditional usages collected during AST analysis.
|
|
171
|
+
* Maps local variable path to array of usages.
|
|
172
|
+
*/
|
|
173
|
+
this.rawConditionalUsages = {};
|
|
52
174
|
this.lastAddToSchemaId = 0;
|
|
53
175
|
this.lastEquivalencyId = 0;
|
|
54
176
|
this.lastEquivalencyDatabaseId = 0;
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
177
|
+
this.pathManager = new PathManager();
|
|
178
|
+
this.visitedTracker = new VisitedTracker();
|
|
57
179
|
this.equivalencyDatabaseCache = new Map();
|
|
58
180
|
// Inverted index: maps uniqueId -> EquivalencyDatabaseEntry for O(1) lookup
|
|
59
181
|
this.intermediatesOrderIndex = new Map();
|
|
60
|
-
|
|
182
|
+
// Index for O(1) lookup of external function calls by name
|
|
183
|
+
// Invalidated by setting to null; rebuilt lazily on next access
|
|
184
|
+
this.externalFunctionCallsIndex = null;
|
|
185
|
+
// Debug tracer for selective path/scope tracing
|
|
186
|
+
// Enable via: CODEYAM_DEBUG=true CODEYAM_DEBUG_PATHS="user.*,signature" npm test
|
|
187
|
+
this.tracer = new DebugTracer({
|
|
188
|
+
enabled: process.env.CODEYAM_DEBUG === 'true',
|
|
189
|
+
pathPatterns: process.env.CODEYAM_DEBUG_PATHS
|
|
190
|
+
? process.env.CODEYAM_DEBUG_PATHS.split(',').map((p) => new RegExp(p))
|
|
191
|
+
: [],
|
|
192
|
+
scopePatterns: process.env.CODEYAM_DEBUG_SCOPES
|
|
193
|
+
? process.env.CODEYAM_DEBUG_SCOPES.split(',').map((p) => new RegExp(p))
|
|
194
|
+
: [],
|
|
195
|
+
maxDepth: 20,
|
|
196
|
+
});
|
|
197
|
+
// Batch processor for converting recursive addToSchema calls to iterative processing
|
|
198
|
+
// This eliminates deep recursion and allows for better work deduplication
|
|
199
|
+
this.batchProcessor = null;
|
|
200
|
+
// Track items already in the batch queue to prevent duplicates
|
|
201
|
+
// For external function calls, uses path-only keys (no value) for more aggressive deduplication
|
|
202
|
+
this.batchQueuedSet = null;
|
|
61
203
|
this.equivalencyManagers.push(...managers);
|
|
62
|
-
this.
|
|
204
|
+
this.scopeTreeManager.setRootName(scopeName);
|
|
63
205
|
this.addScopeAnalysis(scopeName, scopeText, scopeAnalysis);
|
|
64
206
|
}
|
|
65
207
|
addScopeAnalysis(scopeNodeName, scopeText, scopeAnalysis, parentScopeName, isStatic) {
|
|
66
208
|
try {
|
|
67
|
-
if (scopeNodeName !== this.
|
|
68
|
-
parentScopeName
|
|
209
|
+
if (scopeNodeName !== this.scopeTreeManager.getRootName() &&
|
|
210
|
+
!parentScopeName) {
|
|
211
|
+
parentScopeName = this.scopeTreeManager.getRootName();
|
|
69
212
|
}
|
|
70
213
|
let tree = [];
|
|
71
214
|
if (parentScopeName) {
|
|
@@ -106,7 +249,7 @@ export class ScopeDataStructure {
|
|
|
106
249
|
}
|
|
107
250
|
catch (error) {
|
|
108
251
|
console.log('CodeYam Error: Failed to add scope analysis for scope:', JSON.stringify({
|
|
109
|
-
rootScopeName: this.
|
|
252
|
+
rootScopeName: this.scopeTreeManager.getRootName(),
|
|
110
253
|
scopeNodeName,
|
|
111
254
|
scopeNodeText: scopeText,
|
|
112
255
|
isolatedStructure: scopeAnalysis.isolatedStructure,
|
|
@@ -115,26 +258,46 @@ export class ScopeDataStructure {
|
|
|
115
258
|
throw error;
|
|
116
259
|
}
|
|
117
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Phase 2: Build complete schemas by following all equivalencies.
|
|
263
|
+
*
|
|
264
|
+
* This is the main entry point for schema building. Call this after all
|
|
265
|
+
* scopes have been added via `addScopeAnalysis()`.
|
|
266
|
+
*
|
|
267
|
+
* ## What Happens
|
|
268
|
+
*
|
|
269
|
+
* 1. Resets state (visited tracker, schemas, database)
|
|
270
|
+
* 2. For each scope, follows equivalencies to build complete schemas
|
|
271
|
+
* 3. Filters out internal function calls (keeps only external-facing)
|
|
272
|
+
* 4. Propagates source/usage relationships for querying
|
|
273
|
+
*
|
|
274
|
+
* ## After Calling
|
|
275
|
+
*
|
|
276
|
+
* You can then use:
|
|
277
|
+
* - `getSchema()` - Get the built schema for a scope
|
|
278
|
+
* - `getSourceEquivalencies()` - Find where data comes from
|
|
279
|
+
* - `getUsageEquivalencies()` - Find where data is used
|
|
280
|
+
*/
|
|
118
281
|
async captureCompleteSchema() {
|
|
282
|
+
// Reset state for Phase 2
|
|
119
283
|
this.onlyEquivalencies = false;
|
|
120
284
|
this.equivalencyDatabase = [];
|
|
121
|
-
this.equivalencyDatabaseCache.clear();
|
|
122
|
-
this.intermediatesOrderIndex.clear();
|
|
123
|
-
this.
|
|
285
|
+
this.equivalencyDatabaseCache.clear();
|
|
286
|
+
this.intermediatesOrderIndex.clear();
|
|
287
|
+
this.visitedTracker.resetGlobalVisited();
|
|
124
288
|
for (const externalFunctionCall of this.externalFunctionCalls) {
|
|
125
289
|
externalFunctionCall.schema = {};
|
|
126
290
|
}
|
|
127
|
-
// for
|
|
291
|
+
// Build schemas for all scopes in parallel
|
|
128
292
|
await Promise.all(Object.values(this.scopeNodes).map(async (scopeNode) => {
|
|
129
293
|
scopeNode.schema = {};
|
|
130
294
|
await this.determineEquivalenciesAndBuildSchema(scopeNode);
|
|
131
295
|
}));
|
|
132
|
-
// }
|
|
133
296
|
const validExternalFacingScopeNames = new Set([
|
|
134
|
-
this.
|
|
297
|
+
this.scopeTreeManager.getRootName(),
|
|
135
298
|
]);
|
|
136
299
|
this.externalFunctionCalls = this.externalFunctionCalls.filter((efc) => {
|
|
137
|
-
const efcName = efc.name
|
|
300
|
+
const efcName = this.pathManager.stripGenerics(efc.name);
|
|
138
301
|
for (const manager of this.equivalencyManagers) {
|
|
139
302
|
if (manager.internalFunctions.has(efcName)) {
|
|
140
303
|
return false;
|
|
@@ -143,54 +306,90 @@ export class ScopeDataStructure {
|
|
|
143
306
|
validExternalFacingScopeNames.add(efcName);
|
|
144
307
|
return true;
|
|
145
308
|
});
|
|
309
|
+
this.invalidateExternalFunctionCallsIndex();
|
|
310
|
+
// Pre-compute array methods list once (avoids Array.from() in hot loop)
|
|
311
|
+
const arrayMethodsList = Array.from(arrayMethodsSet);
|
|
312
|
+
const containsArrayMethod = (path) => arrayMethodsList.some((method) => path.includes(`.${method}(`));
|
|
146
313
|
for (const entry of this.equivalencyDatabase) {
|
|
147
|
-
entry.usages = entry.usages.filter((usage) =>
|
|
148
|
-
(usage.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
314
|
+
entry.usages = entry.usages.filter((usage) => {
|
|
315
|
+
const baseName = this.pathManager.stripGenerics(usage.scopeNodeName);
|
|
316
|
+
return (validExternalFacingScopeNames.has(baseName) &&
|
|
317
|
+
(usage.schemaPath.startsWith('returnValue') ||
|
|
318
|
+
usage.schemaPath.startsWith(baseName)) &&
|
|
319
|
+
!containsArrayMethod(usage.schemaPath));
|
|
320
|
+
});
|
|
321
|
+
entry.sourceCandidates = entry.sourceCandidates.filter((candidate) => {
|
|
322
|
+
const baseName = this.pathManager.stripGenerics(candidate.scopeNodeName);
|
|
323
|
+
return (validExternalFacingScopeNames.has(baseName) &&
|
|
324
|
+
(candidate.schemaPath.startsWith('signature[') ||
|
|
325
|
+
candidate.schemaPath.startsWith(baseName)) &&
|
|
326
|
+
!containsArrayMethod(candidate.schemaPath));
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
this.propagateSourceAndUsageEquivalencies(this.scopeNodes[this.scopeTreeManager.getRootName()]);
|
|
157
330
|
for (const externalFunctionCall of this.externalFunctionCalls) {
|
|
158
|
-
const t = new Date().getTime();
|
|
159
|
-
// console.info("Start Propagating", JSON.stringify({
|
|
160
|
-
// externalFunctionCallName: externalFunctionCall.name,
|
|
161
|
-
// // sourceEquivalencies: externalFunctionCall.sourceEquivalencies,
|
|
162
|
-
// }, null, 2));
|
|
163
331
|
this.propagateSourceAndUsageEquivalencies(externalFunctionCall);
|
|
164
|
-
const elapsedTime = new Date().getTime() - t;
|
|
165
|
-
if (elapsedTime > 100) {
|
|
166
|
-
console.warn('Long Propagation Time', {
|
|
167
|
-
externalFunctionCallName: externalFunctionCall.name,
|
|
168
|
-
time: elapsedTime,
|
|
169
|
-
});
|
|
170
|
-
// throw new Error("STOP - LONG PROPAGATION TIME")
|
|
171
|
-
}
|
|
172
|
-
// console.info("Done Propagating", JSON.stringify({
|
|
173
|
-
// externalFunctionCallName: externalFunctionCall.name,
|
|
174
|
-
// // sourceEquivalencies: externalFunctionCall.sourceEquivalencies,
|
|
175
|
-
// // usageEquivalencies: externalFunctionCall.usageEquivalencies,
|
|
176
|
-
// time: elapsedTime
|
|
177
|
-
// }, null, 2))
|
|
178
332
|
}
|
|
179
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Core method: Adds a path/value to a scope's schema and follows equivalencies.
|
|
336
|
+
*
|
|
337
|
+
* This is the heart of schema building. For each path, it:
|
|
338
|
+
* 1. Validates the path and checks if already visited
|
|
339
|
+
* 2. Adds the path → value mapping to the scope's schema
|
|
340
|
+
* 3. Follows any equivalencies to propagate the schema to linked paths
|
|
341
|
+
* 4. Tracks the equivalency chain for source/usage database
|
|
342
|
+
*
|
|
343
|
+
* ## Cycle Detection
|
|
344
|
+
*
|
|
345
|
+
* Uses `visitedTracker.checkAndMarkGlobalVisited()` to prevent infinite loops.
|
|
346
|
+
* A path is considered visited if the exact (scope, path, value) tuple has
|
|
347
|
+
* been processed before.
|
|
348
|
+
*
|
|
349
|
+
* ## Equivalency Following
|
|
350
|
+
*
|
|
351
|
+
* When a path has equivalencies (e.g., `user` → `props.user`), this method
|
|
352
|
+
* recursively calls itself to add the equivalent path to its scope's schema.
|
|
353
|
+
*
|
|
354
|
+
* @param path - Schema path to add (e.g., 'user.id')
|
|
355
|
+
* @param value - Type value (e.g., 'string', 'number')
|
|
356
|
+
* @param scopeNode - The scope to add to
|
|
357
|
+
* @param equivalencyValueChain - Tracks the chain for database population
|
|
358
|
+
* @param traceId - Debug ID for tracing specific paths
|
|
359
|
+
*/
|
|
180
360
|
addToSchema({ path, value, scopeNode, equivalencyValueChain = [], traceId, }) {
|
|
181
361
|
addToSchemaCallCount++;
|
|
362
|
+
// Trace entry for debugging
|
|
363
|
+
this.tracer.traceEnter('addToSchema', {
|
|
364
|
+
path,
|
|
365
|
+
scope: scopeNode?.name,
|
|
366
|
+
value,
|
|
367
|
+
chainDepth: equivalencyValueChain.length,
|
|
368
|
+
});
|
|
369
|
+
// Safety: Detect runaway recursion
|
|
370
|
+
if (addToSchemaCallCount > 500000) {
|
|
371
|
+
console.error('INFINITE LOOP DETECTED in addToSchema', {
|
|
372
|
+
callCount: addToSchemaCallCount,
|
|
373
|
+
path,
|
|
374
|
+
value,
|
|
375
|
+
scopeNodeName: scopeNode?.name,
|
|
376
|
+
});
|
|
377
|
+
throw new Error(`Infinite loop detected: addToSchema called ${addToSchemaCallCount} times`);
|
|
378
|
+
}
|
|
182
379
|
// Track max chain depth
|
|
183
380
|
if (equivalencyValueChain.length > maxEquivalencyChainDepth) {
|
|
184
381
|
maxEquivalencyChainDepth = equivalencyValueChain.length;
|
|
185
382
|
}
|
|
186
|
-
if (!scopeNode)
|
|
383
|
+
if (!scopeNode) {
|
|
187
384
|
return;
|
|
385
|
+
}
|
|
188
386
|
if (!this.isValidPath(path)) {
|
|
189
387
|
if (traceId) {
|
|
190
388
|
console.info('Debug propagation: not a valid path', { path, traceId });
|
|
191
389
|
}
|
|
192
390
|
return;
|
|
193
391
|
}
|
|
392
|
+
// Update chain metadata for database tracking
|
|
194
393
|
if (equivalencyValueChain.length > 0) {
|
|
195
394
|
equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
|
|
196
395
|
++this.lastAddToSchemaId;
|
|
@@ -200,87 +399,35 @@ export class ScopeDataStructure {
|
|
|
200
399
|
value,
|
|
201
400
|
};
|
|
202
401
|
}
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
// }
|
|
209
|
-
// if (traceId > 30) {
|
|
210
|
-
// console.warn(
|
|
211
|
-
// 'HIGH TRACEID',
|
|
212
|
-
// JSON.stringify(
|
|
213
|
-
// {
|
|
214
|
-
// path,
|
|
215
|
-
// value,
|
|
216
|
-
// scopeNodeName: scopeNode.name,
|
|
217
|
-
// equivalencyValueChain,
|
|
218
|
-
// },
|
|
219
|
-
// null,
|
|
220
|
-
// 2,
|
|
221
|
-
// ),
|
|
222
|
-
// );
|
|
223
|
-
// throw new Error('STOP - HIGH TRACEID');
|
|
224
|
-
// }
|
|
225
|
-
// Use this debugging to trace a specific path through the propagation
|
|
226
|
-
const debugLevel = 0; // 0 for minimal, 1 for executed paths, 2 for all paths info
|
|
227
|
-
// if ((!this.onlyEquivalencies && path === 'entity.sha') || traceId) {
|
|
228
|
-
// traceId ||= 0;
|
|
229
|
-
// traceId += 1;
|
|
230
|
-
// if (traceId === 1) {
|
|
231
|
-
// this.debugCount += 1;
|
|
232
|
-
// if (this.debugCount > 5) throw new Error('STOP - HIGH DEBUG COUNT');
|
|
233
|
-
// console.warn('START');
|
|
234
|
-
// }
|
|
235
|
-
// console.info(
|
|
236
|
-
// 'Debug Propagation: Adding to schema',
|
|
237
|
-
// JSON.stringify(
|
|
238
|
-
// {
|
|
239
|
-
// // traceId,
|
|
240
|
-
// path,
|
|
241
|
-
// value,
|
|
242
|
-
// scopeNodeName: scopeNode.name,
|
|
243
|
-
// reason:
|
|
244
|
-
// equivalencyValueChain[equivalencyValueChain.length - 1]?.reason,
|
|
245
|
-
// // previous:
|
|
246
|
-
// // equivalencyValueChain[equivalencyValueChain.length - 1],
|
|
247
|
-
// text: scopeNode.text,
|
|
248
|
-
// // tree: scopeNode.tree,
|
|
249
|
-
// // onlyEquivalencies: this.onlyEquivalencies,
|
|
250
|
-
// // equivalencyValueChain,
|
|
251
|
-
// // scopeNode
|
|
252
|
-
// // instatiatedVeriables: scopeNode.instantiatedVariables,
|
|
253
|
-
// // parentInstantiatedVariables: scopeNode.parentInstantiatedVariables,
|
|
254
|
-
// // isolatedStructure: scopeNode.analysis.isolatedStructure,
|
|
255
|
-
// // isolatedEquivalencies: scopeNode.analysis.isolatedEquivalentVariables,
|
|
256
|
-
// // equivalencies: traceId === 1 ? scopeNode.equivalencies : 'skipped',
|
|
257
|
-
// // functionCalls: scopeNode.functionCalls,
|
|
258
|
-
// // externalFunctionCalls: this.externalFunctionCalls.filter(fc => fc.callScope.includes(scopeNode.name))
|
|
259
|
-
// },
|
|
260
|
-
// null,
|
|
261
|
-
// 2,
|
|
262
|
-
// ),
|
|
263
|
-
// );
|
|
264
|
-
// // if (traceId > 1) traceId = undefined;
|
|
265
|
-
// throw new Error('STOP ON ADD');
|
|
266
|
-
// }
|
|
402
|
+
// Debug level: 0=minimal, 1=executed paths, 2=all paths (set via traceId)
|
|
403
|
+
const debugLevel = 0;
|
|
404
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
405
|
+
// SECTION 1: Handle complex source paths (paths with multiple data origins)
|
|
406
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
267
407
|
const equivalenciesDatabaseEntry = this.getEquivalenciesDatabaseEntry(scopeNode.name, path);
|
|
408
|
+
// Process complex source paths (before visited check, per original design)
|
|
268
409
|
this.addComplexSourcePathVariables(equivalenciesDatabaseEntry, scopeNode, path, equivalencyValueChain, traceId);
|
|
269
|
-
|
|
270
|
-
if
|
|
410
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
411
|
+
// SECTION 2: Cycle detection - skip if already visited with this value
|
|
412
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
413
|
+
if (this.visitedTracker.checkAndMarkGlobalVisited(scopeNode.name, path, value)) {
|
|
271
414
|
if (traceId) {
|
|
272
|
-
console.info('Debug
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}, null, 2));
|
|
415
|
+
console.info('Debug: already visited', {
|
|
416
|
+
key: `${scopeNode.name}::${path}::${value}`,
|
|
417
|
+
});
|
|
276
418
|
}
|
|
419
|
+
// Still record in database even if visited (captures full chain)
|
|
277
420
|
if (!this.onlyEquivalencies) {
|
|
278
421
|
this.addToEquivalencyDatabase(equivalencyValueChain, traceId);
|
|
279
422
|
}
|
|
280
423
|
return;
|
|
281
424
|
}
|
|
282
|
-
|
|
425
|
+
// Continue complex source processing after visited check
|
|
283
426
|
this.captureComplexSourcePaths(equivalenciesDatabaseEntry, scopeNode, path, equivalencyValueChain, traceId);
|
|
427
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
428
|
+
// SECTION 3: Process each subpath to follow equivalencies
|
|
429
|
+
// For path "user.profile.name", processes: "user", "user.profile", "user.profile.name"
|
|
430
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
284
431
|
const pathParts = this.splitPath(path);
|
|
285
432
|
this.checkForArrayItemPath(pathParts, scopeNode, equivalencyValueChain);
|
|
286
433
|
let propagated = false;
|
|
@@ -368,45 +515,42 @@ export class ScopeDataStructure {
|
|
|
368
515
|
}
|
|
369
516
|
}
|
|
370
517
|
}
|
|
518
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
519
|
+
// SECTION 4: Write to schema if appropriate
|
|
520
|
+
// Only writes if: (a) path not set or is 'unknown', AND
|
|
521
|
+
// (b) path belongs to this scope (instantiated, signature, or return)
|
|
522
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
371
523
|
const writeToCurrentScopeSchema = (!scopeNode.schema[path] || scopeNode.schema[path] === 'unknown') &&
|
|
372
524
|
(!scopeNode.instantiatedVariables ||
|
|
373
525
|
scopeNode.instantiatedVariables.includes(pathParts[0]) ||
|
|
374
526
|
pathParts[0].startsWith('signature[') ||
|
|
375
527
|
pathParts[0].startsWith('returnValue'));
|
|
376
|
-
//
|
|
528
|
+
// Early exit if schema already has this exact value
|
|
377
529
|
if (scopeNode.schema[path] === value && value !== 'unknown') {
|
|
378
530
|
return;
|
|
379
531
|
}
|
|
380
532
|
if (writeToCurrentScopeSchema) {
|
|
381
533
|
if (traceId && debugLevel > 0) {
|
|
382
|
-
console.info('Debug
|
|
383
|
-
traceId,
|
|
534
|
+
console.info('Debug: writing schema', {
|
|
384
535
|
path,
|
|
385
|
-
|
|
386
|
-
|
|
536
|
+
value,
|
|
537
|
+
scope: scopeNode.name,
|
|
387
538
|
});
|
|
388
539
|
}
|
|
389
540
|
scopeNode.schema[path] = value;
|
|
390
541
|
}
|
|
542
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
543
|
+
// SECTION 5: Record in equivalency database (Phase 2 only)
|
|
544
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
391
545
|
if (!this.onlyEquivalencies) {
|
|
392
546
|
this.addToEquivalencyDatabase(equivalencyValueChain, traceId);
|
|
393
547
|
}
|
|
394
548
|
if (traceId) {
|
|
395
|
-
console.info('Debug
|
|
396
|
-
|
|
397
|
-
scopeNodeName: scopeNode.name,
|
|
549
|
+
console.info('Debug: addToSchema complete', {
|
|
550
|
+
scope: scopeNode.name,
|
|
398
551
|
path,
|
|
399
552
|
value,
|
|
400
|
-
|
|
401
|
-
// propagated,
|
|
402
|
-
// scopeInfoText: scopeNode.text,
|
|
403
|
-
// equivalencyValueChain//: equivalencyValueChain.map(
|
|
404
|
-
// (ev) => ev.currentPath.schemaPath,
|
|
405
|
-
// ),
|
|
406
|
-
// sourceEquivalencies: scopeNode.sourceEquivalencies[path] ?? [],
|
|
407
|
-
// usageEquivalencies: scopeNode.usageEquivalencies[path] ?? [],
|
|
408
|
-
// checkpoints,
|
|
409
|
-
}, null, 2));
|
|
553
|
+
});
|
|
410
554
|
}
|
|
411
555
|
}
|
|
412
556
|
removeFromSchema(path, schema = {}, scopeName) {
|
|
@@ -414,50 +558,29 @@ export class ScopeDataStructure {
|
|
|
414
558
|
}
|
|
415
559
|
addEquivalency(path, equivalentPath, equivalentScopeName, scopeNode, equivalencyReason, equivalencyValueChain, traceId) {
|
|
416
560
|
var _a;
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
'
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
'Node .then() equivalency', // 1 failure
|
|
434
|
-
'Explicit array deconstruction equivalency value', // 1 failure
|
|
435
|
-
'forwardRef equivalency',
|
|
436
|
-
'forwardRef signature to child signature equivalency', // 1 failure
|
|
437
|
-
'captured function call return value equivalency', // 1 failure (in ScopeDataStructure.test.ts)
|
|
438
|
-
'original equivalency - rerouted via useCallback', // 1 failure
|
|
439
|
-
'non-object function argument function signature equivalency1 - rerouted via useCallback', // 1 failure
|
|
440
|
-
'non-object function argument function signature equivalency2 - rerouted via useCallback', // 1 failure
|
|
441
|
-
'implicit parent equivalency - rerouted via useCallback', // 1 failure
|
|
442
|
-
'Spread operator equivalency key update: implicit parent equivalency', // 1 failure
|
|
443
|
-
'Array.from() equivalency',
|
|
444
|
-
].includes(equivalencyReason)) {
|
|
445
|
-
if ([
|
|
446
|
-
'signature of functionCall',
|
|
447
|
-
'transformed non-object function equivalency - implicit parent equivalency',
|
|
448
|
-
'transformed non-object function equivalency - non-object function argument function signature equivalency1',
|
|
449
|
-
'transformed non-object function equivalency - non-object function argument function signature equivalency2',
|
|
450
|
-
'transformed non-object function equivalency - equivalency to external function call',
|
|
451
|
-
'Explicit array deconstruction equivalency key',
|
|
452
|
-
'transformed non-object function equivalency - useState setter call equivalency',
|
|
453
|
-
'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
|
|
454
|
-
'transformed non-object function equivalency - Array.from() equivalency',
|
|
455
|
-
'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
|
|
456
|
-
].includes(equivalencyReason)) {
|
|
561
|
+
// DEBUG: Detect infinite loops
|
|
562
|
+
addEquivalencyCallCount++;
|
|
563
|
+
if (addEquivalencyCallCount > 50000) {
|
|
564
|
+
console.error('INFINITE LOOP DETECTED in addEquivalency', {
|
|
565
|
+
callCount: addEquivalencyCallCount,
|
|
566
|
+
path,
|
|
567
|
+
equivalentPath,
|
|
568
|
+
equivalentScopeName,
|
|
569
|
+
scopeNodeName: scopeNode.name,
|
|
570
|
+
equivalencyReason,
|
|
571
|
+
});
|
|
572
|
+
throw new Error(`Infinite loop detected: addEquivalency called ${addEquivalencyCallCount} times`);
|
|
573
|
+
}
|
|
574
|
+
// Filter equivalency reasons - use pre-computed Sets for O(1) lookup
|
|
575
|
+
if (!ALLOWED_EQUIVALENCY_REASONS.has(equivalencyReason)) {
|
|
576
|
+
if (SILENTLY_IGNORED_EQUIVALENCY_REASONS.has(equivalencyReason)) {
|
|
457
577
|
return;
|
|
458
578
|
}
|
|
459
579
|
else {
|
|
580
|
+
// Log and skip - if an equivalency reason isn't in ALLOWED or SILENTLY_IGNORED,
|
|
581
|
+
// it shouldn't be stored (was previously missing the return)
|
|
460
582
|
console.info('Not tracked equivalency reason', { equivalencyReason });
|
|
583
|
+
return;
|
|
461
584
|
}
|
|
462
585
|
}
|
|
463
586
|
if (!equivalentScopeName) {
|
|
@@ -471,8 +594,41 @@ export class ScopeDataStructure {
|
|
|
471
594
|
}
|
|
472
595
|
(_a = scopeNode.equivalencies)[path] || (_a[path] = []);
|
|
473
596
|
const existing = scopeNode.equivalencies[path];
|
|
474
|
-
|
|
475
|
-
v.scopeNodeName === equivalentScopeName)
|
|
597
|
+
const existingEquivalency = existing.find((v) => v.schemaPath === equivalentPath &&
|
|
598
|
+
v.scopeNodeName === equivalentScopeName);
|
|
599
|
+
if (existingEquivalency) {
|
|
600
|
+
// During Phase 2 (onlyEquivalencies=false), we need to still process the equivalency
|
|
601
|
+
// to build the chain and add to the database, even if the equivalency already exists
|
|
602
|
+
if (!this.onlyEquivalencies) {
|
|
603
|
+
const equivalentScopeNode = this.getScopeOrFunctionCallInfo(equivalentScopeName);
|
|
604
|
+
if (equivalentScopeNode) {
|
|
605
|
+
// Extract function call name from path if it looks like a function call path
|
|
606
|
+
// e.g., "ChildComponent().signature[0].dataItem" -> "ChildComponent"
|
|
607
|
+
const pathMatch = path.match(/^([^().]+)\(\)/);
|
|
608
|
+
const previousPathScopeNodeName = pathMatch
|
|
609
|
+
? pathMatch[1]
|
|
610
|
+
: scopeNode.name;
|
|
611
|
+
this.addToSchema({
|
|
612
|
+
path: equivalentPath,
|
|
613
|
+
value: 'unknown',
|
|
614
|
+
scopeNode: equivalentScopeNode,
|
|
615
|
+
equivalencyValueChain: [
|
|
616
|
+
...(equivalencyValueChain ?? []),
|
|
617
|
+
{
|
|
618
|
+
id: existingEquivalency.id,
|
|
619
|
+
source: 'duplicate equivalency - Phase 2',
|
|
620
|
+
reason: equivalencyReason,
|
|
621
|
+
previousPath: {
|
|
622
|
+
scopeNodeName: previousPathScopeNodeName,
|
|
623
|
+
schemaPath: path,
|
|
624
|
+
value: scopeNode.schema[path],
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
traceId,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
476
632
|
return;
|
|
477
633
|
}
|
|
478
634
|
const id = ++this.lastEquivalencyId;
|
|
@@ -553,7 +709,8 @@ export class ScopeDataStructure {
|
|
|
553
709
|
if (!functionCallInfo.equivalencies) {
|
|
554
710
|
functionCallInfo.equivalencies = {};
|
|
555
711
|
}
|
|
556
|
-
const
|
|
712
|
+
const searchKey = getFunctionCallRoot(functionCallInfo.callSignature);
|
|
713
|
+
const existingFunctionCall = this.getExternalFunctionCallsIndex().get(searchKey);
|
|
557
714
|
if (existingFunctionCall) {
|
|
558
715
|
existingFunctionCall.schema = {
|
|
559
716
|
...existingFunctionCall.schema,
|
|
@@ -563,6 +720,15 @@ export class ScopeDataStructure {
|
|
|
563
720
|
...existingFunctionCall.equivalencies,
|
|
564
721
|
...functionCallInfo.equivalencies,
|
|
565
722
|
};
|
|
723
|
+
// Track all call signatures that get merged (e.g., logger.info, logger.debug, etc.)
|
|
724
|
+
if (!existingFunctionCall.allCallSignatures) {
|
|
725
|
+
existingFunctionCall.allCallSignatures = [
|
|
726
|
+
existingFunctionCall.callSignature,
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
if (!existingFunctionCall.allCallSignatures.includes(functionCallInfo.callSignature)) {
|
|
730
|
+
existingFunctionCall.allCallSignatures.push(functionCallInfo.callSignature);
|
|
731
|
+
}
|
|
566
732
|
}
|
|
567
733
|
else {
|
|
568
734
|
const functionCallInfoNameParts = this.splitPath(functionCallInfo.name);
|
|
@@ -570,6 +736,7 @@ export class ScopeDataStructure {
|
|
|
570
736
|
!callingScopeNode.parentInstantiatedVariables?.includes(functionCallInfoNameParts[0]);
|
|
571
737
|
if (isExternal) {
|
|
572
738
|
this.externalFunctionCalls.push(functionCallInfo);
|
|
739
|
+
this.invalidateExternalFunctionCallsIndex();
|
|
573
740
|
}
|
|
574
741
|
}
|
|
575
742
|
}
|
|
@@ -591,7 +758,7 @@ export class ScopeDataStructure {
|
|
|
591
758
|
// );
|
|
592
759
|
// }
|
|
593
760
|
const getRootOrExternalFunctionCallInfo = (name) => {
|
|
594
|
-
return name === this.
|
|
761
|
+
return name === this.scopeTreeManager.getRootName()
|
|
595
762
|
? this.getScopeNode()
|
|
596
763
|
: this.getExternalFunctionCallInfo(name);
|
|
597
764
|
};
|
|
@@ -609,82 +776,49 @@ export class ScopeDataStructure {
|
|
|
609
776
|
schemaPath === safePath ||
|
|
610
777
|
safePath.startsWith(schemaPath));
|
|
611
778
|
});
|
|
779
|
+
// PERF: Build a Map for O(1) lookup instead of O(n) inner loop
|
|
780
|
+
// Map from "remaining parts joined" to equivalentSchemaPath
|
|
781
|
+
const equivalentSchemaPathMap = new Map();
|
|
782
|
+
for (const equivalentSchemaPath of Object.keys(equivalentScopeNode.schema)) {
|
|
783
|
+
// Quick string check before expensive path splitting
|
|
784
|
+
if (!(equivalentSchemaPath.startsWith(equivalentPath) ||
|
|
785
|
+
equivalentSchemaPath === equivalentPath ||
|
|
786
|
+
equivalentPath.startsWith(equivalentSchemaPath))) {
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
const equivalentSchemaPathParts = this.splitPath(equivalentSchemaPath);
|
|
790
|
+
if (!equivalentPathParts.every((p, i) => equivalentSchemaPathParts[i] === p)) {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
const remainingEquivalentSchemaPathParts = equivalentSchemaPathParts.slice(equivalentPathParts.length);
|
|
794
|
+
// Use | as separator since it won't appear in path parts
|
|
795
|
+
const key = remainingEquivalentSchemaPathParts.join('|');
|
|
796
|
+
equivalentSchemaPathMap.set(key, equivalentSchemaPath);
|
|
797
|
+
}
|
|
612
798
|
for (const schemaPath of relevantSchemaPaths) {
|
|
613
799
|
const schemaPathParts = this.splitPath(schemaPath);
|
|
614
800
|
if (!pathParts.every((p, i) => schemaPathParts[i] === p)) {
|
|
615
801
|
continue;
|
|
616
802
|
}
|
|
617
803
|
const remainingSchemaPathParts = schemaPathParts.slice(pathParts.length);
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
return (equivalentSchemaPath.startsWith(equivalentPath) ||
|
|
623
|
-
equivalentSchemaPath === equivalentPath ||
|
|
624
|
-
equivalentPath.startsWith(equivalentSchemaPath));
|
|
625
|
-
});
|
|
626
|
-
for (const equivalentSchemaPath of relevantEquivalentSchemaPaths) {
|
|
627
|
-
const equivalentSchemaPathParts = this.splitPath(equivalentSchemaPath);
|
|
628
|
-
if (!equivalentPathParts.every((p, i) => equivalentSchemaPathParts[i] === p)) {
|
|
629
|
-
continue;
|
|
630
|
-
}
|
|
631
|
-
const remainingEquivalentSchemaPathParts = equivalentSchemaPathParts.slice(equivalentPathParts.length);
|
|
632
|
-
if (remainingSchemaPathParts.length !==
|
|
633
|
-
remainingEquivalentSchemaPathParts.length ||
|
|
634
|
-
!remainingEquivalentSchemaPathParts.every((p, i) => p === remainingSchemaPathParts[i])) {
|
|
635
|
-
missingEquivalentPath = true;
|
|
636
|
-
continue;
|
|
637
|
-
}
|
|
638
|
-
missingEquivalentPath = false;
|
|
804
|
+
// PERF: O(1) Map lookup instead of O(n) inner loop
|
|
805
|
+
const remainingKey = remainingSchemaPathParts.join('|');
|
|
806
|
+
const equivalentSchemaPath = equivalentSchemaPathMap.get(remainingKey);
|
|
807
|
+
if (equivalentSchemaPath) {
|
|
639
808
|
const value1 = scopeNode.schema[schemaPath];
|
|
640
809
|
const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
|
|
641
|
-
|
|
642
|
-
if (value2 &&
|
|
643
|
-
((bestValue === 'unknown' && value2 !== 'unknown') ||
|
|
644
|
-
(bestValue.includes('unknown') && !value2.includes('unknown')))) {
|
|
645
|
-
bestValue = value2;
|
|
646
|
-
}
|
|
810
|
+
const bestValue = selectBestValue(value1, value2);
|
|
647
811
|
scopeNode.schema[schemaPath] = bestValue;
|
|
648
812
|
equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
|
|
649
|
-
// if (traceId) {
|
|
650
|
-
// console.info('Debug Propagate: Assign Best Value', {
|
|
651
|
-
// traceId,
|
|
652
|
-
// sourceScopeNodeName: scopeNode.name,
|
|
653
|
-
// path,
|
|
654
|
-
// schemaPath,
|
|
655
|
-
// usageScopeNodeName: equivalentScopeNode.name,
|
|
656
|
-
// equivalentPath,
|
|
657
|
-
// equivalentSchemaPath,
|
|
658
|
-
// remainingSchemaPathParts,
|
|
659
|
-
// remainingEquivalentSchemaPathParts,
|
|
660
|
-
// value1,
|
|
661
|
-
// value2,
|
|
662
|
-
// bestValue,
|
|
663
|
-
// });
|
|
664
|
-
// }
|
|
665
|
-
break;
|
|
666
813
|
}
|
|
667
|
-
if (
|
|
668
|
-
(
|
|
669
|
-
|
|
814
|
+
else if (scopeNode.name.includes('____cyScope') ||
|
|
815
|
+
!('instantiatedVariables' in equivalentScopeNode)) {
|
|
816
|
+
// No matching equivalent path found - create one if needed
|
|
670
817
|
// Only necessary for internal function scopes or external function scopes
|
|
671
818
|
const newEquivalentPath = this.joinPathParts([
|
|
672
819
|
equivalentPath,
|
|
673
820
|
...remainingSchemaPathParts,
|
|
674
821
|
]);
|
|
675
|
-
// if (traceId) {
|
|
676
|
-
// console.info('Debug Propagate: missing equivalent path', {
|
|
677
|
-
// traceId,
|
|
678
|
-
// scopeNodeName: scopeNode.name,
|
|
679
|
-
// path,
|
|
680
|
-
// equivalentPath,
|
|
681
|
-
// schemaPath,
|
|
682
|
-
// remainingSchemaPathParts,
|
|
683
|
-
// equivalentScopeNodeName: equivalentScopeNode.name,
|
|
684
|
-
// // equivalentScopeNodeSchema: equivalentScopeNode.schema,
|
|
685
|
-
// newEquivalentPath,
|
|
686
|
-
// });
|
|
687
|
-
// }
|
|
688
822
|
equivalentScopeNode.schema[newEquivalentPath] =
|
|
689
823
|
scopeNode.schema[schemaPath];
|
|
690
824
|
}
|
|
@@ -707,83 +841,26 @@ export class ScopeDataStructure {
|
|
|
707
841
|
}
|
|
708
842
|
}
|
|
709
843
|
splitPath(path) {
|
|
710
|
-
|
|
711
|
-
return structuredClone(this.pathPartsCache.get(path));
|
|
712
|
-
}
|
|
713
|
-
const pathParts = splitOutsideParenthesesAndArrays(path);
|
|
714
|
-
this.pathPartsCache.set(path, structuredClone(pathParts));
|
|
715
|
-
return pathParts;
|
|
844
|
+
return this.pathManager.splitPath(path);
|
|
716
845
|
}
|
|
717
846
|
joinPathParts(pathParts) {
|
|
718
|
-
|
|
719
|
-
if (this.pathJoinCache.has(cacheKey)) {
|
|
720
|
-
return this.pathJoinCache.get(cacheKey);
|
|
721
|
-
}
|
|
722
|
-
const result = joinParenthesesAndArrays(pathParts);
|
|
723
|
-
this.pathJoinCache.set(cacheKey, result);
|
|
724
|
-
return result;
|
|
847
|
+
return this.pathManager.joinPathParts(pathParts);
|
|
725
848
|
}
|
|
726
849
|
// PRIVATE METHODS //
|
|
727
|
-
uniqueId(
|
|
728
|
-
|
|
729
|
-
return parts.join('::');
|
|
850
|
+
uniqueId(params) {
|
|
851
|
+
return uniqueId(params);
|
|
730
852
|
}
|
|
731
853
|
uniqueScopeVariables(scopeVariables) {
|
|
732
|
-
return
|
|
854
|
+
return uniqueScopeVariables(scopeVariables);
|
|
733
855
|
}
|
|
734
856
|
uniqueScopeAndPaths(scopeVariables) {
|
|
735
|
-
|
|
736
|
-
return [];
|
|
737
|
-
// Optimize from O(n²) to O(n) using Set for deduplication
|
|
738
|
-
const seen = new Set();
|
|
739
|
-
return scopeVariables.filter((varItem) => {
|
|
740
|
-
const key = `${varItem.scopeNodeName}::${varItem.schemaPath}`;
|
|
741
|
-
if (seen.has(key)) {
|
|
742
|
-
return false;
|
|
743
|
-
}
|
|
744
|
-
seen.add(key);
|
|
745
|
-
return true;
|
|
746
|
-
});
|
|
857
|
+
return uniqueScopeAndPaths(scopeVariables);
|
|
747
858
|
}
|
|
748
859
|
isValidPath(path) {
|
|
749
|
-
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
if (!path) {
|
|
753
|
-
return false;
|
|
754
|
-
}
|
|
755
|
-
if (path === 'true' || path === 'false') {
|
|
756
|
-
return false;
|
|
757
|
-
}
|
|
758
|
-
if (!isNaN(Number(path))) {
|
|
759
|
-
return false;
|
|
760
|
-
}
|
|
761
|
-
if (path.match(/^['"]/)) {
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
|
-
return this.splitPath(path).every((part) => {
|
|
765
|
-
if (cleanOutBoundary(cleanOutBoundary(cleanOutBoundary(part, '<', '>'), '[', ']')).match(/\s/)) {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
return true;
|
|
769
|
-
});
|
|
860
|
+
return this.pathManager.isValidPath(path);
|
|
770
861
|
}
|
|
771
862
|
addToTree(pathParts) {
|
|
772
|
-
|
|
773
|
-
for (const pathPart of pathParts) {
|
|
774
|
-
const existingChild = scopeTreeNode.children.find((child) => child.name === pathPart);
|
|
775
|
-
if (existingChild) {
|
|
776
|
-
scopeTreeNode = existingChild;
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
const childScopeTreeNode = {
|
|
780
|
-
name: pathPart,
|
|
781
|
-
children: [],
|
|
782
|
-
};
|
|
783
|
-
scopeTreeNode.children.push(childScopeTreeNode);
|
|
784
|
-
scopeTreeNode = childScopeTreeNode;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
863
|
+
this.scopeTreeManager.addPath(pathParts);
|
|
787
864
|
}
|
|
788
865
|
setInstantiatedVariables(scopeNode) {
|
|
789
866
|
let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
|
|
@@ -834,14 +911,63 @@ export class ScopeDataStructure {
|
|
|
834
911
|
path = cleanPath(path.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
835
912
|
equivalentValue = cleanPath(equivalentValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
836
913
|
this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
|
|
914
|
+
// Propagate sub-property equivalencies when the equivalentValue is a simple variable
|
|
915
|
+
// that has sub-properties defined in the isolatedEquivalentVariables.
|
|
916
|
+
// This handles cases like: dataItem={{ structure: completeDataStructure }}
|
|
917
|
+
// where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
|
|
918
|
+
// We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
|
|
919
|
+
const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
|
|
920
|
+
!equivalentValue.includes('functionCallReturnValue') &&
|
|
921
|
+
!equivalentValue.includes('.') &&
|
|
922
|
+
!equivalentValue.includes('[');
|
|
923
|
+
if (isSimpleVariable) {
|
|
924
|
+
// Look in current scope and all parent scopes for sub-properties
|
|
925
|
+
const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
|
|
926
|
+
for (const scopeName of scopesToCheck) {
|
|
927
|
+
const checkScope = this.scopeNodes[scopeName];
|
|
928
|
+
if (!checkScope?.analysis?.isolatedEquivalentVariables)
|
|
929
|
+
continue;
|
|
930
|
+
for (const [subPath, subValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
|
|
931
|
+
// Check if this is a sub-property of the equivalentValue variable
|
|
932
|
+
// e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
|
|
933
|
+
const matchesDot = subPath.startsWith(equivalentValue + '.');
|
|
934
|
+
const matchesBracket = subPath.startsWith(equivalentValue + '[');
|
|
935
|
+
if (matchesDot || matchesBracket) {
|
|
936
|
+
const subPropertyPath = subPath.substring(equivalentValue.length);
|
|
937
|
+
const newPath = cleanPath(path + subPropertyPath, allPaths);
|
|
938
|
+
const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
939
|
+
if (newEquivalentValue &&
|
|
940
|
+
this.isValidPath(newEquivalentValue)) {
|
|
941
|
+
this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
|
|
942
|
+
scopeNode, 'propagated sub-property equivalency');
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
// Also check if equivalentValue itself maps to a functionCallReturnValue
|
|
946
|
+
// e.g., result = useMemo(...).functionCallReturnValue
|
|
947
|
+
if (subPath === equivalentValue &&
|
|
948
|
+
typeof subValue === 'string' &&
|
|
949
|
+
subValue.endsWith('.functionCallReturnValue')) {
|
|
950
|
+
this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
// Handle function call return values by propagating returnValue.* sub-properties
|
|
956
|
+
// from the callback scope to the usage path
|
|
957
|
+
if (equivalentValue.endsWith('.functionCallReturnValue')) {
|
|
958
|
+
this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
|
|
959
|
+
}
|
|
837
960
|
}
|
|
838
961
|
}
|
|
962
|
+
// PERF: Enable batch processing to convert recursive addToSchema calls to iterative
|
|
963
|
+
// This eliminates deep call stacks and improves deduplication
|
|
964
|
+
this.batchProcessor = new BatchSchemaProcessor();
|
|
965
|
+
this.batchQueuedSet = new Set();
|
|
839
966
|
for (const key of Array.from(allPaths)) {
|
|
840
967
|
let value = isolatedStructure[key] ?? 'unknown';
|
|
841
968
|
if (['null', 'undefined'].includes(value)) {
|
|
842
969
|
value = 'unknown';
|
|
843
970
|
}
|
|
844
|
-
const startTime = new Date().getTime();
|
|
845
971
|
this.addToSchema({
|
|
846
972
|
path: cleanPath(key, allPaths),
|
|
847
973
|
value,
|
|
@@ -854,25 +980,221 @@ export class ScopeDataStructure {
|
|
|
854
980
|
},
|
|
855
981
|
],
|
|
856
982
|
});
|
|
857
|
-
//
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
// });
|
|
866
|
-
// }
|
|
867
|
-
}
|
|
983
|
+
// Process any work queued by followEquivalencies
|
|
984
|
+
this.processBatchQueue();
|
|
985
|
+
}
|
|
986
|
+
// Final pass to ensure all queued work is processed
|
|
987
|
+
this.processBatchQueue();
|
|
988
|
+
// Clean up batch processor
|
|
989
|
+
this.batchProcessor = null;
|
|
990
|
+
this.batchQueuedSet = null;
|
|
868
991
|
this.validateSchema(scopeNode, false, false);
|
|
869
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Process all items in the batch queue.
|
|
995
|
+
* Each item may queue more work via followEquivalencies.
|
|
996
|
+
*/
|
|
997
|
+
processBatchQueue() {
|
|
998
|
+
if (!this.batchProcessor)
|
|
999
|
+
return;
|
|
1000
|
+
while (this.batchProcessor.hasWork()) {
|
|
1001
|
+
const item = this.batchProcessor.getNextWork();
|
|
1002
|
+
if (!item)
|
|
1003
|
+
break;
|
|
1004
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(item.scopeNodeName);
|
|
1005
|
+
if (!scopeNode)
|
|
1006
|
+
continue;
|
|
1007
|
+
this.addToSchema({
|
|
1008
|
+
path: item.path,
|
|
1009
|
+
value: item.value,
|
|
1010
|
+
scopeNode,
|
|
1011
|
+
equivalencyValueChain: item.equivalencyValueChain,
|
|
1012
|
+
traceId: item.traceId,
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Propagates returnValue.* sub-properties from a callback scope to the usage path.
|
|
1018
|
+
*
|
|
1019
|
+
* When we have an equivalency like:
|
|
1020
|
+
* DataItemEditor().signature[0].structure -> getData().functionCallReturnValue
|
|
1021
|
+
*
|
|
1022
|
+
* And the callback scope for getData has:
|
|
1023
|
+
* returnValue.args -> dataStructure.arguments
|
|
1024
|
+
*
|
|
1025
|
+
* This method creates the transitive equivalency:
|
|
1026
|
+
* DataItemEditor().signature[0].structure.args -> signature[0].dataStructure.arguments
|
|
1027
|
+
*
|
|
1028
|
+
* It also resolves variable references through parent scopes (e.g., dataStructure -> signature[0].dataStructure)
|
|
1029
|
+
* and ensures the database entry is updated with the usage path.
|
|
1030
|
+
*/
|
|
1031
|
+
propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths) {
|
|
1032
|
+
// Try to find the callback scope name from different patterns:
|
|
1033
|
+
// 1. "getData().functionCallReturnValue" → look up getData variable to find scope
|
|
1034
|
+
// 2. "useMemo(cyScope1(), [...]).functionCallReturnValue" → extract cyScope1 directly
|
|
1035
|
+
let callbackScopeName;
|
|
1036
|
+
// Pattern 1: Simple function call like getData().functionCallReturnValue
|
|
1037
|
+
const simpleFunctionMatch = equivalentValue.match(/^(\w+)\(\)\.functionCallReturnValue$/);
|
|
1038
|
+
if (simpleFunctionMatch) {
|
|
1039
|
+
const functionName = simpleFunctionMatch[1];
|
|
1040
|
+
// Find the function reference in current or parent scopes
|
|
1041
|
+
const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
|
|
1042
|
+
for (const scopeName of scopesToCheck) {
|
|
1043
|
+
const checkScope = this.scopeNodes[scopeName];
|
|
1044
|
+
if (!checkScope?.analysis?.isolatedEquivalentVariables)
|
|
1045
|
+
continue;
|
|
1046
|
+
const functionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
|
|
1047
|
+
if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
|
|
1048
|
+
callbackScopeName = functionRef.slice(0, -1);
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
// Pattern 2: useMemo/useCallback with callback scope
|
|
1054
|
+
// e.g., "useMemo(cyScope1(), [deps]).functionCallReturnValue"
|
|
1055
|
+
if (!callbackScopeName) {
|
|
1056
|
+
const useMemoMatch = equivalentValue.match(/^useMemo\((\w+)\(\),\s*\[.*\]\)\.functionCallReturnValue$/);
|
|
1057
|
+
if (useMemoMatch) {
|
|
1058
|
+
callbackScopeName = useMemoMatch[1];
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
if (!callbackScopeName)
|
|
1062
|
+
return;
|
|
1063
|
+
const callbackScope = this.scopeNodes[callbackScopeName];
|
|
1064
|
+
if (!callbackScope)
|
|
1065
|
+
return;
|
|
1066
|
+
// Look for returnValue.* sub-properties in the callback scope
|
|
1067
|
+
if (!callbackScope.analysis?.isolatedEquivalentVariables)
|
|
1068
|
+
return;
|
|
1069
|
+
const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
|
|
1070
|
+
// First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
|
|
1071
|
+
// If so, we need to look for that variable's sub-properties too
|
|
1072
|
+
const returnValueAlias = typeof isolatedVars.returnValue === 'string' &&
|
|
1073
|
+
!isolatedVars.returnValue.includes('.')
|
|
1074
|
+
? isolatedVars.returnValue
|
|
1075
|
+
: undefined;
|
|
1076
|
+
// Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
|
|
1077
|
+
// When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
|
|
1078
|
+
let reduceSourceVar;
|
|
1079
|
+
if (typeof isolatedVars.returnValue === 'string') {
|
|
1080
|
+
const reduceMatch = isolatedVars.returnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
|
|
1081
|
+
if (reduceMatch) {
|
|
1082
|
+
reduceSourceVar = reduceMatch[1];
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
for (const [subPath, subValue] of Object.entries(isolatedVars)) {
|
|
1086
|
+
// Check for direct returnValue.* sub-properties
|
|
1087
|
+
const isReturnValueSub = subPath.startsWith('returnValue.') ||
|
|
1088
|
+
subPath.startsWith('returnValue[');
|
|
1089
|
+
// Also check for alias.* sub-properties (e.g., intermediate.args when returnValue = intermediate)
|
|
1090
|
+
const isAliasSub = returnValueAlias &&
|
|
1091
|
+
(subPath.startsWith(returnValueAlias + '.') ||
|
|
1092
|
+
subPath.startsWith(returnValueAlias + '['));
|
|
1093
|
+
// Also check for reduce source.* sub-properties (e.g., source['Function Arguments'] when returnValue = Object.keys(source).reduce())
|
|
1094
|
+
const isReduceSourceSub = reduceSourceVar &&
|
|
1095
|
+
(subPath.startsWith(reduceSourceVar + '.') ||
|
|
1096
|
+
subPath.startsWith(reduceSourceVar + '['));
|
|
1097
|
+
if (typeof subValue !== 'string' ||
|
|
1098
|
+
(!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
|
|
1099
|
+
continue;
|
|
1100
|
+
// Convert alias/reduceSource paths to returnValue paths
|
|
1101
|
+
let effectiveSubPath = subPath;
|
|
1102
|
+
if (isAliasSub && !isReturnValueSub) {
|
|
1103
|
+
// Replace the alias prefix with returnValue
|
|
1104
|
+
effectiveSubPath =
|
|
1105
|
+
'returnValue' + subPath.substring(returnValueAlias.length);
|
|
1106
|
+
}
|
|
1107
|
+
else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
|
|
1108
|
+
// Replace the reduce source prefix with returnValue
|
|
1109
|
+
effectiveSubPath =
|
|
1110
|
+
'returnValue' + subPath.substring(reduceSourceVar.length);
|
|
1111
|
+
}
|
|
1112
|
+
const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
|
|
1113
|
+
const newPath = cleanPath(path + subPropertyPath, allPaths);
|
|
1114
|
+
let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
|
|
1115
|
+
// Resolve variable references through parent scope equivalencies
|
|
1116
|
+
const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
|
|
1117
|
+
newEquivalentValue = resolved.resolvedPath;
|
|
1118
|
+
const equivalentScopeName = resolved.scopeName;
|
|
1119
|
+
if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
|
|
1120
|
+
continue;
|
|
1121
|
+
this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
|
|
1122
|
+
// Ensure the database entry has the usage path
|
|
1123
|
+
this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Resolves a variable path through parent scope equivalencies.
|
|
1128
|
+
*
|
|
1129
|
+
* For example, if the path is "dataStructure.arguments" and the parent scope has
|
|
1130
|
+
* dataStructure -> signature[0].dataStructure, this returns:
|
|
1131
|
+
* { resolvedPath: "signature[0].dataStructure.arguments", scopeName: "ParentScope" }
|
|
1132
|
+
*/
|
|
1133
|
+
resolveVariableThroughParentScopes(path, callbackScope, allPaths) {
|
|
1134
|
+
if (!path)
|
|
1135
|
+
return { resolvedPath: undefined, scopeName: callbackScope.name };
|
|
1136
|
+
// Extract the root variable name
|
|
1137
|
+
const dotIndex = path.indexOf('.');
|
|
1138
|
+
const bracketIndex = path.indexOf('[');
|
|
1139
|
+
let firstDelimiter = -1;
|
|
1140
|
+
if (dotIndex > -1 && bracketIndex > -1) {
|
|
1141
|
+
firstDelimiter = Math.min(dotIndex, bracketIndex);
|
|
1142
|
+
}
|
|
1143
|
+
else {
|
|
1144
|
+
firstDelimiter = dotIndex > -1 ? dotIndex : bracketIndex;
|
|
1145
|
+
}
|
|
1146
|
+
if (firstDelimiter === -1)
|
|
1147
|
+
return { resolvedPath: path, scopeName: callbackScope.name };
|
|
1148
|
+
const rootVar = path.substring(0, firstDelimiter);
|
|
1149
|
+
const restOfPath = path.substring(firstDelimiter);
|
|
1150
|
+
// Look in parent scopes for the root variable's equivalency
|
|
1151
|
+
for (const parentScopeName of callbackScope.tree || []) {
|
|
1152
|
+
const parentScope = this.scopeNodes[parentScopeName];
|
|
1153
|
+
if (!parentScope?.analysis?.isolatedEquivalentVariables)
|
|
1154
|
+
continue;
|
|
1155
|
+
const rootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
|
|
1156
|
+
if (typeof rootEquiv === 'string') {
|
|
1157
|
+
return {
|
|
1158
|
+
resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
|
|
1159
|
+
scopeName: parentScopeName,
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return { resolvedPath: path, scopeName: callbackScope.name };
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Adds a usage path to the equivalency database entry that has the given source.
|
|
1167
|
+
*
|
|
1168
|
+
* The addEquivalency call creates the equivalency but doesn't always properly
|
|
1169
|
+
* link the usage in the database, so we need to do it explicitly.
|
|
1170
|
+
*/
|
|
1171
|
+
addUsageToEquivalencyDatabaseEntry(usagePath, sourcePath, sourceScopeName, fallbackScopeName) {
|
|
1172
|
+
const usageEntry = {
|
|
1173
|
+
scopeNodeName: usagePath.match(/^([^().]+)\(\)/)
|
|
1174
|
+
? (usagePath.match(/^([^().]+)\(\)/)?.[1] ?? fallbackScopeName)
|
|
1175
|
+
: fallbackScopeName,
|
|
1176
|
+
schemaPath: usagePath,
|
|
1177
|
+
};
|
|
1178
|
+
const sourceKey = `${sourceScopeName}::${sourcePath}`;
|
|
1179
|
+
for (const entry of this.equivalencyDatabase) {
|
|
1180
|
+
if (entry.intermediatesOrder[sourceKey] === 0 ||
|
|
1181
|
+
entry.sourceCandidates.some((sc) => sc.scopeNodeName === sourceScopeName &&
|
|
1182
|
+
sc.schemaPath === sourcePath)) {
|
|
1183
|
+
const usageExists = entry.usages.some((u) => u.scopeNodeName === usageEntry.scopeNodeName &&
|
|
1184
|
+
u.schemaPath === usageEntry.schemaPath);
|
|
1185
|
+
if (!usageExists) {
|
|
1186
|
+
entry.usages.push(usageEntry);
|
|
1187
|
+
}
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
870
1192
|
checkForArrayItemPath(pathParts, scopeNode, equivalencyValueChain) {
|
|
871
|
-
const arrayItemPath =
|
|
1193
|
+
const arrayItemPath = this.joinPathParts([...pathParts, '[]']);
|
|
872
1194
|
if (scopeNode.equivalencies[arrayItemPath]) {
|
|
873
1195
|
const firstEquivalency = equivalencyValueChain[0].currentPath;
|
|
874
|
-
const newFirstEquivalencyPath =
|
|
875
|
-
...
|
|
1196
|
+
const newFirstEquivalencyPath = this.joinPathParts([
|
|
1197
|
+
...this.splitPath(firstEquivalency.schemaPath),
|
|
876
1198
|
'[]',
|
|
877
1199
|
]);
|
|
878
1200
|
this.addToSchema({
|
|
@@ -889,27 +1211,77 @@ export class ScopeDataStructure {
|
|
|
889
1211
|
});
|
|
890
1212
|
}
|
|
891
1213
|
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Follows equivalencies for a subpath and recursively calls addToSchema.
|
|
1216
|
+
*
|
|
1217
|
+
* This is the recursive heart of schema propagation. When we have:
|
|
1218
|
+
* `user` equivalent to `props.user`
|
|
1219
|
+
* And we're processing `user.id`, this method will:
|
|
1220
|
+
* 1. Find the equivalency `user` → `props.user`
|
|
1221
|
+
* 2. Reconstruct the full path: `props.user.id`
|
|
1222
|
+
* 3. Recursively call addToSchema for the equivalent scope
|
|
1223
|
+
*
|
|
1224
|
+
* ## Function-Ambivalent Paths
|
|
1225
|
+
*
|
|
1226
|
+
* Handles paths like `data.map(fn)` by also checking equivalencies
|
|
1227
|
+
* for `data.map` (without the function argument). This allows
|
|
1228
|
+
* array method chains to propagate correctly.
|
|
1229
|
+
*
|
|
1230
|
+
* @param scopeNode - Current scope being processed
|
|
1231
|
+
* @param path - Full original path (e.g., 'user.profile.name')
|
|
1232
|
+
* @param pathParts - Split version of path
|
|
1233
|
+
* @param subPath - Current subpath being checked (e.g., 'user.profile')
|
|
1234
|
+
* @param subPathParts - Split version of subPath
|
|
1235
|
+
* @param value - Type value to propagate
|
|
1236
|
+
* @param equivalencyValueChain - Chain tracking for database
|
|
1237
|
+
* @param traceId - Debug ID
|
|
1238
|
+
* @param debugLevel - 0=minimal, 1=executed, 2=verbose
|
|
1239
|
+
*/
|
|
892
1240
|
followEquivalencies(scopeNode, path, pathParts, subPath, subPathParts, value, equivalencyValueChain, traceId, debugLevel = 0) {
|
|
893
1241
|
followEquivalenciesCallCount++;
|
|
1242
|
+
// Trace for debugging
|
|
1243
|
+
this.tracer.trace('followEquivalencies', {
|
|
1244
|
+
path,
|
|
1245
|
+
scope: scopeNode.name,
|
|
1246
|
+
subPath,
|
|
1247
|
+
hasEquivalencies: (scopeNode.equivalencies[subPath]?.length ?? 0) > 0,
|
|
1248
|
+
});
|
|
894
1249
|
let propagated = false;
|
|
1250
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
1251
|
+
// Step 1: Collect equivalencies (including function-ambivalent paths)
|
|
1252
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
895
1253
|
let equivalentValues = scopeNode.equivalencies[subPath] ?? [];
|
|
896
1254
|
let functionAmbivalentSubPath = subPath;
|
|
897
1255
|
let functionAmbivalentSubPathParts = subPathParts;
|
|
898
|
-
|
|
1256
|
+
// For paths like `data.map(fn)`, also check `data.map` equivalencies
|
|
1257
|
+
// PERF: Only do the expensive function-ambivalent processing if:
|
|
1258
|
+
// 1. No equivalencies found yet, AND
|
|
1259
|
+
// 2. The subpath ends with a function call (contains '(')
|
|
1260
|
+
const lastPart = subPathParts[subPathParts.length - 1];
|
|
1261
|
+
if (lastPart.indexOf('(') > -1) {
|
|
1262
|
+
// Check function-ambivalent path for equivalencies
|
|
899
1263
|
functionAmbivalentSubPathParts = [
|
|
900
1264
|
...subPathParts.slice(0, -1),
|
|
901
|
-
|
|
1265
|
+
lastPart.split('(')[0],
|
|
902
1266
|
];
|
|
903
1267
|
functionAmbivalentSubPath = this.joinPathParts(functionAmbivalentSubPathParts);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1268
|
+
const functionAmbivalentEquivalencies = scopeNode.equivalencies[functionAmbivalentSubPath];
|
|
1269
|
+
if (functionAmbivalentEquivalencies?.length > 0) {
|
|
1270
|
+
equivalentValues = [
|
|
1271
|
+
...equivalentValues,
|
|
1272
|
+
...functionAmbivalentEquivalencies,
|
|
1273
|
+
];
|
|
1274
|
+
}
|
|
908
1275
|
}
|
|
909
1276
|
// Early exit optimization: if no equivalencies to follow, skip expensive processing
|
|
910
1277
|
if (equivalentValues.length === 0) {
|
|
1278
|
+
followEquivalenciesEarlyExitCount++;
|
|
1279
|
+
if (this.onlyEquivalencies) {
|
|
1280
|
+
followEquivalenciesEarlyExitPhase1Count++;
|
|
1281
|
+
}
|
|
911
1282
|
return false;
|
|
912
1283
|
}
|
|
1284
|
+
followEquivalenciesWithWorkCount++;
|
|
913
1285
|
if (traceId && debugLevel > 1) {
|
|
914
1286
|
console.info('Debug Propagation: equivalence', JSON.stringify({
|
|
915
1287
|
traceId,
|
|
@@ -925,10 +1297,17 @@ export class ScopeDataStructure {
|
|
|
925
1297
|
}, null, 2));
|
|
926
1298
|
}
|
|
927
1299
|
const uniqueEquivalentValues = this.uniqueScopeVariables(equivalentValues);
|
|
1300
|
+
// PERF: Only create Set when chain is non-empty (common case avoids allocation)
|
|
1301
|
+
// Pre-compute Set of chain IDs for O(1) cycle detection instead of O(n) .some()
|
|
1302
|
+
const chainIdSet = equivalencyValueChain.length > 0
|
|
1303
|
+
? new Set(equivalencyValueChain.map((ev) => ev.id))
|
|
1304
|
+
: null;
|
|
928
1305
|
for (let index = 0; index < uniqueEquivalentValues.length; ++index) {
|
|
929
1306
|
const equivalentValue = uniqueEquivalentValues[index];
|
|
930
|
-
|
|
931
|
-
|
|
1307
|
+
// O(1) cycle check using Set instead of O(n) .some()
|
|
1308
|
+
if (chainIdSet &&
|
|
1309
|
+
equivalentValue.id !== -1 &&
|
|
1310
|
+
chainIdSet.has(equivalentValue.id)) {
|
|
932
1311
|
if (traceId) {
|
|
933
1312
|
console.info('Debug Propagation: skipping circular equivalence', JSON.stringify({
|
|
934
1313
|
traceId,
|
|
@@ -956,8 +1335,12 @@ export class ScopeDataStructure {
|
|
|
956
1335
|
if (lastRelevantSubPathPart.endsWith(')') &&
|
|
957
1336
|
schemaPathParts[schemaPathParts.length - 1] ===
|
|
958
1337
|
lastRelevantSubPathPart.split('(')[0]) {
|
|
959
|
-
|
|
960
|
-
|
|
1338
|
+
// PERF: Don't mutate the array - create a new one to avoid requiring structuredClone
|
|
1339
|
+
const updatedSchemaPathParts = [
|
|
1340
|
+
...schemaPathParts.slice(0, -1),
|
|
1341
|
+
lastRelevantSubPathPart,
|
|
1342
|
+
];
|
|
1343
|
+
schemaPath = this.joinPathParts(updatedSchemaPathParts);
|
|
961
1344
|
}
|
|
962
1345
|
const remainingPathParts = pathParts.slice(relevantSubPathParts.length);
|
|
963
1346
|
const remainingPath = this.joinPathParts(remainingPathParts);
|
|
@@ -1000,23 +1383,27 @@ export class ScopeDataStructure {
|
|
|
1000
1383
|
// equivalencies: scopeNode.equivalencies,
|
|
1001
1384
|
}, null, 2));
|
|
1002
1385
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1386
|
+
// PERF: Use spread instead of structuredClone - the chain items are immutable
|
|
1387
|
+
// so shallow copy is sufficient and much faster (structuredClone is expensive)
|
|
1388
|
+
const localEquivalencyValueChain = [
|
|
1389
|
+
...equivalencyValueChain,
|
|
1390
|
+
{
|
|
1391
|
+
id: equivalentValue.id,
|
|
1392
|
+
source: 'equivalence',
|
|
1393
|
+
previousPath: {
|
|
1394
|
+
scopeNodeName: scopeNode.name,
|
|
1395
|
+
schemaPath: path,
|
|
1396
|
+
value,
|
|
1397
|
+
},
|
|
1398
|
+
currentPath: {
|
|
1399
|
+
scopeNodeName: equivalentScopeNode.name,
|
|
1400
|
+
schemaPath: newEquivalentPath,
|
|
1401
|
+
value,
|
|
1402
|
+
},
|
|
1403
|
+
reason: equivalentValue.equivalencyReason,
|
|
1404
|
+
traceId,
|
|
1016
1405
|
},
|
|
1017
|
-
|
|
1018
|
-
traceId,
|
|
1019
|
-
});
|
|
1406
|
+
];
|
|
1020
1407
|
// writeEquivalencyToFile(
|
|
1021
1408
|
// scopeNode.name,
|
|
1022
1409
|
// subPath,
|
|
@@ -1026,13 +1413,48 @@ export class ScopeDataStructure {
|
|
|
1026
1413
|
// equivalentValue.equivalencyReason,
|
|
1027
1414
|
// )
|
|
1028
1415
|
propagated = true;
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1416
|
+
// PERF: If batch processor is active, queue work instead of recursing
|
|
1417
|
+
// This converts deep recursion to iterative processing
|
|
1418
|
+
if (this.batchProcessor) {
|
|
1419
|
+
// PERF OPTIMIZATION: For external function calls, use path-only key (ignore value)
|
|
1420
|
+
// External FCs don't have internals to analyze, so processing the same path
|
|
1421
|
+
// with different values is redundant - we're just tracking data flow
|
|
1422
|
+
const isExternalFc = equivalentValue.equivalencyReason ===
|
|
1423
|
+
'equivalency to external function call' ||
|
|
1424
|
+
this.getExternalFunctionCallInfo(equivalentScopeNode.name) !==
|
|
1425
|
+
undefined;
|
|
1426
|
+
const queueKey = isExternalFc
|
|
1427
|
+
? `${equivalentScopeNode.name}::${newEquivalentPath}` // path-only for external FC
|
|
1428
|
+
: `${equivalentScopeNode.name}::${newEquivalentPath}::${value}`; // full key otherwise
|
|
1429
|
+
// Always check visited - it catches already-processed items
|
|
1430
|
+
const alreadyVisited = this.visitedTracker.hasGlobalVisited(equivalentScopeNode.name, newEquivalentPath, value);
|
|
1431
|
+
// For external FCs, queueKey is path-only so this catches any-value duplicates
|
|
1432
|
+
const alreadyQueued = this.batchQueuedSet?.has(queueKey);
|
|
1433
|
+
if (alreadyVisited || alreadyQueued) {
|
|
1434
|
+
// Still record in database to capture the chain (as addToSchema does)
|
|
1435
|
+
this.addToEquivalencyDatabase(localEquivalencyValueChain, traceId);
|
|
1436
|
+
}
|
|
1437
|
+
else {
|
|
1438
|
+
// Mark as queued to prevent duplicate queue entries
|
|
1439
|
+
this.batchQueuedSet?.add(queueKey);
|
|
1440
|
+
this.batchProcessor.addWork({
|
|
1441
|
+
scopeNodeName: equivalentScopeNode.name,
|
|
1442
|
+
path: newEquivalentPath,
|
|
1443
|
+
value,
|
|
1444
|
+
equivalencyValueChain: localEquivalencyValueChain,
|
|
1445
|
+
traceId,
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
else {
|
|
1450
|
+
this.addToSchema({
|
|
1451
|
+
path: newEquivalentPath,
|
|
1452
|
+
value,
|
|
1453
|
+
scopeNode: equivalentScopeNode,
|
|
1454
|
+
equivalencyValueChain: localEquivalencyValueChain,
|
|
1455
|
+
traceId,
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1036
1458
|
}
|
|
1037
1459
|
}
|
|
1038
1460
|
return propagated;
|
|
@@ -1054,6 +1476,11 @@ export class ScopeDataStructure {
|
|
|
1054
1476
|
return;
|
|
1055
1477
|
}
|
|
1056
1478
|
const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
|
|
1479
|
+
// Guard against infinite recursion by tracking which paths we've already
|
|
1480
|
+
// added from addComplexSourcePathVariables
|
|
1481
|
+
if (this.visitedTracker.checkAndMarkComplexSourceVisited(usageScopeNode.name, newUsageEquivalentPath)) {
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1057
1484
|
this.addToSchema({
|
|
1058
1485
|
path: newUsageEquivalentPath,
|
|
1059
1486
|
value: 'unknown',
|
|
@@ -1162,6 +1589,7 @@ export class ScopeDataStructure {
|
|
|
1162
1589
|
}
|
|
1163
1590
|
for (let i = 0; i < cleanEquivalencyValueChain.length; ++i) {
|
|
1164
1591
|
const pathInfo = cleanEquivalencyValueChain[i].currentPath;
|
|
1592
|
+
const previousPath = cleanEquivalencyValueChain[i].previousPath;
|
|
1165
1593
|
const schemaPathParts = this.splitPath(pathInfo.schemaPath);
|
|
1166
1594
|
const isSignaturePath = schemaPathParts.findIndex((p) => p.startsWith('signature[')) > 0;
|
|
1167
1595
|
if (schemaPathParts[0].startsWith('returnValue') ||
|
|
@@ -1171,6 +1599,17 @@ export class ScopeDataStructure {
|
|
|
1171
1599
|
) {
|
|
1172
1600
|
databaseEntry.usages.push(pathInfo);
|
|
1173
1601
|
}
|
|
1602
|
+
// Also add previousPath as a usage if it matches the criteria
|
|
1603
|
+
// This handles propagated sub-property equivalencies where the JSX prop path
|
|
1604
|
+
// is in previousPath and should be tracked as a usage
|
|
1605
|
+
if (previousPath) {
|
|
1606
|
+
const prevSchemaPathParts = this.splitPath(previousPath.schemaPath);
|
|
1607
|
+
const isPrevSignaturePath = prevSchemaPathParts.findIndex((p) => p.startsWith('signature[')) > 0;
|
|
1608
|
+
if (prevSchemaPathParts[0].startsWith('returnValue') ||
|
|
1609
|
+
isPrevSignaturePath) {
|
|
1610
|
+
databaseEntry.usages.push(previousPath);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1174
1613
|
const pathId = this.uniqueId(pathInfo);
|
|
1175
1614
|
let intermediateIndex = cleanEquivalencyValueChain.length - i - 1;
|
|
1176
1615
|
const existingIntermediateIndex = databaseEntry.intermediatesOrder[pathId];
|
|
@@ -1236,6 +1675,7 @@ export class ScopeDataStructure {
|
|
|
1236
1675
|
if (functionScope) {
|
|
1237
1676
|
functionScope.functionCalls.push(externalFunctionCallInfo);
|
|
1238
1677
|
this.externalFunctionCalls.splice(i, 1);
|
|
1678
|
+
this.invalidateExternalFunctionCallsIndex();
|
|
1239
1679
|
for (const equivalentPath in externalFunctionCallInfo.equivalencies) {
|
|
1240
1680
|
let localEquivalentPath = equivalentPath;
|
|
1241
1681
|
if (localEquivalentPath.startsWith(externalFunctionCallInfo.callSignature)) {
|
|
@@ -1278,15 +1718,17 @@ export class ScopeDataStructure {
|
|
|
1278
1718
|
for (const key in scopeNode.equivalencies) {
|
|
1279
1719
|
const keyParts = this.splitPath(key);
|
|
1280
1720
|
if (keyParts.length > 1) {
|
|
1281
|
-
|
|
1721
|
+
// PERF: Don't mutate the array - use indexing instead of pop() to avoid requiring structuredClone
|
|
1722
|
+
const lastPart = keyParts[keyParts.length - 1];
|
|
1282
1723
|
if (lastPart.startsWith('signature[')) {
|
|
1283
|
-
const
|
|
1724
|
+
const keyPartsWithoutLast = keyParts.slice(0, -1);
|
|
1725
|
+
const functionCall = keyPartsWithoutLast[keyPartsWithoutLast.length - 1];
|
|
1284
1726
|
const argumentsIndex = functionCall.indexOf('(');
|
|
1285
1727
|
const functionName = this.joinPathParts([
|
|
1286
|
-
...
|
|
1728
|
+
...keyPartsWithoutLast.slice(0, -1),
|
|
1287
1729
|
functionCall.slice(0, argumentsIndex === -1 ? undefined : argumentsIndex),
|
|
1288
1730
|
]);
|
|
1289
|
-
const callSignature = this.joinPathParts(
|
|
1731
|
+
const callSignature = this.joinPathParts(keyPartsWithoutLast);
|
|
1290
1732
|
const functionCallInfo = {
|
|
1291
1733
|
name: functionName,
|
|
1292
1734
|
callSignature,
|
|
@@ -1298,15 +1740,17 @@ export class ScopeDataStructure {
|
|
|
1298
1740
|
for (const equivalentValues of scopeNode.equivalencies[key]) {
|
|
1299
1741
|
const equivalentValueParts = this.splitPath(equivalentValues.schemaPath);
|
|
1300
1742
|
if (equivalentValueParts.length > 1) {
|
|
1301
|
-
|
|
1743
|
+
// PERF: Don't mutate the array - use indexing instead of pop() to avoid requiring structuredClone
|
|
1744
|
+
const lastPart = equivalentValueParts[equivalentValueParts.length - 1];
|
|
1302
1745
|
if (lastPart.startsWith('functionCallReturnValue')) {
|
|
1303
|
-
const
|
|
1746
|
+
const partsWithoutLast = equivalentValueParts.slice(0, -1);
|
|
1747
|
+
const functionCall = partsWithoutLast[partsWithoutLast.length - 1];
|
|
1304
1748
|
const argumentsIndex = functionCall.indexOf('(');
|
|
1305
1749
|
const functionName = this.joinPathParts([
|
|
1306
|
-
...
|
|
1750
|
+
...partsWithoutLast.slice(0, -1),
|
|
1307
1751
|
functionCall.slice(0, argumentsIndex === -1 ? undefined : argumentsIndex),
|
|
1308
1752
|
]);
|
|
1309
|
-
const callSignature = this.joinPathParts(
|
|
1753
|
+
const callSignature = this.joinPathParts(partsWithoutLast);
|
|
1310
1754
|
const functionCallInfo = {
|
|
1311
1755
|
name: functionName,
|
|
1312
1756
|
callSignature,
|
|
@@ -1451,7 +1895,7 @@ export class ScopeDataStructure {
|
|
|
1451
1895
|
return this.getExternalFunctionCallInfo(scopeName);
|
|
1452
1896
|
}
|
|
1453
1897
|
getScopeNode(scopeName) {
|
|
1454
|
-
const scopeNode = this.scopeNodes[scopeName ?? this.
|
|
1898
|
+
const scopeNode = this.scopeNodes[scopeName ?? this.scopeTreeManager.getRootName()];
|
|
1455
1899
|
if (scopeNode)
|
|
1456
1900
|
return scopeNode;
|
|
1457
1901
|
for (const scopeNodeName in this.scopeNodes) {
|
|
@@ -1460,20 +1904,54 @@ export class ScopeDataStructure {
|
|
|
1460
1904
|
}
|
|
1461
1905
|
}
|
|
1462
1906
|
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Gets or builds the external function calls index for O(1) lookup.
|
|
1909
|
+
* The index maps both the full name and the name without generics to the FunctionCallInfo.
|
|
1910
|
+
*/
|
|
1911
|
+
getExternalFunctionCallsIndex() {
|
|
1912
|
+
if (this.externalFunctionCallsIndex === null) {
|
|
1913
|
+
this.externalFunctionCallsIndex = new Map();
|
|
1914
|
+
for (const efc of this.externalFunctionCalls) {
|
|
1915
|
+
this.externalFunctionCallsIndex.set(efc.name, efc);
|
|
1916
|
+
// Also index by name without generics (e.g., 'MyFunction<T>' -> 'MyFunction')
|
|
1917
|
+
const nameWithoutGenerics = this.pathManager.stripGenerics(efc.name);
|
|
1918
|
+
if (nameWithoutGenerics !== efc.name) {
|
|
1919
|
+
this.externalFunctionCallsIndex.set(nameWithoutGenerics, efc);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return this.externalFunctionCallsIndex;
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* Invalidates the external function calls index.
|
|
1927
|
+
* Call this after any mutation to externalFunctionCalls array.
|
|
1928
|
+
*/
|
|
1929
|
+
invalidateExternalFunctionCallsIndex() {
|
|
1930
|
+
this.externalFunctionCallsIndex = null;
|
|
1931
|
+
}
|
|
1463
1932
|
getExternalFunctionCallInfo(functionName) {
|
|
1464
|
-
|
|
1465
|
-
|
|
1933
|
+
const searchKey = getFunctionCallRoot(functionName);
|
|
1934
|
+
const index = this.getExternalFunctionCallsIndex();
|
|
1935
|
+
// First try exact match
|
|
1936
|
+
const exact = index.get(searchKey);
|
|
1937
|
+
if (exact)
|
|
1938
|
+
return exact;
|
|
1939
|
+
// Fallback to the original find for edge cases not covered by index
|
|
1940
|
+
return this.externalFunctionCalls.find((efc) => efc.name === searchKey ||
|
|
1941
|
+
this.pathManager.stripGenerics(efc.name) === searchKey);
|
|
1466
1942
|
}
|
|
1467
1943
|
getScopeAnalysis(scopeName) {
|
|
1468
|
-
return this.scopeNodes[scopeName ?? this.
|
|
1944
|
+
return this.scopeNodes[scopeName ?? this.scopeTreeManager.getRootName()]
|
|
1945
|
+
.analysis;
|
|
1469
1946
|
}
|
|
1470
1947
|
getAnalysisTree() {
|
|
1471
1948
|
return this.scopeTree;
|
|
1472
1949
|
}
|
|
1473
1950
|
getSchema({ scopeName, fillInUnknowns, }) {
|
|
1474
|
-
const scopeNode = this.scopeNodes[scopeName ?? this.
|
|
1951
|
+
const scopeNode = this.scopeNodes[scopeName ?? this.scopeTreeManager.getRootName()];
|
|
1475
1952
|
if (!scopeNode) {
|
|
1476
|
-
const
|
|
1953
|
+
const searchKey = getFunctionCallRoot(scopeName);
|
|
1954
|
+
const externalFunctionCallSchema = this.getExternalFunctionCallsIndex().get(searchKey)?.schema;
|
|
1477
1955
|
if (!externalFunctionCallSchema)
|
|
1478
1956
|
return;
|
|
1479
1957
|
return Object.keys(externalFunctionCallSchema).reduce((acc, key) => {
|
|
@@ -1485,6 +1963,35 @@ export class ScopeDataStructure {
|
|
|
1485
1963
|
}
|
|
1486
1964
|
this.validateSchema(scopeNode, true, fillInUnknowns);
|
|
1487
1965
|
const { schema } = scopeNode;
|
|
1966
|
+
// For root scope, merge in external function call schemas
|
|
1967
|
+
// This ensures that imported objects used as method call targets (like logger.error())
|
|
1968
|
+
// appear in the schema as objects with function properties
|
|
1969
|
+
if (scopeName === undefined ||
|
|
1970
|
+
scopeName === this.scopeTreeManager.getRootName()) {
|
|
1971
|
+
const mergedSchema = { ...schema };
|
|
1972
|
+
for (const efc of this.externalFunctionCalls) {
|
|
1973
|
+
// Add the base object name (e.g., "logger") as an object
|
|
1974
|
+
const baseName = this.splitPath(efc.name)[0];
|
|
1975
|
+
if (!mergedSchema[baseName]) {
|
|
1976
|
+
mergedSchema[baseName] = 'object';
|
|
1977
|
+
}
|
|
1978
|
+
// Get all call signatures (use allCallSignatures if available, otherwise just the single callSignature)
|
|
1979
|
+
const signatures = efc.allCallSignatures ?? [efc.callSignature];
|
|
1980
|
+
for (const signature of signatures) {
|
|
1981
|
+
// Add the method as a function (e.g., "logger.error")
|
|
1982
|
+
// Extract method name from callSignature like "logger.error(args...)"
|
|
1983
|
+
// Get everything before the first '(' to get "logger.error"
|
|
1984
|
+
const parenIndex = signature.indexOf('(');
|
|
1985
|
+
if (parenIndex > 0) {
|
|
1986
|
+
const methodPath = signature.substring(0, parenIndex);
|
|
1987
|
+
if (methodPath.includes('.') && !mergedSchema[methodPath]) {
|
|
1988
|
+
mergedSchema[methodPath] = 'function';
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
return mergedSchema;
|
|
1994
|
+
}
|
|
1488
1995
|
return schema;
|
|
1489
1996
|
}
|
|
1490
1997
|
getEquivalencies(scopeName) {
|
|
@@ -1496,7 +2003,9 @@ export class ScopeDataStructure {
|
|
|
1496
2003
|
if (this.equivalencyDatabaseCache.has(cacheKey)) {
|
|
1497
2004
|
return this.equivalencyDatabaseCache.get(cacheKey);
|
|
1498
2005
|
}
|
|
1499
|
-
|
|
2006
|
+
// PERF: Use inverted index for O(1) lookup instead of O(n) array scan
|
|
2007
|
+
// The intermediatesOrderIndex maps pathId (scopeNodeName::schemaPath) to entry
|
|
2008
|
+
const result = this.intermediatesOrderIndex.get(cacheKey);
|
|
1500
2009
|
this.equivalencyDatabaseCache.set(cacheKey, result);
|
|
1501
2010
|
return result;
|
|
1502
2011
|
}
|
|
@@ -1559,12 +2068,12 @@ export class ScopeDataStructure {
|
|
|
1559
2068
|
}
|
|
1560
2069
|
}
|
|
1561
2070
|
}
|
|
1562
|
-
const tempScopeNode = this.createTempScopeNode(functionName ?? this.
|
|
2071
|
+
const tempScopeNode = this.createTempScopeNode(functionName ?? this.scopeTreeManager.getRootName(), signatureInSchema, equivalencies);
|
|
1563
2072
|
this.validateSchema(tempScopeNode, true, fillInUnknowns);
|
|
1564
2073
|
return tempScopeNode.schema;
|
|
1565
2074
|
}
|
|
1566
2075
|
getReturnValue({ functionName, fillInUnknowns, }) {
|
|
1567
|
-
const scopeName = functionName ?? this.
|
|
2076
|
+
const scopeName = functionName ?? this.scopeTreeManager.getRootName();
|
|
1568
2077
|
const scopeNode = this.scopeNodes[scopeName];
|
|
1569
2078
|
let schema = {};
|
|
1570
2079
|
if (scopeNode) {
|
|
@@ -1581,12 +2090,7 @@ export class ScopeDataStructure {
|
|
|
1581
2090
|
for (const schemaPath in externalFunctionCall.schema) {
|
|
1582
2091
|
const value1 = schema[schemaPath];
|
|
1583
2092
|
const value2 = externalFunctionCall.schema[schemaPath];
|
|
1584
|
-
|
|
1585
|
-
if (bestValue === 'unknown' ||
|
|
1586
|
-
(bestValue.includes('unknown') && !value2.includes('unknown'))) {
|
|
1587
|
-
bestValue = value2;
|
|
1588
|
-
}
|
|
1589
|
-
schema[schemaPath] = bestValue;
|
|
2093
|
+
schema[schemaPath] = selectBestValue(value1, value2, value2);
|
|
1590
2094
|
}
|
|
1591
2095
|
}
|
|
1592
2096
|
}
|
|
@@ -1683,7 +2187,7 @@ export class ScopeDataStructure {
|
|
|
1683
2187
|
return scopeText;
|
|
1684
2188
|
}
|
|
1685
2189
|
getEquivalentSignatureVariables() {
|
|
1686
|
-
const scopeNode = this.scopeNodes[this.
|
|
2190
|
+
const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
|
|
1687
2191
|
const equivalentSignatureVariables = {};
|
|
1688
2192
|
for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
|
|
1689
2193
|
for (const equivalentValue of equivalentValues) {
|
|
@@ -1695,7 +2199,7 @@ export class ScopeDataStructure {
|
|
|
1695
2199
|
return equivalentSignatureVariables;
|
|
1696
2200
|
}
|
|
1697
2201
|
getVariableInfo(variableName, scopeName, final) {
|
|
1698
|
-
const scopeNode = this.getScopeOrFunctionCallInfo(scopeName ?? this.
|
|
2202
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(scopeName ?? this.scopeTreeManager.getRootName());
|
|
1699
2203
|
if (!scopeNode)
|
|
1700
2204
|
return;
|
|
1701
2205
|
let equivalents = scopeNode.equivalencies[variableName];
|
|
@@ -1722,7 +2226,7 @@ export class ScopeDataStructure {
|
|
|
1722
2226
|
});
|
|
1723
2227
|
return { ...acc, ...filterdSchema };
|
|
1724
2228
|
}, {});
|
|
1725
|
-
const tempScopeNode = this.createTempScopeNode(scopeName ?? this.
|
|
2229
|
+
const tempScopeNode = this.createTempScopeNode(scopeName ?? this.scopeTreeManager.getRootName(), relevantSchema);
|
|
1726
2230
|
this.validateSchema(tempScopeNode, true, final);
|
|
1727
2231
|
return {
|
|
1728
2232
|
name: variableName,
|
|
@@ -1736,6 +2240,50 @@ export class ScopeDataStructure {
|
|
|
1736
2240
|
getEnvironmentVariables() {
|
|
1737
2241
|
return this.environmentVariables;
|
|
1738
2242
|
}
|
|
2243
|
+
/**
|
|
2244
|
+
* Add conditional usages from AST analysis.
|
|
2245
|
+
* Called during scope analysis to collect all conditionals.
|
|
2246
|
+
*/
|
|
2247
|
+
addConditionalUsages(usages) {
|
|
2248
|
+
for (const [path, pathUsages] of Object.entries(usages)) {
|
|
2249
|
+
if (!this.rawConditionalUsages[path]) {
|
|
2250
|
+
this.rawConditionalUsages[path] = [];
|
|
2251
|
+
}
|
|
2252
|
+
// Deduplicate usages
|
|
2253
|
+
for (const usage of pathUsages) {
|
|
2254
|
+
const exists = this.rawConditionalUsages[path].some((existing) => existing.location === usage.location &&
|
|
2255
|
+
existing.conditionType === usage.conditionType &&
|
|
2256
|
+
JSON.stringify(existing.comparedValues) ===
|
|
2257
|
+
JSON.stringify(usage.comparedValues));
|
|
2258
|
+
if (!exists) {
|
|
2259
|
+
this.rawConditionalUsages[path].push(usage);
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Get enriched conditional usages with source tracing.
|
|
2266
|
+
* Uses explainPath to trace each local variable back to its data source.
|
|
2267
|
+
*/
|
|
2268
|
+
getEnrichedConditionalUsages() {
|
|
2269
|
+
const enriched = {};
|
|
2270
|
+
for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
|
|
2271
|
+
// Try to trace this path back to a data source
|
|
2272
|
+
// First, try the root scope
|
|
2273
|
+
const rootScopeName = this.scopeTreeManager.getTree().name;
|
|
2274
|
+
const explanation = this.explainPath(rootScopeName, path);
|
|
2275
|
+
let sourceDataPath;
|
|
2276
|
+
if (explanation.source) {
|
|
2277
|
+
// Build the full data path: scopeName.path
|
|
2278
|
+
sourceDataPath = `${explanation.source.scope}.${explanation.source.path}`;
|
|
2279
|
+
}
|
|
2280
|
+
enriched[path] = usages.map((usage) => ({
|
|
2281
|
+
...usage,
|
|
2282
|
+
sourceDataPath,
|
|
2283
|
+
}));
|
|
2284
|
+
}
|
|
2285
|
+
return enriched;
|
|
2286
|
+
}
|
|
1739
2287
|
toSerializable() {
|
|
1740
2288
|
// Helper to convert ScopeVariable to SerializableScopeVariable
|
|
1741
2289
|
const toSerializableVariable = (vars) => vars.map((v) => ({
|
|
@@ -1784,13 +2332,427 @@ export class ScopeDataStructure {
|
|
|
1784
2332
|
// Get equivalent signature variables
|
|
1785
2333
|
const equivalentSignatureVariables = this.getEquivalentSignatureVariables();
|
|
1786
2334
|
const environmentVariables = this.getEnvironmentVariables();
|
|
2335
|
+
// Get enriched conditional usages with source tracing
|
|
2336
|
+
const enrichedConditionalUsages = this.getEnrichedConditionalUsages();
|
|
2337
|
+
const conditionalUsages = Object.keys(enrichedConditionalUsages).length > 0
|
|
2338
|
+
? enrichedConditionalUsages
|
|
2339
|
+
: undefined;
|
|
1787
2340
|
return {
|
|
1788
2341
|
externalFunctionCalls,
|
|
1789
2342
|
rootFunction,
|
|
1790
2343
|
functionResults,
|
|
1791
2344
|
equivalentSignatureVariables,
|
|
1792
2345
|
environmentVariables,
|
|
2346
|
+
conditionalUsages,
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2350
|
+
// DEBUGGING HELPERS
|
|
2351
|
+
// These methods help understand what's happening during analysis.
|
|
2352
|
+
// Use them when investigating why a path is missing or has the wrong type.
|
|
2353
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2354
|
+
/**
|
|
2355
|
+
* Explains a path by tracing its equivalencies and showing where data comes from.
|
|
2356
|
+
*
|
|
2357
|
+
* @example
|
|
2358
|
+
* ```typescript
|
|
2359
|
+
* const explanation = sds.explainPath('MyComponent', 'user.id');
|
|
2360
|
+
* console.log(explanation);
|
|
2361
|
+
* // {
|
|
2362
|
+
* // path: 'user.id',
|
|
2363
|
+
* // scope: 'MyComponent',
|
|
2364
|
+
* // schemaValue: 'string',
|
|
2365
|
+
* // equivalencies: [
|
|
2366
|
+
* // { scope: 'MyComponent', path: 'signature[0].user.id' },
|
|
2367
|
+
* // { scope: 'UserProfile', path: 'props.user.id' }
|
|
2368
|
+
* // ],
|
|
2369
|
+
* // source: { scope: 'fetchUser', path: 'functionCallReturnValue(fetch).data.user.id' }
|
|
2370
|
+
* // }
|
|
2371
|
+
* ```
|
|
2372
|
+
*/
|
|
2373
|
+
explainPath(scopeName, path) {
|
|
2374
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(scopeName);
|
|
2375
|
+
if (!scopeNode) {
|
|
2376
|
+
return {
|
|
2377
|
+
path,
|
|
2378
|
+
scope: scopeName,
|
|
2379
|
+
schemaValue: undefined,
|
|
2380
|
+
equivalencies: [],
|
|
2381
|
+
databaseEntry: undefined,
|
|
2382
|
+
source: undefined,
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
const schemaValue = scopeNode.schema?.[path];
|
|
2386
|
+
const rawEquivalencies = scopeNode.equivalencies?.[path] ?? [];
|
|
2387
|
+
const equivalencies = rawEquivalencies.map((eq) => ({
|
|
2388
|
+
scope: eq.scopeNodeName,
|
|
2389
|
+
path: eq.schemaPath,
|
|
2390
|
+
reason: eq.equivalencyReason,
|
|
2391
|
+
}));
|
|
2392
|
+
const databaseEntry = this.getEquivalenciesDatabaseEntry(scopeName, path);
|
|
2393
|
+
const source = databaseEntry?.sourceCandidates?.[0] &&
|
|
2394
|
+
databaseEntry.sourceCandidates.length > 0
|
|
2395
|
+
? {
|
|
2396
|
+
scope: databaseEntry.sourceCandidates[0].scopeNodeName,
|
|
2397
|
+
path: databaseEntry.sourceCandidates[0].schemaPath,
|
|
2398
|
+
}
|
|
2399
|
+
: undefined;
|
|
2400
|
+
return {
|
|
2401
|
+
path,
|
|
2402
|
+
scope: scopeName,
|
|
2403
|
+
schemaValue,
|
|
2404
|
+
equivalencies,
|
|
2405
|
+
databaseEntry,
|
|
2406
|
+
source,
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
/**
|
|
2410
|
+
* Dumps the current state of analysis for inspection.
|
|
2411
|
+
* Useful for understanding the overall state or finding issues.
|
|
2412
|
+
*
|
|
2413
|
+
* @param options - What to include in the dump
|
|
2414
|
+
* @returns A summary object with requested data
|
|
2415
|
+
*/
|
|
2416
|
+
dumpState(options) {
|
|
2417
|
+
const includeSchemas = options?.includeSchemas ?? false;
|
|
2418
|
+
const includeEquivalencies = options?.includeEquivalencies ?? false;
|
|
2419
|
+
const scopeFilter = options?.scopeFilter;
|
|
2420
|
+
const scopeNames = Object.keys(this.scopeNodes).filter((name) => !scopeFilter || name.includes(scopeFilter));
|
|
2421
|
+
const scopes = scopeNames.map((name) => {
|
|
2422
|
+
const node = this.scopeNodes[name];
|
|
2423
|
+
const result = {
|
|
2424
|
+
name,
|
|
2425
|
+
schemaKeyCount: Object.keys(node.schema ?? {}).length,
|
|
2426
|
+
equivalencyKeyCount: Object.keys(node.equivalencies ?? {}).length,
|
|
2427
|
+
functionCallCount: node.functionCalls?.length ?? 0,
|
|
2428
|
+
};
|
|
2429
|
+
if (includeSchemas) {
|
|
2430
|
+
result.schema = node.schema;
|
|
2431
|
+
}
|
|
2432
|
+
if (includeEquivalencies) {
|
|
2433
|
+
result.equivalencies = Object.entries(node.equivalencies ?? {}).reduce((acc, [key, vals]) => {
|
|
2434
|
+
acc[key] = vals.map((v) => ({
|
|
2435
|
+
scope: v.scopeNodeName,
|
|
2436
|
+
path: v.schemaPath,
|
|
2437
|
+
}));
|
|
2438
|
+
return acc;
|
|
2439
|
+
}, {});
|
|
2440
|
+
}
|
|
2441
|
+
return result;
|
|
2442
|
+
});
|
|
2443
|
+
return {
|
|
2444
|
+
scopeCount: Object.keys(this.scopeNodes).length,
|
|
2445
|
+
externalCallCount: this.externalFunctionCalls.length,
|
|
2446
|
+
equivalencyDatabaseSize: this.equivalencyDatabase.length,
|
|
2447
|
+
metrics: {
|
|
2448
|
+
addToSchemaCallCount,
|
|
2449
|
+
followEquivalenciesCallCount,
|
|
2450
|
+
maxEquivalencyChainDepth,
|
|
2451
|
+
},
|
|
2452
|
+
scopes,
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* Traces the full equivalency chain for a path, showing how data flows.
|
|
2457
|
+
* This is the most detailed debugging tool for understanding data tracing.
|
|
2458
|
+
*
|
|
2459
|
+
* @example
|
|
2460
|
+
* ```typescript
|
|
2461
|
+
* const chain = sds.traceEquivalencyChain('MyComponent', 'user.id');
|
|
2462
|
+
* // Returns array of steps showing how user.id is traced back to its source
|
|
2463
|
+
* ```
|
|
2464
|
+
*/
|
|
2465
|
+
traceEquivalencyChain(scopeName, path, maxDepth = 20) {
|
|
2466
|
+
const chain = [];
|
|
2467
|
+
const visited = new Set();
|
|
2468
|
+
const queue = [
|
|
2469
|
+
{ scope: scopeName, path, depth: 0 },
|
|
2470
|
+
];
|
|
2471
|
+
while (queue.length > 0 && chain.length < maxDepth) {
|
|
2472
|
+
const current = queue.shift();
|
|
2473
|
+
const key = `${current.scope}::${current.path}`;
|
|
2474
|
+
if (visited.has(key))
|
|
2475
|
+
continue;
|
|
2476
|
+
visited.add(key);
|
|
2477
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(current.scope);
|
|
2478
|
+
const schemaValue = scopeNode?.schema?.[current.path];
|
|
2479
|
+
const rawEquivalencies = scopeNode?.equivalencies?.[current.path] ?? [];
|
|
2480
|
+
const nextEquivalencies = rawEquivalencies.map((eq) => ({
|
|
2481
|
+
scope: eq.scopeNodeName,
|
|
2482
|
+
path: eq.schemaPath,
|
|
2483
|
+
reason: eq.equivalencyReason,
|
|
2484
|
+
}));
|
|
2485
|
+
chain.push({
|
|
2486
|
+
step: chain.length + 1,
|
|
2487
|
+
scope: current.scope,
|
|
2488
|
+
path: current.path,
|
|
2489
|
+
schemaValue,
|
|
2490
|
+
nextEquivalencies,
|
|
2491
|
+
});
|
|
2492
|
+
// Add next equivalencies to queue for further tracing
|
|
2493
|
+
for (const eq of nextEquivalencies) {
|
|
2494
|
+
const nextKey = `${eq.scope}::${eq.path}`;
|
|
2495
|
+
if (!visited.has(nextKey)) {
|
|
2496
|
+
queue.push({
|
|
2497
|
+
scope: eq.scope,
|
|
2498
|
+
path: eq.path,
|
|
2499
|
+
depth: current.depth + 1,
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
return chain;
|
|
2505
|
+
}
|
|
2506
|
+
/**
|
|
2507
|
+
* Finds all paths in a scope that match a pattern.
|
|
2508
|
+
* Useful for finding related paths when debugging.
|
|
2509
|
+
*
|
|
2510
|
+
* @example
|
|
2511
|
+
* ```typescript
|
|
2512
|
+
* const paths = sds.findPaths('MyComponent', /user/);
|
|
2513
|
+
* // Returns all schema paths containing "user"
|
|
2514
|
+
* ```
|
|
2515
|
+
*/
|
|
2516
|
+
findPaths(scopeName, pattern) {
|
|
2517
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(scopeName);
|
|
2518
|
+
if (!scopeNode)
|
|
2519
|
+
return [];
|
|
2520
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
2521
|
+
const results = [];
|
|
2522
|
+
// Search in schema
|
|
2523
|
+
for (const [path, value] of Object.entries(scopeNode.schema ?? {})) {
|
|
2524
|
+
if (regex.test(path)) {
|
|
2525
|
+
results.push({
|
|
2526
|
+
path,
|
|
2527
|
+
value,
|
|
2528
|
+
hasEquivalencies: !!scopeNode.equivalencies?.[path]?.length,
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
// Also search equivalency keys that might not be in schema
|
|
2533
|
+
for (const path of Object.keys(scopeNode.equivalencies ?? {})) {
|
|
2534
|
+
if (regex.test(path) && !results.find((r) => r.path === path)) {
|
|
2535
|
+
results.push({
|
|
2536
|
+
path,
|
|
2537
|
+
value: scopeNode.schema?.[path] ?? 'not-in-schema',
|
|
2538
|
+
hasEquivalencies: true,
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
return results.sort((a, b) => a.path.localeCompare(b.path));
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Returns a summary of why a path might be missing from the schema.
|
|
2546
|
+
* Checks common issues that cause paths to not appear.
|
|
2547
|
+
*/
|
|
2548
|
+
diagnoseMissingPath(scopeName, path) {
|
|
2549
|
+
const scopeNode = this.getScopeOrFunctionCallInfo(scopeName);
|
|
2550
|
+
const possibleReasons = [];
|
|
2551
|
+
const suggestions = [];
|
|
2552
|
+
if (!scopeNode) {
|
|
2553
|
+
possibleReasons.push(`Scope "${scopeName}" does not exist`);
|
|
2554
|
+
suggestions.push(`Available scopes: ${Object.keys(this.scopeNodes).join(', ')}`);
|
|
2555
|
+
return {
|
|
2556
|
+
exists: false,
|
|
2557
|
+
inSchema: false,
|
|
2558
|
+
inEquivalencies: false,
|
|
2559
|
+
possibleReasons,
|
|
2560
|
+
suggestions,
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
const inSchema = path in (scopeNode.schema ?? {});
|
|
2564
|
+
const inEquivalencies = path in (scopeNode.equivalencies ?? {});
|
|
2565
|
+
if (inSchema) {
|
|
2566
|
+
return {
|
|
2567
|
+
exists: true,
|
|
2568
|
+
inSchema: true,
|
|
2569
|
+
inEquivalencies,
|
|
2570
|
+
possibleReasons: [],
|
|
2571
|
+
suggestions: [],
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
// Check for similar paths
|
|
2575
|
+
const allPaths = [
|
|
2576
|
+
...Object.keys(scopeNode.schema ?? {}),
|
|
2577
|
+
...Object.keys(scopeNode.equivalencies ?? {}),
|
|
2578
|
+
];
|
|
2579
|
+
const similarPaths = allPaths.filter((p) => {
|
|
2580
|
+
const pathParts = path.split('.');
|
|
2581
|
+
const pParts = p.split('.');
|
|
2582
|
+
return (pathParts.some((part) => pParts.includes(part)) ||
|
|
2583
|
+
p.includes(path) ||
|
|
2584
|
+
path.includes(p));
|
|
2585
|
+
});
|
|
2586
|
+
if (similarPaths.length > 0) {
|
|
2587
|
+
possibleReasons.push(`Path "${path}" not found but similar paths exist`);
|
|
2588
|
+
suggestions.push(`Similar paths: ${similarPaths.slice(0, 5).join(', ')}`);
|
|
2589
|
+
}
|
|
2590
|
+
// Check if it's a partial path
|
|
2591
|
+
const parentPath = path.split('.').slice(0, -1).join('.');
|
|
2592
|
+
if (parentPath && scopeNode.schema?.[parentPath]) {
|
|
2593
|
+
possibleReasons.push(`Parent path "${parentPath}" exists with value "${scopeNode.schema[parentPath]}"`);
|
|
2594
|
+
suggestions.push(`The property might not have been accessed in the analyzed code`);
|
|
2595
|
+
}
|
|
2596
|
+
// Check visited tracker
|
|
2597
|
+
const wasVisited = this.visitedTracker.wasVisited(scopeName, path);
|
|
2598
|
+
if (wasVisited) {
|
|
2599
|
+
possibleReasons.push(`Path was visited during analysis but not written`);
|
|
2600
|
+
suggestions.push(`Check if the path was filtered by isValidPath() or hit cycle detection`);
|
|
2601
|
+
}
|
|
2602
|
+
if (possibleReasons.length === 0) {
|
|
2603
|
+
possibleReasons.push(`Path "${path}" was never encountered during analysis`);
|
|
2604
|
+
suggestions.push(`Verify the path is accessed in the source code being analyzed`);
|
|
2605
|
+
}
|
|
2606
|
+
return {
|
|
2607
|
+
exists: false,
|
|
2608
|
+
inSchema,
|
|
2609
|
+
inEquivalencies,
|
|
2610
|
+
possibleReasons,
|
|
2611
|
+
suggestions,
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Analyzes the stored equivalencies to provide aggregate statistics.
|
|
2616
|
+
* Call this AFTER analysis completes to understand equivalency patterns.
|
|
2617
|
+
*
|
|
2618
|
+
* @example
|
|
2619
|
+
* ```typescript
|
|
2620
|
+
* const analysis = sds.analyzeEquivalencies();
|
|
2621
|
+
* console.log(analysis.byReason); // Count by reason
|
|
2622
|
+
* console.log(analysis.byScope); // Count by scope
|
|
2623
|
+
* console.log(analysis.hotSpots); // Scopes with most equivalencies
|
|
2624
|
+
* ```
|
|
2625
|
+
*/
|
|
2626
|
+
analyzeEquivalencies() {
|
|
2627
|
+
const byReason = {};
|
|
2628
|
+
const byScope = {};
|
|
2629
|
+
let total = 0;
|
|
2630
|
+
// Collect from all scope nodes
|
|
2631
|
+
for (const scopeName of Object.keys(this.scopeNodes)) {
|
|
2632
|
+
const scopeNode = this.scopeNodes[scopeName];
|
|
2633
|
+
const equivalencies = scopeNode.equivalencies ?? {};
|
|
2634
|
+
for (const path of Object.keys(equivalencies)) {
|
|
2635
|
+
for (const eq of equivalencies[path]) {
|
|
2636
|
+
total++;
|
|
2637
|
+
const reason = eq.equivalencyReason ?? 'unknown';
|
|
2638
|
+
byReason[reason] = (byReason[reason] ?? 0) + 1;
|
|
2639
|
+
byScope[scopeName] = (byScope[scopeName] ?? 0) + 1;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
// Also check external function calls
|
|
2644
|
+
for (const fc of this.externalFunctionCalls) {
|
|
2645
|
+
const equivalencies = fc.equivalencies ?? {};
|
|
2646
|
+
for (const path of Object.keys(equivalencies)) {
|
|
2647
|
+
for (const eq of equivalencies[path]) {
|
|
2648
|
+
total++;
|
|
2649
|
+
const reason = eq.equivalencyReason ?? 'unknown';
|
|
2650
|
+
byReason[reason] = (byReason[reason] ?? 0) + 1;
|
|
2651
|
+
byScope[fc.name] = (byScope[fc.name] ?? 0) + 1;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
// Find hot spots (scopes with most equivalencies)
|
|
2656
|
+
const hotSpots = Object.entries(byScope)
|
|
2657
|
+
.map(([scope, count]) => ({ scope, count }))
|
|
2658
|
+
.sort((a, b) => b.count - a.count)
|
|
2659
|
+
.slice(0, 10);
|
|
2660
|
+
// Find reasons that appear in stored equivalencies but aren't in ALLOWED list
|
|
2661
|
+
const unusedReasons = Object.keys(byReason).filter((reason) => !ALLOWED_EQUIVALENCY_REASONS.has(reason));
|
|
2662
|
+
return {
|
|
2663
|
+
total,
|
|
2664
|
+
byReason,
|
|
2665
|
+
byScope,
|
|
2666
|
+
hotSpots,
|
|
2667
|
+
unusedReasons,
|
|
1793
2668
|
};
|
|
1794
2669
|
}
|
|
2670
|
+
/**
|
|
2671
|
+
* Validates equivalencies and identifies potential problems.
|
|
2672
|
+
* Returns actionable issues that may indicate bugs or optimization opportunities.
|
|
2673
|
+
*
|
|
2674
|
+
* @example
|
|
2675
|
+
* ```typescript
|
|
2676
|
+
* const issues = sds.validateEquivalencies();
|
|
2677
|
+
* if (issues.length > 0) {
|
|
2678
|
+
* console.log('Found issues:', issues);
|
|
2679
|
+
* }
|
|
2680
|
+
* ```
|
|
2681
|
+
*/
|
|
2682
|
+
validateEquivalencies() {
|
|
2683
|
+
const issues = [];
|
|
2684
|
+
const allScopeNames = new Set([
|
|
2685
|
+
...Object.keys(this.scopeNodes),
|
|
2686
|
+
...this.externalFunctionCalls.map((fc) => fc.name),
|
|
2687
|
+
]);
|
|
2688
|
+
// Check all scope nodes
|
|
2689
|
+
for (const scopeName of Object.keys(this.scopeNodes)) {
|
|
2690
|
+
const scopeNode = this.scopeNodes[scopeName];
|
|
2691
|
+
const equivalencies = scopeNode.equivalencies ?? {};
|
|
2692
|
+
for (const [path, eqs] of Object.entries(equivalencies)) {
|
|
2693
|
+
for (const eq of eqs) {
|
|
2694
|
+
// Check 1: Does the target scope exist?
|
|
2695
|
+
if (!allScopeNames.has(eq.scopeNodeName)) {
|
|
2696
|
+
issues.push({
|
|
2697
|
+
type: 'broken_reference',
|
|
2698
|
+
severity: 'error',
|
|
2699
|
+
scope: scopeName,
|
|
2700
|
+
path,
|
|
2701
|
+
details: `Equivalency points to non-existent scope "${eq.scopeNodeName}"`,
|
|
2702
|
+
});
|
|
2703
|
+
continue;
|
|
2704
|
+
}
|
|
2705
|
+
// Check 2: Does the target path exist in target scope's schema or equivalencies?
|
|
2706
|
+
const targetScope = this.getScopeOrFunctionCallInfo(eq.scopeNodeName);
|
|
2707
|
+
if (targetScope) {
|
|
2708
|
+
const hasInSchema = eq.schemaPath in (targetScope.schema ?? {});
|
|
2709
|
+
const hasInEquivalencies = eq.schemaPath in (targetScope.equivalencies ?? {});
|
|
2710
|
+
// Only flag as dead end if it's a leaf path (no sub-properties exist)
|
|
2711
|
+
if (!hasInSchema && !hasInEquivalencies) {
|
|
2712
|
+
const hasSubPaths = Object.keys(targetScope.schema ?? {}).some((p) => p.startsWith(eq.schemaPath + '.') ||
|
|
2713
|
+
p.startsWith(eq.schemaPath + '['));
|
|
2714
|
+
if (!hasSubPaths) {
|
|
2715
|
+
issues.push({
|
|
2716
|
+
type: 'dead_end',
|
|
2717
|
+
severity: 'warning',
|
|
2718
|
+
scope: scopeName,
|
|
2719
|
+
path,
|
|
2720
|
+
details: `Equivalency to "${eq.scopeNodeName}::${eq.schemaPath}" - path not in schema`,
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
// Check 3: Trace chain depth
|
|
2727
|
+
const chain = this.traceEquivalencyChain(scopeName, path, 50);
|
|
2728
|
+
if (chain.length >= 20) {
|
|
2729
|
+
issues.push({
|
|
2730
|
+
type: 'long_chain',
|
|
2731
|
+
severity: 'warning',
|
|
2732
|
+
scope: scopeName,
|
|
2733
|
+
path,
|
|
2734
|
+
details: `Equivalency chain depth is ${chain.length} (may impact performance)`,
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
// Check for potential cycles (chain that returns to starting point)
|
|
2738
|
+
const visited = new Set();
|
|
2739
|
+
for (const step of chain) {
|
|
2740
|
+
const key = `${step.scope}::${step.path}`;
|
|
2741
|
+
if (visited.has(key)) {
|
|
2742
|
+
issues.push({
|
|
2743
|
+
type: 'circular',
|
|
2744
|
+
severity: 'warning',
|
|
2745
|
+
scope: scopeName,
|
|
2746
|
+
path,
|
|
2747
|
+
details: `Circular reference detected at ${key}`,
|
|
2748
|
+
});
|
|
2749
|
+
break;
|
|
2750
|
+
}
|
|
2751
|
+
visited.add(key);
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
return issues;
|
|
2756
|
+
}
|
|
1795
2757
|
}
|
|
1796
2758
|
//# sourceMappingURL=ScopeDataStructure.js.map
|