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

babel-plugin-set-display-name

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-set-display-name

Sets the display name of unnamed decorated functions assigned to a constant reference.

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Babel plugin: Set display name

NPM Version DevDependency Status

Sets the display name of unnamed decorated functions assigned to a constant reference.

Installation

npm install babel-plugin-set-display-name

Usage

{
  "plugins": ["babel-plugin-set-display-name"]
}

Options

If setName is set to true, also sets the name property of the function using Object.defineProperty. This enables seeing the intended function name in Node.js as well.

{
  "plugins": [["babel-plugin-set-display-name", { "setName": true }]]
}

Motivation

Functions are often decorated at the same time they are declared. This is often the case for React components, especially when used with Recompose:

const Div = compose(pure)(({ value }) => <div>{value}</div>)

However, in doing so, all components become unnamed, and error logs mention generic names (e.g., "Component") instead of "Div" in the example above.

This plugin only makes sense during development mode, and applies to any decorated function (not just React components) assigned to a const reference.

Example

In

export const Div = React.memo(({ value }) => <div>{value}</div>)

Out

export const Div = React.memo(
  ((name, callable) => {
    callable.displayName = name
    return callable
  })('Div', ({ value }) => <div>{value}</div>),
)

Keywords

FAQs

Package last updated on 05 Feb 2020

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