β¬ οΈ Back to Table of Contents
π extractComputedName¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 4 |
| π¦ Imports | 6 |
| π Interfaces | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/util/class-scope-analyzer/extractComputedName.ts
π¦ Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
Key |
./types |
MemberNode |
./types |
privateKey |
./types |
publicKey |
./types |
Functions¶
extractNameForMember(node: MemberNode): ExtractedName | null¶
Extracts the string name for a member.
Returns: undefined
null if the name cannot be extracted due to it being computed.
Raw JSDoc
Calls:
extractNonComputedNameextractComputedName
Code
export function extractNameForMember(node: MemberNode): ExtractedName | null {
if (node.type === AST_NODE_TYPES.TSParameterProperty) {
const identifier =
node.parameter.type === AST_NODE_TYPES.Identifier
? node.parameter
: node.parameter.left;
return extractNonComputedName(identifier);
}
if (node.computed) {
return extractComputedName(node.key);
}
if (node.key.type === AST_NODE_TYPES.Literal) {
return extractComputedName(node.key);
}
return extractNonComputedName(node.key);
}
extractNameForMemberExpression(node: TSESTree.MemberExpression): ExtractedName | null¶
Extracts the string property name for a member.
Returns: undefined
null if the name cannot be extracted due to it being a computed.
Raw JSDoc
Calls:
extractComputedNameextractNonComputedName
Code
extractComputedName(computedName: TSESTree.Expression): ExtractedName | null¶
Parameters:
computedNameTSESTree.Expression
Returns: ExtractedName | null
Calls:
computedName.value?.toStringpublicKey (from ./types)
Code
function extractComputedName(
computedName: TSESTree.Expression,
): ExtractedName | null {
if (computedName.type === AST_NODE_TYPES.Literal) {
const name = computedName.value?.toString() ?? 'null';
return {
codeName: name,
key: publicKey(name),
nameNode: computedName,
};
}
if (
computedName.type === AST_NODE_TYPES.TemplateLiteral &&
computedName.expressions.length === 0
) {
const name = computedName.quasis[0].value.raw;
return {
codeName: name,
key: publicKey(name),
nameNode: computedName,
};
}
return null;
}
extractNonComputedName(nonComputedName: TSESTree.Identifier | TSESTree.PrivateIβ¦): ExtractedName | null¶
Parameters:
nonComputedNameTSESTree.Identifier | TSESTree.PrivateIdentifier
Returns: ExtractedName | null
Calls:
privateKey (from ./types)publicKey (from ./types)
Code
function extractNonComputedName(
nonComputedName: TSESTree.Identifier | TSESTree.PrivateIdentifier,
): ExtractedName | null {
const name = nonComputedName.name;
if (nonComputedName.type === AST_NODE_TYPES.PrivateIdentifier) {
return {
codeName: `#${name}`,
key: privateKey(nonComputedName),
nameNode: nonComputedName,
};
}
return {
codeName: name,
key: publicKey(name),
nameNode: nonComputedName,
};
}
Interfaces¶
ExtractedName¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
key |
Key |
β | not shown |
codeName |
string |
β | not shown |
nameNode |
TSESTree.Node |
β | not shown |
Generated by Syntax Scribe