packages/babel-plugin-transform-merge-sibling-variables/src/index.js
function(path) {
            if (!path.inList) {
              return;
            }

            const { node } = path;

            let sibling = path.getSibling(path.key + 1);

            let declarations = [];

            while (sibling.isVariableDeclaration({ kind: node.kind })) {
              declarations = declarations.concat(sibling.node.declarations);

              sibling.remove();

              sibling = path.getSibling(path.key + 1);
            }

            if (declarations.length > 0) {
              path.replaceWith(
                t.variableDeclaration(node.kind, [
                  ...node.declarations,
                  ...declarations
                ])
              );
            }
          }
function(path) {
            if (!path.inList) {
              return;
            }

            const { node } = path;

            let sibling = path.getSibling(path.key + 1);

            let declarations = [];

            while (sibling.isVariableDeclaration({ kind: node.kind })) {
              declarations = declarations.concat(sibling.node.declarations);

              sibling.remove();

              sibling = path.getSibling(path.key + 1);
            }

            if (declarations.length > 0) {
              path.replaceWith(
                t.variableDeclaration(node.kind, [
                  ...node.declarations,
                  ...declarations
                ])
              );
            }
          }
function ( path ) { if ( ! path . inList ) { return ; } const { node } = path ; let sibling = path . getSibling ( path . key + 1 ) ; let declarations = [ ] ; while ( sibling . isVariableDeclaration ( { kind : node . kind } ) ) { declarations = declarations . concat ( sibling . node . declarations ) ; sibling . remove ( ) ; sibling = path . getSibling ( path . key + 1 ) ; } if ( declarations . length > 0 ) { path . replaceWith ( t . variableDeclaration ( node . kind , [ ... node . declarations , ... declarations ] ) ) ; } }
concat variables of the same kind with their siblings
concat variables of the same kind with their siblings