Skip to content

Fixed reference searches related to JsxNamespacedName #62124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ import {
isJsxClosingElement,
isJsxElement,
isJsxFragment,
isJsxNamespacedName,
isJsxOpeningElement,
isJsxSelfClosingElement,
isJumpStatementTarget,
Expand Down Expand Up @@ -202,6 +203,7 @@ import {
isVoidExpression,
isWriteAccess,
JSDocPropertyLikeTag,
JsxNamespacedName,
length,
map,
mapDefined,
Expand Down Expand Up @@ -325,7 +327,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 @@ -1835,6 +1837,10 @@ export namespace Core {
// falls through I guess
case SyntaxKind.Identifier:
return (node as PrivateIdentifier | Identifier).text.length === searchSymbolName.length;
case SyntaxKind.JsxNamespacedName: {
const { namespace, name } = node as JsxNamespacedName;
return (namespace.text.length + 1 + name.text.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
4 changes: 3 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 @@ -1547,7 +1548,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"
}
]
}
]
Loading
Loading