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 | 3x 3x 3x 3x 21x 21x 5x 16x 10x 21x 3x 6x 5x 5x 5x | "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleBinaryExp = void 0;
/*
* @copyright Microsoft Corporation. All rights reserved.
*/
const ts_morph_1 = require("ts-morph");
const utils_1 = require("../utils");
function handleBinaryExp(exp) {
const operator = exp.getOperatorToken().getKind();
let newWork;
if (operator === ts_morph_1.SyntaxKind.AmpersandAmpersandToken) {
newWork = exp.getFirstChildByKind(ts_morph_1.SyntaxKind.FalseKeyword)
? exp.replaceWithText('false')
: simplify(exp, ts_morph_1.SyntaxKind.TrueKeyword);
}
else if (operator === ts_morph_1.SyntaxKind.BarBarToken) {
newWork = exp.getFirstChildByKind(ts_morph_1.SyntaxKind.TrueKeyword)
? exp.replaceWithText('true')
: simplify(exp, ts_morph_1.SyntaxKind.FalseKeyword);
}
return (0, utils_1.tryUnwrapParenthese)(newWork);
}
exports.handleBinaryExp = handleBinaryExp;
function simplify(exp, keyword) {
if (exp.getFirstChildByKind(keyword)) {
const lhs = exp.getLeft();
const rhs = exp.getRight();
return lhs.getKind() === keyword
? exp.replaceWithText(rhs.getText())
: exp.replaceWithText(lhs.getText());
}
}
|