Implement --lib flag in the compiler and harness

This commit is contained in:
Kanchalai Tanglertsampan
2016-03-28 14:20:29 -07:00
parent 168118f12b
commit 3fef5ba458
13 changed files with 206 additions and 97 deletions

View File

@@ -15,8 +15,8 @@ namespace ts {
export const version = "1.9.0";
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean): string {
let fileName = "tsconfig.json";
while (true) {
const fileName = combinePaths(searchPath, "tsconfig.json");
if (fileExists(fileName)) {
return fileName;
}
@@ -25,7 +25,6 @@ namespace ts {
break;
}
searchPath = parentPath;
fileName = "../" + fileName;
}
return undefined;
}
@@ -630,10 +629,18 @@ namespace ts {
}
}
function getUserDefinedLibFileName(options: CompilerOptions): string[] {
const directoryPath = getDirectoryPath(normalizePath(sys.getExecutingFilePath()));
return options.lib.map(fileName => {
return combinePaths(directoryPath, fileName);
});
}
const newLine = getNewLineCharacter(options);
return {
getSourceFile,
getUserDefinedLibFileName,
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
writeFile,
getCurrentDirectory: memoize(() => sys.getCurrentDirectory()),
@@ -754,7 +761,17 @@ namespace ts {
// - A 'no-default-lib' reference comment is encountered in
// processing the root files.
if (!skipDefaultLib) {
processRootFile(host.getDefaultLibFileName(options), /*isDefaultLib*/ true);
// If '--lib' is not specified, include default library file according to '--target'
// otherwise, using options specified in '--lib' instead of '--target' default library file
if (!options.lib) {
processRootFile(host.getDefaultLibFileName(options), /*isDefaultLib*/ true);
}
else {
const libFileNames = host.getUserDefinedLibFileName(options);
libFileNames.forEach(libFileName => {
processRootFile(libFileName, /*isDefaultLib*/ true);
});
}
}
}
@@ -1483,7 +1500,7 @@ namespace ts {
const basePath = getDirectoryPath(fileName);
if (!options.noResolve) {
processReferencedFiles(file, basePath);
processReferencedFiles(file, basePath, /*isDefaultLib*/ isDefaultLib);
}
// always process imported modules to record module name resolutions
@@ -1500,10 +1517,10 @@ namespace ts {
return file;
}
function processReferencedFiles(file: SourceFile, basePath: string) {
function processReferencedFiles(file: SourceFile, basePath: string, isDefaultLib: boolean) {
forEach(file.referencedFiles, ref => {
const referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
processSourceFile(referencedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end);
processSourceFile(referencedFileName, isDefaultLib, /*isReference*/ true, file, ref.pos, ref.end);
});
}
@@ -1700,6 +1717,10 @@ namespace ts {
}
}
if (options.lib && options.noLib) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "lib", "noLib"));
}
const languageVersion = options.target || ScriptTarget.ES3;
const outFile = options.outFile || options.out;