Skip to content

Commit 825a397

Browse files
committed
fix: correct code-map line counting
1 parent 94d3323 commit 825a397

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('parse module', () => {
132132
() => multilineCode,
133133
)
134134

135-
expect(result.numLines).toBe(2) // Due to operator precedence: .match(/\n/g)?.length ?? 0 + 1 becomes (2 ?? 1) = 2
135+
expect(result.numLines).toBe(3)
136136
})
137137

138138
it('should deduplicate identifiers and calls', () => {

packages/code-map/src/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function parseTokens(
169169
calls: [] as string[],
170170
}
171171
}
172-
const numLines = sourceCode.match(/\n/g)?.length ?? 0 + 1
172+
const numLines = (sourceCode.match(/\n/g)?.length ?? 0) + 1
173173
if (!parser || !query) {
174174
throw new Error('Parser or query not found')
175175
}

0 commit comments

Comments
 (0)