# All files / gogocode-core/src/js-core/find specific.js

100% Statements 30/30
92.86% Branches 39/42
100% Functions 1/1
100% Lines 30/30

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
    4537x
    37x

    8205x

    111x
    111x
    111x
    57x
    54x
    51x

    76x
    76x
    49x

    76x
    42x
    18x
    18x

    18x
    11x
    10x

    11x
    11x
    11x

    8205x
    10x
    4x
    4x
    4x
    4x
    4x

    8205x
     const generate = require('../generate')
    module.exports = function handleSpecific({ full, partial, prop, extraData, Expando } = {}) {
        let specific, result;
        if (prop == 'body') {
            // 匹配一块代码
            try {
                let bodyContent = partial.body;
                if (Array.isArray(partial.body)) {
                    bodyContent = partial.body[0] || partial.body.body[0];
                } else if (partial.body && partial.body.body) {
                    bodyContent = partial.body.body[0]
                }
                let name = ''
                if (bodyContent) {
                    name = bodyContent.expression ? bodyContent.expression.name : bodyContent.name ? bodyContent.name : ''
                }
                if (name && name.match) {
                    if (name.match(Expando)) {
                        const expandoKey = name.replace(Expando, '') || '0';
                        extraData[expandoKey] = extraData[expandoKey] || [];
                        // 去掉首尾花括号
                        let bodyStr = generate(full.body) || '';
                        if (bodyStr.trim()[0] == '{') {
                            bodyStr = bodyStr.slice(1, -2);
                        }
                        extraData[expandoKey].push({ node: full.body, value: bodyStr });
                        specific = 'body';
                        result = true;
                    }
                }
            } catch (e) {
                // console.log(e)
            }
        }
        if (partial && partial.typeName && !partial.typeParameters) {
            if (partial.typeName.name.match(Expando)) {
                specific = 'TypeAnnotation';
                const expandoKey = partial.typeName.name.replace(Expando, '') || '0';
                extraData[expandoKey] = extraData[expandoKey] || [];
                extraData[expandoKey].push(full);
                result = true;
            }
        }
        return { specific, result }
    }