@webassemblyjs/ast
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -11,2 +11,12 @@ "use strict"; | ||
var partialEvaluation = require("webassemblyjs/lib/interpreter/partial-evaluation"); | ||
var _require = require("webassemblyjs/lib/interpreter/runtime/values/memory"), | ||
Memory = _require.Memory; | ||
var _require2 = require("webassemblyjs/lib/interpreter/kernel/memory"), | ||
createAllocator = _require2.createAllocator; | ||
var t = require("./index"); | ||
function removeNodeInBody(node, fromNode) { | ||
@@ -54,2 +64,19 @@ switch (fromNode.type) { | ||
function evaluate(customNode) { | ||
var n = [node]; | ||
if (typeof customNode !== "undefined") { | ||
n = customNode; | ||
} | ||
var memory = new Memory({ | ||
initial: 100 | ||
}); | ||
var allocator = createAllocator(memory); | ||
var code = n; // $FlowIgnore | ||
code.push(t.instruction("end")); | ||
return partialEvaluation.evaluate(allocator, code); | ||
} | ||
return { | ||
@@ -59,3 +86,4 @@ node: node, | ||
replaceWith: replaceWith, | ||
remove: remove | ||
remove: remove, | ||
evaluate: evaluate | ||
}; | ||
@@ -62,0 +90,0 @@ } |
{ | ||
"name": "@webassemblyjs/ast", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "AST utils for webassemblyjs", | ||
@@ -14,4 +14,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@webassemblyjs/wast-parser": "1.2.3", | ||
"webassemblyjs": "1.2.3" | ||
"@webassemblyjs/wast-parser": "1.2.4", | ||
"webassemblyjs": "1.2.4" | ||
}, | ||
@@ -18,0 +18,0 @@ "repository": { |
@@ -25,2 +25,21 @@ # @webassemblyjs/ast | ||
### Traverse and partial evaluation | ||
```js | ||
import { traverse } from "@webassemblyjs/ast"; | ||
traverse(ast, { | ||
Func(path) { | ||
const res = path.evaluate(); | ||
} | ||
}); | ||
// Or by specified an array of node | ||
traverse(ast, { | ||
Global(path) { | ||
const res = path.evaluate(path.node.init); | ||
} | ||
}); | ||
``` | ||
### Instruction signatures | ||
@@ -27,0 +46,0 @@ |
// @flow | ||
const partialEvaluation = require("webassemblyjs/lib/interpreter/partial-evaluation"); | ||
const { | ||
Memory | ||
} = require("webassemblyjs/lib/interpreter/runtime/values/memory"); | ||
const { | ||
createAllocator | ||
} = require("webassemblyjs/lib/interpreter/kernel/memory"); | ||
const t = require("./index"); | ||
type Cb = (type: string, path: NodePath<Node>) => void; | ||
@@ -45,2 +55,19 @@ | ||
function evaluate(customNode: ?Array<Node>): ?StackLocal { | ||
let n = [node]; | ||
if (typeof customNode !== "undefined") { | ||
n = customNode; | ||
} | ||
const memory = new Memory({ initial: 100 }); | ||
const allocator = createAllocator(memory); | ||
const code = n; | ||
// $FlowIgnore | ||
code.push(t.instruction("end")); | ||
return partialEvaluation.evaluate(allocator, code); | ||
} | ||
return { | ||
@@ -51,3 +78,4 @@ node, | ||
replaceWith, | ||
remove | ||
remove, | ||
evaluate | ||
}; | ||
@@ -54,0 +82,0 @@ } |
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
66954
2335
91
+ Added@webassemblyjs/floating-point-hex-parser@1.2.4(transitive)
+ Added@webassemblyjs/helper-code-frame@1.2.4(transitive)
+ Added@webassemblyjs/helper-fsm@1.2.4(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.2.4(transitive)
+ Added@webassemblyjs/leb128@1.2.4(transitive)
+ Added@webassemblyjs/wasm-parser@1.2.4(transitive)
+ Added@webassemblyjs/wast-parser@1.2.4(transitive)
+ Added@webassemblyjs/wast-printer@1.2.4(transitive)
+ Addedwebassemblyjs@1.2.4(transitive)
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.2.3(transitive)
- Removed@webassemblyjs/helper-fsm@1.2.3(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.2.3(transitive)
- Removed@webassemblyjs/leb128@1.2.3(transitive)
- Removed@webassemblyjs/wasm-parser@1.2.3(transitive)
- Removed@webassemblyjs/wast-parser@1.2.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedpicocolors@1.1.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedwebassemblyjs@1.2.3(transitive)
Updatedwebassemblyjs@1.2.4