Skip to content

Commit f9841a1

Browse files
committed
Limit tree-sitter project indexing memory
1 parent 03a335e commit f9841a1

4 files changed

Lines changed: 442 additions & 171 deletions

File tree

packages/code-map/__tests__/parse.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ describe('parse module', () => {
5151
expect(mockQuery.captures).toHaveBeenCalledWith(mockTree.rootNode)
5252
})
5353

54+
it('should skip parsing source larger than the byte limit', () => {
55+
const mockParser = createMockTreeSitterParser()
56+
const mockLanguageConfig: LanguageConfig = {
57+
extensions: ['.ts'],
58+
wasmFile: 'tree-sitter-typescript.wasm',
59+
queryText: 'mock query',
60+
parser: mockParser,
61+
query: createMockTreeSitterQuery(),
62+
}
63+
64+
const result = parseTokens(
65+
'test.ts',
66+
mockLanguageConfig,
67+
() => 'x'.repeat(20),
68+
{ maxBytes: 10 },
69+
)
70+
71+
expect(result).toEqual({
72+
numLines: 0,
73+
identifiers: [],
74+
calls: [],
75+
})
76+
expect(mockParser.parse).not.toHaveBeenCalled()
77+
})
78+
5479
it('should handle null file content gracefully', () => {
5580
const mockLanguageConfig: LanguageConfig = {
5681
extensions: ['.ts'],

0 commit comments

Comments
 (0)