eslint-plugin-perfectionist
Version:
ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
23 lines (22 loc) • 822 B
JavaScript
import { UnreachableCaseError } from '../../utils/unreachable-case-error.js'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
/**
* Computes the name of an export specifier node.
*
* @param node - The export specifier node.
* @param ignoreAlias - Whether to ignore the alias and use the local name.
* @returns The computed name of the export specifier.
*/
function computeNodeName(node, ignoreAlias) {
let identifierToCheck = ignoreAlias ? node.local : node.exported
switch (identifierToCheck.type) {
case AST_NODE_TYPES.Identifier:
return identifierToCheck.name
case AST_NODE_TYPES.Literal:
return identifierToCheck.value
/* v8 ignore next 2 -- @preserve Exhaustive guard. */
default:
throw new UnreachableCaseError(identifierToCheck)
}
}
export { computeNodeName }