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

Method extract

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

* Extract from Astro source

()

Source from the content-addressed store, hash-verified

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