How to use the ts-morph.TypeGuards.isNullLiteral function in ts-morph

To help you get started, we’ve selected a few ts-morph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airtasker / spot / lib / src / neu / parsers / type-parser.ts View on Github external
export function parseType(
  typeNode: TypeNode,
  typeTable: TypeTable,
  lociTable: LociTable
): Result {
  // Type references must be parsed first to ensure internal type aliases are handled
  if (TypeGuards.isTypeReferenceNode(typeNode)) {
    if (typeNode.getType().isArray()) {
      return parseArrayConstructorType(typeNode, typeTable, lociTable);
    }
    return parseTypeReference(typeNode, typeTable, lociTable);
  } else if (TypeGuards.isNullLiteral(typeNode)) {
    return ok(nullType());
    // TODO: discourage native boolean keyword?
  } else if (TypeGuards.isBooleanKeyword(typeNode)) {
    return ok(booleanType());
    // TODO: discourage native string keyword?
  } else if (TypeGuards.isStringKeyword(typeNode)) {
    return ok(stringType());
    // TODO: discourage native number keyword?
  } else if (TypeGuards.isNumberKeyword(typeNode)) {
    return ok(floatType());
  } else if (TypeGuards.isLiteralTypeNode(typeNode)) {
    return parseLiteralType(typeNode);
  } else if (TypeGuards.isArrayTypeNode(typeNode)) {
    return parseArrayType(typeNode, typeTable, lociTable);
  } else if (TypeGuards.isTypeLiteralNode(typeNode)) {
    return parseObjectLiteralType(typeNode, typeTable, lociTable);
github airtasker / spot / lib / src / parsers / utilities / type-parser.ts View on Github external
export function parseTypeNode(typeNode: TypeNode): DataType {
  // Type references must be parsed first to ensure internal type aliases are handled
  if (TypeGuards.isTypeReferenceNode(typeNode)) {
    return parseTypeReference(typeNode);
  } else if (TypeGuards.isNullLiteral(typeNode)) {
    return NULL;
  } else if (TypeGuards.isBooleanKeyword(typeNode)) {
    return BOOLEAN;
  } else if (TypeGuards.isStringKeyword(typeNode)) {
    return STRING;
  } else if (TypeGuards.isNumberKeyword(typeNode)) {
    return FLOAT;
  } else if (TypeGuards.isLiteralTypeNode(typeNode)) {
    return parseLiteralType(typeNode);
  } else if (TypeGuards.isArrayTypeNode(typeNode)) {
    return parseArrayType(typeNode);
  } else if (TypeGuards.isTypeLiteralNode(typeNode)) {
    return parseObjectLiteralType(typeNode);
  } else if (TypeGuards.isUnionTypeNode(typeNode)) {
    return parseUnionType(typeNode);
  } else if (TypeGuards.isIndexedAccessTypeNode(typeNode)) {
github airtasker / spot / lib / src / parsers / utilities / expression-parser.ts View on Github external
export function parseExpression(expression: Expression): DataExpression {
  if (TypeGuards.isNullLiteral(expression)) {
    return nullExpression();
  } else if (TypeGuards.isBooleanLiteral(expression)) {
    return booleanExpression(expression.getLiteralValue());
  } else if (TypeGuards.isStringLiteral(expression)) {
    return stringExpression(expression.getLiteralValue());
  } else if (TypeGuards.isPrefixUnaryExpression(expression)) {
    const operand = expression.getOperand();
    if (!TypeGuards.isNumericLiteral(operand)) {
      throw new Error("unary operators may only be used with numeric literals");
    }
    switch (expression.getOperatorToken()) {
      case SyntaxKind.MinusToken:
        return numberExpression(-operand.getLiteralValue());
      case SyntaxKind.PlusToken:
        return numberExpression(operand.getLiteralValue());
      default: