@grafema/core 0.1.0-alpha.5 → 0.1.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/Orchestrator.d.ts +24 -2
- package/dist/Orchestrator.d.ts.map +1 -1
- package/dist/Orchestrator.js +197 -24
- package/dist/config/ConfigLoader.d.ts +72 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +187 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/core/ASTWorker.d.ts +11 -36
- package/dist/core/ASTWorker.d.ts.map +1 -1
- package/dist/core/ASTWorker.js +93 -99
- package/dist/core/CoverageAnalyzer.d.ts +65 -0
- package/dist/core/CoverageAnalyzer.d.ts.map +1 -0
- package/dist/core/CoverageAnalyzer.js +198 -0
- package/dist/core/FileNodeManager.d.ts +40 -0
- package/dist/core/FileNodeManager.d.ts.map +1 -0
- package/dist/core/FileNodeManager.js +84 -0
- package/dist/core/GraphFreshnessChecker.d.ts +33 -0
- package/dist/core/GraphFreshnessChecker.d.ts.map +1 -0
- package/dist/core/GraphFreshnessChecker.js +101 -0
- package/dist/core/HashUtils.d.ts +24 -0
- package/dist/core/HashUtils.d.ts.map +1 -0
- package/dist/core/HashUtils.js +45 -0
- package/dist/core/IncrementalReanalyzer.d.ts +36 -0
- package/dist/core/IncrementalReanalyzer.d.ts.map +1 -0
- package/dist/core/IncrementalReanalyzer.js +132 -0
- package/dist/core/NodeFactory.d.ts +225 -17
- package/dist/core/NodeFactory.d.ts.map +1 -1
- package/dist/core/NodeFactory.js +208 -18
- package/dist/core/ScopeTracker.d.ts +84 -0
- package/dist/core/ScopeTracker.d.ts.map +1 -0
- package/dist/core/ScopeTracker.js +116 -0
- package/dist/core/SemanticId.d.ts +90 -0
- package/dist/core/SemanticId.d.ts.map +1 -0
- package/dist/core/SemanticId.js +115 -0
- package/dist/core/VersionManager.d.ts.map +1 -1
- package/dist/core/VersionManager.js +3 -2
- package/dist/core/nodes/ArgumentExpressionNode.d.ts +43 -0
- package/dist/core/nodes/ArgumentExpressionNode.d.ts.map +1 -0
- package/dist/core/nodes/ArgumentExpressionNode.js +60 -0
- package/dist/core/nodes/ArrayLiteralNode.d.ts +27 -0
- package/dist/core/nodes/ArrayLiteralNode.d.ts.map +1 -0
- package/dist/core/nodes/ArrayLiteralNode.js +41 -0
- package/dist/core/nodes/CallSiteNode.d.ts +28 -0
- package/dist/core/nodes/CallSiteNode.d.ts.map +1 -1
- package/dist/core/nodes/CallSiteNode.js +46 -0
- package/dist/core/nodes/ClassNode.d.ts +33 -1
- package/dist/core/nodes/ClassNode.d.ts.map +1 -1
- package/dist/core/nodes/ClassNode.js +46 -2
- package/dist/core/nodes/DecoratorNode.d.ts +42 -0
- package/dist/core/nodes/DecoratorNode.d.ts.map +1 -0
- package/dist/core/nodes/DecoratorNode.js +62 -0
- package/dist/core/nodes/EnumNode.d.ts +42 -0
- package/dist/core/nodes/EnumNode.d.ts.map +1 -0
- package/dist/core/nodes/EnumNode.js +54 -0
- package/dist/core/nodes/ExportNode.d.ts +37 -1
- package/dist/core/nodes/ExportNode.d.ts.map +1 -1
- package/dist/core/nodes/ExportNode.js +48 -2
- package/dist/core/nodes/ExpressionNode.d.ts +97 -0
- package/dist/core/nodes/ExpressionNode.d.ts.map +1 -0
- package/dist/core/nodes/ExpressionNode.js +178 -0
- package/dist/core/nodes/ExternalModuleNode.d.ts +28 -0
- package/dist/core/nodes/ExternalModuleNode.d.ts.map +1 -0
- package/dist/core/nodes/ExternalModuleNode.js +41 -0
- package/dist/core/nodes/ExternalStdioNode.d.ts +13 -6
- package/dist/core/nodes/ExternalStdioNode.d.ts.map +1 -1
- package/dist/core/nodes/ExternalStdioNode.js +15 -8
- package/dist/core/nodes/FunctionNode.d.ts +36 -0
- package/dist/core/nodes/FunctionNode.d.ts.map +1 -1
- package/dist/core/nodes/FunctionNode.js +80 -1
- package/dist/core/nodes/ImportNode.d.ts +19 -5
- package/dist/core/nodes/ImportNode.d.ts.map +1 -1
- package/dist/core/nodes/ImportNode.js +23 -5
- package/dist/core/nodes/InterfaceNode.d.ts +46 -0
- package/dist/core/nodes/InterfaceNode.d.ts.map +1 -0
- package/dist/core/nodes/InterfaceNode.js +55 -0
- package/dist/core/nodes/IssueNode.d.ts +73 -0
- package/dist/core/nodes/IssueNode.d.ts.map +1 -0
- package/dist/core/nodes/IssueNode.js +129 -0
- package/dist/core/nodes/MethodCallNode.d.ts +30 -0
- package/dist/core/nodes/MethodCallNode.d.ts.map +1 -1
- package/dist/core/nodes/MethodCallNode.js +49 -0
- package/dist/core/nodes/MethodNode.d.ts +32 -0
- package/dist/core/nodes/MethodNode.d.ts.map +1 -1
- package/dist/core/nodes/MethodNode.js +48 -0
- package/dist/core/nodes/ModuleNode.d.ts +31 -0
- package/dist/core/nodes/ModuleNode.d.ts.map +1 -1
- package/dist/core/nodes/ModuleNode.js +37 -0
- package/dist/core/nodes/NetworkRequestNode.d.ts +54 -0
- package/dist/core/nodes/NetworkRequestNode.d.ts.map +1 -0
- package/dist/core/nodes/NetworkRequestNode.js +65 -0
- package/dist/core/nodes/ObjectLiteralNode.d.ts +27 -0
- package/dist/core/nodes/ObjectLiteralNode.d.ts.map +1 -0
- package/dist/core/nodes/ObjectLiteralNode.js +41 -0
- package/dist/core/nodes/ScopeNode.d.ts +31 -0
- package/dist/core/nodes/ScopeNode.d.ts.map +1 -1
- package/dist/core/nodes/ScopeNode.js +49 -0
- package/dist/core/nodes/TypeNode.d.ts +36 -0
- package/dist/core/nodes/TypeNode.d.ts.map +1 -0
- package/dist/core/nodes/TypeNode.js +53 -0
- package/dist/core/nodes/VariableDeclarationNode.d.ts +27 -0
- package/dist/core/nodes/VariableDeclarationNode.d.ts.map +1 -1
- package/dist/core/nodes/VariableDeclarationNode.js +40 -0
- package/dist/core/nodes/index.d.ts +12 -1
- package/dist/core/nodes/index.d.ts.map +1 -1
- package/dist/core/nodes/index.js +14 -0
- package/dist/diagnostics/DiagnosticCollector.d.ts +98 -0
- package/dist/diagnostics/DiagnosticCollector.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticCollector.js +129 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts +77 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticReporter.js +159 -0
- package/dist/diagnostics/DiagnosticWriter.d.ts +31 -0
- package/dist/diagnostics/DiagnosticWriter.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticWriter.js +43 -0
- package/dist/diagnostics/index.d.ts +14 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +11 -0
- package/dist/errors/GrafemaError.d.ts +118 -0
- package/dist/errors/GrafemaError.d.ts.map +1 -0
- package/dist/errors/GrafemaError.js +131 -0
- package/dist/index.d.ts +57 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -1
- package/dist/logging/Logger.d.ts +48 -0
- package/dist/logging/Logger.d.ts.map +1 -0
- package/dist/logging/Logger.js +134 -0
- package/dist/plugins/Plugin.d.ts +5 -1
- package/dist/plugins/Plugin.d.ts.map +1 -1
- package/dist/plugins/Plugin.js +33 -0
- package/dist/plugins/analysis/DatabaseAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/DatabaseAnalyzer.js +13 -6
- package/dist/plugins/analysis/ExpressAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ExpressAnalyzer.js +27 -19
- package/dist/plugins/analysis/ExpressRouteAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ExpressRouteAnalyzer.js +21 -14
- package/dist/plugins/analysis/FetchAnalyzer.d.ts +1 -0
- package/dist/plugins/analysis/FetchAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/FetchAnalyzer.js +34 -14
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts +6 -3
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts.map +1 -1
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.js +76 -80
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts +180 -17
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/JSASTAnalyzer.js +1171 -471
- package/dist/plugins/analysis/ReactAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ReactAnalyzer.js +56 -57
- package/dist/plugins/analysis/RustAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/RustAnalyzer.js +15 -10
- package/dist/plugins/analysis/SQLiteAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/SQLiteAnalyzer.js +9 -7
- package/dist/plugins/analysis/ServiceLayerAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ServiceLayerAnalyzer.js +21 -9
- package/dist/plugins/analysis/SocketIOAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/SocketIOAnalyzer.js +27 -15
- package/dist/plugins/analysis/SystemDbAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/SystemDbAnalyzer.js +15 -5
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts +34 -4
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/GraphBuilder.js +318 -298
- package/dist/plugins/analysis/ast/IdGenerator.d.ts +105 -0
- package/dist/plugins/analysis/ast/IdGenerator.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/IdGenerator.js +116 -0
- package/dist/plugins/analysis/ast/types.d.ts +176 -5
- package/dist/plugins/analysis/ast/types.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/utils/createParameterNodes.d.ts +33 -0
- package/dist/plugins/analysis/ast/utils/createParameterNodes.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/utils/createParameterNodes.js +89 -0
- package/dist/plugins/analysis/ast/utils/index.d.ts +6 -0
- package/dist/plugins/analysis/ast/utils/index.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/utils/index.js +5 -0
- package/dist/plugins/analysis/ast/utils/location.d.ts +87 -0
- package/dist/plugins/analysis/ast/utils/location.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/utils/location.js +78 -0
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts +9 -4
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.js +6 -5
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts +99 -9
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.js +663 -125
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts +4 -1
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.js +72 -32
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts +4 -1
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.js +128 -63
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.js +11 -8
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts +12 -1
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.js +36 -14
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts +4 -1
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.js +17 -13
- package/dist/plugins/discovery/MonorepoServiceDiscovery.d.ts.map +1 -1
- package/dist/plugins/discovery/MonorepoServiceDiscovery.js +3 -2
- package/dist/plugins/discovery/SimpleProjectDiscovery.d.ts.map +1 -1
- package/dist/plugins/discovery/SimpleProjectDiscovery.js +5 -1
- package/dist/plugins/discovery/WorkspaceDiscovery.d.ts +22 -0
- package/dist/plugins/discovery/WorkspaceDiscovery.d.ts.map +1 -0
- package/dist/plugins/discovery/WorkspaceDiscovery.js +136 -0
- package/dist/plugins/discovery/resolveSourceEntrypoint.d.ts +46 -0
- package/dist/plugins/discovery/resolveSourceEntrypoint.d.ts.map +1 -0
- package/dist/plugins/discovery/resolveSourceEntrypoint.js +86 -0
- package/dist/plugins/discovery/workspaces/detector.d.ts +21 -0
- package/dist/plugins/discovery/workspaces/detector.d.ts.map +1 -0
- package/dist/plugins/discovery/workspaces/detector.js +49 -0
- package/dist/plugins/discovery/workspaces/globResolver.d.ts +35 -0
- package/dist/plugins/discovery/workspaces/globResolver.d.ts.map +1 -0
- package/dist/plugins/discovery/workspaces/globResolver.js +184 -0
- package/dist/plugins/discovery/workspaces/index.d.ts +9 -0
- package/dist/plugins/discovery/workspaces/index.d.ts.map +1 -0
- package/dist/plugins/discovery/workspaces/index.js +8 -0
- package/dist/plugins/discovery/workspaces/parsers.d.ts +38 -0
- package/dist/plugins/discovery/workspaces/parsers.d.ts.map +1 -0
- package/dist/plugins/discovery/workspaces/parsers.js +80 -0
- package/dist/plugins/enrichment/AliasTracker.d.ts.map +1 -1
- package/dist/plugins/enrichment/AliasTracker.js +14 -8
- package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts.map +1 -1
- package/dist/plugins/enrichment/HTTPConnectionEnricher.js +14 -7
- package/dist/plugins/enrichment/ImportExportLinker.d.ts.map +1 -1
- package/dist/plugins/enrichment/ImportExportLinker.js +23 -6
- package/dist/plugins/enrichment/MethodCallResolver.d.ts.map +1 -1
- package/dist/plugins/enrichment/MethodCallResolver.js +18 -12
- package/dist/plugins/enrichment/MountPointResolver.d.ts.map +1 -1
- package/dist/plugins/enrichment/MountPointResolver.js +8 -3
- package/dist/plugins/enrichment/PrefixEvaluator.d.ts.map +1 -1
- package/dist/plugins/enrichment/PrefixEvaluator.js +16 -7
- package/dist/plugins/enrichment/RustFFIEnricher.d.ts.map +1 -1
- package/dist/plugins/enrichment/RustFFIEnricher.js +6 -5
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts +17 -0
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts.map +1 -1
- package/dist/plugins/enrichment/ValueDomainAnalyzer.js +129 -10
- package/dist/plugins/indexing/IncrementalModuleIndexer.d.ts.map +1 -1
- package/dist/plugins/indexing/IncrementalModuleIndexer.js +23 -14
- package/dist/plugins/indexing/JSModuleIndexer.d.ts.map +1 -1
- package/dist/plugins/indexing/JSModuleIndexer.js +63 -31
- package/dist/plugins/indexing/RustModuleIndexer.d.ts.map +1 -1
- package/dist/plugins/indexing/RustModuleIndexer.js +5 -4
- package/dist/plugins/indexing/ServiceDetector.d.ts +10 -0
- package/dist/plugins/indexing/ServiceDetector.d.ts.map +1 -1
- package/dist/plugins/indexing/ServiceDetector.js +28 -15
- package/dist/plugins/validation/CallResolverValidator.d.ts.map +1 -1
- package/dist/plugins/validation/CallResolverValidator.js +8 -7
- package/dist/plugins/validation/DataFlowValidator.d.ts.map +1 -1
- package/dist/plugins/validation/DataFlowValidator.js +17 -12
- package/dist/plugins/validation/EvalBanValidator.d.ts.map +1 -1
- package/dist/plugins/validation/EvalBanValidator.js +17 -16
- package/dist/plugins/validation/GraphConnectivityValidator.d.ts.map +1 -1
- package/dist/plugins/validation/GraphConnectivityValidator.js +19 -23
- package/dist/plugins/validation/NodeCreationValidator.d.ts +85 -0
- package/dist/plugins/validation/NodeCreationValidator.d.ts.map +1 -0
- package/dist/plugins/validation/NodeCreationValidator.js +415 -0
- package/dist/plugins/validation/SQLInjectionValidator.d.ts.map +1 -1
- package/dist/plugins/validation/SQLInjectionValidator.js +59 -16
- package/dist/plugins/validation/ShadowingDetector.d.ts.map +1 -1
- package/dist/plugins/validation/ShadowingDetector.js +6 -5
- package/dist/plugins/validation/TypeScriptDeadCodeValidator.d.ts.map +1 -1
- package/dist/plugins/validation/TypeScriptDeadCodeValidator.js +12 -11
- package/dist/plugins/vcs/GitPlugin.d.ts.map +1 -1
- package/dist/plugins/vcs/GitPlugin.js +10 -12
- package/dist/plugins/vcs/VCSPlugin.d.ts +3 -2
- package/dist/plugins/vcs/VCSPlugin.d.ts.map +1 -1
- package/dist/plugins/vcs/VCSPlugin.js +5 -5
- package/dist/storage/backends/RFDBServerBackend.d.ts +10 -17
- package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -1
- package/dist/storage/backends/RFDBServerBackend.js +31 -10
- package/dist/validation/PathValidator.d.ts +1 -2
- package/dist/validation/PathValidator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Orchestrator.ts +237 -24
- package/src/config/ConfigLoader.ts +263 -0
- package/src/config/index.ts +5 -0
- package/src/core/ASTWorker.ts +143 -139
- package/src/core/CoverageAnalyzer.ts +243 -0
- package/src/core/FileNodeManager.ts +100 -0
- package/src/core/GraphFreshnessChecker.ts +143 -0
- package/src/core/HashUtils.ts +48 -0
- package/src/core/IncrementalReanalyzer.ts +192 -0
- package/src/core/NodeFactory.ts +401 -18
- package/src/core/ScopeTracker.ts +154 -0
- package/src/core/SemanticId.ts +192 -0
- package/src/core/VersionManager.ts +3 -2
- package/src/core/nodes/ArgumentExpressionNode.ts +89 -0
- package/src/core/nodes/ArrayLiteralNode.ts +65 -0
- package/src/core/nodes/CallSiteNode.ts +58 -0
- package/src/core/nodes/ClassNode.ts +63 -2
- package/src/core/nodes/DecoratorNode.ts +91 -0
- package/src/core/nodes/EnumNode.ts +86 -0
- package/src/core/nodes/ExportNode.ts +70 -2
- package/src/core/nodes/ExpressionNode.ts +231 -0
- package/src/core/nodes/ExternalModuleNode.ts +56 -0
- package/src/core/nodes/ExternalStdioNode.ts +17 -9
- package/src/core/nodes/FunctionNode.ts +101 -1
- package/src/core/nodes/ImportNode.ts +32 -10
- package/src/core/nodes/InterfaceNode.ts +91 -0
- package/src/core/nodes/IssueNode.ts +177 -0
- package/src/core/nodes/MethodCallNode.ts +64 -0
- package/src/core/nodes/MethodNode.ts +63 -0
- package/src/core/nodes/ModuleNode.ts +50 -0
- package/src/core/nodes/NetworkRequestNode.ts +77 -0
- package/src/core/nodes/ObjectLiteralNode.ts +65 -0
- package/src/core/nodes/ScopeNode.ts +65 -0
- package/src/core/nodes/TypeNode.ts +78 -0
- package/src/core/nodes/VariableDeclarationNode.ts +52 -0
- package/src/core/nodes/index.ts +18 -1
- package/src/diagnostics/DiagnosticCollector.ts +163 -0
- package/src/diagnostics/DiagnosticReporter.ts +204 -0
- package/src/diagnostics/DiagnosticWriter.ts +50 -0
- package/src/diagnostics/index.ts +16 -0
- package/src/errors/GrafemaError.ts +174 -0
- package/src/index.ts +148 -1
- package/src/logging/Logger.ts +152 -0
- package/src/plugins/Plugin.ts +42 -0
- package/src/plugins/analysis/DatabaseAnalyzer.ts +14 -8
- package/src/plugins/analysis/ExpressAnalyzer.ts +29 -19
- package/src/plugins/analysis/ExpressRouteAnalyzer.ts +22 -21
- package/src/plugins/analysis/FetchAnalyzer.ts +39 -16
- package/src/plugins/analysis/IncrementalAnalysisPlugin.ts +84 -101
- package/src/plugins/analysis/JSASTAnalyzer.ts +1483 -503
- package/src/plugins/analysis/ReactAnalyzer.ts +57 -57
- package/src/plugins/analysis/RustAnalyzer.ts +15 -10
- package/src/plugins/analysis/SQLiteAnalyzer.ts +10 -7
- package/src/plugins/analysis/ServiceLayerAnalyzer.ts +22 -16
- package/src/plugins/analysis/SocketIOAnalyzer.ts +31 -22
- package/src/plugins/analysis/SystemDbAnalyzer.ts +16 -11
- package/src/plugins/analysis/ast/GraphBuilder.ts +439 -327
- package/src/plugins/analysis/ast/IdGenerator.ts +177 -0
- package/src/plugins/analysis/ast/types.ts +209 -6
- package/src/plugins/analysis/ast/utils/createParameterNodes.ts +104 -0
- package/src/plugins/analysis/ast/utils/index.ts +12 -0
- package/src/plugins/analysis/ast/utils/location.ts +103 -0
- package/src/plugins/analysis/ast/visitors/ASTVisitor.ts +11 -8
- package/src/plugins/analysis/ast/visitors/CallExpressionVisitor.ts +909 -83
- package/src/plugins/analysis/ast/visitors/ClassVisitor.ts +97 -44
- package/src/plugins/analysis/ast/visitors/FunctionVisitor.ts +159 -93
- package/src/plugins/analysis/ast/visitors/ImportExportVisitor.ts +12 -8
- package/src/plugins/analysis/ast/visitors/TypeScriptVisitor.ts +41 -14
- package/src/plugins/analysis/ast/visitors/VariableVisitor.ts +37 -17
- package/src/plugins/discovery/MonorepoServiceDiscovery.ts +3 -2
- package/src/plugins/discovery/SimpleProjectDiscovery.ts +6 -1
- package/src/plugins/discovery/WorkspaceDiscovery.ts +177 -0
- package/src/plugins/discovery/resolveSourceEntrypoint.ts +103 -0
- package/src/plugins/discovery/workspaces/detector.ts +63 -0
- package/src/plugins/discovery/workspaces/globResolver.ts +229 -0
- package/src/plugins/discovery/workspaces/index.ts +23 -0
- package/src/plugins/discovery/workspaces/parsers.ts +99 -0
- package/src/plugins/enrichment/AliasTracker.ts +14 -8
- package/src/plugins/enrichment/HTTPConnectionEnricher.ts +14 -7
- package/src/plugins/enrichment/ImportExportLinker.ts +24 -6
- package/src/plugins/enrichment/MethodCallResolver.ts +18 -12
- package/src/plugins/enrichment/MountPointResolver.ts +8 -3
- package/src/plugins/enrichment/PrefixEvaluator.ts +16 -7
- package/src/plugins/enrichment/RustFFIEnricher.ts +6 -5
- package/src/plugins/enrichment/ValueDomainAnalyzer.ts +149 -12
- package/src/plugins/indexing/IncrementalModuleIndexer.ts +23 -14
- package/src/plugins/indexing/JSModuleIndexer.ts +74 -34
- package/src/plugins/indexing/RustModuleIndexer.ts +5 -4
- package/src/plugins/validation/CallResolverValidator.ts +8 -7
- package/src/plugins/validation/DataFlowValidator.ts +16 -12
- package/src/plugins/validation/EvalBanValidator.ts +17 -16
- package/src/plugins/validation/GraphConnectivityValidator.ts +19 -23
- package/src/plugins/validation/NodeCreationValidator.ts +554 -0
- package/src/plugins/validation/SQLInjectionValidator.ts +61 -15
- package/src/plugins/validation/ShadowingDetector.ts +6 -5
- package/src/plugins/validation/TypeScriptDeadCodeValidator.ts +12 -11
- package/src/plugins/vcs/GitPlugin.ts +40 -12
- package/src/plugins/vcs/VCSPlugin.ts +7 -5
- package/src/storage/backends/RFDBServerBackend.ts +43 -29
- package/src/validation/PathValidator.ts +1 -1
- package/dist/core/AnalysisWorker.d.ts +0 -14
- package/dist/core/AnalysisWorker.d.ts.map +0 -1
- package/dist/core/AnalysisWorker.js +0 -307
- package/dist/core/ParallelAnalyzer.d.ts +0 -120
- package/dist/core/ParallelAnalyzer.d.ts.map +0 -1
- package/dist/core/ParallelAnalyzer.js +0 -331
- package/dist/core/QueueWorker.d.ts +0 -12
- package/dist/core/QueueWorker.d.ts.map +0 -1
- package/dist/core/QueueWorker.js +0 -567
- package/dist/core/RFDBClient.d.ts +0 -179
- package/dist/core/RFDBClient.d.ts.map +0 -1
- package/dist/core/RFDBClient.js +0 -429
- package/dist/plugins/discovery/ZonServiceDiscovery.d.ts +0 -19
- package/dist/plugins/discovery/ZonServiceDiscovery.d.ts.map +0 -1
- package/dist/plugins/discovery/ZonServiceDiscovery.js +0 -204
- package/src/core/AnalysisWorker.ts +0 -410
- package/src/core/ParallelAnalyzer.ts +0 -476
- package/src/core/QueueWorker.ts +0 -780
- package/src/plugins/indexing/ServiceDetector.ts +0 -230
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { readFileSync, existsSync, statSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { parse as parseYAML } from 'yaml';
|
|
4
|
+
/**
|
|
5
|
+
* Default plugin configuration.
|
|
6
|
+
* Matches current DEFAULT_PLUGINS in analyze.ts and config.ts (MCP).
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_CONFIG = {
|
|
9
|
+
plugins: {
|
|
10
|
+
discovery: [],
|
|
11
|
+
indexing: ['JSModuleIndexer'],
|
|
12
|
+
analysis: [
|
|
13
|
+
'JSASTAnalyzer',
|
|
14
|
+
'ExpressRouteAnalyzer',
|
|
15
|
+
'SocketIOAnalyzer',
|
|
16
|
+
'DatabaseAnalyzer',
|
|
17
|
+
'FetchAnalyzer',
|
|
18
|
+
'ServiceLayerAnalyzer',
|
|
19
|
+
],
|
|
20
|
+
enrichment: [
|
|
21
|
+
'MethodCallResolver',
|
|
22
|
+
'AliasTracker',
|
|
23
|
+
'ValueDomainAnalyzer',
|
|
24
|
+
'MountPointResolver',
|
|
25
|
+
'PrefixEvaluator',
|
|
26
|
+
'ImportExportLinker',
|
|
27
|
+
'HTTPConnectionEnricher',
|
|
28
|
+
],
|
|
29
|
+
validation: [
|
|
30
|
+
'CallResolverValidator',
|
|
31
|
+
'EvalBanValidator',
|
|
32
|
+
'SQLInjectionValidator',
|
|
33
|
+
'ShadowingDetector',
|
|
34
|
+
'GraphConnectivityValidator',
|
|
35
|
+
'DataFlowValidator',
|
|
36
|
+
'TypeScriptDeadCodeValidator',
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
services: [], // Empty by default (uses auto-discovery)
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Load Grafema config from project directory.
|
|
43
|
+
*
|
|
44
|
+
* Priority:
|
|
45
|
+
* 1. config.yaml (preferred)
|
|
46
|
+
* 2. config.json (deprecated, fallback)
|
|
47
|
+
* 3. DEFAULT_CONFIG (if neither exists)
|
|
48
|
+
*
|
|
49
|
+
* Warnings:
|
|
50
|
+
* - Logs deprecation warning if config.json is used
|
|
51
|
+
* - Logs parse errors but doesn't throw (returns defaults)
|
|
52
|
+
*
|
|
53
|
+
* @param projectPath - Absolute path to project root
|
|
54
|
+
* @param logger - Optional logger for warnings (defaults to console.warn)
|
|
55
|
+
* @returns Parsed config or defaults
|
|
56
|
+
*/
|
|
57
|
+
export function loadConfig(projectPath, logger = console) {
|
|
58
|
+
const grafemaDir = join(projectPath, '.grafema');
|
|
59
|
+
const yamlPath = join(grafemaDir, 'config.yaml');
|
|
60
|
+
const jsonPath = join(grafemaDir, 'config.json');
|
|
61
|
+
// 1. Try YAML first (preferred)
|
|
62
|
+
if (existsSync(yamlPath)) {
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
const content = readFileSync(yamlPath, 'utf-8');
|
|
66
|
+
parsed = parseYAML(content);
|
|
67
|
+
// Validate structure - ensure plugins sections are arrays if they exist
|
|
68
|
+
if (parsed.plugins) {
|
|
69
|
+
for (const phase of ['discovery', 'indexing', 'analysis', 'enrichment', 'validation']) {
|
|
70
|
+
const value = parsed.plugins[phase];
|
|
71
|
+
if (value !== undefined && value !== null && !Array.isArray(value)) {
|
|
72
|
+
throw new Error(`plugins.${phase} must be an array, got ${typeof value}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
79
|
+
logger.warn(`Failed to parse config.yaml: ${error.message}`);
|
|
80
|
+
logger.warn('Using default configuration');
|
|
81
|
+
return DEFAULT_CONFIG;
|
|
82
|
+
}
|
|
83
|
+
// Validate services array if present (THROWS on error per Linus review)
|
|
84
|
+
// This is OUTSIDE try-catch - config errors MUST throw
|
|
85
|
+
validateServices(parsed.services, projectPath);
|
|
86
|
+
// Merge with defaults (user config may be partial)
|
|
87
|
+
return mergeConfig(DEFAULT_CONFIG, parsed);
|
|
88
|
+
}
|
|
89
|
+
// 2. Fallback to JSON (migration path)
|
|
90
|
+
if (existsSync(jsonPath)) {
|
|
91
|
+
logger.warn('⚠ config.json is deprecated. Run "grafema init --force" to migrate to config.yaml');
|
|
92
|
+
let parsed;
|
|
93
|
+
try {
|
|
94
|
+
const content = readFileSync(jsonPath, 'utf-8');
|
|
95
|
+
parsed = JSON.parse(content);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
99
|
+
logger.warn(`Failed to parse config.json: ${error.message}`);
|
|
100
|
+
logger.warn('Using default configuration');
|
|
101
|
+
return DEFAULT_CONFIG;
|
|
102
|
+
}
|
|
103
|
+
// Validate services array if present (THROWS on error)
|
|
104
|
+
// This is OUTSIDE try-catch - config errors MUST throw
|
|
105
|
+
validateServices(parsed.services, projectPath);
|
|
106
|
+
return mergeConfig(DEFAULT_CONFIG, parsed);
|
|
107
|
+
}
|
|
108
|
+
// 3. No config file - return defaults
|
|
109
|
+
return DEFAULT_CONFIG;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Validate services array structure.
|
|
113
|
+
* THROWS on error (fail loudly per Linus review).
|
|
114
|
+
*
|
|
115
|
+
* @param services - Parsed services array (may be undefined)
|
|
116
|
+
* @param projectPath - Project root for path validation
|
|
117
|
+
*/
|
|
118
|
+
function validateServices(services, projectPath) {
|
|
119
|
+
// undefined/null is valid (means use defaults)
|
|
120
|
+
if (services === undefined || services === null) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// Must be an array
|
|
124
|
+
if (!Array.isArray(services)) {
|
|
125
|
+
throw new Error(`Config error: services must be an array, got ${typeof services}`);
|
|
126
|
+
}
|
|
127
|
+
// Validate each service
|
|
128
|
+
for (let i = 0; i < services.length; i++) {
|
|
129
|
+
const svc = services[i];
|
|
130
|
+
// Must be an object
|
|
131
|
+
if (typeof svc !== 'object' || svc === null) {
|
|
132
|
+
throw new Error(`Config error: services[${i}] must be an object`);
|
|
133
|
+
}
|
|
134
|
+
// Name validation - required, non-empty string
|
|
135
|
+
if (typeof svc.name !== 'string') {
|
|
136
|
+
throw new Error(`Config error: services[${i}].name must be a string, got ${typeof svc.name}`);
|
|
137
|
+
}
|
|
138
|
+
if (!svc.name.trim()) {
|
|
139
|
+
throw new Error(`Config error: services[${i}].name cannot be empty or whitespace-only`);
|
|
140
|
+
}
|
|
141
|
+
// Path validation - required, non-empty string
|
|
142
|
+
if (typeof svc.path !== 'string') {
|
|
143
|
+
throw new Error(`Config error: services[${i}].path must be a string, got ${typeof svc.path}`);
|
|
144
|
+
}
|
|
145
|
+
if (!svc.path.trim()) {
|
|
146
|
+
throw new Error(`Config error: services[${i}].path cannot be empty or whitespace-only`);
|
|
147
|
+
}
|
|
148
|
+
// Path validation - must be relative (reject absolute paths per Linus review)
|
|
149
|
+
if (svc.path.startsWith('/') || svc.path.startsWith('~')) {
|
|
150
|
+
throw new Error(`Config error: services[${i}].path must be relative to project root, got "${svc.path}"`);
|
|
151
|
+
}
|
|
152
|
+
// Path validation - must exist
|
|
153
|
+
const absolutePath = join(projectPath, svc.path);
|
|
154
|
+
if (!existsSync(absolutePath)) {
|
|
155
|
+
throw new Error(`Config error: services[${i}].path "${svc.path}" does not exist`);
|
|
156
|
+
}
|
|
157
|
+
// Path validation - must be directory
|
|
158
|
+
if (!statSync(absolutePath).isDirectory()) {
|
|
159
|
+
throw new Error(`Config error: services[${i}].path "${svc.path}" must be a directory`);
|
|
160
|
+
}
|
|
161
|
+
// entryPoint validation (optional field) - must be non-empty string if provided
|
|
162
|
+
if (svc.entryPoint !== undefined) {
|
|
163
|
+
if (typeof svc.entryPoint !== 'string') {
|
|
164
|
+
throw new Error(`Config error: services[${i}].entryPoint must be a string, got ${typeof svc.entryPoint}`);
|
|
165
|
+
}
|
|
166
|
+
if (!svc.entryPoint.trim()) {
|
|
167
|
+
throw new Error(`Config error: services[${i}].entryPoint cannot be empty or whitespace-only`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Merge user config with defaults.
|
|
174
|
+
* User config takes precedence, but missing sections use defaults.
|
|
175
|
+
*/
|
|
176
|
+
function mergeConfig(defaults, user) {
|
|
177
|
+
return {
|
|
178
|
+
plugins: {
|
|
179
|
+
discovery: user.plugins?.discovery ?? defaults.plugins.discovery,
|
|
180
|
+
indexing: user.plugins?.indexing ?? defaults.plugins.indexing,
|
|
181
|
+
analysis: user.plugins?.analysis ?? defaults.plugins.analysis,
|
|
182
|
+
enrichment: user.plugins?.enrichment ?? defaults.plugins.enrichment,
|
|
183
|
+
validation: user.plugins?.validation ?? defaults.plugins.validation,
|
|
184
|
+
},
|
|
185
|
+
services: user.services ?? defaults.services,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/core/ASTWorker.d.ts
CHANGED
|
@@ -3,32 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Receives: { filePath, moduleId, moduleName }
|
|
5
5
|
* Returns: { collections } - extracted AST data for GraphBuilder
|
|
6
|
+
*
|
|
7
|
+
* Uses ScopeTracker for semantic ID generation (REG-133).
|
|
8
|
+
* IDs are stable and don't change when unrelated code is added/removed.
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
interface ImportNode {
|
|
11
|
-
id: string;
|
|
12
|
-
type: 'IMPORT';
|
|
13
|
-
name: string;
|
|
14
|
-
importedName: string;
|
|
15
|
-
source: string;
|
|
16
|
-
file: string;
|
|
17
|
-
line: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Export node structure
|
|
21
|
-
*/
|
|
22
|
-
interface ExportNode {
|
|
23
|
-
id: string;
|
|
24
|
-
type: 'EXPORT';
|
|
25
|
-
name: string;
|
|
26
|
-
exportType?: string;
|
|
27
|
-
localName?: string;
|
|
28
|
-
isDefault?: boolean;
|
|
29
|
-
file: string;
|
|
30
|
-
line: number;
|
|
31
|
-
}
|
|
10
|
+
import { type ClassNodeRecord } from './nodes/ClassNode.js';
|
|
11
|
+
import { type ImportNodeRecord } from './nodes/ImportNode.js';
|
|
12
|
+
import { type ExportNodeRecord } from './nodes/ExportNode.js';
|
|
32
13
|
/**
|
|
33
14
|
* Variable declaration node
|
|
34
15
|
*/
|
|
@@ -56,7 +37,6 @@ interface ClassInstantiationInfo {
|
|
|
56
37
|
*/
|
|
57
38
|
interface FunctionNode {
|
|
58
39
|
id: string;
|
|
59
|
-
stableId: string;
|
|
60
40
|
type: 'FUNCTION' | 'METHOD';
|
|
61
41
|
name: string;
|
|
62
42
|
file: string;
|
|
@@ -84,15 +64,10 @@ interface ParameterNode {
|
|
|
84
64
|
line: number;
|
|
85
65
|
}
|
|
86
66
|
/**
|
|
87
|
-
* Class declaration node
|
|
67
|
+
* Class declaration node (matches ClassNodeRecord from ClassNode factory)
|
|
68
|
+
* Workers use legacy line-based IDs
|
|
88
69
|
*/
|
|
89
|
-
interface ClassDeclarationNode {
|
|
90
|
-
id: string;
|
|
91
|
-
type: 'CLASS';
|
|
92
|
-
name: string;
|
|
93
|
-
file: string;
|
|
94
|
-
line: number;
|
|
95
|
-
superClass: string | null;
|
|
70
|
+
interface ClassDeclarationNode extends ClassNodeRecord {
|
|
96
71
|
}
|
|
97
72
|
/**
|
|
98
73
|
* Call site node
|
|
@@ -123,8 +98,8 @@ export interface ASTCollections {
|
|
|
123
98
|
classDeclarations: ClassDeclarationNode[];
|
|
124
99
|
methodCallbacks: unknown[];
|
|
125
100
|
callArguments: unknown[];
|
|
126
|
-
imports:
|
|
127
|
-
exports:
|
|
101
|
+
imports: ImportNodeRecord[];
|
|
102
|
+
exports: ExportNodeRecord[];
|
|
128
103
|
httpRequests: unknown[];
|
|
129
104
|
literals: unknown[];
|
|
130
105
|
variableAssignments: unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ASTWorker.d.ts","sourceRoot":"","sources":["../../src/core/ASTWorker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ASTWorker.d.ts","sourceRoot":"","sources":["../../src/core/ASTWorker.ts"],"names":[],"mappings":"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"}
|
package/dist/core/ASTWorker.js
CHANGED
|
@@ -3,17 +3,30 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Receives: { filePath, moduleId, moduleName }
|
|
5
5
|
* Returns: { collections } - extracted AST data for GraphBuilder
|
|
6
|
+
*
|
|
7
|
+
* Uses ScopeTracker for semantic ID generation (REG-133).
|
|
8
|
+
* IDs are stable and don't change when unrelated code is added/removed.
|
|
6
9
|
*/
|
|
7
10
|
import { parentPort } from 'worker_threads';
|
|
8
11
|
import { readFileSync } from 'fs';
|
|
12
|
+
import { basename } from 'path';
|
|
9
13
|
import { parse } from '@babel/parser';
|
|
10
14
|
import traverseModule from '@babel/traverse';
|
|
15
|
+
import { ClassNode } from './nodes/ClassNode.js';
|
|
16
|
+
import { ImportNode } from './nodes/ImportNode.js';
|
|
17
|
+
import { ExportNode } from './nodes/ExportNode.js';
|
|
18
|
+
import { ScopeTracker } from './ScopeTracker.js';
|
|
19
|
+
import { computeSemanticId } from './SemanticId.js';
|
|
20
|
+
import { getLine, getColumn } from '../plugins/analysis/ast/utils/location.js';
|
|
11
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
22
|
const traverse = traverseModule.default || traverseModule;
|
|
13
23
|
// Simplified visitors for extraction (no graph access needed)
|
|
14
24
|
import { ExpressionEvaluator } from '../plugins/analysis/ast/ExpressionEvaluator.js';
|
|
15
25
|
/**
|
|
16
26
|
* Parse a single module and extract all collections
|
|
27
|
+
*
|
|
28
|
+
* Uses ScopeTracker for semantic ID generation - IDs are stable
|
|
29
|
+
* and don't change when unrelated code is added/removed.
|
|
17
30
|
*/
|
|
18
31
|
function parseModule(filePath, moduleId, moduleName) {
|
|
19
32
|
const code = readFileSync(filePath, 'utf-8');
|
|
@@ -21,6 +34,9 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
21
34
|
sourceType: 'module',
|
|
22
35
|
plugins: ['jsx', 'typescript']
|
|
23
36
|
});
|
|
37
|
+
// Create ScopeTracker for semantic ID generation
|
|
38
|
+
// Use basename for shorter, more readable IDs
|
|
39
|
+
const scopeTracker = new ScopeTracker(basename(filePath));
|
|
24
40
|
// Collections to extract
|
|
25
41
|
const collections = {
|
|
26
42
|
functions: [],
|
|
@@ -40,17 +56,7 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
40
56
|
literals: [],
|
|
41
57
|
variableAssignments: []
|
|
42
58
|
};
|
|
43
|
-
//
|
|
44
|
-
const counters = {
|
|
45
|
-
ifScope: 0,
|
|
46
|
-
scope: 0,
|
|
47
|
-
varDecl: 0,
|
|
48
|
-
callSite: 0,
|
|
49
|
-
function: 0,
|
|
50
|
-
httpRequest: 0,
|
|
51
|
-
literal: 0
|
|
52
|
-
};
|
|
53
|
-
// Processed nodes tracking
|
|
59
|
+
// Processed nodes tracking (still needed for deduplication)
|
|
54
60
|
const processed = {
|
|
55
61
|
callSites: new Set(),
|
|
56
62
|
methodCalls: new Set(),
|
|
@@ -78,54 +84,35 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
78
84
|
importedName = spec.imported?.name || spec.local.name;
|
|
79
85
|
localName = spec.local.name;
|
|
80
86
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
87
|
+
// Babel AST guarantees node.loc exists with locations: true option
|
|
88
|
+
const importNode = ImportNode.create(localName, // name
|
|
89
|
+
filePath, // file
|
|
90
|
+
getLine(node), // line (non-null - Babel guarantees location)
|
|
91
|
+
0, // column (not available in this worker)
|
|
92
|
+
source, // source
|
|
93
|
+
{ imported: importedName, local: localName });
|
|
94
|
+
collections.imports.push(importNode);
|
|
90
95
|
});
|
|
91
96
|
}
|
|
92
97
|
});
|
|
93
|
-
// Extract exports
|
|
98
|
+
// Extract exports using semantic IDs (via createWithContext)
|
|
94
99
|
traverse(ast, {
|
|
95
100
|
ExportNamedDeclaration(path) {
|
|
96
101
|
const node = path.node;
|
|
97
102
|
if (node.declaration) {
|
|
98
103
|
if (node.declaration.type === 'FunctionDeclaration' && node.declaration.id) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
type: 'EXPORT',
|
|
102
|
-
name: node.declaration.id.name,
|
|
103
|
-
exportType: 'function',
|
|
104
|
-
file: filePath,
|
|
105
|
-
line: node.loc.start.line
|
|
106
|
-
});
|
|
104
|
+
const exportNode = ExportNode.createWithContext(node.declaration.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
|
|
105
|
+
collections.exports.push(exportNode);
|
|
107
106
|
}
|
|
108
107
|
else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
type: 'EXPORT',
|
|
112
|
-
name: node.declaration.id.name,
|
|
113
|
-
exportType: 'class',
|
|
114
|
-
file: filePath,
|
|
115
|
-
line: node.loc.start.line
|
|
116
|
-
});
|
|
108
|
+
const exportNode = ExportNode.createWithContext(node.declaration.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
|
|
109
|
+
collections.exports.push(exportNode);
|
|
117
110
|
}
|
|
118
111
|
else if (node.declaration.type === 'VariableDeclaration') {
|
|
119
112
|
node.declaration.declarations.forEach(decl => {
|
|
120
113
|
if (decl.id.type === 'Identifier') {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
type: 'EXPORT',
|
|
124
|
-
name: decl.id.name,
|
|
125
|
-
exportType: 'variable',
|
|
126
|
-
file: filePath,
|
|
127
|
-
line: node.loc.start.line
|
|
128
|
-
});
|
|
114
|
+
const exportNode = ExportNode.createWithContext(decl.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
|
|
115
|
+
collections.exports.push(exportNode);
|
|
129
116
|
}
|
|
130
117
|
});
|
|
131
118
|
}
|
|
@@ -135,38 +122,32 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
135
122
|
if (spec.type !== 'ExportSpecifier')
|
|
136
123
|
return;
|
|
137
124
|
const exportedName = spec.exported.type === 'Identifier' ? spec.exported.name : spec.exported.value;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
name: exportedName,
|
|
142
|
-
localName: spec.local.name,
|
|
143
|
-
file: filePath,
|
|
144
|
-
line: node.loc.start.line
|
|
125
|
+
const exportNode = ExportNode.createWithContext(exportedName, scopeTracker.getContext(), { line: getLine(node), column: 0 }, {
|
|
126
|
+
local: spec.local.name,
|
|
127
|
+
exportType: 'named'
|
|
145
128
|
});
|
|
129
|
+
collections.exports.push(exportNode);
|
|
146
130
|
});
|
|
147
131
|
}
|
|
148
132
|
},
|
|
149
133
|
ExportDefaultDeclaration(path) {
|
|
150
134
|
const node = path.node;
|
|
151
|
-
let
|
|
135
|
+
let localName = 'default';
|
|
152
136
|
if (node.declaration.type === 'Identifier') {
|
|
153
|
-
|
|
137
|
+
localName = node.declaration.name;
|
|
154
138
|
}
|
|
155
139
|
else if ('id' in node.declaration && node.declaration.id) {
|
|
156
|
-
|
|
140
|
+
localName = node.declaration.id.name;
|
|
157
141
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
localName: name,
|
|
163
|
-
isDefault: true,
|
|
164
|
-
file: filePath,
|
|
165
|
-
line: node.loc.start.line
|
|
142
|
+
const exportNode = ExportNode.createWithContext('default', scopeTracker.getContext(), { line: getLine(node), column: 0 }, {
|
|
143
|
+
local: localName,
|
|
144
|
+
default: true,
|
|
145
|
+
exportType: 'default'
|
|
166
146
|
});
|
|
147
|
+
collections.exports.push(exportNode);
|
|
167
148
|
}
|
|
168
149
|
});
|
|
169
|
-
// Extract top-level variables
|
|
150
|
+
// Extract top-level variables using semantic IDs
|
|
170
151
|
traverse(ast, {
|
|
171
152
|
VariableDeclaration(path) {
|
|
172
153
|
if (path.getFunctionParent())
|
|
@@ -176,15 +157,14 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
176
157
|
node.declarations.forEach(decl => {
|
|
177
158
|
if (decl.id.type === 'Identifier') {
|
|
178
159
|
const varName = decl.id.name;
|
|
179
|
-
const line = decl.id
|
|
180
|
-
const column = decl.id.loc.start.column;
|
|
160
|
+
const line = getLine(decl.id);
|
|
181
161
|
const literalValue = ExpressionEvaluator.extractLiteralValue(decl.init);
|
|
182
162
|
const isLiteral = literalValue !== null;
|
|
183
163
|
const isNewExpr = decl.init?.type === 'NewExpression';
|
|
184
164
|
const shouldBeConstant = isConst && (isLiteral || isNewExpr);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
165
|
+
// Generate semantic ID using ScopeTracker
|
|
166
|
+
const nodeType = shouldBeConstant ? 'CONSTANT' : 'VARIABLE';
|
|
167
|
+
const varId = computeSemanticId(nodeType, varName, scopeTracker.getContext());
|
|
188
168
|
collections.variableDeclarations.push({
|
|
189
169
|
id: varId,
|
|
190
170
|
type: shouldBeConstant ? 'CONSTANT' : 'VARIABLE',
|
|
@@ -207,7 +187,7 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
207
187
|
});
|
|
208
188
|
}
|
|
209
189
|
});
|
|
210
|
-
// Extract functions and classes
|
|
190
|
+
// Extract functions and classes using semantic IDs
|
|
211
191
|
traverse(ast, {
|
|
212
192
|
FunctionDeclaration(path) {
|
|
213
193
|
if (path.getFunctionParent())
|
|
@@ -216,33 +196,38 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
216
196
|
if (!node.id)
|
|
217
197
|
return;
|
|
218
198
|
const funcName = node.id.name;
|
|
219
|
-
|
|
199
|
+
// Generate semantic ID using ScopeTracker
|
|
200
|
+
const functionId = computeSemanticId('FUNCTION', funcName, scopeTracker.getContext());
|
|
220
201
|
collections.functions.push({
|
|
221
202
|
id: functionId,
|
|
222
|
-
stableId: functionId,
|
|
223
203
|
type: 'FUNCTION',
|
|
224
204
|
name: funcName,
|
|
225
205
|
file: filePath,
|
|
226
|
-
line: node
|
|
227
|
-
column: node
|
|
206
|
+
line: getLine(node),
|
|
207
|
+
column: getColumn(node),
|
|
228
208
|
async: node.async || false,
|
|
229
209
|
generator: node.generator || false,
|
|
230
210
|
exported: path.parent?.type === 'ExportNamedDeclaration' || path.parent?.type === 'ExportDefaultDeclaration'
|
|
231
211
|
});
|
|
232
|
-
//
|
|
212
|
+
// Enter function scope for parameter extraction
|
|
213
|
+
scopeTracker.enterScope(funcName, 'FUNCTION');
|
|
214
|
+
// Extract parameters with semantic IDs
|
|
233
215
|
node.params.forEach((param, index) => {
|
|
234
216
|
if (param.type === 'Identifier') {
|
|
217
|
+
const paramId = computeSemanticId('PARAMETER', param.name, scopeTracker.getContext(), { discriminator: index });
|
|
235
218
|
collections.parameters.push({
|
|
236
|
-
id:
|
|
219
|
+
id: paramId,
|
|
237
220
|
type: 'PARAMETER',
|
|
238
221
|
name: param.name,
|
|
239
222
|
index,
|
|
240
223
|
functionId,
|
|
241
224
|
file: filePath,
|
|
242
|
-
line: param
|
|
225
|
+
line: getLine(param)
|
|
243
226
|
});
|
|
244
227
|
}
|
|
245
228
|
});
|
|
229
|
+
// Exit function scope
|
|
230
|
+
scopeTracker.exitScope();
|
|
246
231
|
},
|
|
247
232
|
ClassDeclaration(path) {
|
|
248
233
|
if (path.getFunctionParent())
|
|
@@ -251,30 +236,30 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
251
236
|
if (!node.id)
|
|
252
237
|
return;
|
|
253
238
|
const className = node.id.name;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// Extract methods
|
|
239
|
+
// Extract superClass name
|
|
240
|
+
const superClassName = node.superClass && node.superClass.type === 'Identifier'
|
|
241
|
+
? node.superClass.name
|
|
242
|
+
: null;
|
|
243
|
+
// Create CLASS node using ClassNode.createWithContext() for semantic IDs
|
|
244
|
+
const classRecord = ClassNode.createWithContext(className, scopeTracker.getContext(), { line: getLine(node), column: getColumn(node) }, { superClass: superClassName || undefined });
|
|
245
|
+
collections.classDeclarations.push(classRecord);
|
|
246
|
+
// Enter class scope for method extraction
|
|
247
|
+
scopeTracker.enterScope(className, 'CLASS');
|
|
248
|
+
// Extract methods with semantic IDs (including class scope)
|
|
264
249
|
node.body.body.forEach(member => {
|
|
265
250
|
if (member.type === 'ClassMethod' && member.key.type === 'Identifier') {
|
|
266
251
|
const methodName = member.key.name;
|
|
267
|
-
|
|
252
|
+
// Method ID includes class scope: file->ClassName->FUNCTION->methodName
|
|
253
|
+
const methodId = computeSemanticId('FUNCTION', methodName, scopeTracker.getContext());
|
|
268
254
|
collections.functions.push({
|
|
269
255
|
id: methodId,
|
|
270
|
-
stableId: methodId,
|
|
271
256
|
type: 'METHOD',
|
|
272
257
|
name: methodName,
|
|
273
258
|
className,
|
|
274
|
-
classId,
|
|
259
|
+
classId: classRecord.id,
|
|
275
260
|
file: filePath,
|
|
276
|
-
line: member
|
|
277
|
-
column: member
|
|
261
|
+
line: getLine(member),
|
|
262
|
+
column: getColumn(member),
|
|
278
263
|
async: member.async || false,
|
|
279
264
|
isClassMethod: true,
|
|
280
265
|
isConstructor: member.kind === 'constructor',
|
|
@@ -282,9 +267,11 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
282
267
|
});
|
|
283
268
|
}
|
|
284
269
|
});
|
|
270
|
+
// Exit class scope
|
|
271
|
+
scopeTracker.exitScope();
|
|
285
272
|
}
|
|
286
273
|
});
|
|
287
|
-
// Extract call expressions at module level
|
|
274
|
+
// Extract call expressions at module level using semantic IDs with discriminators
|
|
288
275
|
traverse(ast, {
|
|
289
276
|
CallExpression(path) {
|
|
290
277
|
if (path.getFunctionParent())
|
|
@@ -295,14 +282,18 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
295
282
|
if (processed.callSites.has(nodeKey))
|
|
296
283
|
return;
|
|
297
284
|
processed.callSites.add(nodeKey);
|
|
285
|
+
// Get discriminator for same-named calls in current scope
|
|
286
|
+
const calleeName = node.callee.name;
|
|
287
|
+
const discriminator = scopeTracker.getItemCounter(`CALL:${calleeName}`);
|
|
288
|
+
const callId = computeSemanticId('CALL', calleeName, scopeTracker.getContext(), { discriminator });
|
|
298
289
|
collections.callSites.push({
|
|
299
|
-
id:
|
|
290
|
+
id: callId,
|
|
300
291
|
type: 'CALL',
|
|
301
|
-
name:
|
|
292
|
+
name: calleeName,
|
|
302
293
|
file: filePath,
|
|
303
|
-
line: node
|
|
294
|
+
line: getLine(node),
|
|
304
295
|
parentScopeId: moduleId,
|
|
305
|
-
targetFunctionName:
|
|
296
|
+
targetFunctionName: calleeName
|
|
306
297
|
});
|
|
307
298
|
}
|
|
308
299
|
else if (node.callee.type === 'MemberExpression') {
|
|
@@ -315,14 +306,17 @@ function parseModule(filePath, moduleId, moduleName) {
|
|
|
315
306
|
const objectName = obj.type === 'Identifier' ? obj.name : 'this';
|
|
316
307
|
const methodName = prop.name;
|
|
317
308
|
const fullName = `${objectName}.${methodName}`;
|
|
309
|
+
// Get discriminator for same-named method calls
|
|
310
|
+
const discriminator = scopeTracker.getItemCounter(`CALL:${fullName}`);
|
|
311
|
+
const callId = computeSemanticId('CALL', fullName, scopeTracker.getContext(), { discriminator });
|
|
318
312
|
collections.methodCalls.push({
|
|
319
|
-
id:
|
|
313
|
+
id: callId,
|
|
320
314
|
type: 'CALL',
|
|
321
315
|
name: fullName,
|
|
322
316
|
object: objectName,
|
|
323
317
|
method: methodName,
|
|
324
318
|
file: filePath,
|
|
325
|
-
line: node
|
|
319
|
+
line: getLine(node),
|
|
326
320
|
parentScopeId: moduleId
|
|
327
321
|
});
|
|
328
322
|
}
|