Skip to content

Commit 7fca926

Browse files
authored
fix(41740): disallow renaming/exclude from references default keyword (microsoft#41947)
1 parent 20ce292 commit 7fca926

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

src/services/findAllReferences.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ namespace ts.FindAllReferences {
921921
// When renaming at an export specifier, rename the export and not the thing being exported.
922922
getReferencesAtExportSpecifier(exportSpecifier.name, symbol, exportSpecifier, state.createSearch(node, originalSymbol, /*comingFrom*/ undefined), state, /*addReferencesHere*/ true, /*alwaysGetReferences*/ true);
923923
}
924-
else if (node && node.kind === SyntaxKind.DefaultKeyword) {
924+
else if (node && node.kind === SyntaxKind.DefaultKeyword && symbol.escapedName === InternalSymbolName.Default) {
925925
addReference(node, symbol, state);
926926
searchForImportsOfExport(node, symbol, { exportingModuleSymbol: Debug.checkDefined(symbol.parent, "Expected export symbol to have a parent"), exportKind: ExportKind.Default }, state);
927927
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
undefined
2+
3+
undefined
4+
5+
undefined
6+
7+
undefined
8+
9+
// === /tests/cases/fourslash/findAllRefsForDefaultKeyword.ts ===
10+
// function f(value: string, default: string) {}
11+
//
12+
// const default = 1;
13+
//
14+
// function default() {}
15+
//
16+
// class default {}
17+
//
18+
// const foo = {
19+
// /*FIND ALL REFS*/[|default|]: 1
20+
// }
21+
22+
[
23+
{
24+
"definition": {
25+
"containerKind": "",
26+
"containerName": "",
27+
"fileName": "/tests/cases/fourslash/findAllRefsForDefaultKeyword.ts",
28+
"kind": "property",
29+
"name": "(property) default: number",
30+
"textSpan": {
31+
"start": 126,
32+
"length": 7
33+
},
34+
"displayParts": [
35+
{
36+
"text": "(",
37+
"kind": "punctuation"
38+
},
39+
{
40+
"text": "property",
41+
"kind": "text"
42+
},
43+
{
44+
"text": ")",
45+
"kind": "punctuation"
46+
},
47+
{
48+
"text": " ",
49+
"kind": "space"
50+
},
51+
{
52+
"text": "default",
53+
"kind": "propertyName"
54+
},
55+
{
56+
"text": ":",
57+
"kind": "punctuation"
58+
},
59+
{
60+
"text": " ",
61+
"kind": "space"
62+
},
63+
{
64+
"text": "number",
65+
"kind": "keyword"
66+
}
67+
],
68+
"contextSpan": {
69+
"start": 126,
70+
"length": 10
71+
}
72+
},
73+
"references": [
74+
{
75+
"textSpan": {
76+
"start": 126,
77+
"length": 7
78+
},
79+
"fileName": "/tests/cases/fourslash/findAllRefsForDefaultKeyword.ts",
80+
"contextSpan": {
81+
"start": 126,
82+
"length": 10
83+
},
84+
"isWriteAccess": true,
85+
"isDefinition": true
86+
}
87+
]
88+
}
89+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @noLib: true
4+
////function f(value: string, /*1*/default: string) {}
5+
////
6+
////const /*2*/default = 1;
7+
////
8+
////function /*3*/default() {}
9+
////
10+
////class /*4*/default {}
11+
////
12+
////const foo = {
13+
//// /*5*/default: 1
14+
////}
15+
16+
verify.baselineFindAllReferences("1", "2", "3", "4", "5");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @noLib: true
4+
////function f(value: string, /*1*/default: string) {}
5+
////
6+
////const /*2*/default = 1;
7+
////
8+
////function /*3*/default() {}
9+
////
10+
////class /*4*/default {}
11+
////
12+
////const foo = {
13+
//// /*5*/[|default|]: 1
14+
////}
15+
16+
for (const marker of ["1", "2", "3", "4"]) {
17+
goTo.marker(marker);
18+
verify.renameInfoFailed(ts.Diagnostics.You_cannot_rename_this_element.message);
19+
}
20+
21+
goTo.marker("5");
22+
verify.renameInfoSucceeded("default");

0 commit comments

Comments
 (0)