Skip to main content

babel-plugin-transform-merge-sibling-variables

Example

In

JavaScript
// merge into a single VariableDeclaration
var foo = "bar";
var bar = "foo";
foobar();

// merge into the next for loop
var i = 0;
for (var x = 0; x < 10; x++) {}

Out

JavaScript
var foo = "bar",
bar = "foo";
foobar();

for (var i = 0, x = 0; x < 10; x++) {}

Installation

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

Usage

babel.config.json
{
"plugins": ["transform-merge-sibling-variables"]
}

Via CLI

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

Via Node API

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