babeland
A collection of babel helpers, types, and plugins
Table of Contents
Motivation
@babel/*
packages
I DON'T WANT to install so many 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.
babel-shared
?
Different to 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