How to use the typescript.isIdentifier function in typescript

To help you get started, we’ve selected a few typescript 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 angular / tsickle / src / googmodule.ts View on Github external
function maybeRewriteDeclareModuleId(
          original: ts.Statement, call: ts.CallExpression): ts.Statement|null {
        // Verify that the call is a call to goog.declareModuleId(...).
        if (!ts.isPropertyAccessExpression(call.expression)) {
          return null;
        }
        const propAccess = call.expression;
        if (propAccess.name.escapedText !== 'declareModuleId') {
          return null;
        }
        if (!ts.isIdentifier(propAccess.expression) ||
            propAccess.expression.escapedText !== 'goog') {
          return null;
        }

        // Verify the call takes a single string argument and grab it.
        if (call.arguments.length !== 1) {
          return null;
        }
        const arg = call.arguments[0];
        if (!ts.isStringLiteral(arg)) {
          return null;
        }
        const moduleId = arg.text;
        // replace goog.declareModuleId['foo.bar'] with:
        // goog.loadedModules_['foo.bar'] = {
        //   exports: exports,
github JoshuaKGoldberg / TypeStat / src / mutators / builtIn / fixIncompleteTypes / fixIncompleteInterfaceOrTypeLiteralGenerics / expandValuesAssignedToReferenceNodes.ts View on Github external
type: typeChecker.getTypeAtLocation(node.parent.parent.right),
            };
        }

        // Case:
        //   declare class Container { values: T; }
        //   type Values = {};
        //   const container = new Container({});
        //   container.values.laterAssigned = true;
        // Case:
        //   declare class Container { values: T; }
        //   type Values = {};
        //   new Container({}).values.quicklyAssigned = true;
        if (
            ts.isPropertyAccessExpression(node.parent.parent) &&
            ts.isIdentifier(node.parent.parent.name) &&
            isNodeAssigningBinaryExpression(node.parent.parent.parent) &&
            typeChecker.getTypeAtLocation(node.parent) === originalType
        ) {
            return {
                name: node.parent.parent.name.getText(),
                type: typeChecker.getTypeAtLocation(node.parent.parent.parent.right),
            };
        }
    }

    return undefined;
};
github angular / components / src / material / schematics / ng-update / upgrade-rules / hammer-gestures-v9 / hammer-gestures-rule.ts View on Github external
private _isReferenceToHammerConfigToken(expr: ts.Expression) {
    const unwrapped = unwrapExpression(expr);
    if (ts.isIdentifier(unwrapped)) {
      return this._hammerConfigTokenReferences.some(r => r.node === unwrapped);
    } else if (ts.isPropertyAccessExpression(unwrapped)) {
      return this._hammerConfigTokenReferences.some(r => r.node === unwrapped.name);
    }
    return false;
  }
github relay-tools / relay-compiler-language-typescript / src / FindGraphQLTags.ts View on Github external
function createContainerName(
  callExpr: ts.CallExpression
):
  | "createFragmentContainer"
  | "createRefetchContainer"
  | "createPaginationContainer" {
  if (
    ts.isIdentifier(callExpr.expression) &&
    isCreateContainerFunction(callExpr.expression.text)
  ) {
    return callExpr.expression.text;
  }
  if (
    ts.isPropertyAccessExpression(callExpr.expression) &&
    ts.isIdentifier(callExpr.expression.expression) &&
    callExpr.expression.expression.text === "Relay"
  ) {
    if (isCreateContainerFunction(callExpr.expression.name.text)) {
      return callExpr.expression.name.text;
    }
  }
  throw new Error("Not a relay create container call");
}
github angular / angular / packages / compiler-cli / src / ngtsc / switch / src / switch.ts View on Github external
function findPostSwitchIdentifier(
    statements: ReadonlyArray, name: string): ts.Identifier|null {
  for (const stmt of statements) {
    if (ts.isVariableStatement(stmt)) {
      const decl = stmt.declarationList.declarations.find(
          decl => ts.isIdentifier(decl.name) && decl.name.text === name);
      if (decl !== undefined) {
        return decl.name as ts.Identifier;
      }
    } else if (ts.isFunctionDeclaration(stmt) || ts.isClassDeclaration(stmt)) {
      if (stmt.name !== undefined && ts.isIdentifier(stmt.name) && stmt.name.text === name) {
        return stmt.name;
      }
    }
  }
  return null;
}
github angular / angular / packages / compiler-cli / src / ngtsc / reflection / src / typescript.ts View on Github external
function getQualifiedNameRoot(qualifiedName: ts.QualifiedName): ts.Identifier|null {
  while (ts.isQualifiedName(qualifiedName.left)) {
    qualifiedName = qualifiedName.left;
  }
  return ts.isIdentifier(qualifiedName.left) ? qualifiedName.left : null;
}
github angular / angular / packages / compiler-cli / ngcc / src / host / commonjs_host.ts View on Github external
function findNamespaceOfIdentifier(id: ts.Identifier): ts.Identifier|null {
  return id.parent && ts.isPropertyAccessExpression(id.parent) &&
          ts.isIdentifier(id.parent.expression) ?
      id.parent.expression :
      null;
}
github GoogleChrome / lighthouse / lighthouse-core / scripts / i18n / collect-strings.js View on Github external
function getIdentifier(node) {
  if (!node.name || !tsc.isIdentifier(node.name)) throw new Error('no Identifier found');

  return node.name.text;
}
github airtasker / spot / lib / src / parser.ts View on Github external
function extractObjectType(
  sourceFile: ts.SourceFile,
  declaration: ts.TypeLiteralNode | ts.InterfaceDeclaration
): ObjectType {
  const properties: {
    [key: string]: Type;
  } = {};
  for (const member of declaration.members) {
    if (
      !member.name ||
      !ts.isIdentifier(member.name) ||
      !ts.isPropertySignature(member) ||
      !member.type
    ) {
      throw panic(
        `Expected a named and typed property, got this instead: ${member.getText(
          sourceFile
        )}`
      );
    }
    let type = extractType(sourceFile, member.type);
    if (member.questionToken) {
      type = optionalType(type);
    }
    properties[member.name.getText(sourceFile)] = type;
  }
  return objectType(properties);
github govim / govim / cmd / govim / internal / golang_org_x_tools / lsp / protocol / typescript / util.ts View on Github external
function f(n: ts.Node) {
    seenAdd(kinds(n));
    if (ts.isIdentifier(n)) {
      pr(`${indent} ${loc(n)} ${strKind(n)} ${n.text} \n`);
    }
    else if (ts.isPropertySignature(n) || ts.isEnumMember(n)) {
      pra(`${indent} ${loc(n)} ${strKind(n)} \n`);
    }
    else if (ts.isTypeLiteralNode(n)) {
      let m = n.members;
      pr(`${indent} ${loc(n)} ${strKind(n)} ${m.length} \n`);
    }
    else if (ts.isStringLiteral(n)) {
      pr(`${indent} ${loc(n)} ${strKind(n)} ${n.text} \n`);
    }
    else { pr(`${indent} ${loc(n)} ${strKind(n)} \n`); }
    indent += ' .';
    ts.forEachChild(n, f);
    indent = indent.slice(0, indent.length - 2);