Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

remove.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.removeSections = removeSections;
  6. var _ast = require("@webassemblyjs/ast");
  7. var _helperBuffer = require("@webassemblyjs/helper-buffer");
  8. function removeSections(ast, uint8Buffer, section) {
  9. var sectionMetadatas = (0, _ast.getSectionMetadatas)(ast, section);
  10. if (sectionMetadatas.length === 0) {
  11. throw new Error("Section metadata not found");
  12. }
  13. return sectionMetadatas.reverse().reduce(function (uint8Buffer, sectionMetadata) {
  14. var startsIncludingId = sectionMetadata.startOffset - 1;
  15. var ends = section === "start" ? sectionMetadata.size.loc.end.column + 1 : sectionMetadata.startOffset + sectionMetadata.size.value + 1;
  16. var delta = -(ends - startsIncludingId);
  17. /**
  18. * update AST
  19. */
  20. // Once we hit our section every that is after needs to be shifted by the delta
  21. var encounteredSection = false;
  22. (0, _ast.traverse)(ast, {
  23. SectionMetadata: function SectionMetadata(path) {
  24. if (path.node.section === section) {
  25. encounteredSection = true;
  26. return path.remove();
  27. }
  28. if (encounteredSection === true) {
  29. (0, _ast.shiftSection)(ast, path.node, delta);
  30. }
  31. }
  32. }); // replacement is nothing
  33. var replacement = [];
  34. return (0, _helperBuffer.overrideBytesInBuffer)(uint8Buffer, startsIncludingId, ends, replacement);
  35. }, uint8Buffer);
  36. }