0.2.3 • Published 1 year ago

babeland v0.2.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

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