How to use the esprima.Syntax.ForStatement function in esprima

To help you get started, we’ve selected a few esprima 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 yanhaijing / template.js / packages / precompiler / src / index.ts View on Github external
function hasContext(type) {
    return [
        Syntax.ArrowFunctionExpression,
        Syntax.FunctionDeclaration,
        Syntax.FunctionExpression,
        Syntax.ForStatement,
        Syntax.ForInStatement,
        Syntax.ForOfStatement,
        Syntax.BlockStatement,
    ].indexOf(type) !== -1;
}
github stryker-mutator / stryker / packages / stryker / src / mutators / RemoveConditionalsMutator.ts View on Github external
import { Syntax } from 'esprima';
import * as estree from 'estree';
import NodeMutator from './NodeMutator';
import { IdentifiedNode, Identified } from './IdentifiedNode';

type ConditionExpression = estree.DoWhileStatement | estree.IfStatement | estree.ForStatement | estree.WhileStatement | estree.ConditionalExpression;

/**
 * Represents a mutator which can remove the conditional clause from statements.
 */
export default class RemoveConditionalsMutator implements NodeMutator {
  public name = 'RemoveConditionals';
  private readonly types: string[] = [Syntax.DoWhileStatement, Syntax.IfStatement, Syntax.ForStatement, Syntax.WhileStatement, Syntax.ConditionalExpression];

  constructor() { }

  public applyMutations(node: IdentifiedNode, copy:  (obj: T, deep?: boolean) => T): IdentifiedNode[] | void {
    if (this.canMutate(node)) {
      const nodes: IdentifiedNode[] = [];

      if (node.test) {
        nodes.push(this.booleanLiteralNode((node.test as IdentifiedNode).nodeID, false));
      } else {
        const mutatedNode = copy(node);
        mutatedNode.test = this.booleanLiteralNode(-1, false);
        nodes.push(mutatedNode);
      }

      if (node.type === Syntax.IfStatement || node.type === Syntax.ConditionalExpression) {