Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5518,11 +5518,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 && endsWith(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 && getCanonicalFileName(ts.normalizePath(sourceFile.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) {
return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library.key));
}
}
}

Expand All @@ -5544,10 +5546,6 @@ 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 getRenameInfoError(localizedErrorMessage: string): RenameInfo {
return {
canRename: false,
Expand Down
5 changes: 1 addition & 4 deletions src/services/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still need the comment, and you still need to shim it.

the problem is that the released 1.4 VS plugin do not have a function called "getDefaultLibFileName", it is called "getDefaultLibFilename" with lowercase "n". this if you use the latest from master on an existing 1.4 installation it will fail. this affects users who want to try the latest bits from master.

so, to work around this, you need to shim it.. something like:

if (typeof this.shimHost.getDefaultLibFileName === "function") { 
   return this.shimHost.getDefaultLibFileName(JSON.stringify(options));
}
return "";

and i would give it a quick try in the shipped 1.4 VS as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just discussed with Mohamed. I was going to add the typeof check for getDefaultLibFileName to ensure it is backward compatible with the previous lower-cased version (getDefaultLibFilename). Case does not appear to matter for the shimHost though as both work (they return typeof "unknown"). Using a completely different method that isn't on shimHost would return typeof "undefined".

}
}

Expand Down