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 🙏

© 2025 – Pkg Stats / Ryan Hefner

babel-plugin-inline-functions

v1.0.1

Published

A Babel plugin to inline selected functions

Downloads

13

Readme

babel-plugin-inline-functions

Build Status NPM Version

NAME

babel-plugin-inline-functions - a Babel plugin to inline selected functions

INSTALLATION

$ npm install babel-plugin-inline-functions

SYNOPSIS

$ cat test.js

function __INLINE__coalesce (value) {
    return value ?? ''
}

const foo = __INLINE__coalesce(options.foo)

$ babel --plugins inline-functions test.js

const foo = options.foo ?? ''

DESCRIPTION

This is a Babel plugin which inlines calls to selected functions within the scope in which the functions are declared. Only functions which contain a single return statement are inlined. Arguments passed to inlined functions are substituted for the corresponding parameters in the function body and (by default) the original function is removed.

Functions can be marked for inlining by using a custom prefix in the function name, a comment before the function declaration, or a label for the return statement in the function's body. By default, functions whose names begin with "__INLINE__" are inlined, but this can be modified or disabled via the plugin's options.

OPTIONS

The following plugin options are supported.

comment

  • Type: string | false
  • Default: false

Select functions for inlining by the presence of a block comment before the function keyword in the declaration. If set, the comment body is trimmed and compared to the option's value, and, if equal, the function is inlined. If set to false (as it is by default), function declaration comments are not checked.

Config

{
    "plugins": [
        ["inline-functions", {
            "comment": "inline"
        }]
    ]
}

Input

/* inline */ function coalesce (value) {
    return value ?? ''
}

const foo = coalesce(options.foo)

Output

const foo = options.foo ?? ''

label

  • Type: string | false
  • Default: false

Select functions for inlining by the presence of a label with this name before the return statement. If set to false (as it is by default), return statement labels are not checked.

Config

{
    "plugins": [
        ["inline-functions", {
            "label": "inline"
        }]
    ]
}

Input

function coalesce (value) {
    inline: return value ?? ''
}

const foo = coalesce(options.foo)

Output

const foo = options.foo ?? ''

prefix

  • Type: string | false
  • Default: "__INLINE__"

Select functions for inlining whose names start with the specified prefix. If set to false, function names are not checked.

Config

{
    "plugins": [
        ["inline-functions", {
            "prefix": "__inline__"
        }]
    ]
}

Input

function __inline__coalesce (value) {
    return value ?? ''
}

const foo = __inline__coalesce(options.foo)

Output

const foo = options.foo ?? ''

remove

  • Type: boolean
  • Default: true

Remove the inlined function declaration. If set to false, the declaration is preserved.

Config

{
    "plugins": [
        ["inline-functions", {
            "remove": false
        }]
    ]
}

Input

function __INLINE__coalesce (value) {
    return value ?? ''
}

const foo = __INLINE__coalesce(options.foo)

Output

function __INLINE__coalesce (value) {
    return value ?? ''
}

const foo = options.foo ?? ''

USAGE

.babelrc

$ cat .babelrc

{
    "plugins": ["inline-functions"]
}

CLI

$ babel --plugins inline-functions script.js

API

require('@babel/core').transform(code, {
    plugins: ['inline-functions']
})

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • doctoc - generate the TOC (table of contents) in the README
  • test - run the test suite

COMPATIBILITY

CAVEATS

  • inlining may bloat your code
  • inlining may not speed things up and may even slow things down1
  • only works with functions that have a single return statement and simple (i.e. non-destructuring) parameters: keep things simple

1 Particularly on v8, which may have a better idea of what should be inlined when, and the memory/speed tradeoffs, than the developer.

SEE ALSO

VERSION

1.0.1

AUTHOR

COPYRIGHT AND LICENSE

Copyright © 2016-2020 by Emile Cantin.

This is free software; you can redistribute it and/or modify it under the terms of the ISC License.