Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-preprocessor

Simple identifier replacements for Babel

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-preprocessor

Simple identifier replacements for Babel, supporting function name (__funcname) as well as any custom mapping, such as would usually be handled by a preprocessor in other languages. This is particularly useful if you have a profiling build that wants additional instrumentation.

Example (__funcname and custom replace)

Configuration (.babelrc or otherwise):

{
  "plugins": [
    ["transform-preprocessor", {
      "replace": {
        "trace()": "if (_enabled) logTrace(__funcname)",
      }
    }]
  ]
}

Input:

function test1() {
  console.log(__funcname);
}

function test2() {
  trace();
}

Output:

function test1() {
  console.log("test1");
}

function test2() {
  if (_enabled) logTrace("test2");
}

Options

{
  replace: {
    'source': 'dest', // simple replacement applied to Identifiers, replaces with specified code
    'source()': 'dest()', // simple replacement applied to a CallExpressions, replaces with specified code
    'source': (path) => {}, // calls replacement function, maybe just write a Babel plugin instead?
    'source()': '', // replace a CallExpression with nothing
    '__funcname': null, // disable a default replacement (__funcname will remain in output source)
  }
}

Default options

{
  replace: {
    '__funcname': replacerFuncName, // see lib/transform-preprocessor.js
  }
}

Future work

  • Support more complex call expression replacements, e.g. F(A, B) => f(A + 1, B, c)
  • Extend this to support some simple per-file macros in a JS-friendly way, e.g. const WIDTH = __define(10), or leave this kind of optimization to the minifiers?

FAQs

Package last updated on 22 Jul 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc