pruneVarReferences(assignments) {
        var engine = this;

        // Remove redundant variables by deleting declarations and replacing variable references
        estraverse.replace(this.ast, {
            enter: function (node, parent) {
                if (node.type === 'VariableDeclarator') {
                    if (node.id.name in assignments) {
                        engine.changed = true;
                        return this.remove();
                    }
                } else if (node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression') {
                    if (node.expression.left.name in assignments) {
                        engine.preserveCommentsBasedOnOption(node, parent, engine.keep_comments);
                        engine.changed = true;
                        return this.remove();
                    }
                } else if (node.type === 'Identifier') {
                    if (node.name in assignments) {
                        if (assignments[node.name] === true) {
                            engine.changed = true;
                            return engine.trueLiteral();
                        } else if (assignments[node.name] === false) {
                            engine.changed = true;
                            return engine.falseLiteral();
                        }
                    }
                }
            },

            // After previous step, some declaration may have no declarators, delete them.
            leave: function (node, parent) {
                if (node.type === 'VariableDeclaration') {
                    if (node.declarations.length === 0) {
                        engine.preserveCommentsBasedOnOption(node, parent, engine.keep_comments);
                        engine.changed = true;
                        return this.remove();
                    }
                }
            },

            fallback: 'iteration',
        });
    }
// Replace all references of variables in `assignments` with the corresponding literal
Replace all references of variables in `assignments` with the corresponding literal
Replace all references of variables in ` assignments ` with the corresponding literal
pruneVarReferences(assignments) {
        var engine = this;
        estraverse.replace(this.ast, {
            enter: function (node, parent) {
                if (node.type === 'VariableDeclarator') {
                    if (node.id.name in assignments) {
                        engine.changed = true;
                        return this.remove();
                    }
                } else if (node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression') {
                    if (node.expression.left.name in assignments) {
                        engine.preserveCommentsBasedOnOption(node, parent, engine.keep_comments);
                        engine.changed = true;
                        return this.remove();
                    }
                } else if (node.type === 'Identifier') {
                    if (node.name in assignments) {
                        if (assignments[node.name] === true) {
                            engine.changed = true;
                            return engine.trueLiteral();
                        } else if (assignments[node.name] === false) {
                            engine.changed = true;
                            return engine.falseLiteral();
                        }
                    }
                }
            },
            leave: function (node, parent) {
                if (node.type === 'VariableDeclaration') {
                    if (node.declarations.length === 0) {
                        engine.preserveCommentsBasedOnOption(node, parent, engine.keep_comments);
                        engine.changed = true;
                        return this.remove();
                    }
                }
            },
            fallback: 'iteration',
        });
    }
pruneVarReferences ( assignments ) { var engine = this ; estraverse . replace ( this . ast , { enter : function ( node , parent ) { if ( node . type === 'VariableDeclarator' ) { if ( node . id . name in assignments ) { engine . changed = true ; return this . remove ( ) ; } } else if ( node . type === 'ExpressionStatement' && node . expression . type === 'AssignmentExpression' ) { if ( node . expression . left . name in assignments ) { engine . preserveCommentsBasedOnOption ( node , parent , engine . keep_comments ) ; engine . changed = true ; return this . remove ( ) ; } } else if ( node . type === 'Identifier' ) { if ( node . name in assignments ) { if ( assignments [ node . name ] === true ) { engine . changed = true ; return engine . trueLiteral ( ) ; } else if ( assignments [ node . name ] === false ) { engine . changed = true ; return engine . falseLiteral ( ) ; } } } } , leave : function ( node , parent ) { if ( node . type === 'VariableDeclaration' ) { if ( node . declarations . length === 0 ) { engine . preserveCommentsBasedOnOption ( node , parent , engine . keep_comments ) ; engine . changed = true ; return this . remove ( ) ; } } } , fallback : 'iteration' , } ) ; }
Replace all references of variables in `assignments` with the corresponding literal
Replace all references of variables in ` assignments ` with the corresponding literal
// Remove redundant variables by deleting declarations and replacing variable references // After previous step, some declaration may have no declarators, delete them.