MCPcopy Index your code
hub / github.com/nodejs/node / printSourceFileOrBundle

Function printSourceFileOrBundle

test/fixtures/snapshot/typescript.js:110425–110467  ·  view source on GitHub ↗
(jsFilePath, sourceMapFilePath, sourceFileOrBundle, printer, mapOptions)

Source from the content-addressed store, hash-verified

110423 ts.forEachChild(node, collectLinkedAliases);
110424 }
110425 function printSourceFileOrBundle(jsFilePath, sourceMapFilePath, sourceFileOrBundle, printer, mapOptions) {
110426 var bundle = sourceFileOrBundle.kind === 306 /* SyntaxKind.Bundle */ ? sourceFileOrBundle : undefined;
110427 var sourceFile = sourceFileOrBundle.kind === 305 /* SyntaxKind.SourceFile */ ? sourceFileOrBundle : undefined;
110428 var sourceFiles = bundle ? bundle.sourceFiles : [sourceFile];
110429 var sourceMapGenerator;
110430 if (shouldEmitSourceMaps(mapOptions, sourceFileOrBundle)) {
110431 sourceMapGenerator = ts.createSourceMapGenerator(host, ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)), getSourceRoot(mapOptions), getSourceMapDirectory(mapOptions, jsFilePath, sourceFile), mapOptions);
110432 }
110433 if (bundle) {
110434 printer.writeBundle(bundle, writer, sourceMapGenerator);
110435 }
110436 else {
110437 printer.writeFile(sourceFile, writer, sourceMapGenerator);
110438 }
110439 var sourceMapUrlPos;
110440 if (sourceMapGenerator) {
110441 if (sourceMapDataList) {
110442 sourceMapDataList.push({
110443 inputSourceFileNames: sourceMapGenerator.getSources(),
110444 sourceMap: sourceMapGenerator.toJSON()
110445 });
110446 }
110447 var sourceMappingURL = getSourceMappingURL(mapOptions, sourceMapGenerator, jsFilePath, sourceMapFilePath, sourceFile);
110448 if (sourceMappingURL) {
110449 if (!writer.isAtStartOfLine())
110450 writer.rawWrite(newLine);
110451 sourceMapUrlPos = writer.getTextPos();
110452 writer.writeComment("//# ".concat("sourceMappingURL", "=").concat(sourceMappingURL)); // Tools can sometimes see this line as a source mapping url comment
110453 }
110454 // Write the source map
110455 if (sourceMapFilePath) {
110456 var sourceMap = sourceMapGenerator.toString();
110457 ts.writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap, /*writeByteOrderMark*/ false, sourceFiles);
110458 }
110459 }
110460 else {
110461 writer.writeLine();
110462 }
110463 // Write the output file
110464 ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles, { sourceMapUrlPos: sourceMapUrlPos });
110465 // Reset state
110466 writer.clear();
110467 }
110468 function shouldEmitSourceMaps(mapOptions, sourceFileOrBundle) {
110469 return (mapOptions.sourceMap || mapOptions.inlineSourceMap)
110470 && (sourceFileOrBundle.kind !== 305 /* SyntaxKind.SourceFile */ || !ts.fileExtensionIs(sourceFileOrBundle.fileName, ".json" /* Extension.Json */));

Callers 2

emitJsFileOrBundleFunction · 0.85

Calls 10

shouldEmitSourceMapsFunction · 0.85
getSourceRootFunction · 0.85
getSourceMapDirectoryFunction · 0.85
getSourceMappingURLFunction · 0.85
concatMethod · 0.80
clearMethod · 0.65
writeFileMethod · 0.45
pushMethod · 0.45
toJSONMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected