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 Jun 10, 2024
1 parent 51957bb commit 830fe7c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type ImmutabilityOverrides,
getTypeImmutability,
} from "is-immutable-type";
import { isIntrinsicErrorType } from "ts-api-utils";
import { type Node as TSNode, type Type, type TypeNode } from "typescript";

import ts from "#eslint-plugin-functional/conditional-imports/typescript";
Expand Down Expand Up @@ -262,14 +263,19 @@ 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);
let m_typeLike: Type | TypeNode | undefined = (tsNode as { type?: TypeNode })
.type;

if (m_typeLike === undefined) {
m_typeLike = getTypeOfTSNode(tsNode, context);
if (isIntrinsicErrorType(m_typeLike)) {
return Immutability.Unknown;
}
}

return getTypeImmutability(
parserServices.program,
typeLike,
m_typeLike,
overrides,
// Don't use the global cache in testing environments as it may cause errors when switching between different config options.
process.env["NODE_ENV"] !== "test",
Expand Down

0 comments on commit 830fe7c

Please sign in to comment.