MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract

Method extract

src/extraction/astro-extractor.ts:45–88  ·  view source on GitHub ↗

* Extract from Astro source

()

Source from the content-addressed store, hash-verified

43 * Extract from Astro source
44 */
45 extract(): ExtractionResult {
46 const startTime = Date.now();
47
48 try {
49 // The file, holding the component the .astro file is
50 this.nodes.push(sfcFileNode(this.filePath, this.source, 'astro'));
51 const componentNode = this.createComponentNode();
52 this.edges.push({ source: `file:${this.filePath}`, target: componentNode.id, kind: 'contains' });
53
54 // Extract and process the frontmatter block (--- fenced, TypeScript)
55 const frontmatter = this.extractFrontmatter();
56 if (frontmatter) {
57 this.processScriptContent(frontmatter, componentNode.id, 'frontmatter');
58 }
59
60 // Extract and process <script> blocks (client-side, TypeScript-capable)
61 for (const block of this.extractScriptBlocks()) {
62 this.processScriptContent(block, componentNode.id, 'script');
63 }
64
65 // Ranges the template scans must skip: frontmatter + <script>/<style>
66 const coveredRanges = this.getCoveredRanges(frontmatter);
67
68 // Extract function calls from template expressions ({fn(...)})
69 this.extractTemplateCalls(componentNode.id, coveredRanges);
70
71 // Extract component usages from template (<ComponentName>)
72 this.extractTemplateComponents(componentNode.id, coveredRanges);
73 } catch (error) {
74 this.errors.push({
75 message: `Astro extraction error: ${error instanceof Error ? error.message : String(error)}`,
76 severity: 'error',
77 code: 'parse_error',
78 });
79 }
80
81 return {
82 nodes: this.nodes,
83 edges: this.edges,
84 unresolvedReferences: this.unresolvedReferences,
85 errors: this.errors,
86 durationMs: Date.now() - startTime,
87 };
88 }
89
90 /**
91 * Create a component node for the .astro file

Callers

nothing calls this directly

Calls 9

createComponentNodeMethod · 0.95
extractFrontmatterMethod · 0.95
processScriptContentMethod · 0.95
extractScriptBlocksMethod · 0.95
getCoveredRangesMethod · 0.95
extractTemplateCallsMethod · 0.95
sfcFileNodeFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected