Skip to content

Commit 5becc3b

Browse files
author
Andy
authored
Rename of non-intrinsic JSX element should rename the declaration (#28066)
1 parent 82773b8 commit 5becc3b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ namespace ts {
30893089

30903090
export function isIntrinsicJsxName(name: __String | string) {
30913091
const ch = (name as string).charCodeAt(0);
3092-
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || (name as string).indexOf("-") > -1;
3092+
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || stringContains((name as string), "-");
30933093
}
30943094

30953095
function get16BitUnicodeEscapeSequence(charCode: number): string {

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ namespace ts {
15421542
synchronizeHostData();
15431543
const sourceFile = getValidSourceFile(fileName);
15441544
const node = getTouchingPropertyName(sourceFile, position);
1545-
if (isIdentifier(node) && isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) {
1545+
if (isIdentifier(node) && (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) && isIntrinsicJsxName(node.escapedText)) {
15461546
const { openingElement, closingElement } = node.parent.parent;
15471547
return [openingElement, closingElement].map((node): RenameLocation =>
15481548
({ fileName: sourceFile.fileName, textSpan: createTextSpanFromNode(node.tagName, sourceFile) }));

tests/cases/fourslash/tsxRename4.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
/// <reference path='fourslash.ts' />
22

3+
// @jsx: preserve
4+
35
//@Filename: file.tsx
46
////declare module JSX {
57
//// interface Element {}
6-
//// interface IntrinsicElements {}
8+
//// interface IntrinsicElements {
9+
//// div: {};
10+
//// }
711
////}
812
////class [|MyClass|] {}
913
////
1014
////<[|MyClass|]></[|MyClass|]>;
1115
////<[|MyClass|]/>;
16+
////
17+
////<[|div|]> </[|div|]>
18+
19+
verify.noErrors();
1220

13-
const [r0, r1, r2, r3] = test.ranges();
14-
verify.renameLocations([r0, r3], [r0, r1, r2, r3]);
15-
verify.renameLocations([r1, r2], [r1, r2]);
21+
const [r0, r1, r2, r3, d0, d1] = test.ranges();
22+
verify.rangesAreRenameLocations([r0, r1, r2, r3]);
23+
verify.rangesAreRenameLocations([d0, d1]);

0 commit comments

Comments
 (0)