MCPcopy Index your code
hub / github.com/TypeStrong/ts-node / createTranspileOnlyGetOutputFunction

Function createTranspileOnlyGetOutputFunction

src/index.ts:1334–1383  ·  view source on GitHub ↗
(
    overrideModuleType?: _ts.ModuleKind,
    nodeModuleEmitKind?: NodeModuleEmitKind
  )

Source from the content-addressed store, hash-verified

1332 }
1333
1334 function createTranspileOnlyGetOutputFunction(
1335 overrideModuleType?: _ts.ModuleKind,
1336 nodeModuleEmitKind?: NodeModuleEmitKind
1337 ): GetOutputFunction {
1338 const compilerOptions = { ...config.options };
1339 if (overrideModuleType !== undefined)
1340 compilerOptions.module = overrideModuleType;
1341 let customTranspiler = createTranspiler?.(
1342 compilerOptions,
1343 nodeModuleEmitKind
1344 );
1345 let tsTranspileModule = versionGteLt(ts.version, '4.7.0')
1346 ? createTsTranspileModule(ts, {
1347 compilerOptions,
1348 reportDiagnostics: true,
1349 transformers: transformers as _ts.CustomTransformers | undefined,
1350 })
1351 : undefined;
1352 return (code: string, fileName: string): SourceOutput => {
1353 let result: _ts.TranspileOutput;
1354 if (customTranspiler) {
1355 result = customTranspiler.transpile(code, {
1356 fileName,
1357 });
1358 } else if (tsTranspileModule) {
1359 result = tsTranspileModule(
1360 code,
1361 {
1362 fileName,
1363 },
1364 nodeModuleEmitKind === 'nodeesm' ? 'module' : 'commonjs'
1365 );
1366 } else {
1367 result = ts.transpileModule(code, {
1368 fileName,
1369 compilerOptions,
1370 reportDiagnostics: true,
1371 transformers: transformers as _ts.CustomTransformers | undefined,
1372 });
1373 }
1374
1375 const diagnosticList = filterDiagnostics(
1376 result.diagnostics || [],
1377 diagnosticFilters
1378 );
1379 if (diagnosticList.length) reportTSError(diagnosticList);
1380
1381 return [result.outputText, result.sourceMapText as string, false];
1382 };
1383 }
1384
1385 // When true, these mean that a `moduleType` override will cause a different emit
1386 // than the TypeScript compiler, so we *must* overwrite the emit.

Callers 1

Calls 6

versionGteLtFunction · 0.90
createTsTranspileModuleFunction · 0.90
createTranspilerFunction · 0.85
filterDiagnosticsFunction · 0.85
reportTSErrorFunction · 0.85
transpileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…