@webassemblyjs/ast
Advanced tools
Comparing version 1.2.7 to 1.2.8
@@ -78,2 +78,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "sortSectionMetadata", { | ||
enumerable: true, | ||
get: function () { | ||
return _utils.sortSectionMetadata; | ||
} | ||
}); | ||
Object.defineProperty(exports, "cloneNode", { | ||
@@ -214,3 +220,5 @@ enumerable: true, | ||
function sectionMetadata(section, startOffset, size) { | ||
var vectorOfSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1; | ||
var vectorOfSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : numberLiteral(-1); | ||
assert(size.type === "NumberLiteral"); | ||
assert(vectorOfSize.type === "NumberLiteral"); | ||
return { | ||
@@ -217,0 +225,0 @@ type: "SectionMetadata", |
@@ -11,4 +11,40 @@ "use strict"; | ||
var debug = require("debug")("wasm:traverse"); | ||
function _shift(node, delta) { | ||
if (node.type === "SectionMetadata") { | ||
node.startOffset += delta; | ||
if (_typeof(node.size.loc) === "object") { | ||
// $FlowIgnore | ||
node.size.loc.start.column += delta; // $FlowIgnore | ||
node.size.loc.end.column += delta; | ||
} | ||
if (_typeof(node.vectorOfSize.loc) === "object") { | ||
// $FlowIgnore | ||
node.vectorOfSize.loc.start.column += delta; // $FlowIgnore | ||
node.vectorOfSize.loc.end.column += delta; | ||
} | ||
debug("shifted %s startOffset=%d", node.type, node.startOffset); | ||
} else { | ||
// // $FlowIgnore | ||
// node.loc.start.column += delta; | ||
// // $FlowIgnore | ||
// node.loc.end.column += delta; | ||
throw new Error("Can not shift node " + JSON.stringify(node.type)); | ||
} | ||
} | ||
function removeNodeInBody(node, fromNode) { | ||
switch (fromNode.type) { | ||
case "ModuleMetadata": | ||
fromNode.sections = fromNode.sections.filter(function (n) { | ||
return n !== node; | ||
}); | ||
break; | ||
case "Module": | ||
@@ -58,3 +94,6 @@ fromNode.fields = fromNode.fields.filter(function (n) { | ||
replaceWith: replaceWith, | ||
remove: remove | ||
remove: remove, | ||
shift: function shift(delta) { | ||
return _shift(node, delta); | ||
} | ||
}; | ||
@@ -61,0 +100,0 @@ } |
@@ -7,5 +7,10 @@ "use strict"; | ||
exports.getSectionMetadata = getSectionMetadata; | ||
exports.sortSectionMetadata = sortSectionMetadata; | ||
var _traverse = require("./traverse"); | ||
var _helperWasmBytecode = _interopRequireDefault(require("@webassemblyjs/helper-wasm-bytecode")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getSectionMetadata(ast, name) { | ||
@@ -33,2 +38,21 @@ var section; | ||
return section; | ||
} | ||
function sortSectionMetadata(m) { | ||
if (m.metadata == null) { | ||
console.warn("sortSectionMetadata: no metadata to sort"); | ||
return; | ||
} // $FlowIgnore | ||
m.metadata.sections.sort(function (a, b) { | ||
var aId = _helperWasmBytecode.default.sections[a.section]; | ||
var bId = _helperWasmBytecode.default.sections[b.section]; | ||
if (typeof aId !== "number" || typeof bId !== "number") { | ||
throw new Error("Section id not found"); | ||
} | ||
return aId > bId; | ||
}); | ||
} |
{ | ||
"name": "@webassemblyjs/ast", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"description": "AST utils for webassemblyjs", | ||
@@ -14,4 +14,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@webassemblyjs/wast-parser": "1.2.7", | ||
"webassemblyjs": "1.2.7" | ||
"@webassemblyjs/helper-wasm-bytecode": "1.2.8", | ||
"@webassemblyjs/wast-parser": "1.2.8", | ||
"webassemblyjs": "1.2.8" | ||
}, | ||
@@ -18,0 +19,0 @@ "repository": { |
@@ -133,5 +133,9 @@ // @flow | ||
startOffset: number, | ||
size: number, | ||
vectorOfSize: number = -1 | ||
size: NumberLiteral, | ||
// $FlowIgnore | ||
vectorOfSize: NumberLiteral = numberLiteral(-1) | ||
): SectionMetadata { | ||
assert(size.type === "NumberLiteral"); | ||
assert(vectorOfSize.type === "NumberLiteral"); | ||
return { | ||
@@ -677,3 +681,3 @@ type: "SectionMetadata", | ||
export { signatures } from "./signatures"; | ||
export { getSectionMetadata } from "./utils"; | ||
export { getSectionMetadata, sortSectionMetadata } from "./utils"; | ||
export { cloneNode } from "./clone"; |
@@ -5,4 +5,38 @@ // @flow | ||
const debug = require("debug")("wasm:traverse"); | ||
function shift(node: Node, delta: number) { | ||
if (node.type === "SectionMetadata") { | ||
node.startOffset += delta; | ||
if (typeof node.size.loc === "object") { | ||
// $FlowIgnore | ||
node.size.loc.start.column += delta; | ||
// $FlowIgnore | ||
node.size.loc.end.column += delta; | ||
} | ||
if (typeof node.vectorOfSize.loc === "object") { | ||
// $FlowIgnore | ||
node.vectorOfSize.loc.start.column += delta; | ||
// $FlowIgnore | ||
node.vectorOfSize.loc.end.column += delta; | ||
} | ||
debug("shifted %s startOffset=%d", node.type, node.startOffset); | ||
} else { | ||
// // $FlowIgnore | ||
// node.loc.start.column += delta; | ||
// // $FlowIgnore | ||
// node.loc.end.column += delta; | ||
throw new Error("Can not shift node " + JSON.stringify(node.type)); | ||
} | ||
} | ||
function removeNodeInBody(node: Node, fromNode: Node) { | ||
switch (fromNode.type) { | ||
case "ModuleMetadata": | ||
fromNode.sections = fromNode.sections.filter(n => n !== node); | ||
break; | ||
case "Module": | ||
@@ -51,3 +85,4 @@ fromNode.fields = fromNode.fields.filter(n => n !== node); | ||
replaceWith, | ||
remove | ||
remove, | ||
shift: delta => shift(node, delta) | ||
}; | ||
@@ -54,0 +89,0 @@ } |
// @flow | ||
import { traverse } from "./traverse"; | ||
import constants from "@webassemblyjs/helper-wasm-bytecode"; | ||
@@ -21,1 +22,20 @@ export function getSectionMetadata( | ||
} | ||
export function sortSectionMetadata(m: Module) { | ||
if (m.metadata == null) { | ||
console.warn("sortSectionMetadata: no metadata to sort"); | ||
return; | ||
} | ||
// $FlowIgnore | ||
m.metadata.sections.sort((a, b) => { | ||
const aId = constants.sections[a.section]; | ||
const bId = constants.sections[b.section]; | ||
if (typeof aId !== "number" || typeof bId !== "number") { | ||
throw new Error("Section id not found"); | ||
} | ||
return aId > bId; | ||
}); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75317
2612
3
+ Added@webassemblyjs/floating-point-hex-parser@1.2.8(transitive)
+ Added@webassemblyjs/helper-code-frame@1.2.8(transitive)
+ Added@webassemblyjs/helper-fsm@1.2.8(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.2.8(transitive)
+ Added@webassemblyjs/leb128@1.2.8(transitive)
+ Added@webassemblyjs/validation@1.2.8(transitive)
+ Added@webassemblyjs/wasm-parser@1.2.8(transitive)
+ Added@webassemblyjs/wast-parser@1.2.8(transitive)
+ Added@webassemblyjs/wast-printer@1.2.8(transitive)
+ Addedwebassemblyjs@1.2.8(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.2.7(transitive)
- Removed@webassemblyjs/helper-code-frame@1.2.7(transitive)
- Removed@webassemblyjs/helper-fsm@1.2.7(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.2.7(transitive)
- Removed@webassemblyjs/leb128@1.2.7(transitive)
- Removed@webassemblyjs/validation@1.2.7(transitive)
- Removed@webassemblyjs/wasm-parser@1.2.7(transitive)
- Removed@webassemblyjs/wast-parser@1.2.7(transitive)
- Removed@webassemblyjs/wast-printer@1.2.7(transitive)
- Removedwebassemblyjs@1.2.7(transitive)
Updatedwebassemblyjs@1.2.8