npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oxc-parser

v0.42.0

Published

Oxc Parser Node API

Downloads

40,325

Readme

Oxc Parser

Features

  • Returns ESM information.
  • Built-in magic-string on the Rust side exposed through N-API.
  • "clever" approach to overcome the Rust UTF8 vs JavaScript UTF16 length problem.

Caveat

The parser alone does not fully check for syntax errors that are associated with semantic data (symbols and scopes). The full compiler is needed for such case, as the compiler does an additional semantic pass.

With this caveat, oxc-parser is best suited for parser plugins, where you need quick access to ESM information, as well as fast magic-string operations.

API

import oxc from './index.js';

// The emoji makes the span of `import.meta.url` to be different in UTF8 and UTF16.
const code = 'const url: String = /* 🤨 */ import.meta.url;';

// File extension is used to determine which dialect to parse source as.
const filename = 'test.tsx';

const result = oxc.parseSync(filename, code);
// or `await oxc.parseAsync(filename, code)`

// An array of errors, if any.
console.log(result.errors);

// AST and comments.
console.log(result.program, result.comments);

// ESM information - imports, exports, `import.meta`s.
console.log(result.module);

// A `magic-string` instance for accessing and manipulating the source text.
// All returned spans are in UTF8 offsets, which cannot be used directly on our JavaScript.
// JavaScript string lengths are in UTF16 offsets.
const ms = result.magicString;

for (const span of result.module.importMetas) {
  // Extra methods for access the source text through spans with UTF8 offsets.
  console.log(ms.getSourceText(span.start, span.end)); // prints `import.meta`
  console.log(ms.getLineColumnNumber(span.start)); // prints `{ line: 0, column: 20 }`
  console.log(code.substring(ms.getUtf16ByteOffset(span.start)).startsWith('import.meta.url')); // prints `true`
}