Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@webassemblyjs/wast-parser

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webassemblyjs/wast-parser

WebAssembly text format parser

  • 1.12.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7M
increased by7.8%
Maintainers
1
Weekly downloads
 
Created

What is @webassemblyjs/wast-parser?

@webassemblyjs/wast-parser is a JavaScript library that provides tools for parsing WebAssembly Text Format (WAT or WAST) into an Abstract Syntax Tree (AST). This is useful for developers who need to analyze, transform, or generate WebAssembly code programmatically.

What are @webassemblyjs/wast-parser's main functionalities?

Parsing WAST to AST

This feature allows you to parse a WAST string into an AST. The code sample demonstrates how to parse a simple WebAssembly module written in WAST format into its corresponding AST representation.

const wastParser = require('@webassemblyjs/wast-parser');
const wast = `(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    get_local $lhs
    get_local $rhs
    i32.add)
)`;
const ast = wastParser.parse(wast);
console.log(JSON.stringify(ast, null, 2));

Error Handling

This feature provides error handling capabilities when parsing invalid WAST code. The code sample shows how to catch and handle parsing errors.

const wastParser = require('@webassemblyjs/wast-parser');
const invalidWast = `(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    get_local $lhs
    get_local $rhs
    i32.add
)`; // Missing closing parenthesis
try {
  const ast = wastParser.parse(invalidWast);
} catch (e) {
  console.error('Parsing error:', e.message);
}

AST Traversal

This feature allows you to traverse the AST generated from WAST. The code sample demonstrates a simple traversal function that logs the type of each node in the AST.

const wastParser = require('@webassemblyjs/wast-parser');
const wast = `(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    get_local $lhs
    get_local $rhs
    i32.add)
)`;
const ast = wastParser.parse(wast);
function traverse(node) {
  console.log(node.type);
  if (node.body) {
    node.body.forEach(traverse);
  }
}
traverse(ast);

Other packages similar to @webassemblyjs/wast-parser

Keywords

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc