| 10288 | * Their nodes/references/errors are merged into the returned result. |
| 10289 | */ |
| 10290 | export function extractFromSource( |
| 10291 | filePath: string, |
| 10292 | source: string, |
| 10293 | language?: Language, |
| 10294 | frameworkNames?: string[] |
| 10295 | ): ExtractionResult { |
| 10296 | const detectedLanguage = language || detectLanguage(filePath, source); |
| 10297 | const fileExtension = path.extname(filePath).toLowerCase(); |
| 10298 | |
| 10299 | let result: ExtractionResult; |
| 10300 | |
| 10301 | // Use custom extractor for Svelte |
| 10302 | if (detectedLanguage === 'svelte') { |
| 10303 | const extractor = new SvelteExtractor(filePath, source); |
| 10304 | result = extractor.extract(); |
| 10305 | } else if (detectedLanguage === 'vue') { |
| 10306 | // Use custom extractor for Vue |
| 10307 | const extractor = new VueExtractor(filePath, source); |
| 10308 | result = extractor.extract(); |
| 10309 | } else if (detectedLanguage === 'astro') { |
| 10310 | // Use custom extractor for Astro (frontmatter + template delegation) |
| 10311 | const extractor = new AstroExtractor(filePath, source); |
| 10312 | result = extractor.extract(); |
| 10313 | } else if (detectedLanguage === 'liquid') { |
| 10314 | // Use custom extractor for Liquid |
| 10315 | const extractor = new LiquidExtractor(filePath, source); |
| 10316 | result = extractor.extract(); |
| 10317 | } else if (detectedLanguage === 'razor') { |
| 10318 | // Use custom extractor for ASP.NET Razor (.cshtml) / Blazor (.razor) markup |
| 10319 | const extractor = new RazorExtractor(filePath, source); |
| 10320 | result = extractor.extract(); |
| 10321 | } else if (detectedLanguage === 'xml') { |
| 10322 | // Custom extractor for MyBatis mapper XML. Non-mapper XML returns just a |
| 10323 | // file node so the watcher tracks it without emitting symbols. |
| 10324 | const extractor = new MyBatisExtractor(filePath, source); |
| 10325 | result = extractor.extract(); |
| 10326 | } else if (detectedLanguage === 'cfml' || detectedLanguage === 'cfscript') { |
| 10327 | // Custom extractor for CFML (.cfc/.cfm) — dialect-switches between the |
| 10328 | // tag-based cfml grammar and the bare-script cfscript grammar. Standalone |
| 10329 | // `.cfs` files (language 'cfscript') are always pure script (never `<`-led), |
| 10330 | // so routing them through here too gets them the same anonymous-component |
| 10331 | // filename fallback as a bare-script `.cfc` — without it a `.cfs` whose |
| 10332 | // `component { ... }` declares no name (the grammar has no `name` field; |
| 10333 | // CFML never spells one in source) stays `<anonymous>`. |
| 10334 | const extractor = new CfmlExtractor(filePath, source, detectedLanguage); |
| 10335 | result = extractor.extract(); |
| 10336 | } else if (isFileLevelOnlyLanguage(detectedLanguage)) { |
| 10337 | // No symbol extraction at this stage — files are tracked at the file-record |
| 10338 | // level only. Framework extractors (Drupal routing yml, Spring `@Value` |
| 10339 | // resolution against application.yml/application.properties) run later and |
| 10340 | // add per-file nodes/references when they apply. |
| 10341 | result = { nodes: [], edges: [], unresolvedReferences: [], errors: [], durationMs: 0 }; |
| 10342 | } else if ( |
| 10343 | detectedLanguage === 'pascal' && |
| 10344 | (fileExtension === '.dfm' || fileExtension === '.fmx') |
| 10345 | ) { |
| 10346 | // Use custom extractor for DFM/FMX form files |
| 10347 | const extractor = new DfmExtractor(filePath, source); |