analyze.js
// Emulation of member function statements hoisting of by doing some reordering within AST
Emulation of member function statements hoisting of by doing some reordering within AST
Emulation of member function statements hoisting of by doing some reordering within AST
function hoist(obj, scope) {
    scope = scope || obj;
    let newScope = scope;
    if (obj.type === "FunctionExpression" && obj.body.type === "BlockStatement")
        newScope = obj.body;
    for (const key of Object.keys(obj)) {
        if (obj[key] !== null && typeof obj[key] === "object") {
            const hoisted = [];
            if (Array.isArray(obj[key])) {
                obj[key] = obj[key].reduce((arr, el) => {
                    if (el && el.hoist) {
                        el.hoist = false;
                        hoisted.push(el);
                        if (el.hoistExpression)
                            arr.push(el.expression.left);
                    } else
                        arr.push(el);
                    return arr;
                }, []);
            } else if (obj[key].hoist) {
                const el = obj[key];
                el.hoist = false;
                hoisted.push(el);
                obj[key] = el.expression.left;
            }
            scope.body.unshift(...hoisted);
            hoist(obj[key], newScope);
        }
    }
}
function hoist ( obj , scope ) { scope = scope || obj ; let newScope = scope ; if ( obj . type === "FunctionExpression" && obj . body . type === "BlockStatement" ) newScope = obj . body ; for ( const key of Object . keys ( obj ) ) { if ( obj [ key ] !== null && typeof obj [ key ] === "object" ) { const hoisted = [ ] ; if ( Array . isArray ( obj [ key ] ) ) { obj [ key ] = obj [ key ] . reduce ( ( arr , el ) => { if ( el && el . hoist ) { el . hoist = false ; hoisted . push ( el ) ; if ( el . hoistExpression ) arr . push ( el . expression . left ) ; } else arr . push ( el ) ; return arr ; } , [ ] ) ; } else if ( obj [ key ] . hoist ) { const el = obj [ key ] ; el . hoist = false ; hoisted . push ( el ) ; obj [ key ] = el . expression . left ; } scope . body . unshift ( ... hoisted ) ; hoist ( obj [ key ] , newScope ) ; } } }
Emulation of member function statements hoisting of by doing some reordering within AST
Emulation of member function statements hoisting of by doing some reordering within AST
// All declarations should be moved to the top of current function scope // Mark as hoisted yet // Should be hoisted? Add to array and filter out from current. // If it was an expression: leave identifier // Hoist all elements