(code: string, fileName: string, lineOffset = 0)
| 1420 | |
| 1421 | // Create a simple TypeScript compiler proxy. |
| 1422 | function compile(code: string, fileName: string, lineOffset = 0) { |
| 1423 | const normalizedFileName = normalizeSlashes(fileName); |
| 1424 | const classification = |
| 1425 | moduleTypeClassifier.classifyModuleByModuleTypeOverrides( |
| 1426 | normalizedFileName |
| 1427 | ); |
| 1428 | let value: string | undefined = ''; |
| 1429 | let sourceMap: string | undefined = ''; |
| 1430 | let emitSkipped = true; |
| 1431 | if (getOutput) { |
| 1432 | // Must always call normal getOutput to throw typechecking errors |
| 1433 | [value, sourceMap, emitSkipped] = getOutput(code, normalizedFileName); |
| 1434 | } |
| 1435 | // If module classification contradicts the above, call the relevant transpiler |
| 1436 | if ( |
| 1437 | classification.moduleType === 'cjs' && |
| 1438 | (shouldOverwriteEmitWhenForcingCommonJS || emitSkipped) |
| 1439 | ) { |
| 1440 | [value, sourceMap] = getOutputForceCommonJS(code, normalizedFileName); |
| 1441 | } else if ( |
| 1442 | classification.moduleType === 'esm' && |
| 1443 | (shouldOverwriteEmitWhenForcingEsm || emitSkipped) |
| 1444 | ) { |
| 1445 | [value, sourceMap] = getOutputForceESM(code, normalizedFileName); |
| 1446 | } else if (emitSkipped) { |
| 1447 | // Happens when ts compiler skips emit or in transpileOnly mode |
| 1448 | const classification = classifyModule(fileName, isNodeModuleType); |
| 1449 | [value, sourceMap] = |
| 1450 | classification === 'nodecjs' |
| 1451 | ? getOutputForceNodeCommonJS(code, normalizedFileName) |
| 1452 | : classification === 'nodeesm' |
| 1453 | ? getOutputForceNodeESM(code, normalizedFileName) |
| 1454 | : classification === 'cjs' |
| 1455 | ? getOutputForceCommonJS(code, normalizedFileName) |
| 1456 | : classification === 'esm' |
| 1457 | ? getOutputForceESM(code, normalizedFileName) |
| 1458 | : getOutputTranspileOnly(code, normalizedFileName); |
| 1459 | } |
| 1460 | const output = updateOutput( |
| 1461 | value!, |
| 1462 | normalizedFileName, |
| 1463 | sourceMap!, |
| 1464 | getEmitExtension |
| 1465 | ); |
| 1466 | outputCache.set(normalizedFileName, { content: output }); |
| 1467 | return output; |
| 1468 | } |
| 1469 | |
| 1470 | let active = true; |
| 1471 | const enabled = (enabled?: boolean) => |
nothing calls this directly
no test coverage detected
searching dependent graphs…