| 2 | const visit = recast.types.visit; |
| 3 | module.exports = class NodePath { |
| 4 | constructor(node, parent, parentPath) { |
| 5 | if (!parent && !parentPath && node.program) { |
| 6 | const nodePath = this; |
| 7 | visit(node, { |
| 8 | visitFile(path) { |
| 9 | ['node', 'value', 'parent', 'get', 'getValueProperty', '__childCache', '__proto__', 'name'].forEach(key => { |
| 10 | nodePath[key] = path[key] |
| 11 | }) |
| 12 | this.abort(); |
| 13 | } |
| 14 | }) |
| 15 | } else { |
| 16 | this.node = node; |
| 17 | this.parent = parent || null; |
| 18 | this.parentPath = parentPath || null; |
| 19 | this.value = node; |
| 20 | } |
| 21 | } |
| 22 | } |