How to use the regenerator.transform function in regenerator

To help you get started, we’ve selected a few regenerator 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 / src / babel / transformation / transformers / other / regenerator.js View on Github external
exit(node) {
      if (node.async || node.generator) {
        // Although this code transforms only the subtree rooted at the given
        // Function node, that node might contain other generator functions
        // that will also be transformed. It might help performance to ignore
        // nested functions, and rely on the traversal to visit them later,
        // but that's a small optimization. Starting here instead of at the
        // root of the AST is the key optimization, since huge async/generator
        // functions are relatively rare.
        regenerator.transform(convertNodePath(this));
      }
    }
  }
github babel / babel / packages / babel-core / src / transformation / transformers / other / regenerator.js View on Github external
exit(node) {
      if (node.async || node.generator) {
        // Although this code transforms only the subtree rooted at the given
        // Function node, that node might contain other generator functions
        // that will also be transformed. It might help performance to ignore
        // nested functions, and rely on the traversal to visit them later,
        // but that's a small optimization. Starting here instead of at the
        // root of the AST is the key optimization, since huge async/generator
        // functions are relatively rare.
        regenerator.transform(convertNodePath(this));
      }
    }
  }
github serh11p / rollup-plugin-regenerator / lib / rollup-plugin-regenerator.es.js View on Github external
transform: function (code, id) {
      // if `opts.include` is omitted or has zero length, filter
      // will return `true` by default. Otherwise, an ID must match
      // one or more of the minimatch patterns, and must not match
      // any of the `opts.exclude` patterns.
      if (!filter(id)) {
        return;
      }

      // proceed with the transformation...
      var res;
      if (withSourceMap) {
        var inputAst = recastParse(code, {
          sourceFileName: id
        });
        var outputAst = regeneratorTransform(inputAst);

        res = recastPrint(outputAst, {
          sourceMapName: id
        });
      } else {
        res = regeneratorCompile(code);
      }

      return {
        code: res.code,
        map: withSourceMap && res.map ? res.map : { mappings: '' }
      };
    }
  };
github serh11p / rollup-plugin-regenerator / lib / rollup-plugin-regenerator.js View on Github external
transform: function (code, id) {
      // if `opts.include` is omitted or has zero length, filter
      // will return `true` by default. Otherwise, an ID must match
      // one or more of the minimatch patterns, and must not match
      // any of the `opts.exclude` patterns.
      if (!filter(id)) {
        return;
      }

      // proceed with the transformation...
      var res;
      if (withSourceMap) {
        var inputAst = recast.parse(code, {
          sourceFileName: id
        });
        var outputAst = regenerator.transform(inputAst);

        res = recast.print(outputAst, {
          sourceMapName: id
        });
      } else {
        res = regenerator.compile(code);
      }

      return {
        code: res.code,
        map: withSourceMap && res.map ? res.map : { mappings: '' }
      };
    }
  };
github kevinbarabash / debugger / src / es5-transform.js View on Github external
var genFunc = {
        type: "FunctionDeclaration",
        id: builder.createIdentifier("genFunc"),
        params: [ builder.createIdentifier("context") ],
        defaults: [ ],
        rest: null,
        body: {
            type: "BlockStatement",
            body: ast.body
        },
        generator: true,
        expression: false
    };

    console.log(escodegen.generate(genFunc));
    regenerator.transform(genFunc);

    var body = genFunc.body.body;
    var success = false;
    for (var i = 0; i < body.length; i++) {
        var stmt = body[i];
        if (stmt.type === "ReturnStatement") {
            var arg = stmt.argument;
            if (arg.type === "CallExpression") {
                var callee = arg.callee;
                if (callee.type === "MemberExpression") {
                    if (callee.object.type === "Identifier" &&
                        callee.property.type === "Identifier") {
                        
                        var objName = callee.object.name;
                        var propName = callee.property.name;
github kevinbarabash / debugger / src / transform.js View on Github external
${escodegen.generate(ast)}
        }`;

        generator = new Function(debugCode);
    } else {
        var entry = {
            type: "Program",
            body: [functionDeclaration(
                identifier("entry"),
                [identifier(contextName)],
                blockStatement(ast.body),
                true
            )]
        };

        debugCode = escodegen.generate(regenerator.transform(entry));

        generator = new Function(debugCode + "\n" + "return entry;");
    }

    if (options.debug) {
        console.log(debugCode);
    }

    return generator;
};
github amasad / debugjs / lib / machine.js View on Github external
Machine.prototype.$transform = function (code, filename) {
  var ast = recast.parse(code);
  filename = filename || ('file' + (++this.$anonFileId));
  var transformed = transform(ast, { filename: filename });
  if (!isGenSupported) {
    transformed = regenerator.transform(transformed);
  }
  return recast.print(transformed).code;
};
github resugar / resugar / lib / index.js View on Github external
}

  if (options['class'] !== false) {
    ast = es6class.transform(ast);
  }

  if (options.rest !== false) {
    ast = es6restParams.transform(ast);
  }

  if (options.defaultParams !== false) {
    ast = es6defaultParams.transform(ast);
  }

  if (options.generator !== false) {
    ast = regenerator.transform(ast);
  }

  if (options.regexpu !== false) {
    ast = regexpu.transform(ast);
  }

  if (options.spread !== false) {
    ast = es6spread.transform(ast);
  }

  if (options.templates !== false) {
    ast = es6templates.transform(ast);
  }

  if (options.generator !== false && options.includeRuntime) {
    var runtime = fs.readFileSync(regenerator.runtime.path, 'utf8');

regenerator

Source transformer enabling ECMAScript 6 generator functions (yield) in JavaScript-of-today (ES5)

MIT
Latest version published 7 months ago

Package Health Score

68 / 100
Full package analysis