All files / lib/optimization optimize.js

95% Statements 19/20
100% Branches 9/9
50% Functions 1/2
95% Lines 19/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        3x 3x 3x 3x 3x 3x       3x   21x 1x   20x   7x 7x   7x 7x   2x 2x     20x 10x     3x  
"use strict";
/*
 * @copyright Microsoft Corporation. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.optimizeNode = exports.optimize = void 0;
const ts_morph_1 = require("ts-morph");
const binaryExp_1 = require("./binaryExp");
const conditionalExp_1 = require("./conditionalExp");
const if_1 = require("./if");
function optimize(nodes) {
    nodes.forEach(optimizeNode);
}
exports.optimize = optimize;
function optimizeNode(node) {
    if (!node || node.wasForgotten())
        return;
    let newWork;
    switch (node.getKind()) {
        case ts_morph_1.SyntaxKind.BinaryExpression:
            newWork = (0, binaryExp_1.handleBinaryExp)(node);
            break;
        case ts_morph_1.SyntaxKind.ConditionalExpression:
            newWork = (0, conditionalExp_1.handleConditionalExp)(node);
            break;
        case ts_morph_1.SyntaxKind.IfStatement:
            (0, if_1.handleIf)(node);
            break;
    }
    // if there's any optimization happened
    if (newWork) {
        optimizeNode(newWork.getParent());
    }
}
exports.optimizeNode = optimizeNode;