index.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.encodeNode = encodeNode;
  7. exports.encodeU32 = void 0;
  8. var encoder = _interopRequireWildcard(require("./encoder"));
  9. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  10. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  11. function encodeNode(n) {
  12. switch (n.type) {
  13. case "ModuleImport":
  14. // $FlowIgnore: ModuleImport ensure that the node is well formated
  15. return encoder.encodeModuleImport(n);
  16. case "SectionMetadata":
  17. // $FlowIgnore: SectionMetadata ensure that the node is well formated
  18. return encoder.encodeSectionMetadata(n);
  19. case "CallInstruction":
  20. // $FlowIgnore: SectionMetadata ensure that the node is well formated
  21. return encoder.encodeCallInstruction(n);
  22. case "CallIndirectInstruction":
  23. // $FlowIgnore: SectionMetadata ensure that the node is well formated
  24. return encoder.encodeCallIndirectInstruction(n);
  25. case "TypeInstruction":
  26. return encoder.encodeTypeInstruction(n);
  27. case "Instr":
  28. // $FlowIgnore
  29. return encoder.encodeInstr(n);
  30. case "ModuleExport":
  31. // $FlowIgnore: SectionMetadata ensure that the node is well formated
  32. return encoder.encodeModuleExport(n);
  33. case "Global":
  34. // $FlowIgnore
  35. return encoder.encodeGlobal(n);
  36. case "Func":
  37. return encoder.encodeFuncBody(n);
  38. case "IndexInFuncSection":
  39. return encoder.encodeIndexInFuncSection(n);
  40. case "StringLiteral":
  41. return encoder.encodeStringLiteral(n);
  42. case "Elem":
  43. return encoder.encodeElem(n);
  44. default:
  45. throw new Error("Unsupported encoding for node of type: " + JSON.stringify(n.type));
  46. }
  47. }
  48. var encodeU32 = encoder.encodeU32;
  49. exports.encodeU32 = encodeU32;