mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Merge pull request #1952 from Microsoft/jasonra-disallowRenameForStandardTSLib
Disallow rename for elements that are defined in the standard TypeScript...
This commit is contained in:
commit
dc06b2f6de
@ -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." },
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user