index.js 2.1 KB

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