1 | 'use strict';
|
2 |
|
3 | var syntax = require('estraverse').Syntax,
|
4 | locationOf = require('./location');
|
5 |
|
6 | function EsNode (path, currentNode, parentNode, espathToValue, jsCode, jsAST) {
|
7 | if (path) {
|
8 | this.espath = path.join('/');
|
9 | this.parentEspath = path.slice(0, path.length - 1).join('/');
|
10 | this.currentProp = path[path.length - 1];
|
11 | } else {
|
12 | this.espath = '';
|
13 | this.parentEspath = '';
|
14 | this.currentProp = null;
|
15 | }
|
16 | this.currentNode = currentNode;
|
17 | this.parentNode = parentNode;
|
18 | this.parentEsNode = null;
|
19 | this.espathToValue = espathToValue;
|
20 | this.jsCode = jsCode;
|
21 | this.jsAST = jsAST;
|
22 | }
|
23 |
|
24 | EsNode.prototype.setParent = function (parentEsNode) {
|
25 | this.parentEsNode = parentEsNode;
|
26 | };
|
27 |
|
28 | EsNode.prototype.getParent = function () {
|
29 | return this.parentEsNode;
|
30 | };
|
31 |
|
32 | EsNode.prototype.code = function () {
|
33 | return this.jsCode.slice(this.currentNode.loc.start.column, this.currentNode.loc.end.column);
|
34 | };
|
35 |
|
36 | EsNode.prototype.value = function () {
|
37 | if (this.currentNode.type === syntax.Literal) {
|
38 | return this.currentNode.value;
|
39 | }
|
40 | return this.espathToValue[this.espath];
|
41 | };
|
42 |
|
43 | EsNode.prototype.isCaptured = function () {
|
44 | return this.espathToValue.hasOwnProperty(this.espath);
|
45 | };
|
46 |
|
47 | EsNode.prototype.location = function () {
|
48 | return locationOf(this.currentNode, this.jsAST.tokens);
|
49 | };
|
50 |
|
51 | module.exports = EsNode;
|