browser.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.transformFileSync = exports.transformFile = exports.transformFromAst = exports.transform = exports.analyse = exports.Pipeline = exports.Plugin = exports.OptionManager = exports.traverse = exports.types = exports.messages = exports.util = exports.version = exports.template = exports.buildExternalHelpers = exports.options = exports.File = undefined;
  4. var _node = require("./node");
  5. Object.defineProperty(exports, "File", {
  6. enumerable: true,
  7. get: function get() {
  8. return _node.File;
  9. }
  10. });
  11. Object.defineProperty(exports, "options", {
  12. enumerable: true,
  13. get: function get() {
  14. return _node.options;
  15. }
  16. });
  17. Object.defineProperty(exports, "buildExternalHelpers", {
  18. enumerable: true,
  19. get: function get() {
  20. return _node.buildExternalHelpers;
  21. }
  22. });
  23. Object.defineProperty(exports, "template", {
  24. enumerable: true,
  25. get: function get() {
  26. return _node.template;
  27. }
  28. });
  29. Object.defineProperty(exports, "version", {
  30. enumerable: true,
  31. get: function get() {
  32. return _node.version;
  33. }
  34. });
  35. Object.defineProperty(exports, "util", {
  36. enumerable: true,
  37. get: function get() {
  38. return _node.util;
  39. }
  40. });
  41. Object.defineProperty(exports, "messages", {
  42. enumerable: true,
  43. get: function get() {
  44. return _node.messages;
  45. }
  46. });
  47. Object.defineProperty(exports, "types", {
  48. enumerable: true,
  49. get: function get() {
  50. return _node.types;
  51. }
  52. });
  53. Object.defineProperty(exports, "traverse", {
  54. enumerable: true,
  55. get: function get() {
  56. return _node.traverse;
  57. }
  58. });
  59. Object.defineProperty(exports, "OptionManager", {
  60. enumerable: true,
  61. get: function get() {
  62. return _node.OptionManager;
  63. }
  64. });
  65. Object.defineProperty(exports, "Plugin", {
  66. enumerable: true,
  67. get: function get() {
  68. return _node.Plugin;
  69. }
  70. });
  71. Object.defineProperty(exports, "Pipeline", {
  72. enumerable: true,
  73. get: function get() {
  74. return _node.Pipeline;
  75. }
  76. });
  77. Object.defineProperty(exports, "analyse", {
  78. enumerable: true,
  79. get: function get() {
  80. return _node.analyse;
  81. }
  82. });
  83. Object.defineProperty(exports, "transform", {
  84. enumerable: true,
  85. get: function get() {
  86. return _node.transform;
  87. }
  88. });
  89. Object.defineProperty(exports, "transformFromAst", {
  90. enumerable: true,
  91. get: function get() {
  92. return _node.transformFromAst;
  93. }
  94. });
  95. Object.defineProperty(exports, "transformFile", {
  96. enumerable: true,
  97. get: function get() {
  98. return _node.transformFile;
  99. }
  100. });
  101. Object.defineProperty(exports, "transformFileSync", {
  102. enumerable: true,
  103. get: function get() {
  104. return _node.transformFileSync;
  105. }
  106. });
  107. exports.run = run;
  108. exports.load = load;
  109. function run(code) {
  110. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  111. return new Function((0, _node.transform)(code, opts).code)();
  112. }
  113. function load(url, callback) {
  114. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  115. var hold = arguments[3];
  116. opts.filename = opts.filename || url;
  117. var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
  118. xhr.open("GET", url, true);
  119. if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
  120. xhr.onreadystatechange = function () {
  121. if (xhr.readyState !== 4) return;
  122. var status = xhr.status;
  123. if (status === 0 || status === 200) {
  124. var param = [xhr.responseText, opts];
  125. if (!hold) run(param);
  126. if (callback) callback(param);
  127. } else {
  128. throw new Error("Could not load " + url);
  129. }
  130. };
  131. xhr.send(null);
  132. }
  133. function runScripts() {
  134. var scripts = [];
  135. var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
  136. var index = 0;
  137. function exec() {
  138. var param = scripts[index];
  139. if (param instanceof Array) {
  140. run(param, index);
  141. index++;
  142. exec();
  143. }
  144. }
  145. function run(script, i) {
  146. var opts = {};
  147. if (script.src) {
  148. load(script.src, function (param) {
  149. scripts[i] = param;
  150. exec();
  151. }, opts, true);
  152. } else {
  153. opts.filename = "embedded";
  154. scripts[i] = [script.innerHTML, opts];
  155. }
  156. }
  157. var _scripts = global.document.getElementsByTagName("script");
  158. for (var i = 0; i < _scripts.length; ++i) {
  159. var _script = _scripts[i];
  160. if (types.indexOf(_script.type) >= 0) scripts.push(_script);
  161. }
  162. for (var _i = 0; _i < scripts.length; _i++) {
  163. run(scripts[_i], _i);
  164. }
  165. exec();
  166. }
  167. if (global.addEventListener) {
  168. global.addEventListener("DOMContentLoaded", runScripts, false);
  169. } else if (global.attachEvent) {
  170. global.attachEvent("onload", runScripts);
  171. }