processIncludesWithVisited processes import directives with cycle detection
(content, baseDir string, extractTools bool, visited map[string]struct {
})
| 19 | |
| 20 | // processIncludesWithVisited processes import directives with cycle detection |
| 21 | func processIncludesWithVisited(content, baseDir string, extractTools bool, visited map[string]struct { |
| 22 | }) (string, error) { |
| 23 | if fastResult, fastPath := fastPathForNoIncludes(content, extractTools); fastPath { |
| 24 | return fastResult, nil |
| 25 | } |
| 26 | |
| 27 | scanner := bufio.NewScanner(strings.NewReader(content)) |
| 28 | var result bytes.Buffer |
| 29 | |
| 30 | for scanner.Scan() { |
| 31 | line := scanner.Text() |
| 32 | |
| 33 | // Parse import directive |
| 34 | directive := ParseImportDirective(line) |
| 35 | if directive != nil { |
| 36 | includedContent, shouldSkip, err := processIncludeDirectiveWithVisited(directive, baseDir, extractTools, visited) |
| 37 | if err != nil { |
| 38 | return "", err |
| 39 | } |
| 40 | if shouldSkip { |
| 41 | continue |
| 42 | } |
| 43 | if extractTools { |
| 44 | result.WriteString(includedContent + "\n") |
| 45 | } else { |
| 46 | result.WriteString(includedContent) |
| 47 | } |
| 48 | } else { |
| 49 | // Regular line, just pass through (unless extracting tools) |
| 50 | if !extractTools { |
| 51 | result.WriteString(line + "\n") |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return result.String(), nil |
| 57 | } |
| 58 | |
| 59 | func fastPathForNoIncludes(content string, extractTools bool) (string, bool) { |
| 60 | // Fast path: skip scanner allocation when no include/import directives are present. |
no test coverage detected