How to use the regenerator.compile 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 vigour-io / builder-boy / lib / ast / es5.js View on Github external
const deps = []

      if (es6.async) {
        console.log('  ', chalk.blue('has async -- convert to generator'), file.key)
        result = asyncToGen(result).toString()
      }

      if (es6.fetch) {
        console.log('  ', chalk.blue('has fetch -- add shim'), file.key)
        deps.push(addDependency({ browser: 'whatwg-fetch', dependencies, result }))
        // deps.push(addDependency({ node: 'node-fetch', dependencies, result }))
      }

      if (es6.generator) {
        console.log('  ', chalk.blue('has generator -- add shim'), file.key)
        es5 = regenerator.compile(result).code
        deps.push(addDependency({ browser: 'regenerator-runtime/runtime', dependencies, result }))
      }

      if (es6.promise) {
        console.log('  ', chalk.blue('has promise -- add shim'), file.key)
        deps.push(addDependency({ browser: 'promise-polyfill', dependencies, result }))
      }

      Promise.all(deps).then(() => {
        es5 = buble.transform(es5 || result).code
        resolve({ result, dependencies, es5 })
      }).catch(err => reject(err))
    } else {
      es5 = buble.transform(result).code
      resolve({ result, dependencies, es5 })
    }
github vigour-io / builder-boy / lib / plugins / js / ast / es5.js View on Github external
const id = file.id.val.join('/')

      if (es6.async) {
        if (boy.__verbose__) console.log('  ', chalk.blue('has async - convert to generator'), id)
        result = asyncToGen(result).toString()
      }

      if (es6.fetch) {
        if (boy.__verbose__) console.log('  ', chalk.blue('has fetch - add shim'), id)
        deps.push(addDependency({ file, browser: 'whatwg-fetch', dependencies, result }))
        // deps.push(addDependency({ node: 'node-fetch', dependencies, result }))
      }

      if (es6.generator) {
        if (boy.__verbose__) console.log('  ', chalk.blue('has generator - add shim'), id)
        es5 = regenerator.compile(result).code
        deps.push(addDependency({ file, browser: 'regenerator-runtime/runtime', dependencies, result }))
      }

      if (es6.promise && file.id.val.join('/') !== 'promise-polyfill/promise.js') {
        if (boy.__verbose__) console.log('  ', chalk.blue('has promise -- add shim'), id)
        deps.push(addDependency({ file, browser: 'promise-polyfill', dependencies, result }))
      }

      Promise.all(deps).then((results) => {
        results.forEach((val) => {
          dependencies.push(val)
        })

        es5 = buble.transform(es5 || result, bubleOptions).code
        resolve({ result, dependencies, es5 })
      }).catch(err => reject(err))
github serh11p / rollup-plugin-regenerator / lib / rollup-plugin-regenerator.es.js View on Github external
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 TooTallNate / gnode / fallback.js View on Github external
function evalScript (name) {
  var Module = require('module');
  var path = require('path');
  var cwd = process.cwd();

  var module = new Module(name);
  module.filename = path.join(cwd, name);
  module.paths = Module._nodeModulePaths(cwd);
  var script = process._eval;

  // compile JS via facebook/regenerator
  script = regenerator.compile(script, {
    includeRuntime: 'object' !== typeof regeneratorRuntime
  }).code;

  if (!Module._contextLoad) {
    var body = script;
    script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
             'global.exports = exports;\n' +
             'global.module = module;\n' +
             'global.__dirname = __dirname;\n' +
             'global.require = require;\n' +
             'return require("vm").runInThisContext(' +
             JSON.stringify(body) + ', ' +
             JSON.stringify(name) + ', true);\n';
  }

  var result = module._compile(script, name + '-wrapper');
github TooTallNate / gnode / fallback.js View on Github external
function gnodeEval (code, context, file, fn) {
  var err, result;
  try {
    // compile JS via facebook/regenerator
    code = regenerator.compile(code, {
      includeRuntime: 'object' !== typeof regeneratorRuntime
    }).code;
  } catch (e) {
    // Treat regenerator errors as syntax errors in repl.
    // A hack to have repl interpret certain js structures correctly.
    e.name = 'SyntaxError'
    err = e;
  }
  try {
    if (this.useGlobal) {
      result = vm.runInThisContext(code, file);
    } else {
      result = vm.runInContext(code, context, file);
    }
  } catch (e) {
    err = e;
github serh11p / rollup-plugin-regenerator / lib / rollup-plugin-regenerator.js View on Github external
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 bbondy / khan-academy-fxos / src / preprocessor.js View on Github external
process: function(src) {
        src = es6defaultParams.compile(src).code;
        // Regenerator has a bug when using backbone
        if (src.indexOf("\"enable_regenerator\"") !== -1) {
            src = regenerator.compile(src, {
                includeRuntime: true
            }).code;
        }
        src = ReactTools.transform(src, {
            stripTypes: true,
            harmony: true
        });
        return src;
    }
};
github AppliedMathematicsANU / plexus-csp / regenerator-loader.js View on Github external
module.exports = function(source) {
  this.cacheable(true);
  return regenerator.compile(source).code;
};
github stephenmathieson-boneyard / duo-regenerator / index.js View on Github external
function compile(js, includeRuntime) {
  includeRuntime = includeRuntime || false;
  return regenerator.compile(js, { includeRuntime: includeRuntime }).code;
}

regenerator

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

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis