@babel/traverse 7.0.0-beta.45 → 7.0.0-beta.49

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