@babel/traverse 7.0.0-beta.43 → 7.0.0-beta.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

@@ -8,9 +8,9 @@ exports.default = void 0;
8
8
  var _binding = _interopRequireDefault(require("../binding"));
9
9
 
10
10
  function _helperSplitExportDeclaration() {
11
- const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
11
+ var data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
12
12
 
13
- _helperSplitExportDeclaration = function () {
13
+ _helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
14
14
  return data;
15
15
  };
16
16
 
@@ -18,9 +18,9 @@ function _helperSplitExportDeclaration() {
18
18
  }
19
19
 
20
20
  function t() {
21
- const data = _interopRequireWildcard(require("@babel/types"));
21
+ var data = _interopRequireWildcard(require("@babel/types"));
22
22
 
23
- t = function () {
23
+ t = function t() {
24
24
  return data;
25
25
  };
26
26
 
@@ -31,40 +31,39 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
31
31
 
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
33
 
34
- const renameVisitor = {
35
- ReferencedIdentifier({
36
- node
37
- }, state) {
34
+ var renameVisitor = {
35
+ ReferencedIdentifier: function ReferencedIdentifier(_ref, state) {
36
+ var node = _ref.node;
37
+
38
38
  if (node.name === state.oldName) {
39
39
  node.name = state.newName;
40
40
  }
41
41
  },
42
-
43
- Scope(path, state) {
42
+ Scope: function Scope(path, state) {
44
43
  if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
45
44
  path.skip();
46
45
  }
47
46
  },
47
+ "AssignmentExpression|Declaration": function AssignmentExpressionDeclaration(path, state) {
48
+ var ids = path.getOuterBindingIdentifiers();
48
49
 
49
- "AssignmentExpression|Declaration"(path, state) {
50
- const ids = path.getOuterBindingIdentifiers();
51
-
52
- for (const name in ids) {
50
+ for (var name in ids) {
53
51
  if (name === state.oldName) ids[name].name = state.newName;
54
52
  }
55
53
  }
56
-
57
54
  };
58
55
 
59
- class Renamer {
60
- constructor(binding, oldName, newName) {
56
+ var Renamer = function () {
57
+ function Renamer(binding, oldName, newName) {
61
58
  this.newName = newName;
62
59
  this.oldName = oldName;
63
60
  this.binding = binding;
64
61
  }
65
62
 
66
- maybeConvertFromExportDeclaration(parentDeclar) {
67
- const maybeExportDeclar = parentDeclar.parentPath;
63
+ var _proto = Renamer.prototype;
64
+
65
+ _proto.maybeConvertFromExportDeclaration = function maybeConvertFromExportDeclaration(parentDeclar) {
66
+ var maybeExportDeclar = parentDeclar.parentPath;
68
67
 
69
68
  if (!maybeExportDeclar.isExportDeclaration()) {
70
69
  return;
@@ -75,18 +74,18 @@ class Renamer {
75
74
  }
76
75
 
77
76
  (0, _helperSplitExportDeclaration().default)(maybeExportDeclar);
78
- }
77
+ };
79
78
 
80
- maybeConvertFromClassFunctionDeclaration(path) {
79
+ _proto.maybeConvertFromClassFunctionDeclaration = function maybeConvertFromClassFunctionDeclaration(path) {
81
80
  return;
82
81
  if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
83
82
  if (this.binding.kind !== "hoisted") return;
84
83
  path.node.id = t().identifier(this.oldName);
85
84
  path.node._blockHoist = 3;
86
85
  path.replaceWith(t().variableDeclaration("let", [t().variableDeclarator(t().identifier(this.newName), t().toExpression(path.node))]));
87
- }
86
+ };
88
87
 
89
- maybeConvertFromClassFunctionExpression(path) {
88
+ _proto.maybeConvertFromClassFunctionExpression = function maybeConvertFromClassFunctionExpression(path) {
90
89
  return;
91
90
  if (!path.isFunctionExpression() && !path.isClassExpression()) return;
92
91
  if (this.binding.kind !== "local") return;
@@ -95,19 +94,17 @@ class Renamer {
95
94
  id: t().identifier(this.newName)
96
95
  });
97
96
  path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node));
98
- }
97
+ };
99
98
 
100
- rename(block) {
101
- const {
102
- binding,
103
- oldName,
104
- newName
105
- } = this;
106
- const {
107
- scope,
108
- path
109
- } = binding;
110
- const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
99
+ _proto.rename = function rename(block) {
100
+ var binding = this.binding,
101
+ oldName = this.oldName,
102
+ newName = this.newName;
103
+ var scope = binding.scope,
104
+ path = binding.path;
105
+ var parentDeclar = path.find(function (path) {
106
+ return path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression();
107
+ });
111
108
 
112
109
  if (parentDeclar) {
113
110
  this.maybeConvertFromExportDeclaration(parentDeclar);
@@ -127,8 +124,9 @@ class Renamer {
127
124
  this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
128
125
  this.maybeConvertFromClassFunctionExpression(parentDeclar);
129
126
  }
130
- }
127
+ };
131
128
 
132
- }
129
+ return Renamer;
130
+ }();
133
131
 
134
132
  exports.default = Renamer;
package/lib/visitors.js CHANGED
@@ -10,9 +10,9 @@ exports.merge = merge;
10
10
  var virtualTypes = _interopRequireWildcard(require("./path/lib/virtual-types"));
11
11
 
12
12
  function t() {
13
- const data = _interopRequireWildcard(require("@babel/types"));
13
+ var data = _interopRequireWildcard(require("@babel/types"));
14
14
 
15
- t = function () {
15
+ t = function t() {
16
16
  return data;
17
17
  };
18
18
 
@@ -20,9 +20,9 @@ function t() {
20
20
  }
21
21
 
22
22
  function _clone() {
23
- const data = _interopRequireDefault(require("lodash/clone"));
23
+ var data = _interopRequireDefault(require("lodash/clone"));
24
24
 
25
- _clone = function () {
25
+ _clone = function _clone() {
26
26
  return data;
27
27
  };
28
28
 
@@ -37,14 +37,26 @@ function explode(visitor) {
37
37
  if (visitor._exploded) return visitor;
38
38
  visitor._exploded = true;
39
39
 
40
- for (const nodeType in visitor) {
40
+ for (var nodeType in visitor) {
41
41
  if (shouldIgnoreKey(nodeType)) continue;
42
- const parts = nodeType.split("|");
42
+ var parts = nodeType.split("|");
43
43
  if (parts.length === 1) continue;
44
- const fns = visitor[nodeType];
44
+ var fns = visitor[nodeType];
45
45
  delete visitor[nodeType];
46
46
 
47
- for (const part of parts) {
47
+ for (var _iterator = parts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
48
+ var _ref;
49
+
50
+ if (_isArray) {
51
+ if (_i >= _iterator.length) break;
52
+ _ref = _iterator[_i++];
53
+ } else {
54
+ _i = _iterator.next();
55
+ if (_i.done) break;
56
+ _ref = _i.value;
57
+ }
58
+
59
+ var part = _ref;
48
60
  visitor[part] = fns;
49
61
  }
50
62
  }
@@ -54,59 +66,80 @@ function explode(visitor) {
54
66
  ensureEntranceObjects(visitor);
55
67
  ensureCallbackArrays(visitor);
56
68
 
57
- for (const nodeType of Object.keys(visitor)) {
58
- if (shouldIgnoreKey(nodeType)) continue;
59
- const wrapper = virtualTypes[nodeType];
69
+ var _arr = Object.keys(visitor);
70
+
71
+ for (var _i2 = 0; _i2 < _arr.length; _i2++) {
72
+ var _nodeType3 = _arr[_i2];
73
+ if (shouldIgnoreKey(_nodeType3)) continue;
74
+ var wrapper = virtualTypes[_nodeType3];
60
75
  if (!wrapper) continue;
61
- const fns = visitor[nodeType];
76
+ var _fns2 = visitor[_nodeType3];
62
77
 
63
- for (const type in fns) {
64
- fns[type] = wrapCheck(wrapper, fns[type]);
78
+ for (var type in _fns2) {
79
+ _fns2[type] = wrapCheck(wrapper, _fns2[type]);
65
80
  }
66
81
 
67
- delete visitor[nodeType];
82
+ delete visitor[_nodeType3];
68
83
 
69
84
  if (wrapper.types) {
70
- for (const type of wrapper.types) {
71
- if (visitor[type]) {
72
- mergePair(visitor[type], fns);
85
+ var _arr2 = wrapper.types;
86
+
87
+ for (var _i4 = 0; _i4 < _arr2.length; _i4++) {
88
+ var _type = _arr2[_i4];
89
+
90
+ if (visitor[_type]) {
91
+ mergePair(visitor[_type], _fns2);
73
92
  } else {
74
- visitor[type] = fns;
93
+ visitor[_type] = _fns2;
75
94
  }
76
95
  }
77
96
  } else {
78
- mergePair(visitor, fns);
97
+ mergePair(visitor, _fns2);
79
98
  }
80
99
  }
81
100
 
82
- for (const nodeType in visitor) {
83
- if (shouldIgnoreKey(nodeType)) continue;
84
- const fns = visitor[nodeType];
85
- let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
86
- const deprecratedKey = t().DEPRECATED_KEYS[nodeType];
101
+ for (var _nodeType in visitor) {
102
+ if (shouldIgnoreKey(_nodeType)) continue;
103
+ var _fns = visitor[_nodeType];
104
+
105
+ var aliases = t().FLIPPED_ALIAS_KEYS[_nodeType];
106
+
107
+ var deprecratedKey = t().DEPRECATED_KEYS[_nodeType];
87
108
 
88
109
  if (deprecratedKey) {
89
- console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`);
110
+ console.trace("Visitor defined for " + _nodeType + " but it has been renamed to " + deprecratedKey);
90
111
  aliases = [deprecratedKey];
91
112
  }
92
113
 
93
114
  if (!aliases) continue;
94
- delete visitor[nodeType];
115
+ delete visitor[_nodeType];
95
116
 
96
- for (const alias of aliases) {
97
- const existing = visitor[alias];
117
+ for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
118
+ var _ref2;
119
+
120
+ if (_isArray2) {
121
+ if (_i3 >= _iterator2.length) break;
122
+ _ref2 = _iterator2[_i3++];
123
+ } else {
124
+ _i3 = _iterator2.next();
125
+ if (_i3.done) break;
126
+ _ref2 = _i3.value;
127
+ }
128
+
129
+ var alias = _ref2;
130
+ var existing = visitor[alias];
98
131
 
99
132
  if (existing) {
100
- mergePair(existing, fns);
133
+ mergePair(existing, _fns);
101
134
  } else {
102
- visitor[alias] = (0, _clone().default)(fns);
135
+ visitor[alias] = (0, _clone().default)(_fns);
103
136
  }
104
137
  }
105
138
  }
106
139
 
107
- for (const nodeType in visitor) {
108
- if (shouldIgnoreKey(nodeType)) continue;
109
- ensureCallbackArrays(visitor[nodeType]);
140
+ for (var _nodeType2 in visitor) {
141
+ if (shouldIgnoreKey(_nodeType2)) continue;
142
+ ensureCallbackArrays(visitor[_nodeType2]);
110
143
  }
111
144
 
112
145
  return visitor;
@@ -119,7 +152,7 @@ function verify(visitor) {
119
152
  throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
120
153
  }
121
154
 
122
- for (const nodeType in visitor) {
155
+ for (var nodeType in visitor) {
123
156
  if (nodeType === "enter" || nodeType === "exit") {
124
157
  validateVisitorMethods(nodeType, visitor[nodeType]);
125
158
  }
@@ -127,17 +160,17 @@ function verify(visitor) {
127
160
  if (shouldIgnoreKey(nodeType)) continue;
128
161
 
129
162
  if (t().TYPES.indexOf(nodeType) < 0) {
130
- throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
163
+ throw new Error("You gave us a visitor for the node type " + nodeType + " but it's not a valid type");
131
164
  }
132
165
 
133
- const visitors = visitor[nodeType];
166
+ var visitors = visitor[nodeType];
134
167
 
135
168
  if (typeof visitors === "object") {
136
- for (const visitorKey in visitors) {
169
+ for (var visitorKey in visitors) {
137
170
  if (visitorKey === "enter" || visitorKey === "exit") {
138
- validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
171
+ validateVisitorMethods(nodeType + "." + visitorKey, visitors[visitorKey]);
139
172
  } else {
140
- throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`);
173
+ throw new Error("You passed `traverse()` a visitor object with the property " + (nodeType + " that has the invalid property " + visitorKey));
141
174
  }
142
175
  }
143
176
  }
@@ -147,31 +180,48 @@ function verify(visitor) {
147
180
  }
148
181
 
149
182
  function validateVisitorMethods(path, val) {
150
- const fns = [].concat(val);
183
+ var fns = [].concat(val);
184
+
185
+ for (var _iterator3 = fns, _isArray3 = Array.isArray(_iterator3), _i5 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
186
+ var _ref3;
187
+
188
+ if (_isArray3) {
189
+ if (_i5 >= _iterator3.length) break;
190
+ _ref3 = _iterator3[_i5++];
191
+ } else {
192
+ _i5 = _iterator3.next();
193
+ if (_i5.done) break;
194
+ _ref3 = _i5.value;
195
+ }
196
+
197
+ var fn = _ref3;
151
198
 
152
- for (const fn of fns) {
153
199
  if (typeof fn !== "function") {
154
- throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
200
+ throw new TypeError("Non-function found defined in " + path + " with type " + typeof fn);
155
201
  }
156
202
  }
157
203
  }
158
204
 
159
- function merge(visitors, states = [], wrapper) {
160
- const rootVisitor = {};
205
+ function merge(visitors, states, wrapper) {
206
+ if (states === void 0) {
207
+ states = [];
208
+ }
209
+
210
+ var rootVisitor = {};
161
211
 
162
- for (let i = 0; i < visitors.length; i++) {
163
- const visitor = visitors[i];
164
- const state = states[i];
212
+ for (var i = 0; i < visitors.length; i++) {
213
+ var visitor = visitors[i];
214
+ var state = states[i];
165
215
  explode(visitor);
166
216
 
167
- for (const type in visitor) {
168
- let visitorType = visitor[type];
217
+ for (var type in visitor) {
218
+ var visitorType = visitor[type];
169
219
 
170
220
  if (state || wrapper) {
171
221
  visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
172
222
  }
173
223
 
174
- const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
224
+ var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
175
225
  mergePair(nodeVisitor, visitorType);
176
226
  }
177
227
  }
@@ -180,16 +230,16 @@ function merge(visitors, states = [], wrapper) {
180
230
  }
181
231
 
182
232
  function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
183
- const newVisitor = {};
233
+ var newVisitor = {};
184
234
 
185
- for (const key in oldVisitor) {
186
- let fns = oldVisitor[key];
187
- if (!Array.isArray(fns)) continue;
235
+ var _loop = function _loop(key) {
236
+ var fns = oldVisitor[key];
237
+ if (!Array.isArray(fns)) return "continue";
188
238
  fns = fns.map(function (fn) {
189
- let newFn = fn;
239
+ var newFn = fn;
190
240
 
191
241
  if (state) {
192
- newFn = function (path) {
242
+ newFn = function newFn(path) {
193
243
  return fn.call(state, path, state);
194
244
  };
195
245
  }
@@ -201,15 +251,21 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
201
251
  return newFn;
202
252
  });
203
253
  newVisitor[key] = fns;
254
+ };
255
+
256
+ for (var key in oldVisitor) {
257
+ var _ret = _loop(key);
258
+
259
+ if (_ret === "continue") continue;
204
260
  }
205
261
 
206
262
  return newVisitor;
207
263
  }
208
264
 
209
265
  function ensureEntranceObjects(obj) {
210
- for (const key in obj) {
266
+ for (var key in obj) {
211
267
  if (shouldIgnoreKey(key)) continue;
212
- const fns = obj[key];
268
+ var fns = obj[key];
213
269
 
214
270
  if (typeof fns === "function") {
215
271
  obj[key] = {
@@ -225,13 +281,15 @@ function ensureCallbackArrays(obj) {
225
281
  }
226
282
 
227
283
  function wrapCheck(wrapper, fn) {
228
- const newFn = function (path) {
284
+ var newFn = function newFn(path) {
229
285
  if (wrapper.checkPath(path)) {
230
286
  return fn.apply(this, arguments);
231
287
  }
232
288
  };
233
289
 
234
- newFn.toString = () => fn.toString();
290
+ newFn.toString = function () {
291
+ return fn.toString();
292
+ };
235
293
 
236
294
  return newFn;
237
295
  }
@@ -248,7 +306,7 @@ function shouldIgnoreKey(key) {
248
306
  }
249
307
 
250
308
  function mergePair(dest, src) {
251
- for (const key in src) {
309
+ for (var key in src) {
252
310
  dest[key] = [].concat(dest[key] || [], src[key]);
253
311
  }
254
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.0.0-beta.43",
3
+ "version": "7.0.0-beta.44",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "Sebastian McKenzie <sebmck@gmail.com>",
6
6
  "homepage": "https://babeljs.io/",
@@ -8,18 +8,18 @@
8
8
  "repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse",
9
9
  "main": "lib/index.js",
10
10
  "dependencies": {
11
- "@babel/code-frame": "7.0.0-beta.43",
12
- "@babel/generator": "7.0.0-beta.43",
13
- "@babel/helper-function-name": "7.0.0-beta.43",
14
- "@babel/helper-split-export-declaration": "7.0.0-beta.43",
15
- "@babel/types": "7.0.0-beta.43",
16
- "babylon": "7.0.0-beta.43",
11
+ "@babel/code-frame": "7.0.0-beta.44",
12
+ "@babel/generator": "7.0.0-beta.44",
13
+ "@babel/helper-function-name": "7.0.0-beta.44",
14
+ "@babel/helper-split-export-declaration": "7.0.0-beta.44",
15
+ "@babel/types": "7.0.0-beta.44",
16
+ "babylon": "7.0.0-beta.44",
17
17
  "debug": "^3.1.0",
18
18
  "globals": "^11.1.0",
19
19
  "invariant": "^2.2.0",
20
20
  "lodash": "^4.2.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@babel/helper-plugin-test-runner": "7.0.0-beta.43"
23
+ "@babel/helper-plugin-test-runner": "7.0.0-beta.44"
24
24
  }
25
25
  }