@babel/traverse 7.0.0-beta.46 → 7.0.0-beta.47

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,7 +8,7 @@ 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
13
  _helperSplitExportDeclaration = function _helperSplitExportDeclaration() {
14
14
  return data;
@@ -18,7 +18,7 @@ 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
23
  t = function t() {
24
24
  return data;
@@ -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,15 @@ 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 binding = this.binding,
102
+ oldName = this.oldName,
103
+ newName = this.newName;
104
+ const scope = binding.scope,
105
+ path = binding.path;
106
+ const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression());
108
107
 
109
108
  if (parentDeclar) {
110
109
  this.maybeConvertFromExportDeclaration(parentDeclar);
@@ -124,9 +123,8 @@ var Renamer = function () {
124
123
  this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
125
124
  this.maybeConvertFromClassFunctionExpression(parentDeclar);
126
125
  }
127
- };
126
+ }
128
127
 
129
- return Renamer;
130
- }();
128
+ }
131
129
 
132
130
  exports.default = Renamer;
package/lib/visitors.js CHANGED
@@ -10,7 +10,7 @@ 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
15
  t = function t() {
16
16
  return data;
@@ -20,7 +20,7 @@ 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
25
  _clone = function _clone() {
26
26
  return data;
@@ -37,11 +37,11 @@ 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
47
  for (var _iterator = parts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
@@ -56,7 +56,7 @@ function explode(visitor) {
56
56
  _ref = _i.value;
57
57
  }
58
58
 
59
- var part = _ref;
59
+ const part = _ref;
60
60
  visitor[part] = fns;
61
61
  }
62
62
  }
@@ -69,50 +69,48 @@ function explode(visitor) {
69
69
  var _arr = Object.keys(visitor);
70
70
 
71
71
  for (var _i2 = 0; _i2 < _arr.length; _i2++) {
72
- var _nodeType3 = _arr[_i2];
73
- if (shouldIgnoreKey(_nodeType3)) continue;
74
- var wrapper = virtualTypes[_nodeType3];
72
+ const nodeType = _arr[_i2];
73
+ if (shouldIgnoreKey(nodeType)) continue;
74
+ const wrapper = virtualTypes[nodeType];
75
75
  if (!wrapper) continue;
76
- var _fns2 = visitor[_nodeType3];
76
+ const fns = visitor[nodeType];
77
77
 
78
- for (var type in _fns2) {
79
- _fns2[type] = wrapCheck(wrapper, _fns2[type]);
78
+ for (const type in fns) {
79
+ fns[type] = wrapCheck(wrapper, fns[type]);
80
80
  }
81
81
 
82
- delete visitor[_nodeType3];
82
+ delete visitor[nodeType];
83
83
 
84
84
  if (wrapper.types) {
85
85
  var _arr2 = wrapper.types;
86
86
 
87
87
  for (var _i4 = 0; _i4 < _arr2.length; _i4++) {
88
- var _type = _arr2[_i4];
88
+ const type = _arr2[_i4];
89
89
 
90
- if (visitor[_type]) {
91
- mergePair(visitor[_type], _fns2);
90
+ if (visitor[type]) {
91
+ mergePair(visitor[type], fns);
92
92
  } else {
93
- visitor[_type] = _fns2;
93
+ visitor[type] = fns;
94
94
  }
95
95
  }
96
96
  } else {
97
- mergePair(visitor, _fns2);
97
+ mergePair(visitor, fns);
98
98
  }
99
99
  }
100
100
 
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];
101
+ for (const nodeType in visitor) {
102
+ if (shouldIgnoreKey(nodeType)) continue;
103
+ const fns = visitor[nodeType];
104
+ let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
105
+ const deprecratedKey = t().DEPRECATED_KEYS[nodeType];
108
106
 
109
107
  if (deprecratedKey) {
110
- console.trace("Visitor defined for " + _nodeType + " but it has been renamed to " + deprecratedKey);
108
+ console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`);
111
109
  aliases = [deprecratedKey];
112
110
  }
113
111
 
114
112
  if (!aliases) continue;
115
- delete visitor[_nodeType];
113
+ delete visitor[nodeType];
116
114
 
117
115
  for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
118
116
  var _ref2;
@@ -126,20 +124,20 @@ function explode(visitor) {
126
124
  _ref2 = _i3.value;
127
125
  }
128
126
 
129
- var alias = _ref2;
130
- var existing = visitor[alias];
127
+ const alias = _ref2;
128
+ const existing = visitor[alias];
131
129
 
132
130
  if (existing) {
133
- mergePair(existing, _fns);
131
+ mergePair(existing, fns);
134
132
  } else {
135
- visitor[alias] = (0, _clone().default)(_fns);
133
+ visitor[alias] = (0, _clone().default)(fns);
136
134
  }
137
135
  }
138
136
  }
139
137
 
140
- for (var _nodeType2 in visitor) {
141
- if (shouldIgnoreKey(_nodeType2)) continue;
142
- ensureCallbackArrays(visitor[_nodeType2]);
138
+ for (const nodeType in visitor) {
139
+ if (shouldIgnoreKey(nodeType)) continue;
140
+ ensureCallbackArrays(visitor[nodeType]);
143
141
  }
144
142
 
145
143
  return visitor;
@@ -152,7 +150,7 @@ function verify(visitor) {
152
150
  throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
153
151
  }
154
152
 
155
- for (var nodeType in visitor) {
153
+ for (const nodeType in visitor) {
156
154
  if (nodeType === "enter" || nodeType === "exit") {
157
155
  validateVisitorMethods(nodeType, visitor[nodeType]);
158
156
  }
@@ -160,17 +158,17 @@ function verify(visitor) {
160
158
  if (shouldIgnoreKey(nodeType)) continue;
161
159
 
162
160
  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");
161
+ throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
164
162
  }
165
163
 
166
- var visitors = visitor[nodeType];
164
+ const visitors = visitor[nodeType];
167
165
 
168
166
  if (typeof visitors === "object") {
169
- for (var visitorKey in visitors) {
167
+ for (const visitorKey in visitors) {
170
168
  if (visitorKey === "enter" || visitorKey === "exit") {
171
- validateVisitorMethods(nodeType + "." + visitorKey, visitors[visitorKey]);
169
+ validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
172
170
  } else {
173
- throw new Error("You passed `traverse()` a visitor object with the property " + (nodeType + " that has the invalid property " + visitorKey));
171
+ throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`);
174
172
  }
175
173
  }
176
174
  }
@@ -180,7 +178,7 @@ function verify(visitor) {
180
178
  }
181
179
 
182
180
  function validateVisitorMethods(path, val) {
183
- var fns = [].concat(val);
181
+ const fns = [].concat(val);
184
182
 
185
183
  for (var _iterator3 = fns, _isArray3 = Array.isArray(_iterator3), _i5 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
186
184
  var _ref3;
@@ -194,34 +192,30 @@ function validateVisitorMethods(path, val) {
194
192
  _ref3 = _i5.value;
195
193
  }
196
194
 
197
- var fn = _ref3;
195
+ const fn = _ref3;
198
196
 
199
197
  if (typeof fn !== "function") {
200
- throw new TypeError("Non-function found defined in " + path + " with type " + typeof fn);
198
+ throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
201
199
  }
202
200
  }
203
201
  }
204
202
 
205
- function merge(visitors, states, wrapper) {
206
- if (states === void 0) {
207
- states = [];
208
- }
209
-
210
- var rootVisitor = {};
203
+ function merge(visitors, states = [], wrapper) {
204
+ const rootVisitor = {};
211
205
 
212
- for (var i = 0; i < visitors.length; i++) {
213
- var visitor = visitors[i];
214
- var state = states[i];
206
+ for (let i = 0; i < visitors.length; i++) {
207
+ const visitor = visitors[i];
208
+ const state = states[i];
215
209
  explode(visitor);
216
210
 
217
- for (var type in visitor) {
218
- var visitorType = visitor[type];
211
+ for (const type in visitor) {
212
+ let visitorType = visitor[type];
219
213
 
220
214
  if (state || wrapper) {
221
215
  visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper);
222
216
  }
223
217
 
224
- var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
218
+ const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
225
219
  mergePair(nodeVisitor, visitorType);
226
220
  }
227
221
  }
@@ -230,13 +224,13 @@ function merge(visitors, states, wrapper) {
230
224
  }
231
225
 
232
226
  function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
233
- var newVisitor = {};
227
+ const newVisitor = {};
234
228
 
235
- var _loop = function _loop(key) {
236
- var fns = oldVisitor[key];
237
- if (!Array.isArray(fns)) return "continue";
229
+ for (const key in oldVisitor) {
230
+ let fns = oldVisitor[key];
231
+ if (!Array.isArray(fns)) continue;
238
232
  fns = fns.map(function (fn) {
239
- var newFn = fn;
233
+ let newFn = fn;
240
234
 
241
235
  if (state) {
242
236
  newFn = function newFn(path) {
@@ -251,21 +245,15 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
251
245
  return newFn;
252
246
  });
253
247
  newVisitor[key] = fns;
254
- };
255
-
256
- for (var key in oldVisitor) {
257
- var _ret = _loop(key);
258
-
259
- if (_ret === "continue") continue;
260
248
  }
261
249
 
262
250
  return newVisitor;
263
251
  }
264
252
 
265
253
  function ensureEntranceObjects(obj) {
266
- for (var key in obj) {
254
+ for (const key in obj) {
267
255
  if (shouldIgnoreKey(key)) continue;
268
- var fns = obj[key];
256
+ const fns = obj[key];
269
257
 
270
258
  if (typeof fns === "function") {
271
259
  obj[key] = {
@@ -281,15 +269,13 @@ function ensureCallbackArrays(obj) {
281
269
  }
282
270
 
283
271
  function wrapCheck(wrapper, fn) {
284
- var newFn = function newFn(path) {
272
+ const newFn = function newFn(path) {
285
273
  if (wrapper.checkPath(path)) {
286
274
  return fn.apply(this, arguments);
287
275
  }
288
276
  };
289
277
 
290
- newFn.toString = function () {
291
- return fn.toString();
292
- };
278
+ newFn.toString = () => fn.toString();
293
279
 
294
280
  return newFn;
295
281
  }
@@ -306,7 +292,7 @@ function shouldIgnoreKey(key) {
306
292
  }
307
293
 
308
294
  function mergePair(dest, src) {
309
- for (var key in src) {
295
+ for (const key in src) {
310
296
  dest[key] = [].concat(dest[key] || [], src[key]);
311
297
  }
312
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.0.0-beta.46",
3
+ "version": "7.0.0-beta.47",
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.46",
12
- "@babel/generator": "7.0.0-beta.46",
13
- "@babel/helper-function-name": "7.0.0-beta.46",
14
- "@babel/helper-split-export-declaration": "7.0.0-beta.46",
15
- "@babel/types": "7.0.0-beta.46",
16
- "babylon": "7.0.0-beta.46",
11
+ "@babel/code-frame": "7.0.0-beta.47",
12
+ "@babel/generator": "7.0.0-beta.47",
13
+ "@babel/helper-function-name": "7.0.0-beta.47",
14
+ "@babel/helper-split-export-declaration": "7.0.0-beta.47",
15
+ "@babel/types": "7.0.0-beta.47",
16
+ "babylon": "7.0.0-beta.47",
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.46"
23
+ "@babel/helper-plugin-test-runner": "7.0.0-beta.47"
24
24
  }
25
25
  }