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

emitkit

v1.3.1

Published

Make your SWC transforms much nicer to write

Downloads

4

Readme

EmitKit

The easiest way to build SWC transforms.

jsxTransform

The @swc/core transform function is very useful, however will also compile any JSX expressions to React.createElement calls.

You can customise which function it calls etc etc, but you cannot just make it output the JSX as-is.

jsxTransform and jsxTransformSync have this capability:

Passed through transform: <div>foo</div> becomes /*#__PURE__*/ React.createElement("div", null, "foo");

Passed through jsxTransform: <div>foo</div> becomes <div >foo</div>;

Emitters

Writing out object literals to create new code is painful.

The feature that gives EmitKit its name: the emitters!

These are functions with a sane API to make writing ASTs a joy.

If any are missing, feel free to open an issue, there are a lot of syntax nodes in SWC!

AuxVisitor

SWC has a very useful utility called Visitor. This will pass every instance of a given syntax node type to a function in a class.

It initialises all of these functions to call each other to make this work.

It has a fatal flaw, however: when you override one of these functions to actually use the Visitor, you must remember to then pass the node back into the Visitor (for example, passing the props and body of a function back in).

For some overrides, such as visitExpression, however, this is infeasible as you would have to manually handle every single type of Expression.

AuxVisitor solves this: for each visit function on the Visitor it exports an equivalent auxVisit function:

For a function visitNODETYPE(n: T): T, there is an equivalent auxVisitNODETYPE(n: T): [T, boolean] | undefined.

Return undefined to do nothing and leave the node untouched, this extra isn't really necessary, but there's no reason not to add it for QoL.

Make any changes you want to your syntax node, then return it in an array. The second value is very important: in most cases this should be true.

The second array value controls if the AuxVisitor will keep the internal routing intact for this call: if you set this false, the Visitor will not visit children of that node, essentially acting as if you overrode the main visit function.

This is useful to prevent infinite loops in some cases, but usually should be left true as the whole point of AuxVisitor is leaving internal routing intact.