@babel/traverse 7.6.2 → 7.7.4

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,19 +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"));
12
-
13
- t = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
10
+ var t = _interopRequireWildcard(require("@babel/types"));
19
11
 
20
12
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
21
13
 
22
- 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; }
14
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; }
23
15
 
24
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
17
 
@@ -38,7 +30,7 @@ class TraversalContext {
38
30
  const opts = this.opts;
39
31
  if (opts.enter || opts.exit) return true;
40
32
  if (opts[node.type]) return true;
41
- const keys = t().VISITOR_KEYS[node.type];
33
+ const keys = t.VISITOR_KEYS[node.type];
42
34
  if (!keys || !keys.length) return false;
43
35
 
44
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
 
@@ -60,7 +44,7 @@ var _hub = _interopRequireDefault(require("./hub"));
60
44
 
61
45
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
62
46
 
63
- 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; }
47
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; }
64
48
 
65
49
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
66
50
 
@@ -74,6 +58,10 @@ function traverse(parent, opts, scope, state, parentPath) {
74
58
  }
75
59
  }
76
60
 
61
+ if (!t.VISITOR_KEYS[parent.type]) {
62
+ return;
63
+ }
64
+
77
65
  visitors.explode(opts);
78
66
  traverse.node(parent, opts, scope, state, parentPath);
79
67
  }
@@ -83,11 +71,11 @@ traverse.verify = visitors.verify;
83
71
  traverse.explode = visitors.explode;
84
72
 
85
73
  traverse.cheap = function (node, enter) {
86
- return t().traverseFast(node, enter);
74
+ return t.traverseFast(node, enter);
87
75
  };
88
76
 
89
77
  traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
90
- const keys = t().VISITOR_KEYS[node.type];
78
+ const keys = t.VISITOR_KEYS[node.type];
91
79
  if (!keys) return;
92
80
  const context = new _context.default(scope, opts, state, parentPath);
93
81
 
@@ -98,12 +86,12 @@ traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
98
86
  };
99
87
 
100
88
  traverse.clearNode = function (node, opts) {
101
- t().removeProperties(node, opts);
89
+ t.removeProperties(node, opts);
102
90
  cache.path.delete(node);
103
91
  };
104
92
 
105
93
  traverse.removeProperties = function (tree, opts) {
106
- t().traverseFast(tree, traverse.clearNode, opts);
94
+ t.traverseFast(tree, traverse.clearNode, opts);
107
95
  return tree;
108
96
  };
109
97
 
@@ -115,7 +103,7 @@ function hasBlacklistedType(path, state) {
115
103
  }
116
104
 
117
105
  traverse.hasType = function (tree, type, blacklistTypes) {
118
- if ((0, _includes().default)(blacklistTypes, tree.type)) return false;
106
+ if ((0, _includes.default)(blacklistTypes, tree.type)) return false;
119
107
  if (tree.type === type) return true;
120
108
  const state = {
121
109
  has: false,
@@ -14,15 +14,7 @@ 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
 
@@ -30,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
30
22
 
31
23
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
32
24
 
33
- 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; }
25
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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
26
 
35
27
  function findParent(callback) {
36
28
  let path = this;
@@ -77,7 +69,7 @@ function getStatementParent() {
77
69
  function getEarliestCommonAncestorFrom(paths) {
78
70
  return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
79
71
  let earliest;
80
- const keys = t().VISITOR_KEYS[deepest.type];
72
+ const keys = t.VISITOR_KEYS[deepest.type];
81
73
 
82
74
  for (const ancestry of ancestries) {
83
75
  const path = ancestry[i + 1];
@@ -7,19 +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"));
12
-
13
- t = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
10
+ var t = _interopRequireWildcard(require("@babel/types"));
19
11
 
20
12
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
21
13
 
22
- 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; }
14
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; }
23
15
 
24
16
  function shareCommentsWithSiblings() {
25
17
  if (typeof this.key === "string") return;
@@ -41,9 +33,9 @@ function shareCommentsWithSiblings() {
41
33
  }
42
34
 
43
35
  function addComment(type, content, line) {
44
- t().addComment(this.node, type, content, line);
36
+ t.addComment(this.node, type, content, line);
45
37
  }
46
38
 
47
39
  function addComments(type, comments) {
48
- t().addComments(this.node, type, comments);
40
+ t.addComments(this.node, type, comments);
49
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,31 +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
18
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
35
19
 
36
- 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; }
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; }
37
21
 
38
22
  function toComputedKey() {
39
23
  const node = this.node;
@@ -48,7 +32,7 @@ function toComputedKey() {
48
32
  }
49
33
 
50
34
  if (!node.computed) {
51
- if (t().isIdentifier(key)) key = t().stringLiteral(key.name);
35
+ if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
52
36
  }
53
37
 
54
38
  return key;
@@ -84,14 +68,14 @@ function ensureBlock() {
84
68
 
85
69
  if (this.isFunction()) {
86
70
  key = "argument";
87
- statements.push(t().returnStatement(body.node));
71
+ statements.push(t.returnStatement(body.node));
88
72
  } else {
89
73
  key = "expression";
90
- statements.push(t().expressionStatement(body.node));
74
+ statements.push(t.expressionStatement(body.node));
91
75
  }
92
76
  }
93
77
 
94
- this.node.body = t().blockStatement(statements);
78
+ this.node.body = t.blockStatement(statements);
95
79
  const parentPath = this.get(stringPath);
96
80
  body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
97
81
  return this.node;
@@ -128,12 +112,12 @@ function arrowFunctionToExpression({
128
112
  if (checkBinding) {
129
113
  this.parentPath.scope.push({
130
114
  id: checkBinding,
131
- init: t().objectExpression([])
115
+ init: t.objectExpression([])
132
116
  });
133
117
  }
134
118
 
135
- this.get("body").unshiftContainer("body", t().expressionStatement(t().callExpression(this.hub.addHelper("newArrowCheck"), [t().thisExpression(), checkBinding ? t().identifier(checkBinding.name) : t().identifier(thisBinding)])));
136
- 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()]));
137
121
  }
138
122
  }
139
123
 
@@ -181,40 +165,25 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
181
165
  });
