mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
fix(41740): disallow renaming/exclude from references default keyword (#41947)
This commit is contained in:
parent
20ce292484
commit
7fca9267e6
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
16
tests/cases/fourslash/findAllRefsForDefaultKeyword.ts
Normal file
16
tests/cases/fourslash/findAllRefsForDefaultKeyword.ts
Normal 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");
|
||||
22
tests/cases/fourslash/renameDefaultKeyword.ts
Normal file
22
tests/cases/fourslash/renameDefaultKeyword.ts
Normal 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");
|
||||
Loading…
x
Reference in New Issue
Block a user