switch to using host.getDefaultLibFileName(options)

This commit is contained in:
Jason Ramsay
2015-02-13 11:56:39 -08:00
parent bf7bb517e0
commit a51ce92500
2 changed files with 8 additions and 19 deletions
+7 -15
View File
@@ -5517,11 +5517,13 @@ module ts {
var declarations = symbol.getDeclarations();
if (declarations && declarations.length > 0) {
// Disallow rename for elements that are defined in the standard TypeScript library.
var defaultLibFile = getDefaultLibFileName(host.getCompilationSettings());
for (var i = 0; i < declarations.length; i++) {
var sourceFile = declarations[i].getSourceFile();
if (sourceFile && isDefaultLibFile(sourceFile.fileName, defaultLibFile)) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key));
var defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings());
if (defaultLibFileName) {
for (var i = 0; i < declarations.length; i++) {
var sourceFile = declarations[i].getSourceFile();
if (sourceFile && ts.normalizePath(sourceFile.fileName) === ts.normalizePath(defaultLibFileName)) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key));
}
}
}
@@ -5543,16 +5545,6 @@ module ts {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key));
function isDefaultLibFile(fileName: string, defaultLibFile: string): boolean {
var hasValidPrefix = true;
var index = fileName.lastIndexOf(defaultLibFile);
if (index - 1 >= 0) {
var prefix = fileName[index - 1];
hasValidPrefix = (prefix === "\\" || prefix === "/");
}
return index >= 0 && hasValidPrefix && (index + defaultLibFile.length === fileName.length);
}
function getRenameInfoError(localizedErrorMessage: string): RenameInfo {
return {
canRename: false,
+1 -4
View File
@@ -274,10 +274,7 @@ module ts {
}
public getDefaultLibFileName(options: CompilerOptions): string {
// Shim the API changes for 1.5 release. This should be removed once
// TypeScript 1.5 has shipped.
return "";
//return this.shimHost.getDefaultLibFileName(JSON.stringify(options));
return this.shimHost.getDefaultLibFileName(JSON.stringify(options));
}
}