pipeline.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. exports.__esModule = true;
  3. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  4. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  5. var _normalizeAst = require("../helpers/normalize-ast");
  6. var _normalizeAst2 = _interopRequireDefault(_normalizeAst);
  7. var _plugin = require("./plugin");
  8. var _plugin2 = _interopRequireDefault(_plugin);
  9. var _file = require("./file");
  10. var _file2 = _interopRequireDefault(_file);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. var Pipeline = function () {
  13. function Pipeline() {
  14. (0, _classCallCheck3.default)(this, Pipeline);
  15. }
  16. Pipeline.prototype.lint = function lint(code) {
  17. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  18. opts.code = false;
  19. opts.mode = "lint";
  20. return this.transform(code, opts);
  21. };
  22. Pipeline.prototype.pretransform = function pretransform(code, opts) {
  23. var file = new _file2.default(opts, this);
  24. return file.wrap(code, function () {
  25. file.addCode(code);
  26. file.parseCode(code);
  27. return file;
  28. });
  29. };
  30. Pipeline.prototype.transform = function transform(code, opts) {
  31. var file = new _file2.default(opts, this);
  32. return file.wrap(code, function () {
  33. file.addCode(code);
  34. file.parseCode(code);
  35. return file.transform();
  36. });
  37. };
  38. Pipeline.prototype.analyse = function analyse(code) {
  39. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40. var visitor = arguments[2];
  41. opts.code = false;
  42. if (visitor) {
  43. opts.plugins = opts.plugins || [];
  44. opts.plugins.push(new _plugin2.default({ visitor: visitor }));
  45. }
  46. return this.transform(code, opts).metadata;
  47. };
  48. Pipeline.prototype.transformFromAst = function transformFromAst(ast, code, opts) {
  49. ast = (0, _normalizeAst2.default)(ast);
  50. var file = new _file2.default(opts, this);
  51. return file.wrap(code, function () {
  52. file.addCode(code);
  53. file.addAst(ast);
  54. return file.transform();
  55. });
  56. };
  57. return Pipeline;
  58. }();
  59. exports.default = Pipeline;
  60. module.exports = exports["default"];