babeland
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

babeland

A collection of babel helpers, types, and plugins

Table of Contents

Motivation

I DON'T WANT to install so many @babel/* packages

If you frequently use babel to manipulate AST transformations, you may find that you must also install these packages as well as there types (@types/babel__*):

That's pretty tedious, so babeland brings them all together and can be used in very quickly when you need it.

Different to babel-shared?

babel-shared only exports basic types and utilities, while babeland exports parser, traverse and generator.

Install

npm i babeland -S  # npm
pnpm i babeland -S # pnpm

Example

Transform JSX

import { transformSync, declarePluginTuple, declarePlugin } from "babeland";

interface PluginOptions {
  name: string;
}
interface PluginState {
  state: unknown;
}

const pluginTuple = declarePluginTuple<PluginOptions, PluginState>(
  declarePlugin((babel) => ({
    name: "solid",
    inherits: require("@babel/plugin-syntax-jsx").default,
    pre() {
      this.templates = [];
    },
    visitor: {
      JSXElement(path) {
        // Your transform
      },
    },
  })),
  {
    name: "babeland",
  }
);

const input = "<div>Hello, {'Babeland'}</div>";

const output = transformSync(input, {
  plugins: [pluginTuple],
});

console.log("input\n", input);
console.log("output\n", output.code);

License

MIT © ULIVZ

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.30latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.30
0.2.20
0.2.10
0.2.00
0.0.10

Package Sidebar

Install

npm i babeland

Weekly Downloads

0

Version

0.2.3

License

none

Unpacked Size

13.2 kB

Total Files

15

Last publish

Collaborators

  • ulivz