babel-plugin-transform-merge-sibling-variables

Example

In

  1. // merge into a single VariableDeclaration
  2. var foo = "bar";
  3. var bar = "foo";
  4. foobar();
  5. // merge into the next for loop
  6. var i = 0;
  7. for (var x = 0; x < 10; x++) {}

Out

  1. var foo = "bar",
  2. bar = "foo";
  3. foobar();
  4. for (var i = 0, x = 0; x < 10; x++) {}

Installation

  1. npm install babel-plugin-transform-merge-sibling-variables --save-dev

Usage

.babelrc

  1. {
  2. "plugins": ["transform-merge-sibling-variables"]
  3. }

Via CLI

  1. babel --plugins transform-merge-sibling-variables script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["transform-merge-sibling-variables"]
  3. });