@babel/traverse 7.5.0 → 7.6.3

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.

package/lib/context.js CHANGED
@@ -7,17 +7,11 @@ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("./path"));
9
9
 
10
- function t() {
11
- const data = _interopRequireWildcard(require("@babel/types"));
10
+ var t = _interopRequireWildcard(require("@babel/types"));
12
11
 
13
- t = function () {
14
- return data;
15
- };
12
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
16
13
 
17
- return data;
18
- }
19
-
20
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
14
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
15
 
22
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
17
 
@@ -36,7 +30,7 @@ class TraversalContext {
36
30
  const opts = this.opts;
37
31
  if (opts.enter || opts.exit) return true;
38
32
  if (opts[node.type]) return true;
39
- const keys = t().VISITOR_KEYS[node.type];
33
+ const keys = t.VISITOR_KEYS[node.type];
40
34
  if (!keys || !keys.length) return false;
41
35
 
42
36
  for (const key of keys) {
package/lib/index.js CHANGED
@@ -30,25 +30,9 @@ var visitors = _interopRequireWildcard(require("./visitors"));
30
30
 
31
31
  exports.visitors = visitors;
32
32
 
33
- function _includes() {
34
- const data = _interopRequireDefault(require("lodash/includes"));
33
+ var _includes = _interopRequireDefault(require("lodash/includes"));
35
34
 
36
- _includes = function () {
37
- return data;
38
- };
39
-
40
- return data;
41
- }
42
-
43
- function t() {
44
- const data = _interopRequireWildcard(require("@babel/types"));
45
-
46
- t = function () {
47
- return data;
48
- };
49
-
50
- return data;
51
- }
35
+ var t = _interopRequireWildcard(require("@babel/types"));
52
36
 
53
37
  var cache = _interopRequireWildcard(require("./cache"));
54
38
 
@@ -58,7 +42,9 @@ var _scope = _interopRequireDefault(require("./scope"));
58
42
 
59
43
  var _hub = _interopRequireDefault(require("./hub"));
60
44
 
61
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
45
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
46
+
47
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
62
48
 
63
49
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
64
50
 
@@ -81,11 +67,11 @@ traverse.verify = visitors.verify;
81
67
  traverse.explode = visitors.explode;
82
68
 
83
69
  traverse.cheap = function (node, enter) {
84
- return t().traverseFast(node, enter);
70
+ return t.traverseFast(node, enter);
85
71
  };
86
72
 
87
73
  traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
88
- const keys = t().VISITOR_KEYS[node.type];
74
+ const keys = t.VISITOR_KEYS[node.type];
89
75
  if (!keys) return;
90
76
  const context = new _context.default(scope, opts, state, parentPath);
91
77
 
@@ -96,12 +82,12 @@ traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
96
82
  };
97
83
 
98
84
  traverse.clearNode = function (node, opts) {
99
- t().removeProperties(node, opts);
85
+ t.removeProperties(node, opts);
100
86
  cache.path.delete(node);
101
87
  };
102
88
 
103
89
  traverse.removeProperties = function (tree, opts) {
104
- t().traverseFast(tree, traverse.clearNode, opts);
90
+ t.traverseFast(tree, traverse.clearNode, opts);
105
91
  return tree;
106
92
  };
107
93
 
@@ -113,7 +99,7 @@ function hasBlacklistedType(path, state) {
113
99
  }
114
100
 
115
101
  traverse.hasType = function (tree, type, blacklistTypes) {
116
- if ((0, _includes().default)(blacklistTypes, tree.type)) return false;
102
+ if ((0, _includes.default)(blacklistTypes, tree.type)) return false;
117
103
  if (tree.type === type) return true;
118
104
  const state = {
119
105
  has: false,
@@ -14,21 +14,15 @@ exports.isAncestor = isAncestor;
14
14
  exports.isDescendant = isDescendant;
15
15
  exports.inType = inType;
16
16
 
17
- function t() {
18
- const data = _interopRequireWildcard(require("@babel/types"));
19
-
20
- t = function () {
21
- return data;
22
- };
23
-
24
- return data;
25
- }
17
+ var t = _interopRequireWildcard(require("@babel/types"));
26
18
 
27
19
  var _index = _interopRequireDefault(require("./index"));
28
20
 
29
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
22
 
31
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
23
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
24
+
25
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
32
26
 
33
27
  function findParent(callback) {
34
28
  let path = this;
@@ -75,7 +69,7 @@ function getStatementParent() {
75
69
  function getEarliestCommonAncestorFrom(paths) {
76
70
  return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
77
71
  let earliest;
78
- const keys = t().VISITOR_KEYS[deepest.type];
72
+ const keys = t.VISITOR_KEYS[deepest.type];
79
73
 
80
74
  for (const ancestry of ancestries) {
81
75
  const path = ancestry[i + 1];
@@ -7,17 +7,11 @@ exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
7
7
  exports.addComment = addComment;
8
8
  exports.addComments = addComments;
9
9
 
10
- function t() {
11
- const data = _interopRequireWildcard(require("@babel/types"));
10
+ var t = _interopRequireWildcard(require("@babel/types"));
12
11
 
13
- t = function () {
14
- return data;
15
- };
12
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
16
13
 
17
- return data;
18
- }
19
-
20
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
14
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
15
 
22
16
  function shareCommentsWithSiblings() {
23
17
  if (typeof this.key === "string") return;
@@ -39,9 +33,9 @@ function shareCommentsWithSiblings() {
39
33
  }
40
34
 
41
35
  function addComment(type, content, line) {
42
- t().addComment(this.node, type, content, line);
36
+ t.addComment(this.node, type, content, line);
43
37
  }
44
38
 
45
39
  function addComments(type, comments) {
46
- t().addComments(this.node, type, comments);
40
+ t.addComments(this.node, type, comments);
47
41
  }
@@ -9,29 +9,15 @@ exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
9
9
  exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
10
10
  exports.arrowFunctionToExpression = arrowFunctionToExpression;
11
11
 
12
- function t() {
13
- const data = _interopRequireWildcard(require("@babel/types"));
12
+ var t = _interopRequireWildcard(require("@babel/types"));
14
13
 
15
- t = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
- function _helperFunctionName() {
23
- const data = _interopRequireDefault(require("@babel/helper-function-name"));
24
-
25
- _helperFunctionName = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
14
+ var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
31
15
 
32
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
17
 
34
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
18
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
+
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
21
 
36
22
  function toComputedKey() {
37
23
  const node = this.node;
@@ -46,7 +32,7 @@ function toComputedKey() {
46
32
  }
47
33
 
48
34
  if (!node.computed) {
49
- if (t().isIdentifier(key)) key = t().stringLiteral(key.name);
35
+ if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
50
36
  }
51
37
 
52
38
  return key;
@@ -82,14 +68,14 @@ function ensureBlock() {
82
68
 
83
69
  if (this.isFunction()) {
84
70
  key = "argument";
85
- statements.push(t().returnStatement(body.node));
71
+ statements.push(t.returnStatement(body.node));
86
72
  } else {
87
73
  key = "expression";
88
- statements.push(t().expressionStatement(body.node));
74
+ statements.push(t.expressionStatement(body.node));
89
75
  }
90
76
  }
91
77
 
92
- this.node.body = t().blockStatement(statements);
78
+ this.node.body = t.blockStatement(statements);
93
79
  const parentPath = this.get(stringPath);
94
80
  body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
95
81
  return this.node;
@@ -126,12 +112,12 @@ function arrowFunctionToExpression({
126
112
  if (checkBinding) {
127
113
  this.parentPath.scope.push({
128
114
  id: checkBinding,
129
- init: t().objectExpression([])
115
+ init: t.objectExpression([])
130
116
  });
131
117
  }
132
118
 
133
- this.get("body").unshiftContainer("body", t().expressionStatement(t().callExpression(this.hub.addHelper("newArrowCheck"), [t().thisExpression(), checkBinding ? t().identifier(checkBinding.name) : t().identifier(thisBinding)])));
134
- this.replaceWith(t().callExpression(t().memberExpression((0, _helperFunctionName().default)(this, true) || this.node, t().identifier("bind")), [checkBinding ? t().identifier(checkBinding.name) : t().thisExpression()]));
119
+ this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(this.hub.addHelper("newArrowCheck"), [t.thisExpression(), checkBinding ? t.identifier(checkBinding.name) : t.identifier(thisBinding)])));
120
+ this.replaceWith(t.callExpression(t.memberExpression((0, _helperFunctionName.default)(this, true) || this.node, t.identifier("bind")), [checkBinding ? t.identifier(checkBinding.name) : t.thisExpression()]));
135
121
  }
136
122
  }
137
123
 
@@ -179,7 +165,7 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
179
165
  });
180
166
  const superBinding = getSuperBinding(thisEnvFn);
181
167
  allSuperCalls.forEach(superCall => {
182
- const callee = t().identifier(superBinding);
168
+ const callee = t.identifier(superBinding);
183
169
  callee.loc = superCall.node.callee.loc;
184
170
  superCall.get("callee").replaceWith(callee);
185
171
  });
@@ -192,7 +178,7 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
192
178
 
193
179
  if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
194
180
  thisPaths.forEach(thisChild => {
195
- const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding);
181
+ const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding);
196
182
  thisRef.loc = thisChild.node.loc;
197
183
  thisChild.replaceWith(thisRef);
198
184
  });
@@ -201,18 +187,18 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
201
187
  }
202
188
 
203
189
  if (argumentsPaths.length > 0) {
204
- const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments"));
190
+ const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments"));
205
191
  argumentsPaths.forEach(argumentsChild => {
206
- const argsRef = t().identifier(argumentsBinding);
192
+ const argsRef = t.identifier(argumentsBinding);
207
193
  argsRef.loc = argumentsChild.node.loc;
208
194
  argumentsChild.replaceWith(argsRef);
209
195
  });
210
196
  }
211
197
 
212
198
  if (newTargetPaths.length > 0) {
213
- const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t().metaProperty(t().identifier("new"), t().identifier("target")));
199
+ const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t.metaProperty(t.identifier("new"), t.identifier("target")));
214
200
  newTargetPaths.forEach(targetChild => {
215
- const targetRef = t().identifier(newTargetBinding);
201
+ const targetRef = t.identifier(newTargetBinding);
216
202
  targetRef.loc = targetChild.node.loc;
217
203
  targetChild.replaceWith(targetRef);
218
204
  });
@@ -234,10 +220,10 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
234
220
 
235
221
  if (superProp.node.computed) {
236
222
  const prop = superProp.get("property").node;
237
- superProp.replaceWith(t().identifier(superBinding));
223
+ superProp.replaceWith(t.identifier(superBinding));
238
224
  superProp.parentPath.node.arguments.unshift(prop);
239
225
  } else {
240
- superProp.replaceWith(t().identifier(superBinding));
226
+ superProp.replaceWith(t.identifier(superBinding));
241
227
  }
242
228
  } else {
243
229
  const isAssignment = superProp.parentPath.isAssignmentExpression({
@@ -253,9 +239,9 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
253
239
  if (isAssignment) {
254
240
  const value = superProp.parentPath.node.right;
255
241
  args.push(value);
256
- superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args));
242
+ superProp.parentPath.replaceWith(t.callExpression(t.identifier(superBinding), args));
257
243
  } else {
258
- superProp.replaceWith(t().callExpression(t().identifier(superBinding), args));
244
+ superProp.replaceWith(t.callExpression(t.identifier(superBinding), args));
259
245
  }
260
246
  }
261
247
  });
@@ -273,11 +259,11 @@ function standardizeSuperProperty(superProp) {
273
259
 
274
260
  if (superProp.node.computed) {
275
261
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
276
- assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, t().assignmentExpression("=", tmp, superProp.node.property), true));
277
- assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(tmp.name), true), value));
262
+ assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, t.assignmentExpression("=", tmp, superProp.node.property), true));
263
+ assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(tmp.name), true), value));
278
264
  } else {
279
- assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, superProp.node.property));
280
- assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(superProp.node.property.name)), value));
265
+ assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, superProp.node.property));
266
+ assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(superProp.node.property.name)), value));
281
267
  }
282
268
 
283
269
  return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
@@ -285,13 +271,13 @@ function standardizeSuperProperty(superProp) {
285
271
  const updateExpr = superProp.parentPath;
286
272
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
287
273
  const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
288
- const parts = [t().assignmentExpression("=", tmp, t().memberExpression(superProp.node.object, computedKey ? t().assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t().assignmentExpression("=", t().memberExpression(superProp.node.object, computedKey ? t().identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t().binaryExpression("+", t().identifier(tmp.name), t().numericLiteral(1)))];
274
+ const parts = [t.assignmentExpression("=", tmp, t.memberExpression(superProp.node.object, computedKey ? t.assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t.assignmentExpression("=", t.memberExpression(superProp.node.object, computedKey ? t.identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t.binaryExpression("+", t.identifier(tmp.name), t.numericLiteral(1)))];
289
275
 
290
276
  if (!superProp.parentPath.node.prefix) {
291
- parts.push(t().identifier(tmp.name));
277
+ parts.push(t.identifier(tmp.name));
292
278
  }
293
279
 
294
- updateExpr.replaceWith(t().sequenceExpression(parts));
280
+ updateExpr.replaceWith(t.sequenceExpression(parts));
295
281
  const left = updateExpr.get("expressions.0.right");
296
282
  const right = updateExpr.get("expressions.1.left");
297
283
  return [left, right];
@@ -306,7 +292,7 @@ function hasSuperClass(thisEnvFn) {
306
292
 
307
293
  function getThisBinding(thisEnvFn, inConstructor) {
308
294
  return getBinding(thisEnvFn, "this", thisBinding => {
309
- if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression();
295
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
310
296
  const supers = new WeakSet();
311
297
  thisEnvFn.traverse({
312
298
  Function(child) {
@@ -322,7 +308,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
322
308
  if (!child.get("callee").isSuper()) return;
323
309
  if (supers.has(child.node)) return;
324
310
  supers.add(child.node);
325
- child.replaceWithMultiple([child.node, t().assignmentExpression("=", t().identifier(thisBinding), t().identifier("this"))]);
311
+ child.replaceWithMultiple([child.node, t.assignmentExpression("=", t.identifier(thisBinding), t.identifier("this"))]);
326
312
  }
327
313
 
328
314
  });
@@ -332,25 +318,25 @@ function getThisBinding(thisEnvFn, inConstructor) {
332
318
  function getSuperBinding(thisEnvFn) {
333
319
  return getBinding(thisEnvFn, "supercall", () => {
334
320
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
335
- return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))]));
321
+ return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
336
322
  });
337
323
  }
338
324
 
339
325
  function getSuperPropCallBinding(thisEnvFn, propName) {
340
326
  return getBinding(thisEnvFn, `superprop_call:${propName || ""}`, () => {
341
327
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
342
- const argsList = [t().restElement(argsBinding)];
328
+ const argsList = [t.restElement(argsBinding)];
343
329
  let fnBody;
344
330
 
345
331
  if (propName) {
346
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]);
332
+ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]);
347
333
  } else {
348
334
  const method = thisEnvFn.scope.generateUidIdentifier("prop");
349
335
  argsList.unshift(method);
350
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]);
336
+ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(method.name), true), [t.spreadElement(t.identifier(argsBinding.name))]);
351
337
  }
352
338
 
353
- return t().arrowFunctionExpression(argsList, fnBody);
339
+ return t.arrowFunctionExpression(argsList, fnBody);
354
340
  });
355
341
  }
356
342
 
@@ -361,20 +347,20 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
361
347
  let fnBody;
362
348
 
363
349
  if (propName) {
364
- fnBody = t().memberExpression(t().super(), t().identifier(propName));
350
+ fnBody = t.memberExpression(t.super(), t.identifier(propName));
365
351
  } else {
366
352
  const method = thisEnvFn.scope.generateUidIdentifier("prop");
367
353
  argsList.unshift(method);
368
- fnBody = t().memberExpression(t().super(), t().identifier(method.name), true);
354
+ fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
369
355
  }
370
356
 
371
357
  if (isAssignment) {
372
358
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
373
359
  argsList.push(valueIdent);
374
- fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name));
360
+ fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
375
361
  }
376
362
 
377
- return t().arrowFunctionExpression(argsList, fnBody);
363
+ return t.arrowFunctionExpression(argsList, fnBody);
378
364
  });
379
365
  }
380
366
 
@@ -20,17 +20,11 @@ exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
20
20
 
21
21
  var _index = _interopRequireDefault(require("./index"));
22
22
 
23
- function t() {
24
- const data = _interopRequireWildcard(require("@babel/types"));
23
+ var t = _interopRequireWildcard(require("@babel/types"));
25
24
 
26
- t = function () {
27
- return data;
28
- };
25
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
29
26
 
30
- return data;
31
- }
32
-
33
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
27
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
34
28
 
