diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 7bf95dcc846..1188d346191 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -451,6 +451,7 @@ module ts { _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, + You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b4944f56d77..b1a794716a4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1798,6 +1798,10 @@ "category": "Error", "code": 8000 }, + "You cannot rename elements that are defined in the standard TypeScript library.": { + "category": "Error", + "code": 8001 + }, "'yield' expressions are not currently supported.": { "category": "Error", "code": 9000 diff --git a/src/services/services.ts b/src/services/services.ts index 677af16bdc4..d328af1ee35 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5544,22 +5544,44 @@ module ts { var symbol = typeInfoResolver.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. - if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol, typeInfoResolver, node); - if (kind) { - return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, - getSymbolModifiers(symbol), - createTextSpan(node.getStart(), node.getWidth())); + if (symbol) { + 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 kind = getSymbolKind(symbol, typeInfoResolver, node); + if (kind) { + return { + canRename: true, + localizedErrorMessage: undefined, + displayName: symbol.name, + fullDisplayName: typeInfoResolver.getFullyQualifiedName(symbol), + kind: kind, + kindModifiers: getSymbolModifiers(symbol), + triggerSpan: createTextSpan(node.getStart(), node.getWidth()) + }; + } } } } 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, - localizedErrorMessage: getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element.key), + localizedErrorMessage: localizedErrorMessage, displayName: undefined, fullDisplayName: undefined, kind: undefined, @@ -5567,18 +5589,6 @@ module ts { triggerSpan: undefined }; } - - function getRenameInfo(displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: TextSpan): RenameInfo { - return { - canRename: true, - localizedErrorMessage: undefined, - displayName, - fullDisplayName, - kind, - kindModifiers, - triggerSpan - }; - } } return {