Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function shiftLocNodeByDelta(node: Node, delta: number) {
assertHasLoc(node);
// $FlowIgnore: assertHasLoc ensures that
node.loc.start.column += delta;
// $FlowIgnore: assertHasLoc ensures that
node.loc.end.column += delta;
}
function applyDelete(ast: Program, uint8Buffer: Uint8Array, node: Node): State {
const deltaElements = -1; // since we removed an element
assertHasLoc(node);
const sectionName = getSectionForNode(node);
if (sectionName === "start") {
const sectionMetadata = getSectionMetadata(ast, "start");
/**
* The start section only contains one element,
* we need to remove the whole section
*/
uint8Buffer = removeSections(ast, uint8Buffer, "start");
const deltaBytes = -(sectionMetadata.size.value + 1); /* section id */
return { uint8Buffer, deltaBytes, deltaElements };
}
function applyUpdate(ast, uint8Buffer, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
oldNode = _ref2[0],
newNode = _ref2[1];
var deltaElements = 0;
assertHasLoc(oldNode);
var sectionName = getSectionForNode(newNode);
var replacementByteArray = encodeNode(newNode);
/**
* Replace new node as bytes
*/
uint8Buffer = overrideBytesInBuffer(uint8Buffer, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.start.column, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.end.column, replacementByteArray);
/**
* Update function body size if needed
*/
if (sectionName === "code") {
// Find the parent func
traverse(ast, {
function shiftLocNodeByDelta(node: Node, delta: number) {
assertHasLoc(node);
// $FlowIgnore: assertHasLoc ensures that
node.loc.start.column += delta;
// $FlowIgnore: assertHasLoc ensures that
node.loc.end.column += delta;
}
function applyDelete(ast, uint8Buffer, node) {
var deltaElements = -1; // since we removed an element
assertHasLoc(node);
var sectionName = getSectionForNode(node);
if (sectionName === "start") {
var sectionMetadata = getSectionMetadata(ast, "start");
/**
* The start section only contains one element,
* we need to remove the whole section
*/
uint8Buffer = removeSections(ast, uint8Buffer, "start");
var _deltaBytes = -(sectionMetadata.size.value + 1)
/* section id */
;
return {
Func({ node }) {
const funcHasThisIntr =
node.body.find(n => n === newNode) !== undefined;
// Update func's body size if needed
if (funcHasThisIntr === true) {
// These are the old functions locations informations
assertHasLoc(node);
const oldNodeSize = encodeNode(oldNode).length;
const bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;
if (bodySizeDeltaBytes !== 0) {
const newValue = node.metadata.bodySize + bodySizeDeltaBytes;
const newByteArray = encodeU32(newValue);
debug("resize func body newValue=%d", newValue);
// function body size byte
// FIXME(sven): only handles one byte u32
const start = node.loc.start.column;
const end = start + 1;
uint8Buffer = overrideBytesInBuffer(
function applyUpdate(ast, uint8Buffer, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
oldNode = _ref2[0],
newNode = _ref2[1];
var deltaElements = 0;
assertHasLoc(oldNode);
var sectionName = getSectionForNode(newNode);
var replacementByteArray = encodeNode(newNode);
/**
* Replace new node as bytes
*/
uint8Buffer = overrideBytesInBuffer(uint8Buffer, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.start.column, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.end.column, replacementByteArray);
/**
* Update function body size if needed
*/
if (sectionName === "code") {
// Find the parent func
traverse(ast, {
function applyUpdate(
ast: Program,
uint8Buffer: Uint8Array,
[oldNode, newNode]: [Node, Node]
): State {
const deltaElements = 0;
assertHasLoc(oldNode);
const sectionName = getSectionForNode(newNode);
const replacementByteArray = encodeNode(newNode);
/**
* Replace new node as bytes
*/
uint8Buffer = overrideBytesInBuffer(
uint8Buffer,
// $FlowIgnore: assertHasLoc ensures that
oldNode.loc.start.column,
// $FlowIgnore: assertHasLoc ensures that
oldNode.loc.end.column,
replacementByteArray
);
function shiftLocNodeByDelta(node, delta) {
assertHasLoc(node); // $FlowIgnore: assertHasLoc ensures that
node.loc.start.column += delta; // $FlowIgnore: assertHasLoc ensures that
node.loc.end.column += delta;
}