UNPKG

eslint-plugin-perfectionist

Version:

ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.

28 lines (27 loc) 922 B
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js' import { AST_NODE_TYPES } from '@typescript-eslint/utils' /** * Computes array elements for the given expression. * * @param expression - The expression to compute array elements from. * @returns An array of elements if the expression is an array or a new * expression, otherwise null. */ function computeArrayElements(expression) { switch (expression.type) { case AST_NODE_TYPES.ArrayExpression: return expression.elements case AST_NODE_TYPES.NewExpression: if (expression.callee.type !== AST_NODE_TYPES.Identifier) { return null } if (expression.callee.name !== 'Array') { return null } return expression.arguments /* v8 ignore next 2 -- @preserve Exhaustive guard. */ default: throw new UnreachableCaseError(expression) } } export { computeArrayElements }