isSimpleType (utilities/is-simple-type.js)

prettier · src/language-js/utilities/is-simple-type.js · javascript · MIT
dev-tools

Utility function that determines if an AST node represents a simple type, used in language parsing.

// Source: https://github.com/prettier/prettier | License: MIT | Copyright James Long and contributors
// Provided via justclaw.it.com; keep this notice with the code.
import isFlowKeywordType from "./is-flow-keyword-type.js";
import { isSimpleTypeAnnotation } from "./is-simple-type-annotation.js";
import isTsKeywordType from "./is-ts-keyword-type.js";

/**
@import {
  Node,
} from "../types/estree.js";
*/

/**
 * @param {Node} node
 * @returns {boolean}
 */
function isSimpleType(node) {
  return (
    isTsKeywordType(node) ||
    isFlowKeywordType(node) ||
    isSimpleTypeAnnotation(node) ||
    (node.type === "GenericTypeAnnotation" && !node.typeParameters) ||
    (node.type === "TSTypeReference" && !node.typeArguments)
  );
}

export { isSimpleType };

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key