arboriculture.js
function iterizeForOf(node, path) {
        if (node.body.type !== 'BlockStatement') {
            node.body = {
                type: 'BlockStatement',
                body: [node.body]
            };
        }
        var index, iterator, initIterator = parsePart("[$0[Symbol.iterator]()]", [node.right]).expr;
        if (node.left.type === 'VariableDeclaration') {
            if (node.left.kind === 'const') 
                node.left.kind = 'let';
            if (node.left.kind === 'let') { 
            	    node.update = literal(null) ;
                node.update.$EmptyExpression = true ;
            }
            index = node.left.declarations[0].id;
            var decls = getDeclNames(node.left.declarations[0].id);
            iterator = ident(generateSymbol("iterator_" + decls.join('_')));
            node.left.declarations = decls.map(function (name) {
                return {
                    type: "VariableDeclarator",
                    id: ident(name)
                };
            });
            node.left.declarations.push({
                type: "VariableDeclarator",
                id: iterator,
                init: initIterator
            });
            node.init = node.left;
        } else {
            index = node.left;
            iterator = ident(generateSymbol("iterator_" + index.name));
            var declaration = {
                type: 'VariableDeclaration',
                kind: 'var',
                declarations: [{
                    type: "VariableDeclarator",
                    id: iterator,
                    init: initIterator
                }]
            };
            node.init = declaration;
        }
        node.type = 'ForStatement';
        node.test = parsePart("!($0[1] = $0[0].next()).done && (($1 = $0[1].value) || true)", [iterator,
            index]).expr;
        delete node.left;
        delete node.right;
    }
function iterizeForOf(node, path) {
        if (node.body.type !== 'BlockStatement') {
            node.body = {
                type: 'BlockStatement',
                body: [node.body]
            };
        }
        var index, iterator, initIterator = parsePart("[$0[Symbol.iterator]()]", [node.right]).expr;
        if (node.left.type === 'VariableDeclaration') {
            if (node.left.kind === 'const') 
                node.left.kind = 'let';
            if (node.left.kind === 'let') { 
            	    node.update = literal(null) ;
                node.update.$EmptyExpression = true ;
            }
            index = node.left.declarations[0].id;
            var decls = getDeclNames(node.left.declarations[0].id);
            iterator = ident(generateSymbol("iterator_" + decls.join('_')));
            node.left.declarations = decls.map(function (name) {
                return {
                    type: "VariableDeclarator",
                    id: ident(name)
                };
            });
            node.left.declarations.push({
                type: "VariableDeclarator",
                id: iterator,
                init: initIterator
            });
            node.init = node.left;
        } else {
            index = node.left;
            iterator = ident(generateSymbol("iterator_" + index.name));
            var declaration = {
                type: 'VariableDeclaration',
                kind: 'var',
                declarations: [{
                    type: "VariableDeclarator",
                    id: iterator,
                    init: initIterator
                }]
            };
            node.init = declaration;
        }
        node.type = 'ForStatement';
        node.test = parsePart("!($0[1] = $0[0].next()).done && (($1 = $0[1].value) || true)", [iterator,
            index]).expr;
        delete node.left;
        delete node.right;
    }
function iterizeForOf ( node , path ) { if ( node . body . type !== 'BlockStatement' ) { node . body = { type : 'BlockStatement' , body : [ node . body ] } ; } var index , iterator , initIterator = parsePart ( "[$0[Symbol.iterator]()]" , [ node . right ] ) . expr ; if ( node . left . type === 'VariableDeclaration' ) { if ( node . left . kind === 'const' ) node . left . kind = 'let' ; if ( node . left . kind === 'let' ) { node . update = literal ( null ) ; node . update . $EmptyExpression = true ; } index = node . left . declarations [ 0 ] . id ; var decls = getDeclNames ( node . left . declarations [ 0 ] . id ) ; iterator = ident ( generateSymbol ( "iterator_" + decls . join ( '_' ) ) ) ; node . left . declarations = decls . map ( function ( name ) { return { type : "VariableDeclarator" , id : ident ( name ) } ; } ) ; node . left . declarations . push ( { type : "VariableDeclarator" , id : iterator , init : initIterator } ) ; node . init = node . left ; } else { index = node . left ; iterator = ident ( generateSymbol ( "iterator_" + index . name ) ) ; var declaration = { type : 'VariableDeclaration' , kind : 'var' , declarations : [ { type : "VariableDeclarator" , id : iterator , init : initIterator } ] } ; node . init = declaration ; } node . type = 'ForStatement' ; node . test = parsePart ( "!($0[1] = $0[0].next()).done && (($1 = $0[1].value) || true)" , [ iterator , index ] ) . expr ; delete node . left ; delete node . right ; }
Transform a for..of into it's iterative equivalent
Transform a for .. of into it s iterative equivalent