main.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright (c) 2014, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
  7. * additional grant of patent rights can be found in the PATENTS file in
  8. * the same directory.
  9. */
  10. var assert = require("assert");
  11. var path = require("path");
  12. var fs = require("fs");
  13. var through = require("through");
  14. var transform = require("./lib/visit").transform;
  15. var utils = require("./lib/util");
  16. var types = require("ast-types");
  17. var genOrAsyncFunExp = /\bfunction\s*\*|\basync\b/;
  18. var blockBindingExp = /\b(let|const)\s+/;
  19. function exports(file, options) {
  20. var data = [];
  21. return through(write, end);
  22. function write(buf) {
  23. data.push(buf);
  24. }
  25. function end() {
  26. this.queue(compile(data.join(""), options).code);
  27. this.queue(null);
  28. }
  29. }
  30. // To get a writable stream for use as a browserify transform, call
  31. // require("regenerator")().
  32. module.exports = exports;
  33. // To include the runtime globally in the current node process, call
  34. // require("regenerator").runtime().
  35. function runtime() {
  36. require("./runtime");
  37. }
  38. exports.runtime = runtime;
  39. runtime.path = path.join(__dirname, "runtime.js");
  40. // To modify an AST directly, call require("regenerator").transform(ast).
  41. exports.transform = transform;