index.js
5.25 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"use strict";
exports.__esModule = true;
// istanbul ignore next
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
// istanbul ignore next
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
// istanbul ignore next
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _libVirtualTypes = require("./lib/virtual-types");
var virtualTypes = _interopRequireWildcard(_libVirtualTypes);
var _index = require("../index");
var _index2 = _interopRequireDefault(_index);
var _lodashObjectAssign = require("lodash/object/assign");
var _lodashObjectAssign2 = _interopRequireDefault(_lodashObjectAssign);
var _scope = require("../scope");
var _scope2 = _interopRequireDefault(_scope);
var _types = require("../../types");
var t = _interopRequireWildcard(_types);
/**
* [Please add a description.]
*/
var NodePath = (function () {
/**
* [Please add a description.]
*/
function NodePath(hub, parent) {
_classCallCheck(this, NodePath);
this.contexts = [];
this.parent = parent;
this.data = {};
this.hub = hub;
this.shouldSkip = false;
this.shouldStop = false;
this.removed = false;
this.state = null;
this.opts = null;
this.skipKeys = null;
this.parentPath = null;
this.context = null;
this.container = null;
this.listKey = null;
this.inList = false;
this.parentKey = null;
this.key = null;
this.node = null;
this.scope = null;
this.type = null;
this.typeAnnotation = null;
}
/**
* [Please add a description.]
*/
/**
* [Please add a description.]
*/
NodePath.get = function get(_ref) {
var hub = _ref.hub;
var parentPath = _ref.parentPath;
var parent = _ref.parent;
var container = _ref.container;
var listKey = _ref.listKey;
var key = _ref.key;
if (!hub && parentPath) {
hub = parentPath.hub;
}
var targetNode = container[key];
var paths = parent._paths = parent._paths || [];
var path;
for (var i = 0; i < paths.length; i++) {
var pathCheck = paths[i];
if (pathCheck.node === targetNode) {
path = pathCheck;
break;
}
}
if (!path) {
path = new NodePath(hub, parent);
paths.push(path);
}
path.setup(parentPath, container, listKey, key);
return path;
};
/**
* [Please add a description.]
*/
NodePath.prototype.getScope = function getScope(scope) {
var ourScope = scope;
// we're entering a new scope so let's construct it!
if (this.isScope()) {
ourScope = new _scope2["default"](this, scope);
}
return ourScope;
};
/**
* [Please add a description.]
*/
NodePath.prototype.setData = function setData(key, val) {
return this.data[key] = val;
};
/**
* [Please add a description.]
*/
NodePath.prototype.getData = function getData(key, def) {
var val = this.data[key];
if (!val && def) val = this.data[key] = def;
return val;
};
/**
* [Please add a description.]
*/
NodePath.prototype.errorWithNode = function errorWithNode(msg) {
var Error = arguments.length <= 1 || arguments[1] === undefined ? SyntaxError : arguments[1];
return this.hub.file.errorWithNode(this.node, msg, Error);
};
/**
* [Please add a description.]
*/
NodePath.prototype.traverse = function traverse(visitor, state) {
_index2["default"](this.node, visitor, this.scope, state, this);
};
return NodePath;
})();
exports["default"] = NodePath;
_lodashObjectAssign2["default"](NodePath.prototype, require("./ancestry"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./inference"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./replacement"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./evaluation"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./conversion"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./introspection"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./context"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./removal"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./modification"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./family"));
_lodashObjectAssign2["default"](NodePath.prototype, require("./comments"));
var _arr = t.TYPES;
var _loop = function () {
var type = _arr[_i];
var typeKey = "is" + type;
NodePath.prototype[typeKey] = function (opts) {
return t[typeKey](this.node, opts);
};
};
for (var _i = 0; _i < _arr.length; _i++) {
_loop();
}
var _loop2 = function (type) {
if (type[0] === "_") return "continue";
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
NodePath.prototype["is" + type] = function (opts) {
return virtualTypes[type].checkPath(this, opts);
};
};
for (var type in virtualTypes) {
var _ret2 = _loop2(type);
// istanbul ignore next
if (_ret2 === "continue") continue;
}
module.exports = exports["default"];