Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
getDeclarationFromName,
getDeclarationOfKind,
getEffectiveModifierFlags,
getEscapedTextOfIdentifierOrLiteral,
getLocalSymbolForExportDefault,
getMeaningFromDeclaration,
getMeaningFromLocation,
Expand Down Expand Up @@ -149,6 +150,7 @@ import {
isJsxClosingElement,
isJsxElement,
isJsxFragment,
isJsxNamespacedName,
isJsxOpeningElement,
isJsxSelfClosingElement,
isJumpStatementTarget,
Expand Down Expand Up @@ -202,6 +204,7 @@ import {
isVoidExpression,
isWriteAccess,
JSDocPropertyLikeTag,
JsxNamespacedName,
length,
map,
mapDefined,
Expand Down Expand Up @@ -325,7 +328,7 @@ export interface SpanEntry {
function nodeEntry(node: Node, kind: NodeEntryKind = EntryKind.Node): NodeEntry {
return {
kind,
node: (node as NamedDeclaration).name || node,
node: isJsxNamespacedName(node) ? node : ((node as NamedDeclaration).name || node),
context: getContextNodeForNodeEntry(node),
};
}
Expand Down Expand Up @@ -1052,11 +1055,14 @@ export namespace Core {
}

export function getAdjustedNode(node: Node, options: Options): Node {
if (isIdentifier(node) && isJsxNamespacedName(node.parent)) {
node = node.parent;
}
if (options.use === FindReferencesUse.References) {
node = getAdjustedReferenceLocation(node);
return getAdjustedReferenceLocation(node);
}
else if (options.use === FindReferencesUse.Rename) {
node = getAdjustedRenameLocation(node);
if (options.use === FindReferencesUse.Rename) {
return getAdjustedRenameLocation(node);
}
return node;
}
Expand Down Expand Up @@ -1835,6 +1841,8 @@ export namespace Core {
// falls through I guess
case SyntaxKind.Identifier:
return (node as PrivateIdentifier | Identifier).text.length === searchSymbolName.length;
case SyntaxKind.JsxNamespacedName:
return (getEscapedTextOfIdentifierOrLiteral(node as JsxNamespacedName) as string).length === searchSymbolName.length;
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.StringLiteral: {
const str = node as StringLiteralLike;
Expand Down
1 change: 1 addition & 0 deletions src/services/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export function nodeIsEligibleForRename(node: Node): boolean {
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.ThisKeyword:
case SyntaxKind.JsxNamespacedName:
return true;
case SyntaxKind.NumericLiteral:
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral);
Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@ export function getNameTable(sourceFile: SourceFile): Map<__String, number> {
function initializeNameTable(sourceFile: SourceFile): void {
const nameTable = sourceFile.nameTable = new Map();
sourceFile.forEachChild(function walk(node) {
if (isIdentifier(node) && !isTagName(node) && node.escapedText || isStringOrNumericLiteralLike(node) && literalIsName(node)) {
if (isIdentifier(node) && !isTagName(node) && node.escapedText || isStringOrNumericLiteralLike(node) && literalIsName(node) || isJsxNamespacedName(node)) {
const text = getEscapedTextOfIdentifierOrLiteral(node);
nameTable.set(text, nameTable.get(text) === undefined ? node.pos : -1);
}
Expand Down
7 changes: 6 additions & 1 deletion src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ import {
isJSDocTypeAlias,
isJsxElement,
isJsxExpression,
isJsxNamespacedName,
isJsxOpeningLikeElement,
isJsxText,
isKeyword,
Expand Down Expand Up @@ -1322,6 +1323,9 @@ function getAdjustedLocationForHeritageClause(node: HeritageClause) {
}

function getAdjustedLocation(node: Node, forRename: boolean): Node {
if (isIdentifier(node) && isJsxNamespacedName(node.parent)) {
node = node.parent;
}
const { parent } = node;
// /**/<modifier> [|name|] ...
// /**/<modifier> <class|interface|type|enum|module|namespace|function|get|set> [|name|] ...
Expand Down Expand Up @@ -1547,7 +1551,8 @@ export function getAdjustedRenameLocation(node: Node): Node {
* @internal
*/
export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node {
return getTouchingToken(sourceFile, position, n => isPropertyNameLiteral(n) || isKeyword(n.kind) || isPrivateIdentifier(n));
const token = getTouchingToken(sourceFile, position, n => isPropertyNameLiteral(n) || isKeyword(n.kind) || isPrivateIdentifier(n));
return isIdentifier(token) && isJsxNamespacedName(token.parent) ? token.parent : token;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// === findAllReferences ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|{| isWriteAccess: true |}prop:foo|]': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el /*FIND ALL REFS*/<|[|prop:foo|]="bar"|> />

// === Definitions ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|prop:foo|]': string;|>
// };
// }
// }

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "property",
"name": "(property) 'prop:foo': string",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "'prop:foo'",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
]
}
]



// === findAllReferences ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|{| isWriteAccess: true |}prop:foo|]': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el <|[|prop:/*FIND ALL REFS*/foo|]="bar"|> />

// === Definitions ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|prop:foo|]': string;|>
// };
// }
// }

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "property",
"name": "(property) 'prop:foo': string",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "'prop:foo'",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
]
}
]



// === findAllReferences ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'/*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}prop:foo|]': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el <|[|prop:foo|]="bar"|> />

// === Definitions ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'/*FIND ALL REFS*/[|prop:foo|]': string;|>
// };
// }
// }

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "property",
"name": "(property) 'prop:foo': string",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "'prop:foo'",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// === findRenameLocations ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|prop:fooRENAME|]': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el /*RENAME*/<|[|prop:fooRENAME|]="bar"|> />



// === findRenameLocations ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|prop:fooRENAME|]': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el <|[|prop:/*RENAME*/fooRENAME|]="bar"|> />



// === findRenameLocations ===
// === /types.d.ts ===
// declare namespace JSX {
// interface IntrinsicElements {
// 'my-el': {
// <|'[|prop:fooRENAME|]/*RENAME*/': string;|>
// };
// }
// }

// === /a.tsx ===
// <my-el <|[|prop:fooRENAME|]="bar"|> />
19 changes: 19 additions & 0 deletions tests/cases/fourslash/findAllReferencesOnJsxNamespacedName1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />

// @jsx: react

// https://github.com/microsoft/TypeScript/issues/61820

// @Filename: /types.d.ts
//// declare namespace JSX {
//// interface IntrinsicElements {
//// 'my-el': {
//// '/*3*/prop:foo': string;
//// };
//// }
//// }

// @filename: /a.tsx
//// <my-el /*1*/prop:/*2*/foo="bar" />

verify.baselineFindAllReferences("1", "2", "3");
21 changes: 21 additions & 0 deletions tests/cases/fourslash/renameOnJsxNamespacedName1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />

// @jsx: react

// https://github.com/microsoft/TypeScript/issues/61820

// @Filename: /types.d.ts
//// declare namespace JSX {
//// interface IntrinsicElements {
//// 'my-el': {
//// 'prop:foo/*3*/': string;
//// };
//// }
//// }

// @filename: /a.tsx
//// <my-el /*1*/prop:/*2*/foo="bar" />

verify.baselineRename("1");
verify.baselineRename("2");
verify.baselineRename("3");
Loading