How to use the esprima.Syntax.BlockStatement 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 / BlockStatementMutator.ts View on Github external
import { Syntax } from 'esprima';
import NodeMutator from './NodeMutator';
import { IdentifiedNode } from './IdentifiedNode';

/**
 * Represents a mutator which can remove the content of a BlockStatement.
 */
export default class BlockStatementMutator implements NodeMutator {
  public name = 'BlockStatement';
  private readonly type = Syntax.BlockStatement;

  constructor() { }

  public applyMutations(node: IdentifiedNode, copy:  (obj: T, deep?: boolean) => T): void | IdentifiedNode {
    if (node.type === this.type && node.body.length > 0) {
      const mutatedNode = copy(node);
      mutatedNode.body = [];
      return mutatedNode;
    }
  }
}