source: trip-planner-front/node_modules/@webassemblyjs/helper-wasm-section/lib/remove.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.removeSections = removeSections;
7
8var _ast = require("@webassemblyjs/ast");
9
10var _helperBuffer = require("@webassemblyjs/helper-buffer");
11
12function 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}
Note: See TracBrowser for help on using the repository browser.