node.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.resolvePreset = exports.resolvePlugin = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined;
  4. var _file = require("../transformation/file");
  5. Object.defineProperty(exports, "File", {
  6. enumerable: true,
  7. get: function get() {
  8. return _interopRequireDefault(_file).default;
  9. }
  10. });
  11. var _config = require("../transformation/file/options/config");
  12. Object.defineProperty(exports, "options", {
  13. enumerable: true,
  14. get: function get() {
  15. return _interopRequireDefault(_config).default;
  16. }
  17. });
  18. var _buildExternalHelpers = require("../tools/build-external-helpers");
  19. Object.defineProperty(exports, "buildExternalHelpers", {
  20. enumerable: true,
  21. get: function get() {
  22. return _interopRequireDefault(_buildExternalHelpers).default;
  23. }
  24. });
  25. var _babelTemplate = require("babel-template");
  26. Object.defineProperty(exports, "template", {
  27. enumerable: true,
  28. get: function get() {
  29. return _interopRequireDefault(_babelTemplate).default;
  30. }
  31. });
  32. var _resolvePlugin = require("../helpers/resolve-plugin");
  33. Object.defineProperty(exports, "resolvePlugin", {
  34. enumerable: true,
  35. get: function get() {
  36. return _interopRequireDefault(_resolvePlugin).default;
  37. }
  38. });
  39. var _resolvePreset = require("../helpers/resolve-preset");
  40. Object.defineProperty(exports, "resolvePreset", {
  41. enumerable: true,
  42. get: function get() {
  43. return _interopRequireDefault(_resolvePreset).default;
  44. }
  45. });
  46. var _package = require("../../package");
  47. Object.defineProperty(exports, "version", {
  48. enumerable: true,
  49. get: function get() {
  50. return _package.version;
  51. }
  52. });
  53. exports.Plugin = Plugin;
  54. exports.transformFile = transformFile;
  55. exports.transformFileSync = transformFileSync;
  56. var _fs = require("fs");
  57. var _fs2 = _interopRequireDefault(_fs);
  58. var _util = require("../util");
  59. var util = _interopRequireWildcard(_util);
  60. var _babelMessages = require("babel-messages");
  61. var messages = _interopRequireWildcard(_babelMessages);
  62. var _babelTypes = require("babel-types");
  63. var t = _interopRequireWildcard(_babelTypes);
  64. var _babelTraverse = require("babel-traverse");
  65. var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
  66. var _optionManager = require("../transformation/file/options/option-manager");
  67. var _optionManager2 = _interopRequireDefault(_optionManager);
  68. var _pipeline = require("../transformation/pipeline");
  69. var _pipeline2 = _interopRequireDefault(_pipeline);
  70. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  71. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  72. exports.util = util;
  73. exports.messages = messages;
  74. exports.types = t;
  75. exports.traverse = _babelTraverse2.default;
  76. exports.OptionManager = _optionManager2.default;
  77. function Plugin(alias) {
  78. throw new Error("The (" + alias + ") Babel 5 plugin is being run with Babel 6.");
  79. }
  80. exports.Pipeline = _pipeline2.default;
  81. var pipeline = new _pipeline2.default();
  82. var analyse = exports.analyse = pipeline.analyse.bind(pipeline);
  83. var transform = exports.transform = pipeline.transform.bind(pipeline);
  84. var transformFromAst = exports.transformFromAst = pipeline.transformFromAst.bind(pipeline);
  85. function transformFile(filename, opts, callback) {
  86. if (typeof opts === "function") {
  87. callback = opts;
  88. opts = {};
  89. }
  90. opts.filename = filename;
  91. _fs2.default.readFile(filename, function (err, code) {
  92. var result = void 0;
  93. if (!err) {
  94. try {
  95. result = transform(code, opts);
  96. } catch (_err) {
  97. err = _err;
  98. }
  99. }
  100. if (err) {
  101. callback(err);
  102. } else {
  103. callback(null, result);
  104. }
  105. });
  106. }
  107. function transformFileSync(filename) {
  108. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  109. opts.filename = filename;
  110. return transform(_fs2.default.readFileSync(filename, "utf8"), opts);
  111. }