You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

5 years ago
  1. if (typeof fetch === "function") {
  2. // Web version of reading a wasm file into an array buffer.
  3. let mappingsWasmUrl = null;
  4. module.exports = function readWasm() {
  5. if (typeof mappingsWasmUrl !== "string") {
  6. throw new Error("You must provide the URL of lib/mappings.wasm by calling " +
  7. "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " +
  8. "before using SourceMapConsumer");
  9. }
  10. return fetch(mappingsWasmUrl)
  11. .then(response => response.arrayBuffer());
  12. };
  13. module.exports.initialize = url => mappingsWasmUrl = url;
  14. } else {
  15. // Node version of reading a wasm file into an array buffer.
  16. const fs = require("fs");
  17. const path = require("path");
  18. module.exports = function readWasm() {
  19. return new Promise((resolve, reject) => {
  20. const wasmPath = path.join(__dirname, "mappings.wasm");
  21. fs.readFile(wasmPath, null, (error, data) => {
  22. if (error) {
  23. reject(error);
  24. return;
  25. }
  26. resolve(data.buffer);
  27. });
  28. });
  29. };
  30. module.exports.initialize = _ => {
  31. console.debug("SourceMapConsumer.initialize is a no-op when running in node.js");
  32. };
  33. }