Skip to content

Commit 8a09e7f

Browse files
committed
Bugfix: Fix Shebang Parsing in SourceParser #8345
SourceParser now strips the shebang line ('#!...') before passing content to Acorn, preventing syntax errors when indexing executable scripts (e.g. CLI tools, test runners).
1 parent bd28172 commit 8a09e7f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

ai/mcp/server/knowledge-base/parser/SourceParser.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class SourceParser extends Base {
4646
const chunks = [];
4747
let ast;
4848

49+
// Strip shebang if present (acorn doesn't handle it)
50+
if (content.startsWith('#!')) {
51+
content = content.replace(/^#!.*\n/, '');
52+
}
53+
4954
try {
5055
ast = acorn.parse(content, { sourceType: 'module', locations: true, ecmaVersion: 2022 });
5156
} catch (e) {

0 commit comments

Comments
 (0)