How to use the regenerator/node_modules/recast.visit 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 / 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();
});

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