From a44ebbbc7eec05931e26b1646630929bba942e58 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 18 Nov 2015 13:19:56 -0800 Subject: [PATCH] only make common dir on call --- src/compiler/program.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d3eb24b7540..bd59410b738 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -374,7 +374,7 @@ namespace ts { } // _Always_ compute a common source directory - let commonSourceDirectory = computeCommonSourceDirectory(files); + let commonSourceDirectory: string; verifyCompilerOptions(); // unconditionally set oldProgram to undefined to prevent it from being captured in closure @@ -395,7 +395,9 @@ namespace ts { getTypeChecker, getClassifiableNames, getDiagnosticsProducingTypeChecker, - getCommonSourceDirectory: () => commonSourceDirectory, + getCommonSourceDirectory: () => { + return typeof commonSourceDirectory === "undefined" ? (commonSourceDirectory = computeCommonSourceDirectory(files)) : commonSourceDirectory; + }, emit, getCurrentDirectory: () => currentDirectory, getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(), @@ -1071,11 +1073,12 @@ namespace ts { } } - if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) { - // Make sure directory path ends with directory separator so this string can directly - // used to replace with "" to get the relative path of the source file and the relative path doesn't - // start with / making it rooted path - commonSourceDirectory += directorySeparator; + if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) { + // Make sure directory path ends with directory separator so this string can directly + // used to replace with "" to get the relative path of the source file and the relative path doesn't + // start with / making it rooted path + commonSourceDirectory += directorySeparator; + } } if (options.noEmit) {