Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 7 Examples of "astq in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'astq' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

export function createTypings(moduleName: string|null, programAst: any, options: IOptions,
    reactImport: string): string {
  // #609: configure eol character
  dom.config.outputEol = options.eol || '\r\n';

  const astq = new ASTQ();
  const ast = {
    ast: programAst,
    query(query: string): any[] {
      return astq.query(programAst, query);
    },
    querySubtree(subtree: any, query: string): any[] {
      return astq.query(subtree, query);
    }
  };
  const reactComponentName = getReactComponentName(ast);
  const importedPropTypes: ImportedPropTypes = {
    propTypesName: getPropTypesName(ast),
    propTypes: getImportedPropTypes(ast)
  };
  const importedTypes = getInstanceOfPropTypes(ast, importedPropTypes);
  const importStatements = getImportStatements(ast, importedTypes, options.instanceOfResolver);
function getEs7StyleClassPropTypes(ast: any, classname: string,
    instanceOfResolver?: InstanceOfResolver): IPropTypes|undefined {
  const astq = new ASTQ();
  const propTypesNodes = astq.query(ast, `
    //ClassDeclaration[/:id Identifier[@name == '${classname}']]
      //ClassProperty[/:key Identifier[@name == 'propTypes']]
  `);
  if (propTypesNodes.length > 0) {
    return parsePropTypes(propTypesNodes[0].value, instanceOfResolver);
  }
  return undefined;
}
function getComponentNameByPropTypeAssignment(ast: any): string|undefined {
  const astq = new ASTQ();
  const componentNames = astq.query(ast, `
    //AssignmentExpression
      /:left MemberExpression[
        /:object Identifier &&
        /:property Identifier[@name == 'propTypes']
      ]
  `);
  if (componentNames.length > 0) {
    return componentNames[0].object.name;
  }
  return undefined;
}
export function parsePropTypes(node: any, instanceOfResolver?: InstanceOfResolver): IPropTypes {
  const astq = new ASTQ();
  return astq
    .query(node, `/ObjectProperty`)
    .reduce((propTypes: IPropTypes, propertyNode: IASTNode) => {
        const prop: IProp = getTypeFromPropType(propertyNode.value, instanceOfResolver);
        prop.documentation = getOptionalDocumentation(propertyNode);
        propTypes[propertyNode.key.name] = prop;
        return propTypes;
    }, {});
}
function getPropTypesFromAssignment(ast: any, componentName: string,
    instanceOfResolver?: InstanceOfResolver): IPropTypes|undefined {
  const astq = new ASTQ();
  const propTypesNodes = astq.query(ast, `
    //AssignmentExpression[
      /:left MemberExpression[
        /:object Identifier[@name == '${componentName}'] &&
        /:property Identifier[@name == 'propTypes']
      ]
    ] /:right *
  `);
  if (propTypesNodes.length > 0) {
    return parsePropTypes(propTypesNodes[0], instanceOfResolver);
  }
  return undefined;
}
function getClassName(ast: any): string|undefined {
  const astq = new ASTQ();
  const classDeclarationNodes = astq.query(ast, `
    //ClassDeclaration[
        /:id Identifier[@name]
    ]
  `);
  if (classDeclarationNodes.length > 0) {
    return classDeclarationNodes[0].id.name;
  }
  return undefined;
}
function getClassExportType(ast: any, classname: string): ExportType|undefined {
  const astq = new ASTQ();
  const exportTypeNodes = astq.query(ast, `
    //ExportNamedDeclaration [
      /ClassDeclaration [ /:id Identifier[@name=='${classname}'] ]
    ],
    //ExportDefaultDeclaration [
      /ClassDeclaration [ /:id Identifier[@name=='${classname}'] ]
    ]
  `);
  if (exportTypeNodes.length > 0) {
    return exportTypeNodes[0].type === 'ExportDefaultDeclaration' ? ExportType.default : ExportType.named;
  }
  return undefined;
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now