MCPcopy
hub / github.com/vitest-dev/vitest / transformCode

Function transformCode

packages/mocker/src/node/parsers.ts:19–29  ·  view source on GitHub ↗
(code: string, filename: string)

Source from the content-addressed store, hash-verified

17 || process.env.NODE_OPTIONS?.includes('--experimental-transform-types')
18
19export function transformCode(code: string, filename: string): string {
20 const ext = extname(filename.split('?')[0])
21 const isTs = ext === '.ts' || ext === '.cts' || ext === '.mts'
22 if (!isTs) {
23 return code
24 }
25 if (!module.stripTypeScriptTypes) {
26 throw new Error(`Cannot parse '${filename}' because "module.stripTypeScriptTypes" is not supported. Module mocking requires Node.js 22.15 or higher. This is NOT a bug of Vitest.`)
27 }
28 return module.stripTypeScriptTypes(code, { mode: isTransform ? 'transform' : 'strip' })
29}
30
31const cachedFileExports = new Map<string, string[]>()
32

Callers 2

automockModuleFunction · 0.90
parseModuleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected