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

            const { node } = path;
            if (node.kind !== "var") {
              return;
            }

            const next = path.getSibling(path.key + 1);
            if (!next.isForStatement()) {
              return;
            }

            const init = next.get("init");
            if (!init.isVariableDeclaration({ kind: node.kind })) {
              return;
            }

            const declarations = node.declarations.concat(
              init.node.declarations
            );

            // temporary workaround to forces babel recalculate scope,
            // references and binding until babel/babel#4818 resolved
            path.remove();
            init.replaceWith(t.variableDeclaration("var", declarations));
          }
function(path) {
            if (!path.inList) {
              return;
            }

            const { node } = path;
            if (node.kind !== "var") {
              return;
            }

            const next = path.getSibling(path.key + 1);
            if (!next.isForStatement()) {
              return;
            }

            const init = next.get("init");
            if (!init.isVariableDeclaration({ kind: node.kind })) {
              return;
            }

            const declarations = node.declarations.concat(
              init.node.declarations
            );

            // temporary workaround to forces babel recalculate scope,
            // references and binding until babel/babel#4818 resolved
            path.remove();
            init.replaceWith(t.variableDeclaration("var", declarations));
          }
function ( path ) { if ( ! path . inList ) { return ; } const { node } = path ; if ( node . kind !== "var" ) { return ; } const next = path . getSibling ( path . key + 1 ) ; if ( ! next . isForStatement ( ) ) { return ; } const init = next . get ( "init" ) ; if ( ! init . isVariableDeclaration ( { kind : node . kind } ) ) { return ; } const declarations = node . declarations . concat ( init . node . declarations ) ; // temporary workaround to forces babel recalculate scope, // references and binding until babel/babel#4818 resolved path . remove ( ) ; init . replaceWith ( t . variableDeclaration ( "var" , declarations ) ) ; }
concat `var` declarations next to for loops with it's initialisers. block-scoped `let` and `const` are not moved because the for loop is a different block scope.
concat var declarations next to for loops with it s initialisers . block - scoped let and const are not moved because the for loop is a different block scope .