182
166
  const superBinding = getSuperBinding(thisEnvFn);
183
167
  allSuperCalls.forEach(superCall => {
184
- const callee = t().identifier(superBinding);
168
+ const callee = t.identifier(superBinding);
185
169
  callee.loc = superCall.node.callee.loc;
186
170
  superCall.get("callee").replaceWith(callee);
187
171
  });
188
172
  }
189
173
 
190
- let thisBinding;
191
-
192
- if (thisPaths.length > 0 || specCompliant) {
193
- thisBinding = getThisBinding(thisEnvFn, inConstructor);
194
-
195
- if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
196
- thisPaths.forEach(thisChild => {
197
- const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding);
198
- thisRef.loc = thisChild.node.loc;
199
- thisChild.replaceWith(thisRef);
200
- });
201
- if (specCompliant) thisBinding = null;
202
- }
203
- }
204
-
205
174
  if (argumentsPaths.length > 0) {
206
- const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments"));
175
+ const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments"));
207
176
  argumentsPaths.forEach(argumentsChild => {
208
- const argsRef = t().identifier(argumentsBinding);
177
+ const argsRef = t.identifier(argumentsBinding);
209
178
  argsRef.loc = argumentsChild.node.loc;
210
179
  argumentsChild.replaceWith(argsRef);
211
180
  });
212
181
  }
213
182
 
214
183
  if (newTargetPaths.length > 0) {
215
- 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")));
216
185
  newTargetPaths.forEach(targetChild => {
217
- const targetRef = t().identifier(newTargetBinding);
186
+ const targetRef = t.identifier(newTargetBinding);
218
187
  targetRef.loc = targetChild.node.loc;
219
188
  targetChild.replaceWith(targetRef);
220
189
  });
@@ -228,41 +197,53 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
228
197
  const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
229
198
  flatSuperProps.forEach(superProp => {
230
199
  const key = superProp.node.computed ? "" : superProp.get("property").node.name;
231
-
232
- if (superProp.parentPath.isCallExpression({
200
+ const isAssignment = superProp.parentPath.isAssignmentExpression({
201
+ left: superProp.node
202
+ });
203
+ const isCall = superProp.parentPath.isCallExpression({
233
204
  callee: superProp.node
234
- })) {
235
- const superBinding = getSuperPropCallBinding(thisEnvFn, key);
236
-
237
- if (superProp.node.computed) {
238
- const prop = superProp.get("property").node;
239
- superProp.replaceWith(t().identifier(superBinding));
240
- superProp.parentPath.node.arguments.unshift(prop);
241
- } else {
242
- superProp.replaceWith(t().identifier(superBinding));
243
- }
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);
244
226
  } else {
245
- const isAssignment = superProp.parentPath.isAssignmentExpression({
246
- left: superProp.node
247
- });
248
- const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
249
- const args = [];
250
-
251
- if (superProp.node.computed) {
252
- args.push(superProp.get("property").node);
253
- }
254
-
255
- if (isAssignment) {
256
- const value = superProp.parentPath.node.right;
257
- args.push(value);
258
- superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args));
259
- } else {
260
- superProp.replaceWith(t().callExpression(t().identifier(superBinding), args));
261
- }
227
+ superProp.replaceWith(call);
262
228
  }
263
229
  });
264
230
  }
265
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
+
266
247
  return thisBinding;
267
248
  }
268
249
 
@@ -275,11 +256,11 @@ function standardizeSuperProperty(superProp) {
275
256
 
276
257
  if (superProp.node.computed) {
277
258
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
278
- assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, t().assignmentExpression("=", tmp, superProp.node.property), true));
279
- 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));
280
261
  } else {
281
- assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, superProp.node.property));
282
- 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));
283
264
  }
