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

Function computeCommonSourceDirectoryOfFilenames

test/fixtures/snapshot/typescript.js:115734–115770  ·  view source on GitHub ↗
(fileNames, currentDirectory, getCanonicalFileName)

Source from the content-addressed store, hash-verified

115732 ts.resolveTripleslashReference = resolveTripleslashReference;
115733 /* @internal */
115734 function computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, getCanonicalFileName) {
115735 var commonPathComponents;
115736 var failed = ts.forEach(fileNames, function (sourceFile) {
115737 // Each file contributes into common source file path
115738 var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile, currentDirectory);
115739 sourcePathComponents.pop(); // The base file name is not part of the common directory path
115740 if (!commonPathComponents) {
115741 // first file
115742 commonPathComponents = sourcePathComponents;
115743 return;
115744 }
115745 var n = Math.min(commonPathComponents.length, sourcePathComponents.length);
115746 for (var i = 0; i < n; i++) {
115747 if (getCanonicalFileName(commonPathComponents[i]) !== getCanonicalFileName(sourcePathComponents[i])) {
115748 if (i === 0) {
115749 // Failed to find any common path component
115750 return true;
115751 }
115752 // New common path found that is 0 -> i-1
115753 commonPathComponents.length = i;
115754 break;
115755 }
115756 }
115757 // If the sourcePathComponents was shorter than the commonPathComponents, truncate to the sourcePathComponents
115758 if (sourcePathComponents.length < commonPathComponents.length) {
115759 commonPathComponents.length = sourcePathComponents.length;
115760 }
115761 });
115762 // A common path can not be found when paths span multiple drives on windows, for example
115763 if (failed) {
115764 return "";
115765 }
115766 if (!commonPathComponents) { // Can happen when all input files are .d.ts files
115767 return currentDirectory;
115768 }
115769 return ts.getPathFromPathComponents(commonPathComponents);
115770 }
115771 ts.computeCommonSourceDirectoryOfFilenames = computeCommonSourceDirectoryOfFilenames;
115772 function createCompilerHost(options, setParentNodes) {
115773 return createCompilerHostWorker(options, setParentNodes);

Callers

nothing calls this directly

Calls 4

getCanonicalFileNameFunction · 0.85
popMethod · 0.80
forEachMethod · 0.65
minMethod · 0.45

Tested by

no test coverage detected