mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
switch to using host.getDefaultLibFileName(options)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user