Open History to see the last commit
1import { describe, expect, test } from 'vitest'
2import { analyzeModule, collectModuleReferences } from '../src'
3β
4const comparisonChain = `const a = 1, b = 2, c = 3
5export const r = a < b > (c)
6export const element = <p>{r}</p>`
7β
8function referencedNames(filename: string) {
9 const module = analyzeModule({ code: comparisonChain, filename })
10 return [...collectModuleReferences(module, module.ast)]
11 .map((binding) => binding.name)
12 .sort()
13}
14β
15describe('source language follows the file extension', () => {
16 // JavaScript has no type arguments: `a < b > (c)` is two comparisons, while
17 // TypeScript reads it as a call of `a` with the type argument `b`.
18 test.each([
19 'route.js',
20 'route.jsx',
21 'route.mjs',
22 'route.cjs',
23 '/src/routes/index.js?tsr-split=component',
24 ])('parses %s as JavaScript with JSX', (filename) => {
25 expect(referencedNames(filename)).toEqual(['a', 'b', 'c', 'r'])
26 })
27β
28 test('parses .tsx files as TypeScript with JSX', () => {
29 expect(referencedNames('route.tsx')).toEqual(['a', 'c', 'r'])
30 })
31})