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