284
265
 
285
266
  return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
@@ -287,13 +268,13 @@ function standardizeSuperProperty(superProp) {
287
268
  const updateExpr = superProp.parentPath;
288
269
  const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
289
270
  const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
290
- 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)))];
291
272
 
292
273
  if (!superProp.parentPath.node.prefix) {
293
- parts.push(t().identifier(tmp.name));
274
+ parts.push(t.identifier(tmp.name));
294
275
  }
295
276
 
296
- updateExpr.replaceWith(t().sequenceExpression(parts));
277
+ updateExpr.replaceWith(t.sequenceExpression(parts));
297
278
  const left = updateExpr.get("expressions.0.right");
298
279
  const right = updateExpr.get("expressions.1.left");
299
280
  return [left, right];
@@ -308,7 +289,7 @@ function hasSuperClass(thisEnvFn) {
308
289
 
309
290
  function getThisBinding(thisEnvFn, inConstructor) {
310
291
  return getBinding(thisEnvFn, "this", thisBinding => {
311
- if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression();
292
+ if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression();
312
293
  const supers = new WeakSet();
313
294
  thisEnvFn.traverse({
314
295
  Function(child) {
@@ -324,7 +305,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
324
305
  if (!child.get("callee").isSuper()) return;
325
306
  if (supers.has(child.node)) return;
326
307
  supers.add(child.node);
327
- 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"))]);
328
309
  }
329
310
 
330
311
  });
@@ -334,25 +315,7 @@ function getThisBinding(thisEnvFn, inConstructor) {
334
315
  function getSuperBinding(thisEnvFn) {
335
316
  return getBinding(thisEnvFn, "supercall", () => {
336
317
  const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
337
- return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))]));
338
- });
339
- }
340
-
341
- function getSuperPropCallBinding(thisEnvFn, propName) {
342
- return getBinding(thisEnvFn, `superprop_call:${propName || ""}`, () => {
343
- const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
344
- const argsList = [t().restElement(argsBinding)];
345
- let fnBody;
346
-
347
- if (propName) {
348
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]);
349
- } else {
350
- const method = thisEnvFn.scope.generateUidIdentifier("prop");
351
- argsList.unshift(method);
352
- fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]);
353
- }
354
-
355
- return t().arrowFunctionExpression(argsList, fnBody);
318
+ return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))]));
356
319
  });
357
320
  }
358
321
 
@@ -363,20 +326,20 @@ function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
363
326
  let fnBody;
364
327
 
365
328
  if (propName) {
366
- fnBody = t().memberExpression(t().super(), t().identifier(propName));
329
+ fnBody = t.memberExpression(t.super(), t.identifier(propName));
367
330
  } else {
368
331
  const method = thisEnvFn.scope.generateUidIdentifier("prop");
369
332
  argsList.unshift(method);
370
- fnBody = t().memberExpression(t().super(), t().identifier(method.name), true);
333
+ fnBody = t.memberExpression(t.super(), t.identifier(method.name), true);
371
334
  }
372
335
 
373
336
  if (isAssignment) {
374
337
  const valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
375
338
  argsList.push(valueIdent);
376
- fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name));
339
+ fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name));
377
340
  }
378
341
 
379
- return t().arrowFunctionExpression(argsList, fnBody);
342
+ return t.arrowFunctionExpression(argsList, fnBody);
380
343
  });
381
344
  }
382
345
 
@@ -20,19 +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"));
25
-
26
- t = function () {
27
- return data;
28
- };
29
-
30
- return data;
31
- }
23
+ var t = _interopRequireWildcard(require("@babel/types"));
32
24
 
33
25
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
34
26
 
35
- 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; }
27
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; }
36
28
 
37
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
30
 
@@ -224,11 +216,11 @@ function _getPattern(parts, context) {
224
216
  }
225
217
 
226
218
  function getBindingIdentifiers(duplicates) {
227
- return t().getBindingIdentifiers(this.node, duplicates);
219
+ return t.getBindingIdentifiers(this.node, duplicates);
228
220
  }
229
221
 
230
222
  function getOuterBindingIdentifiers(duplicates) {
231
- return t().getOuterBindingIdentifiers(this.node, duplicates);
223
+ return t.getOuterBindingIdentifiers(this.node, duplicates);
232
224
  }
233
225
 
234
226
  function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
@@ -240,7 +232,7 @@ function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
240
232
  const id = search.shift();
241
233
  if (!id) continue;
242
234
  if (!id.node) continue;
243
- const keys = t().getBindingIdentifiers.keys[id.node.type];
235
+ const keys = t.getBindingIdentifiers.keys[id.node.type];
244
236
 
245
237
  if (id.isIdentifier()) {
246
238
  if (duplicates) {