diff --git a/src/services/services.ts b/src/services/services.ts index 56e68b2f5a1..ad6643faf3c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5520,7 +5520,7 @@ module ts { var defaultLibFile = getDefaultLibFileName(host.getCompilationSettings()); for (var i = 0; i < declarations.length; i++) { var sourceFile = declarations[i].getSourceFile(); - if (sourceFile && endsWith(sourceFile.fileName, defaultLibFile)) { + if (sourceFile && isDefaultLibFile(sourceFile.fileName, defaultLibFile)) { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key)); } } @@ -5543,8 +5543,14 @@ module ts { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key)); - function endsWith(string: string, value: string): boolean { - return string.lastIndexOf(value) + value.length === string.length; + 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 {