How to use @babel/helper-hoist-variables - 3 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 / babel / packages / babel-helper-call-delegate / src / index.js View on Github external
export default function(path: NodePath, scope = path.scope) {
  const { node } = path;
  const 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 }));

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

  path.traverse(visitor, state);

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

    if (state.foundThis) {
      args.push(t.thisExpression());
    }
github babel / babel / packages / babel-plugin-transform-modules-systemjs / src / index.js View on Github external
}

            sources.push(t.stringLiteral(specifiers.key));
            setters.push(
              t.functionExpression(
                null,
                [t.identifier(target)],
                t.blockStatement(setterBody),
              ),
            );
          });

          let moduleName = this.getModuleName();
          if (moduleName) moduleName = t.stringLiteral(moduleName);

          hoistVariables(
            path,
            (id, name, hasInit) => {
              variableIds.push(id);
              if (!hasInit) {
                exportNames.push(name);
                exportValues.push(undefinedIdent);
              }
            },
            null,
          );

          if (variableIds.length) {
            beforeBody.unshift(
              t.variableDeclaration(
                "var",
                variableIds.map(id => t.variableDeclarator(id)),
github babel / babel / packages / babel-plugin-transform-es2015-modules-systemjs / src / index.js View on Github external
sources.push(t.stringLiteral(specifiers.key));
            setters.push(
              t.functionExpression(
                null,
                [target],
                t.blockStatement(setterBody),
              ),
            );
          });

          let moduleName = this.getModuleName();
          if (moduleName) moduleName = t.stringLiteral(moduleName);

          if (canHoist) {
            hoistVariables(path, id => variableIds.push(id));
          }

          if (variableIds.length) {
            beforeBody.unshift(
              t.variableDeclaration(
                "var",
                variableIds.map(id => t.variableDeclarator(id)),
              ),
            );
          }

          path.traverse(reassignmentVisitor, {
            exports: exportNames,
            buildCall: buildExportCall,
            scope: path.scope,
          });

@babel/helper-hoist-variables

Helper function to hoist variables

MIT
Latest version published 5 months ago

Package Health Score

93 / 100
Full package analysis

Popular @babel/helper-hoist-variables functions

Similar packages