How to use the regenerator.runtime 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 metascript / metascript / lib / build-regenerator-runtime.js View on Github external
// Dumps an escodegen AST for the regenerator minified runtime.
// It allows to merge it directly into the generated program
// to avoid breaking source maps.

var fs = require('fs');

var regenerator = require('regenerator');
// HACK: Use recast from regenerator's deps
var recast = require('regenerator/node_modules/recast');

var runtime = fs.readFileSync(regenerator.runtime.min, "utf-8");
var body = recast.parse(runtime, {
  sourceFileName: regenerator.runtime.min,
}).program.body;

// Reduce source maps size by removing location information
var StripLoc = recast.Visitor.extend({
  visit: function (node) {
    this.genericVisit(node);
    node.loc = null;
    return node;
  }
});
(new StripLoc).visit(body);

fs.writeFileSync('./lib/regenerator-runtime.json', JSON.stringify(body[0]))
github metascript / metascript / gulpfile.js View on Github external
gulp.task('regenerator', function (done) {
  // Dumps an escodegen AST for the regenerator minified runtime.
  // It allows to merge it directly into the generated program
  // to avoid breaking source maps.
  var fs = require('fs');
  var regenerator = require('regenerator');
  // HACK: Use recast from regenerator's deps
  var recast = require('regenerator/node_modules/recast');

  var runtime = fs.readFileSync('node_modules/regenerator/runtime.js', "utf-8");
  var body = recast.parse(runtime, {
    sourceFileName: regenerator.runtime.min,
  }).program.body;

  // Reduce source maps size by removing location information
  recast.visit(body, {
    visitNode: function (path) {
      path.node.loc = null;
      this.traverse(path);
    }
  });

  fs.writeFileSync('./lib/regenerator-runtime.json', JSON.stringify(body[0]))

  done();
});
github metascript / metascript / lib / build-regenerator-runtime.js View on Github external
// Dumps an escodegen AST for the regenerator minified runtime.
// It allows to merge it directly into the generated program
// to avoid breaking source maps.

var fs = require('fs');

var regenerator = require('regenerator');
// HACK: Use recast from regenerator's deps
var recast = require('regenerator/node_modules/recast');

var runtime = fs.readFileSync(regenerator.runtime.min, "utf-8");
var body = recast.parse(runtime, {
  sourceFileName: regenerator.runtime.min,
}).program.body;

// Reduce source maps size by removing location information
var StripLoc = recast.Visitor.extend({
  visit: function (node) {
    this.genericVisit(node);
    node.loc = null;
    return node;
  }
});
(new StripLoc).visit(body);

fs.writeFileSync('./lib/regenerator-runtime.json', JSON.stringify(body[0]))
github resugar / resugar / lib / index.js View on Github external
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');
    injectRuntime(runtime, regenerator.runtime.path, ast.program);
  }

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

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

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

  return ast;
}
github resugar / resugar / lib / index.js View on Github external
}

  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');
    injectRuntime(runtime, regenerator.runtime.path, ast.program);
  }

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

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

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

  return ast;
github TooTallNate / gnode / index.js View on Github external
/**
   * Module dependencies.
   */

  var fs = require('fs');
  var regenerator = require('regenerator');
  var genFunExp = /\bfunction\s*\*/;

  /**
   * First include the regenerator runtime. It gets installed gloablly as
   * `regeneratorRuntime`, so we just need to make sure that global
   * function is available.
   */

  regenerator.runtime();

  /**
   * Entry point for node versions that don't have Generator support.
   *
   * This file replaces the default `.js` require.extensions implementation with
   * one that first compiles the JavaScript code via "facebook/regenerator".
   *
   * Once that is in place then it loads the original entry point .js file.
   */

  require.extensions['.js'] = gnodeJsExtensionCompiler;
}

/**
 * ES6 Generators enabled `require.extensions['.js']` hook.
 *

regenerator

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

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis