All files / gogocode-core/src NodePath.js

100% Statements 13/13
100% Branches 9/9
100% Functions 3/3
100% Lines 13/13

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 2237x 37x 37x   1674x 439x 439x   439x 3512x   439x       1235x 1235x 1235x 1235x      
const recast = require('recast-yx');
const visit = recast.types.visit;
module.exports =  class NodePath {
    constructor(node, parent, parentPath) {
        if (!parent && !parentPath && node.program) {
            const nodePath = this;
            visit(node, {
                visitFile(path) {
                    ['node', 'value', 'parent', 'get', 'getValueProperty', '__childCache', '__proto__', 'name'].forEach(key => {
                        nodePath[key] = path[key]
                    })
                    this.abort();
                }
            })
        } else {
            this.node = node;
            this.parent = parent || null;
            this.parentPath = parentPath || null;
            this.value = node;
        }
    }
}