Socket
Socket
Sign inDemoInstall

@oxc-parser/wasm

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oxc-parser/wasm

Wasm target for the oxc parser.


Version published
Weekly downloads
10K
decreased by-9.76%
Maintainers
1
Weekly downloads
 
Created
Source

About

Experimental wasm package for the oxc parser, with full TypeScript typings support.

This package is built with wasm-pack build --release --target web for bundler (webpack / vite) consumption. Checkout oxc-parser for usage in node.js.

Source code: https://github.com/oxc-project/oxc/tree/main/wasm/parser

Usage

import initWasm, { parseSync } from "@oxc-parser/wasm";

async function main() {
  await initWasm();

  const code = "let foo";
  const result = parseSync(code, { sourceFilename: "test.ts" });
  console.log(result);
}

main();

Notes

UTF8 vs UTF16 byte offsets

The span value returned from the ASTs and diagnostics is in UTF8 byte offsets. Converting to UTF16 byte offsets:

let sourceTextUtf8 = new TextEncoder().encode(sourceText);

const convertToUtf8 = (sourceTextUtf8, d) => {
  return new TextDecoder().decode(sourceTextUtf8.slice(0, d)).length;
}

const diagnostics = result.errors.map((d) => ({
    from: convertToUtf8(sourceTextUtf8, d.start),
    to: convertToUtf8(sourceTextUtf8, d.end),
    severity: d.severity.toLowerCase(),
    message: d.message,
}));

Vite

wasm-pack build --target web is used for the wasm build.

You may need something like https://github.com/nshen/vite-plugin-wasm-pack to get it working with vite, otherwise vite will load the wasm file as a HTML file causing a CompileError: WebAssembly.instantiate(): expected magic word error.

Keywords

FAQs

Package last updated on 31 Jan 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