fix(41740): disallow renaming/exclude from references default keyword (#41947)

This commit is contained in:
Oleksandr T 2021-02-18 03:07:31 +02:00 committed by GitHub
parent 20ce292484
commit 7fca9267e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 1 deletions

View File

@ -921,7 +921,7 @@ namespace ts.FindAllReferences {
// When renaming at an export specifier, rename the export and not the thing being exported.
getReferencesAtExportSpecifier(exportSpecifier.name, symbol, exportSpecifier, state.createSearch(node, originalSymbol, /*comingFrom*/ undefined), state, /*addReferencesHere*/ true, /*alwaysGetReferences*/ true);
}
else if (node && node.kind === SyntaxKind.DefaultKeyword) {
else if (node && node.kind === SyntaxKind.DefaultKeyword && symbol.escapedName === InternalSymbolName.Default) {
addReference(node, symbol, state);
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: Debug.checkDefined(symbol.parent, "Expected export symbol to have a parent"), exportKind: ExportKind.Default }, state);
}

View File

@ -0,0 +1,89 @@
undefined
undefined
undefined
undefined
// === /tests/cases/fourslash/findAllRefsForDefaultKeyword.ts ===
// function f(value: string, default: string) {}
//
// const default = 1;
//
// function default() {}
//
// class default {}
//
// const foo = {
// /*FIND ALL REFS*/[|default|]: 1
// }
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/tests/cases/fourslash/findAllRefsForDefaultKeyword.ts",
"kind": "property",
"name": "(property) default: number",
"textSpan": {
"start": 126,
"length": 7
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "default",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"contextSpan": {
"start": 126,
"length": 10
}
},
"references": [
{
"textSpan": {
"start": 126,
"length": 7
},
"fileName": "/tests/cases/fourslash/findAllRefsForDefaultKeyword.ts",
"contextSpan": {
"start": 126,
"length": 10
},
"isWriteAccess": true,
"isDefinition": true
}
]
}
]

View File

@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @noLib: true
////function f(value: string, /*1*/default: string) {}
////
////const /*2*/default = 1;
////
////function /*3*/default() {}
////
////class /*4*/default {}
////
////const foo = {
//// /*5*/default: 1
////}
verify.baselineFindAllReferences("1", "2", "3", "4", "5");

View File

@ -0,0 +1,22 @@
/// <reference path="fourslash.ts" />
// @noLib: true
////function f(value: string, /*1*/default: string) {}
////
////const /*2*/default = 1;
////
////function /*3*/default() {}
////
////class /*4*/default {}
////
////const foo = {
//// /*5*/[|default|]: 1
////}
for (const marker of ["1", "2", "3", "4"]) {
goTo.marker(marker);
verify.renameInfoFailed(ts.Diagnostics.You_cannot_rename_this_element.message);
}
goTo.marker("5");
verify.renameInfoSucceeded("default");