How to use babel-helper-hoist-variables - 2 common examples

To help you get started, we’ve selected a few babel-helper-hoist-variables 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 babel / kneden / src / index.js View on Github external
enter(path) {
      depth++;
      const {node} = path;
      if (node.async) {
        const decls = [];
        const addVarDecl = id => decls.push(variableDeclarator(id));
        // hoist variables
        hoistVariables(path, addVarDecl);

        // info gathering for this/arguments during the refactoring
        const thisID = identifier(path.scope.generateUid('this'));
        const argumentsID = identifier(path.scope.generateUid('arguments'));
        const used = {thisID: false, argumentsID: false};

        const newBody = [];
        const addFunctionDecl = func => newBody.push(func);

        // refactor code
        const args = {thisID, argumentsID, used, addVarDecl, addFunctionDecl, respID, errID};
        path.traverse(RefactorVisitor, args);
        // add this/arguments vars if necessary
        if (used.thisID) {
          decls.push(variableDeclarator(thisID, thisExpression()));
        }
github babel / babel / packages / babel-helper-call-delegate / src / index.js View on Github external
export default function (path, scope = path.scope) {
  let { node } = path;
  let container = t.functionExpression(null, [], node.body, node.generator, node.async);

  let callee = container;
  let args   = [];

  // todo: only hoist if necessary
  hoistVariables(path, (id) => scope.push({ id }));

  let state = {
    foundThis: false,
    foundArguments: false
  };

  path.traverse(visitor, state);

  if (state.foundArguments) {
    callee = t.memberExpression(container, t.identifier("apply"));
    args = [];

    if (state.foundThis) {
      args.push(t.thisExpression());
    }

babel-helper-hoist-variables

Helper function to hoist variables

MIT
Latest version published 8 years ago

Package Health Score

88 / 100
Full package analysis

Popular babel-helper-hoist-variables functions

Similar packages