Skip to content

Commit

Permalink
fix: special handling of identifiers no longer required
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed May 3, 2024
1 parent d29371e commit 39029f2
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/utils/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ export function getTypeOfNode<Context extends RuleContext<string, BaseOptions>>(
const { esTreeNodeToTSNodeMap } = getParserServices(context);

const tsNode = esTreeNodeToTSNodeMap.get(node);
const typedNode = ts.isIdentifier(tsNode) ? tsNode.parent : tsNode;
return getTypeOfTSNode(typedNode, context);
return getTypeOfTSNode(tsNode, context);
}

/**
Expand All @@ -210,11 +209,10 @@ export function getTypeNodeOfNode<

const { esTreeNodeToTSNodeMap } = getParserServices(context);

const tsNode = esTreeNodeToTSNodeMap.get(node);
const typedNode = (
ts.isIdentifier(tsNode) ? tsNode.parent : tsNode
) as TSNode & { type?: TypeNode };
return typedNode.type ?? null;
const tsNode = esTreeNodeToTSNodeMap.get(node) as TSNode & {
type?: TypeNode;
};
return tsNode.type ?? null;
}

/**
Expand All @@ -227,13 +225,10 @@ export function getTypeDataOfNode<

const { esTreeNodeToTSNodeMap } = getParserServices(context);

const tsNode = esTreeNodeToTSNodeMap.get(node);
const typedNode = (
ts.isIdentifier(tsNode) ? tsNode.parent : tsNode
) as TSNode & {
const tsNode = esTreeNodeToTSNodeMap.get(node) as TSNode & {
type?: TypeNode;
};
return [getTypeOfTSNode(typedNode, context), typedNode.type ?? null];
return [getTypeOfTSNode(tsNode, context), tsNode.type ?? null];
}

/**
Expand Down Expand Up @@ -306,10 +301,9 @@ export function getTypeImmutabilityOfNode<
const overrides =
explicitOverrides ?? getImmutabilityOverrides(context.settings);
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
const typedNode = ts.isIdentifier(tsNode) ? tsNode.parent : tsNode;
const typeLike =
(typedNode as { type?: TypeNode }).type ??
getTypeOfNode(parserServices.tsNodeToESTreeNodeMap.get(typedNode), context);
(tsNode as { type?: TypeNode }).type ??
getTypeOfNode(parserServices.tsNodeToESTreeNodeMap.get(tsNode), context);

return getTypeImmutability(
parserServices.program,
Expand Down

0 comments on commit 39029f2

Please sign in to comment.