npm.io
0.2.1 • Published 5 years ago

babel-plugin-copy-jsx-attribute

Licence
Version
0.2.1
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
2

babel-plugin-copy-jsx-attribute

This project is a work in progress

A babel plugin to copy one JSX attribute to another.

Original use case was copying testID to accessibilityLabel in non-production builds to enable test automation.

Example

In

<Label testID={`${props.testID}-error-label`} styles={errorStyles}>
  {props.constraints}
</Label>

Out

<Label
  testID={`${props.testID}-error-label`}
  styles={errorStyles}
  accessibilityLabel={`${props.testID}-error-label`}
>
  {props.constraints}
</Label>

Installation

$ npm install babel-plugin-copy-jsx-attribute

Usage

.babelrc

{
  "plugins": ["copy-jsx-attribute"]
}
Via CLI
$ babel --plugins copy-jsx-attribute script.js
Via Node API
require("@babel/core").transform("code", {
  plugins: ["copy-jsx-attribute"],
});

Keywords