Open History to see the last commit
1import { expect, test } from 'vitest'
2import { analyzeModule } from '../src'
3β
4test.each(['\n', '\r\n', '\r', '\u2028', '\u2029'])(
5 'reports actionable syntax locations with %j line endings and Unicode source',
6 (newline) => {
7 const code = `// πΓ©${newline}/* πΓ© */ export const broken = ;`
8β
9 expect(() =>
10 analyzeModule({ code, filename: '/routes/index.tsx' }),
11 ).toThrow(
12 expect.objectContaining({
13 name: 'SyntaxError',
14 message: "/routes/index.tsx: Unexpected token ';' (2:32)",
15 loc: { line: 2, column: 32 },
16 pos: code.indexOf(';'),
17 }),
18 )
19 },
20)
21β
22test('reports the first line and a zero-based column for syntax errors', () => {
23 expect(() => analyzeModule({ code: 'const broken = ;' })).toThrow(
24 expect.objectContaining({
25 name: 'SyntaxError',
26 message: "input.tsx: Unexpected token ';' (1:15)",
27 loc: { line: 1, column: 15 },
28 pos: 15,
29 }),
30 )
31})