All files / lib/utils index.js

63.63% Statements 21/33
65% Branches 13/20
62.5% Functions 5/8
60.71% Lines 17/28

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 37 38 39 40 41 42 43 44 45 46 47 48 49        4x 8x 11x         4x 8x   4x 4x 4x             4x     5x   4x   30x 6x   24x   4x                     4x 4x  
"use strict";
/*
 * @copyright Microsoft Corporation. All rights reserved.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.printReference = exports.tryUnwrapParenthese = exports.unwrapBlock = exports.isAncestorOf = void 0;
const ts_morph_1 = require("ts-morph");
/**
 * Determine if nodeA is an ancestor of nodeB
 */
function isAncestorOf(nodeA, nodeB) {
    return nodeB.getAncestors().includes(nodeA);
}
exports.isAncestorOf = isAncestorOf;
function unwrapBlock(target) {
    // https://github.com/dsherret/ts-morph/issues/641
    return target.getChildSyntaxListOrThrow().getText({ trimLeadingIndentation: true });
}
exports.unwrapBlock = unwrapBlock;
function tryUnwrapParenthese(node) {
    if (node && node.getParentIfKind(ts_morph_1.SyntaxKind.ParenthesizedExpression)) {
        return node.getParent().replaceWithText(node.getText());
    }
    return node;
}
exports.tryUnwrapParenthese = tryUnwrapParenthese;
function printReference(reference) {
    console.log('---------');
    console.log('REFERENCE');
    console.log('---------');
    console.log(`File path:  ${reference.getSourceFile().getFilePath()}`);
    console.log(`Start: ${reference.getTextSpan().getStart()}`);
    console.log(`Length: ${reference.getTextSpan().getLength()}`);
    console.log(`Parent kind: ${reference.getNode().getParentOrThrow().getKindName()}`);
    console.log('\n');
}
exports.printReference = printReference;
__exportStar(require("./getInfoFromText"), exports);