Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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]))
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();
});
// 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]))
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;
}
}
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;
/**
* 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.
*