From 0257acebd37374b71d176db050d987b32e8c8315 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 26 Jan 2015 16:45:34 -0800 Subject: [PATCH] Respond to code review comments --- src/compiler/core.ts | 2 +- src/compiler/program.ts | 2 +- src/services/services.ts | 12 ++++++------ tests/cases/unittests/services/documentRegistry.ts | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index d57553d053e..aafec557de4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -633,7 +633,7 @@ module ts { } } - export function getDefaultLibraryFilename(options: CompilerOptions): string { + export function getDefaultLibFilename(options: CompilerOptions): string { return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 21a5d9e7d37..dac92431bea 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -64,7 +64,7 @@ module ts { return { getSourceFile, - getDefaultLibFilename: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibraryFilename(options)), + getDefaultLibFilename: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFilename(options)), writeFile, getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()), useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames, diff --git a/src/services/services.ts b/src/services/services.ts index 875b67aba0f..1a9e49c49a9 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2045,12 +2045,12 @@ module ts { // Now create a new compiler program = createProgram(hostfilenames, compilationSettings, { - getSourceFile: getSourceFile, + getSourceFile, getCancellationToken: () => cancellationToken, getCanonicalFileName: filename => useCaseSensitivefilenames ? filename : filename.toLowerCase(), useCaseSensitiveFileNames: () => useCaseSensitivefilenames, getNewLine: () => host.getNewLine ? host.getNewLine() : "\r\n", - getDefaultLibFilename: getDefaultLibraryFilename, + getDefaultLibFilename, writeFile: (filename, data, writeByteOrderMark) => { }, getCurrentDirectory: () => host.getCurrentDirectory() }); @@ -5698,16 +5698,16 @@ module ts { /// getDefaultLibraryFilePath declare var __dirname: string; - declare var module: any; - + /** * Get the path of the default library file (lib.d.ts) as distributed with the typescript * node package. * The functionality is not supported if the ts module is consumed outside of a node module. */ export function getDefaultLibraryFilePath(options: CompilerOptions): string { - if (typeof module !== "undefined" && module.exports) { - return __dirname + directorySeparator + getDefaultLibraryFilename(options); + // Check __dirname is defined and that we are on a node.js system. + if (typeof __dirname !== "undefined") { + return __dirname + directorySeparator + getDefaultLibFilename(options); } throw new Error("getDefaultLibraryFilename is only supported when consumed as a node module. "); diff --git a/tests/cases/unittests/services/documentRegistry.ts b/tests/cases/unittests/services/documentRegistry.ts index 598416b9812..339c8866329 100644 --- a/tests/cases/unittests/services/documentRegistry.ts +++ b/tests/cases/unittests/services/documentRegistry.ts @@ -5,8 +5,8 @@ describe("DocumentRegistry", () => { var documentRegistry = ts.createDocumentRegistry(); var defaultCompilerOptions = ts.getDefaultCompilerOptions(); - var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); - var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); + var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); + var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); assert(f1 === f2, "DocumentRegistry should return the same document for the same name"); }); @@ -17,21 +17,21 @@ describe("DocumentRegistry", () => { // change compilation setting that doesn't affect parsing - should have the same document compilerOptions.declaration = true; - var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); + var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); compilerOptions.declaration = false; - var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); + var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); assert(f1 === f2, "Expected to have the same document instance"); // change value of compilation setting that is used during production of AST - new document is required compilerOptions.target = ts.ScriptTarget.ES3; - var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); + var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); assert(f1 !== f3, "Changed target: Expected to have different instances of document"); compilerOptions.module = ts.ModuleKind.CommonJS; - var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), "1"); + var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, ts.ScriptSnapshot.fromString("var x = 1;"), /* version */ "1"); assert(f3 === f4, "Changed module: Expected to have the same instance of the document"); });