How to use the typescript.isCallExpression 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 CyriacBr / es5-to-dts / src / generator / classCollector.ts View on Github external
_checkPropertiesDefinition(node: ts.ExpressionStatement) {
    const str = node.getText();
    if (str.match(/Object\.definePropert.+\((.+?),/i) && ts.isCallExpression(node.expression)) {
      // - Extract properties from getter/setter
      const properties: Property[] = [];
      const value = RegExp.$1;
      let symbol: string, _static: boolean;
      if (value.match(/(.+)\.prototype/)) {
        symbol = RegExp.$1;
        _static = false;
      } else {
        symbol = value;
        _static = true;
      }
      const arg = (node.expression as ts.CallExpression).arguments[1];
      if (ts.isStringLiteral(arg)) {
        let jsDoc: ts.JSDoc = (node as any).jsDoc || null;
        const lastJsDoc: ts.JSDoc = jsDoc ? jsDoc[(jsDoc as any).length - 1] : null;
        const objArg = (node.expression as ts.CallExpression).arguments[2];
github rimeto / ts-optchain / src / transform / transform.ts View on Github external
function visitNode(node: ts.Node, program: ts.Program): ts.Node {

  const typeChecker = program.getTypeChecker();
  if (ts.isCallExpression(node)) {
    // Check if function call expression is an oc chain, e.g.,
    //   oc(x).y.z()
    if (_isValidOCType(typeChecker.typeToTypeNode(typeChecker.getTypeAtLocation(node.expression)))) {
      // We found an OCType data accessor call
      if (!node.arguments.length) {
        // No default value argument: replace CallExpression node with child expression
        return _expandOCExpression(node.expression);
      }

      // Default argument is provided: replace CallExpression with child expression OR default
      return _expandOCExpression(node.expression, node.arguments[0]);
    } else if (node.arguments.length) {
      // Check for a naked oc(x) call
      const callTypeNode = typeChecker.typeToTypeNode(typeChecker.getTypeAtLocation(node));
      if (_isValidOCType(callTypeNode)) {
        // Unwrap oc(x) -> x
github angular / tsickle / src / decorators.ts View on Github external
function rewriteDecorator(node: ts.Node, context: ts.TransformationContext): ts.Node|undefined {
  if (!ts.isCallExpression(node)) {
    return;
  }
  const identifier = node.expression;
  if (!ts.isIdentifier(identifier) || identifier.text !== '__decorate') {
    return;
  }
  const args = [...node.arguments];
  if (args.length !== 4) {
    // Some decorators, like class decorators, have fewer arguments, and don't
    // need help to be renaming-safe.
    return;
  }
  const untypedFieldNameLiteral = args[2];
  if (!ts.isStringLiteral(untypedFieldNameLiteral)) {
    // This is allowed, for example:
    //
github fossasia / susper.com / node_modules / @angular-devkit / build-optimizer / src / transforms / prefix-classes.js View on Github external
&& returnStatement.expression.text === firstStatement.name.text;
    }
    else if (functionExpression.parameters.length !== 1) {
        return false;
    }
    // Potential extended class
    const functionParameter = functionExpression.parameters[0];
    if (!ts.isIdentifier(functionParameter.name)
        || functionParameter.name.text !== superParameterName) {
        return false;
    }
    if (functionStatements.length < 3) {
        return false;
    }
    if (!ts.isExpressionStatement(firstStatement)
        || !ts.isCallExpression(firstStatement.expression)) {
        return false;
    }
    const extendCallExpression = firstStatement.expression;
    if (!ts.isIdentifier(extendCallExpression.expression)
        || !extendCallExpression.expression.text.endsWith(extendsHelperName)) {
        return false;
    }
    if (extendCallExpression.arguments.length === 0) {
        return false;
    }
    const lastArgument = extendCallExpression.arguments[extendCallExpression.arguments.length - 1];
    if (!ts.isIdentifier(lastArgument) || lastArgument.text !== functionParameter.name.text) {
        return false;
    }
    const secondStatement = functionStatements[1];
    return ts.isFunctionDeclaration(secondStatement)
github theseanl / tscc / packages / tscc / src / transformer / transformer_utils.ts View on Github external
export function isVariableRequireStatement(stmt: ts.Statement): {
	importedUrl: string,
	newIdent: ts.Identifier
} {
	if (!ts.isVariableStatement(stmt)) return;
	// Verify it's a single decl (and not "var x = ..., y = ...;").
	if (stmt.declarationList.declarations.length !== 1) return;
	const decl = stmt.declarationList.declarations[0];

	// Grab the variable name (avoiding things like destructuring binds).
	if (decl.name.kind !== ts.SyntaxKind.Identifier) return;
	if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {
		return;
	}
	const importedUrl = extractRequire(decl.initializer);
	if (!importedUrl) return;
	return {importedUrl, newIdent: decl.name};
}
github ionic-team / stencil / src / compiler / transformers / static-to-meta / vdom.ts View on Github external
export const gatherVdomMeta = (m: d.Module | d.ComponentCompilerMeta, args: ts.NodeArray) => {
  m.hasVdomRender = true;

  // Parse vdom tag
  const hTag = args[0];
  if (!ts.isStringLiteral(hTag) && (!ts.isIdentifier(hTag) || hTag.text !== 'Host')) {
    m.hasVdomFunctional = true;
  }

  // Parse attributes
  if (args.length > 1) {
    const objectLiteral = args[1];
    if (ts.isCallExpression(objectLiteral) || ts.isIdentifier(objectLiteral)) {
      m.hasVdomAttribute = true;
      m.hasVdomKey = true;
      m.hasVdomClass = true;
      m.hasVdomListener = true;
      m.hasVdomRef = true;
      m.hasVdomXlink = true;
      m.hasVdomStyle = true;

    } else if (ts.isObjectLiteralExpression(objectLiteral)) {
      objectLiteral.properties.forEach(prop => {
        m.hasVdomAttribute = true;
        if (ts.isSpreadAssignment(prop) || ts.isComputedPropertyName(prop.name)) {
          m.hasVdomKey = true;
          m.hasVdomClass = true;
          m.hasVdomListener = true;
          m.hasVdomXlink = true;
github aurelia / aurelia / compiler / ts-util.ts View on Github external
return decorators.slice(0).find(dec => {
    let expression = dec.expression;
    if (ts.isCallExpression(expression)) {
      let innerExpression = expression.expression;
      return ts.isIdentifier(innerExpression) && innerExpression.escapedText.toString() === name;
    } else if (ts.isIdentifier(dec.expression)) {
      return dec.expression.escapedText.toString() === name;
    }
    return false;
  }) || null;
}
github angular / components / tools / dgeni / common / directive-metadata.ts View on Github external
    .filter(decorator => decorator.expression && isCallExpression(decorator.expression))
    .map(decorator => decorator.expression as CallExpression)
github neo-one-suite / neo-one / packages / neo-one-smart-contract-compiler / src / compile / helper / function / CallLikeHelper.ts View on Github external
const handleBuiltinMemberCall = (builtinProp: Builtin, memberLike: CallMemberLikeExpression, visited: boolean) => {
      if (ts.isCallExpression(expression)) {
        if (isBuiltinMemberCall(builtinProp)) {
          builtinProp.emitCall(sb, memberLike, expression, optionsIn);

          return;
        }

        if (isBuiltinInstanceMemberCall(builtinProp)) {
          builtinProp.emitCall(sb, memberLike, expression, optionsIn, visited);

          return;
        }
      } else if (ts.isTaggedTemplateExpression(expression)) {
        if (isBuiltinMemberTemplate(builtinProp)) {
          builtinProp.emitCall(sb, memberLike, expression, optionsIn);

          return;