🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-inline-helpers

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-inline-helpers

Babel plugin to inline simple static `const` variables or TypeScript type guard functions that are only one line when a leading comment contains `@inline`.

1.0.1
latest
npm
Version published
Maintainers
1
Created
Source

babel-plugin-transform-inline-helpers

Babel plugin to inline simple static const variables or TypeScript type guard functions that are only one line when a leading comment contains @inline.

This plugin was written to make working on Preact easier. It is not intended to be a full blown inlining solution or anything. There will likely be no support outside of the use case we have for Preact.

Usage

npm install --save-dev babel-plugin-transform-inline-helpers

Configuration in your babel.config.js:

const fs = require("fs");
const path = require("path");

// Path to file with helpers that should be inlined
const inlineFile = path.join(__dirname, "path/to/my-helpers.js");
const inlineCode = fs.readFileSync(inlineFile, "utf-8");

module.exports = function () {
  return {
    plugins: [
      "babel-plugin-transform-inline-helpers",
      {
        inlineCode,
      },
    ],
  };
};

Example

helper.js:

/** @inline */
export const FOO = 2;

/** @inline */
export const addTwo = (x) => x + 2;

/** @inline */
export function addTwo2(x) {
  return x + 2;
}
import { addTwo } from "./helper.js";

const num = 42;
console.log(addTwo(num));

...becomes:

const num = 42;
console.log(num + 2);

License

MIT, see the LICENSE file.

FAQs

Package last updated on 22 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts