@babel/traverse 7.6.0 → 7.7.2

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
 
@@ -72,6 +58,10 @@ function traverse(parent, opts, scope, state, parentPath) {
72
58
  }
73
59
  }
74
60
 
61
+ if (!t.VISITOR_KEYS[parent.type]) {
62
+ return;
63
+ }
64
+
75
65
  visitors.explode(opts);
76
66
  traverse.node(parent, opts, scope, state, parentPath);
77
67
  }
@@ -81,11 +71,11 @@ traverse.verify = visitors.verify;
81
71
  traverse.explode = visitors.explode;
82
72
 
83
73
  traverse.cheap = function (node, enter) {
84
- return t().traverseFast(node, enter);
74
+ return t.traverseFast(node, enter);
85
75
  };
86
76
 
87
77
  traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
88
- const keys = t().VISITOR_KEYS[node.type];
78
+ const keys = t.VISITOR_KEYS[node.type];
89
79
  if (!keys) return;
90
80
  const context = new _context.default(scope, opts, state, parentPath);
91
81
 
@@ -96,12 +86,12 @@ traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
96
86
  };
97
87
 
98
88
  traverse.clearNode = function (node, opts) {
99
- t().removeProperties(node, opts);
89
+ t.removeProperties(node, opts);
100
90
  cache.path.delete(node);
101
91
  };
102
92
 
103
93
  traverse.removeProperties = function (tree, opts) {
104
- t().traverseFast(tree, traverse.clearNode, opts);
94
+ t.traverseFast(tree, traverse.clearNode, opts);
105
95
  return tree;
106
96
  };
107
97
 
@@ -113,7 +103,7 @@ function hasBlacklistedType(path, state) {
113
103
  }
114
104
 
115
105
  traverse.hasType = function (tree, type, blacklistTypes) {
116
- if ((0, _includes().default)(blacklistTypes, tree.type)) return false;
106
+ if ((0, _includes.default)(blacklistTypes, tree.type)) return false;
117
107
  if (tree.type === type) return true;
118
108
  const state = {
119
109
  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
  }
@@ -26,6 +26,8 @@ exports._getQueueContexts = _getQueueContexts;
26
26
 
27
27
  var _index = _interopRequireDefault(require("../index"));
28
28
 
29
+ var _index2 = require("./index");
30
+
29
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
32
 
31
33
  function call(key) {
@@ -61,7 +63,7 @@ function _call(fns) {
61
63
  }
62
64
 
63
65
  if (this.node !== node) return true;
64
- if (this.shouldStop || this.shouldSkip || this.removed) return true;
66
+ if (this._traverseFlags > 0) return true;
65
67
  }
66
68
 
67
69
  return false;
@@ -85,7 +87,7 @@ function visit() {
85
87
  return false;
86
88
  }
87
89
 
88
- if (this.call("enter") || this.shouldSkip) {
90
+ if (this.shouldSkip || this.call("enter") || this.shouldSkip) {
89
91
  this.debug("Skip...");
90
92
  return this.shouldStop;
91
93
  }
@@ -103,12 +105,15 @@ function skip() {
103
105
  }
104
106
 
105
107
  function skipKey(key) {
108
+ if (this.skipKeys == null) {
109
+ this.skipKeys = {};
110
+ }
111
+
106
112
  this.skipKeys[key] = true;
107
113
  }
108
114
 
109
115
  function stop() {
110
- this.shouldStop = true;
111
- this.shouldSkip = true;
116
+ this._traverseFlags |= _index2.SHOULD_SKIP | _index2.SHOULD_STOP;
112
117
  }
113
118
 
114
119
  function setScope() {
@@ -127,10 +132,11 @@ function setScope() {
127
132
  }
128
133
 
129
134
  function setContext(context) {
130
- this.shouldSkip = false;
131
- this.shouldStop = false;
132
- this.removed = false;
133
- this.skipKeys = {};
135
+ if (this.skipKeys != null) {
136
+ this.skipKeys = {};
137
+ }
138
+
139
+ this._traverseFlags = 0;
134
140
 
135
141
  if (context) {
136
142
  this.context = context;
@@ -208,9 +214,7 @@ function pushContext(context) {
208
214
  }
209
215
 
210
216
  function setup(parentPath, container, listKey, key) {
211
- this.inList = !!listKey;
212
217
  this.listKey = listKey;
213
- this.parentKey = listKey || key;
214
218
  this.container = container;
215
219
  this.parentPath = parentPath || this.parentPath;
216
220
  this.setKey(key);
@@ -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,40 +165,25 @@ 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
  });
186
172
  }
187
173
 
188
- let thisBinding;
189
-
190
- if (thisPaths.length > 0 || specCompliant) {
191
- thisBinding = getThisBinding(thisEnvFn, inConstructor);
192
-
193
- if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
194
- thisPaths.forEach(thisChild => {
195
- const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding);
196
- thisRef.loc = thisChild.node.loc;
197
- thisChild.replaceWith(thisRef);
198
- });
199
- if (specCompliant) thisBinding = null;
200
- }
201
- }
202
-
203
174
  if (argumentsPaths.length > 0) {
204
- const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments"));
175
+ const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments"));
205
176
  argumentsPaths.forEach(argumentsChild => {
206
- const argsRef = t().identifier(argumentsBinding);
177
+ const argsRef = t.identifier(argumentsBinding);
207
178
  argsRef.loc = argumentsChild.node.loc;
208
179
  argumentsChild.replaceWith(argsRef);
209
180
  });
210
181
  }
211
182
 
212
183
  if (newTargetPaths.length > 0) {
213
- const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t().metaProperty(t().identifier("new"), t().identifier("target")));
184
+ const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t.metaProperty(t.identifier("new"), t.identifier("target")));
214
185
  newTargetPaths.forEach(targetChild => {
215
- const targetRef = t().identifier(newTargetBinding);
186
+ const targetRef = t.identifier(newTargetBinding);
216
187
  targetRef.loc = targetChild.node.loc;
217
188
  targetChild.replaceWith(targetRef);
218
189
  });
@@ -226,41 +197,53 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
226
197
  const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
227
198
  flatSuperProps.forEach(superProp => {
228
199
  const key = superProp.node.computed ? "" : superProp.get("property").node.name;
229
-
230
- if (superProp.parentPath.isCallExpression({
200
+ const isAssignment = superProp.parentPath.isAssignmentExpression({
201
+ left: superProp.node
202
+ });
203
+ const isCall = superProp.parentPath.isCallExpression({
231
204
  callee: superProp.node
232
- })) {
233
- const superBinding = getSuperPropCallBinding(thisEnvFn, key);
234
-
235
- if (superProp.node.computed) {
236
- const prop = superProp.get("property").node;
237
- superProp.replaceWith(t().identifier(superBinding));
238
- superProp.parentPath.node.arguments.unshift(prop);
239
- } else {
240
- superProp.replaceWith(t().identifier(superBinding));
241
- }
205
+ });
206
+ const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
207
+ const args = [];
208
+
209
+ if (superProp.node.computed) {
210
+ args.push(superProp.get("property").node);
211
+ }
212
+
213
+ if (isAssignment) {
214
+ const value = superProp.parentPath.node.right;
215
+ args.push(value);
216
+ }
217
+
218
+ const call = t.callExpression(t.identifier(superBinding), args);
219
+
220
+ if (isCall) {
221
+ superProp.parentPath.unshiftContainer("arguments", t.thisExpression());
222
+ superProp.replaceWith(t.memberExpression(call, t.identifier("call")));
223
+ thisPaths.push(superProp.parentPath.get("arguments.0"));
224
+ } else if (isAssignment) {
225
+ superProp.parentPath.replaceWith(call);
242
226
  } else {
243
- const isAssignment = superProp.parentPath.isAssignmentExpression({
244
- left: superProp.node
245
- });
246
- const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
247
- const args = [];
248
-
249
- if (superProp.node.computed) {
250
- args.push(superProp.get("property").node);
251
- }
252
-
253
- if (isAssignment) {
254
- const value = superProp.parentPath.node.right;
255
- args.push(value);
256
- superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args));
257
- } else {
258
- superProp.replaceWith(t().callExpression(t().identifier(superBinding), args));
259
- }
227
+ superProp.replaceWith(call);
260
228
  }
261
229
  });
262
230
  }
263
231
 
232
+ let thisBinding;
233
+
234
+ if (thisPaths.length > 0 || specCompliant) {
235
+ thisBinding = getThisBinding(thisEnvFn, inConstructor);
236
+
237
+ if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
238
+ thisPaths.forEach(thisChild => {
239
+ const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding);
240
+ thisRef.loc = thisChild.node.loc;
241
+ thisChild.replaceWith(thisRef);
242
+ });
243
+ if (specCompliant) thisBinding = null;
244
+ }
245
+ }
246
+
264
247
  return thisBinding;
265
248
  }
266
249
 
@@ -273,11 +256,11 @@ function standardizeSuperProperty(superProp) {
273
256
 
274
257
  if (superProp.node.computed) {
275
258
  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));
259
+ assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, t.assignmentExpression("=", tmp, superProp.node.property), true));
260
+ assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(tmp.name), true), value));
278
261
  } 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));
262
+ assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, superProp.node.property));
263
+ assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(superProp.node.property.name)), value));
281
264
  }
282
265
 
283
266
  return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
@@ -285,13 +268,13 @@ function standardizeSuperProperty(superProp) {
285
268
  const updateExpr = superProp.parentPath;
286
269
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
287
270
  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)))];
271
+ 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
272
 
290
273
  if (!superProp.parentPath.node.prefix) {
291
- parts.push(t().identifier(tmp.name));
274
+ parts.push(t.identifier(tmp.name));
292
275
  }
293
276
 
294
- updateExpr.replaceWith(t().sequenceExpression(parts));
277
+ updateExpr.replaceWith(t.sequenceExpression(parts));
295
278
  const left = updateExpr.get("expressions.0.right");
296
279
  const right = updateExpr.get("expressions.1.left");
297
280
  return [left, right];
@@ -306,7 +289,7 @@ function hasSuperClass(thisEnvFn) {
306
289
 
307
290
  function getThisBinding(thisEnvFn, inConstructor) {
308
291
  return getBinding(thisEnvFn, "this", thisBinding => {
309
- if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression();
292
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
310
293
  const supers = new WeakSet();
311
294
  thisEnvFn.traverse({
312
295
  Function(child) {
@@ -322,7 +305,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
322
305
  if (!child.get("callee").isSuper()) return;
323
306
  if (supers.has(child.node)) return;
324
307
  supers.add(child.node);
325
- child.replaceWithMultiple([child.node, t().assignmentExpression("=", t().identifier(thisBinding), t().identifier("this"))]);
308
+ child.replaceWithMultiple([child.node, t.assignmentExpression("=", t.identifier(thisBinding), t.identifier("this"))]);
326
309
  }
327
310
 
328
311
  });
@@ -332,25 +315,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
332
315
  function getSuperBinding(thisEnvFn) {
333
316
  return getBinding(thisEnvFn, "supercall", () => {
334
317
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
335
- return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))]));
336
- });
337
- }
338
-
339
- function getSuperPropCallBinding(thisEnvFn, propName) {
340
- return getBinding(thisEnvFn, `superprop_call:${propName || ""}`, () => {
341
- const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
342
- const argsList = [t().restElement(argsBinding)];
343
- let fnBody;
344
-
345
- if (propName) {
346
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]);
347
- } else {
348
- const method = thisEnvFn.scope.generateUidIdentifier("prop");
349
- argsList.unshift(method);
350
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]);
351
- }
352
-
353
- return t().arrowFunctionExpression(argsList, fnBody);
318
+ return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
354
319
  });
355
320
  }
356
321
 
@@ -361,20 +326,20 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
361
326
  let fnBody;
362
327
 
363
328
  if (propName) {
364
- fnBody = t().memberExpression(t().super(), t().identifier(propName));
329
+ fnBody = t.memberExpression(t.super(), t.identifier(propName));
365
330
  } else {
366
331
  const method = thisEnvFn.scope.generateUidIdentifier("prop");
367
332
  argsList.unshift(method);
368
- fnBody = t().memberExpression(t().super(), t().identifier(method.name), true);
333
+ fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
369
334
  }
370
335
 
371
336
  if (isAssignment) {
372
337
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
373
338
  argsList.push(valueIdent);
374
- fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name));
339
+ fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
375
340
  }
376
341
 
377
- return t().arrowFunctionExpression(argsList, fnBody);
342
+ return t.arrowFunctionExpression(argsList, fnBody);
378
343
  });
379
344
  }
380
345
 
@@ -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
 
@@ -222,11 +216,11 @@ function _getPattern(parts, context) {
222
216
  }
223
217
 
224
218
  function getBindingIdentifiers(duplicates) {
225
- return t().getBindingIdentifiers(this.node, duplicates);
219
+ return t.getBindingIdentifiers(this.node, duplicates);
226
220
  }
227
221
 
228
222
  function getOuterBindingIdentifiers(duplicates) {
229
- return t().getOuterBindingIdentifiers(this.node, duplicates);
223
+ return t.getOuterBindingIdentifiers(this.node, duplicates);
230
224
  }
231
225
 
232
226
  function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
@@ -238,7 +232,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
238
232
  const id = search.shift();
239
233
  if (!id) continue;
240
234
  if (!id.node) continue;
241
- const keys = t().getBindingIdentifiers.keys[id.node.type];
235
+ const keys = t.getBindingIdentifiers.keys[id.node.type];
242
236
 
243
237
  if (id.isIdentifier()) {
244
238
  if (duplicates) {