source: trip-planner-front/node_modules/@webassemblyjs/helper-wasm-section/esm/remove.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import { traverse, getSectionMetadatas, shiftSection } from "@webassemblyjs/ast";
2import { overrideBytesInBuffer } from "@webassemblyjs/helper-buffer";
3export function removeSections(ast, uint8Buffer, section) {
4 var sectionMetadatas = getSectionMetadatas(ast, section);
5
6 if (sectionMetadatas.length === 0) {
7 throw new Error("Section metadata not found");
8 }
9
10 return sectionMetadatas.reverse().reduce(function (uint8Buffer, sectionMetadata) {
11 var startsIncludingId = sectionMetadata.startOffset - 1;
12 var ends = section === "start" ? sectionMetadata.size.loc.end.column + 1 : sectionMetadata.startOffset + sectionMetadata.size.value + 1;
13 var delta = -(ends - startsIncludingId);
14 /**
15 * update AST
16 */
17 // Once we hit our section every that is after needs to be shifted by the delta
18
19 var encounteredSection = false;
20 traverse(ast, {
21 SectionMetadata: function SectionMetadata(path) {
22 if (path.node.section === section) {
23 encounteredSection = true;
24 return path.remove();
25 }
26
27 if (encounteredSection === true) {
28 shiftSection(ast, path.node, delta);
29 }
30 }
31 }); // replacement is nothing
32
33 var replacement = [];
34 return overrideBytesInBuffer(uint8Buffer, startsIncludingId, ends, replacement);
35 }, uint8Buffer);
36}
Note: See TracBrowser for help on using the repository browser.