35
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
30
 
@@ -47,6 +41,57 @@ function addCompletionRecords(path, paths) {
47
41
  return paths;
48
42
  }
49
43
 
44
+ function completionRecordForSwitch(cases, paths) {
45
+ let isLastCaseWithConsequent = true;
46
+
47
+ for (let i = cases.length - 1; i >= 0; i--) {
48
+ const switchCase = cases[i];
49
+ const consequent = switchCase.get("consequent");
50
+ let breakStatement;
51
+
52
+ findBreak: for (const statement of consequent) {
53
+ if (statement.isBlockStatement()) {
54
+ for (const statementInBlock of statement.get("body")) {
55
+ if (statementInBlock.isBreakStatement()) {
56
+ breakStatement = statementInBlock;
57
+ break findBreak;
58
+ }
59
+ }
60
+ } else if (statement.isBreakStatement()) {
61
+ breakStatement = statement;
62
+ break;
63
+ }
64
+ }
65
+
66
+ if (breakStatement) {
67
+ while (breakStatement.key === 0 && breakStatement.parentPath.isBlockStatement()) {
68
+ breakStatement = breakStatement.parentPath;
69
+ }
70
+
71
+ const prevSibling = breakStatement.getPrevSibling();
72
+
73
+ if (breakStatement.key > 0 && (prevSibling.isExpressionStatement() || prevSibling.isBlockStatement())) {
74
+ paths = addCompletionRecords(prevSibling, paths);
75
+ breakStatement.remove();
76
+ } else {
77
+ breakStatement.replaceWith(breakStatement.scope.buildUndefinedNode());
78
+ paths = addCompletionRecords(breakStatement, paths);
79
+ }
80
+ } else if (isLastCaseWithConsequent) {
81
+ const statementFinder = statement => !statement.isBlockStatement() || statement.get("body").some(statementFinder);
82
+
83
+ const hasConsequent = consequent.some(statementFinder);
84
+
85
+ if (hasConsequent) {
86
+ paths = addCompletionRecords(consequent[consequent.length - 1], paths);
87
+ isLastCaseWithConsequent = false;
88
+ }
89
+ }
90
+ }
91
+
92
+ return paths;
93
+ }
94
+
50
95
  function getCompletionRecords() {
51
96
  let paths = [];
52
97
 
@@ -62,9 +107,10 @@ function getCompletionRecords() {
62
107
  } else if (this.isTryStatement()) {
63
108
  paths = addCompletionRecords(this.get("block"), paths);
64
109
  paths = addCompletionRecords(this.get("handler"), paths);
65
- paths = addCompletionRecords(this.get("finalizer"), paths);
66
110
  } else if (this.isCatchClause()) {
67
111
  paths = addCompletionRecords(this.get("body"), paths);
112
+ } else if (this.isSwitchStatement()) {
113
+ paths = completionRecordForSwitch(this.get("cases"), paths);
68
114
  } else {
69
115
  paths.push(this);
70
116
  }
@@ -170,11 +216,11 @@ function _getPattern(parts, context) {
170
216
  }
171
217
 
172
218
  function getBindingIdentifiers(duplicates) {
173
- return t().getBindingIdentifiers(this.node, duplicates);
219
+ return t.getBindingIdentifiers(this.node, duplicates);
174
220
  }
175
221
 
176
222
  function getOuterBindingIdentifiers(duplicates) {
177
- return t().getOuterBindingIdentifiers(this.node, duplicates);
223
+ return t.getOuterBindingIdentifiers(this.node, duplicates);
178
224
  }
179
225
 
180
226
  function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
@@ -186,7 +232,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
186
232
  const id = search.shift();
187
233
  if (!id) continue;
188
234
  if (!id.node) continue;
189
- const keys = t().getBindingIdentifiers.keys[id.node.type];
235
+ const keys = t.getBindingIdentifiers.keys[id.node.type];
190
236
 
191
237
  if (id.isIdentifier()) {
192
238
  if (duplicates) {
package/lib/path/index.js CHANGED
@@ -7,41 +7,17 @@ exports.default = void 0;
7
7
 
8
8
  var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types"));
9
9
 
10
- function _debug() {
11
- const data = _interopRequireDefault(require("debug"));
12
-
13
- _debug = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
10
+ var _debug = _interopRequireDefault(require("debug"));
19
11
 
20
12
  var _index = _interopRequireDefault(require("../index"));
21
13
 
22
14
  var _scope = _interopRequireDefault(require("../scope"));
23
15
 
24
- function t() {
25
- const data = _interopRequireWildcard(require("@babel/types"));
26
-
27
- t = function () {
28
- return data;
29
- };
30
-
31
- return data;
32
- }
16
+ var t = _interopRequireWildcard(require("@babel/types"));
33
17
 
34
18
  var _cache = require("../cache");
35
19
 
36
- function _generator() {
37
- const data = _interopRequireDefault(require("@babel/generator"));
38
-
39
- _generator = function () {
40
- return data;
41
- };
42
-
43
- return data;
44
- }
20
+ var _generator = _interopRequireDefault(require("@babel/generator"));
45
21
 
46
22
  var NodePath_ancestry = _interopRequireWildcard(require("./ancestry"));
47
23
 
@@ -67,9 +43,11 @@ var NodePath_comments = _interopRequireWildcard(require("./comments"));
67
43
 
68
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
45
 
70
- 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
46
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
47
+
48
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
71
49
 
72
- const debug = (0, _debug().default)("babel");
50
+ const debug = (0, _debug.default)("babel");
73
51
 
74
52
  class NodePath {
75
53
  constructor(hub, parent) {
@@ -162,7 +140,7 @@ class NodePath {
162
140
  }
163
141
 
164
142
  set(key, node) {
165
- t().validate(this.node, key, node);
143
+ t.validate(this.node, key, node);
166
144
  this.node[key] = node;
167
145
  }
168
146
 
@@ -185,7 +163,7 @@ class NodePath {
185
163
  }
186
164
 
187
165
  toString() {
188
- return (0, _generator().default)(this.node).code;
166
+ return (0, _generator.default)(this.node).code;
189
167
  }
190
168
 
191
169
  }
@@ -193,9 +171,9 @@ class NodePath {
193
171
  exports.default = NodePath;
194
172
  Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
195
173
 
196
- for (const type of t().TYPES) {
174
+ for (const type of t.TYPES) {
197
175
  const typeKey = `is${type}`;
198
- const fn = t()[typeKey];
176
+ const fn = t[typeKey];
199
177
 
200
178
  NodePath.prototype[typeKey] = function (opts) {
201
179
  return fn(this.node, opts);
@@ -210,7 +188,7 @@ for (const type of t().TYPES) {
210
188
 
211
189
  for (const type of Object.keys(virtualTypes)) {
212
190
  if (type[0] === "_") continue;
213
- if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
191
+ if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
214
192
  const virtualType = virtualTypes[type];
215
193
 
216
194
  NodePath.prototype[`is${type}`] = function (opts) {