# All files / gogocode-core/src/html-core filter-prop.js

100% Statements 15/15
100% Branches 8/8
100% Functions 2/2
100% Lines 15/15

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
    3837x

    37x

    37x
    734x

    2584x
    1376x
    579x
    138x
    138x
    177x
    177x

    441x
    441x

    797x

    37xconst { isObject } = require('../util')

    // 查找时 ast无用属性
    const Props = [
        'startPosition',
        'endPosition',
        'parentRef',
        'openStart',
        'openEnd',
        'startWrapper',
        'endWrapper',
        'close'
    ]

    const filterProps = function (node, structure) {
        for (const key in node) {
            // 过滤值为空的字段
            if (Props.indexOf(key) == -1 && node[key]) {
                if (isObject(node[key])) {
                    if (Array.isArray(node[key])) {
                        structure[key] = [];
                        node[key].forEach((n, i) => {
                            structure[key][i] = {};
                            filterProps(n, structure[key][i]);
                        });
                    } else {
                        structure[key] = {};
                        filterProps(node[key], structure[key]);
                    }
                } else {
                    structure[key] = node[key];
                }
            }
        }
    }

    module.exports = filterProps;