@babel/traverse 7.0.0-beta.43 → 7.0.0-beta.44
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/cache.js +2 -2
- package/lib/context.js +75 -35
- package/lib/hub.js +3 -6
- package/lib/index.js +24 -12
- package/lib/path/ancestry.js +40 -26
- package/lib/path/comments.js +9 -9
- package/lib/path/context.js +45 -17
- package/lib/path/conversion.js +132 -124
- package/lib/path/evaluation.js +136 -97
- package/lib/path/family.js +40 -27
- package/lib/path/index.js +80 -60
- package/lib/path/inference/index.js +16 -12
- package/lib/path/inference/inferer-reference.js +41 -37
- package/lib/path/inference/inferers.js +16 -18
- package/lib/path/introspection.js +82 -49
- package/lib/path/lib/hoister.js +56 -48
- package/lib/path/lib/removal-hooks.js +2 -2
- package/lib/path/lib/virtual-types.js +46 -76
- package/lib/path/modification.js +53 -31
- package/lib/path/removal.js +10 -3
- package/lib/path/replacement.js +50 -32
- package/lib/scope/binding.js +22 -20
- package/lib/scope/index.js +400 -280
- package/lib/scope/lib/renamer.js +35 -37
- package/lib/visitors.js +120 -62
- package/package.json +8 -8
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
|
7
7
|
|
8
8
|
function t() {
|
9
|
-
|
9
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
10
10
|
|
11
|
-
t = function () {
|
11
|
+
t = function t() {
|
12
12
|
return data;
|
13
13
|
};
|
14
14
|
|
@@ -17,13 +17,12 @@ function t() {
|
|
17
17
|
|
18
18
|
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; } }
|
19
19
|
|
20
|
-
|
20
|
+
var ReferencedIdentifier = {
|
21
21
|
types: ["Identifier", "JSXIdentifier"],
|
22
|
+
checkPath: function checkPath(_ref, opts) {
|
23
|
+
var node = _ref.node,
|
24
|
+
parent = _ref.parent;
|
22
25
|
|
23
|
-
checkPath({
|
24
|
-
node,
|
25
|
-
parent
|
26
|
-
}, opts) {
|
27
26
|
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
|
28
27
|
if (t().isJSXIdentifier(node, opts)) {
|
29
28
|
if (t().react.isCompatTag(node.name)) return false;
|
@@ -34,40 +33,32 @@ const ReferencedIdentifier = {
|
|
34
33
|
|
35
34
|
return t().isReferenced(node, parent);
|
36
35
|
}
|
37
|
-
|
38
36
|
};
|
39
37
|
exports.ReferencedIdentifier = ReferencedIdentifier;
|
40
|
-
|
38
|
+
var ReferencedMemberExpression = {
|
41
39
|
types: ["MemberExpression"],
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
parent
|
46
|
-
}) {
|
40
|
+
checkPath: function checkPath(_ref2) {
|
41
|
+
var node = _ref2.node,
|
42
|
+
parent = _ref2.parent;
|
47
43
|
return t().isMemberExpression(node) && t().isReferenced(node, parent);
|
48
44
|
}
|
49
|
-
|
50
45
|
};
|
51
46
|
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
52
|
-
|
47
|
+
var BindingIdentifier = {
|
53
48
|
types: ["Identifier"],
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
parent
|
58
|
-
}) {
|
49
|
+
checkPath: function checkPath(_ref3) {
|
50
|
+
var node = _ref3.node,
|
51
|
+
parent = _ref3.parent;
|
59
52
|
return t().isIdentifier(node) && t().isBinding(node, parent);
|
60
53
|
}
|
61
|
-
|
62
54
|
};
|
63
55
|
exports.BindingIdentifier = BindingIdentifier;
|
64
|
-
|
56
|
+
var Statement = {
|
65
57
|
types: ["Statement"],
|
58
|
+
checkPath: function checkPath(_ref4) {
|
59
|
+
var node = _ref4.node,
|
60
|
+
parent = _ref4.parent;
|
66
61
|
|
67
|
-
checkPath({
|
68
|
-
node,
|
69
|
-
parent
|
70
|
-
}) {
|
71
62
|
if (t().isStatement(node)) {
|
72
63
|
if (t().isVariableDeclaration(node)) {
|
73
64
|
if (t().isForXStatement(parent, {
|
@@ -83,81 +74,68 @@ const Statement = {
|
|
83
74
|
return false;
|
84
75
|
}
|
85
76
|
}
|
86
|
-
|
87
77
|
};
|
88
78
|
exports.Statement = Statement;
|
89
|
-
|
79
|
+
var Expression = {
|
90
80
|
types: ["Expression"],
|
91
|
-
|
92
|
-
checkPath(path) {
|
81
|
+
checkPath: function checkPath(path) {
|
93
82
|
if (path.isIdentifier()) {
|
94
83
|
return path.isReferencedIdentifier();
|
95
84
|
} else {
|
96
85
|
return t().isExpression(path.node);
|
97
86
|
}
|
98
87
|
}
|
99
|
-
|
100
88
|
};
|
101
89
|
exports.Expression = Expression;
|
102
|
-
|
90
|
+
var Scope = {
|
103
91
|
types: ["Scopable"],
|
104
|
-
|
105
|
-
checkPath(path) {
|
92
|
+
checkPath: function checkPath(path) {
|
106
93
|
return t().isScope(path.node, path.parent);
|
107
94
|
}
|
108
|
-
|
109
95
|
};
|
110
96
|
exports.Scope = Scope;
|
111
|
-
|
112
|
-
checkPath(path) {
|
97
|
+
var Referenced = {
|
98
|
+
checkPath: function checkPath(path) {
|
113
99
|
return t().isReferenced(path.node, path.parent);
|
114
100
|
}
|
115
|
-
|
116
101
|
};
|
117
102
|
exports.Referenced = Referenced;
|
118
|
-
|
119
|
-
checkPath(path) {
|
103
|
+
var BlockScoped = {
|
104
|
+
checkPath: function checkPath(path) {
|
120
105
|
return t().isBlockScoped(path.node);
|
121
106
|
}
|
122
|
-
|
123
107
|
};
|
124
108
|
exports.BlockScoped = BlockScoped;
|
125
|
-
|
109
|
+
var Var = {
|
126
110
|
types: ["VariableDeclaration"],
|
127
|
-
|
128
|
-
checkPath(path) {
|
111
|
+
checkPath: function checkPath(path) {
|
129
112
|
return t().isVar(path.node);
|
130
113
|
}
|
131
|
-
|
132
114
|
};
|
133
115
|
exports.Var = Var;
|
134
|
-
|
135
|
-
checkPath(path) {
|
116
|
+
var User = {
|
117
|
+
checkPath: function checkPath(path) {
|
136
118
|
return path.node && !!path.node.loc;
|
137
119
|
}
|
138
|
-
|
139
120
|
};
|
140
121
|
exports.User = User;
|
141
|
-
|
142
|
-
checkPath(path) {
|
122
|
+
var Generated = {
|
123
|
+
checkPath: function checkPath(path) {
|
143
124
|
return !path.isUser();
|
144
125
|
}
|
145
|
-
|
146
126
|
};
|
147
127
|
exports.Generated = Generated;
|
148
|
-
|
149
|
-
checkPath(path, opts) {
|
128
|
+
var Pure = {
|
129
|
+
checkPath: function checkPath(path, opts) {
|
150
130
|
return path.scope.isPure(path.node, opts);
|
151
131
|
}
|
152
|
-
|
153
132
|
};
|
154
133
|
exports.Pure = Pure;
|
155
|
-
|
134
|
+
var Flow = {
|
156
135
|
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
136
|
+
checkPath: function checkPath(_ref5) {
|
137
|
+
var node = _ref5.node;
|
157
138
|
|
158
|
-
checkPath({
|
159
|
-
node
|
160
|
-
}) {
|
161
139
|
if (t().isFlow(node)) {
|
162
140
|
return true;
|
163
141
|
} else if (t().isImportDeclaration(node)) {
|
@@ -170,43 +148,35 @@ const Flow = {
|
|
170
148
|
return false;
|
171
149
|
}
|
172
150
|
}
|
173
|
-
|
174
151
|
};
|
175
152
|
exports.Flow = Flow;
|
176
|
-
|
153
|
+
var RestProperty = {
|
177
154
|
types: ["RestElement"],
|
178
|
-
|
179
|
-
checkPath(path) {
|
155
|
+
checkPath: function checkPath(path) {
|
180
156
|
return path.parentPath && path.parentPath.isObjectPattern();
|
181
157
|
}
|
182
|
-
|
183
158
|
};
|
184
159
|
exports.RestProperty = RestProperty;
|
185
|
-
|
160
|
+
var SpreadProperty = {
|
186
161
|
types: ["RestElement"],
|
187
|
-
|
188
|
-
checkPath(path) {
|
162
|
+
checkPath: function checkPath(path) {
|
189
163
|
return path.parentPath && path.parentPath.isObjectExpression();
|
190
164
|
}
|
191
|
-
|
192
165
|
};
|
193
166
|
exports.SpreadProperty = SpreadProperty;
|
194
|
-
|
167
|
+
var ExistentialTypeParam = {
|
195
168
|
types: ["ExistsTypeAnnotation"]
|
196
169
|
};
|
197
170
|
exports.ExistentialTypeParam = ExistentialTypeParam;
|
198
|
-
|
171
|
+
var NumericLiteralTypeAnnotation = {
|
199
172
|
types: ["NumberLiteralTypeAnnotation"]
|
200
173
|
};
|
201
174
|
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
202
|
-
|
175
|
+
var ForAwaitStatement = {
|
203
176
|
types: ["ForOfStatement"],
|
204
|
-
|
205
|
-
|
206
|
-
node
|
207
|
-
}) {
|
177
|
+
checkPath: function checkPath(_ref6) {
|
178
|
+
var node = _ref6.node;
|
208
179
|
return node.await === true;
|
209
180
|
}
|
210
|
-
|
211
181
|
};
|
212
182
|
exports.ForAwaitStatement = ForAwaitStatement;
|
package/lib/path/modification.js
CHANGED
@@ -21,9 +21,9 @@ var _hoister = _interopRequireDefault(require("./lib/hoister"));
|
|
21
21
|
var _index = _interopRequireDefault(require("./index"));
|
22
22
|
|
23
23
|
function t() {
|
24
|
-
|
24
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
25
25
|
|
26
|
-
t = function () {
|
26
|
+
t = function t() {
|
27
27
|
return data;
|
28
28
|
};
|
29
29
|
|
@@ -47,7 +47,7 @@ function insertBefore(nodes) {
|
|
47
47
|
} else if (Array.isArray(this.container)) {
|
48
48
|
return this._containerInsertBefore(nodes);
|
49
49
|
} else if (this.isStatementOrBlock()) {
|
50
|
-
|
50
|
+
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
51
51
|
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
52
52
|
return this.unshiftContainer("body", nodes);
|
53
53
|
} else {
|
@@ -56,13 +56,16 @@ function insertBefore(nodes) {
|
|
56
56
|
}
|
57
57
|
|
58
58
|
function _containerInsert(from, nodes) {
|
59
|
+
var _container;
|
60
|
+
|
59
61
|
this.updateSiblingKeys(from, nodes.length);
|
60
|
-
|
61
|
-
|
62
|
+
var paths = [];
|
63
|
+
|
64
|
+
(_container = this.container).splice.apply(_container, [from, 0].concat(nodes));
|
62
65
|
|
63
|
-
for (
|
64
|
-
|
65
|
-
|
66
|
+
for (var i = 0; i < nodes.length; i++) {
|
67
|
+
var to = from + i;
|
68
|
+
var path = this.getSibling(to);
|
66
69
|
paths.push(path);
|
67
70
|
|
68
71
|
if (this.context && this.context.queue) {
|
@@ -70,14 +73,29 @@ function _containerInsert(from, nodes) {
|
|
70
73
|
}
|
71
74
|
}
|
72
75
|
|
73
|
-
|
76
|
+
var contexts = this._getQueueContexts();
|
77
|
+
|
78
|
+
for (var _i = 0; _i < paths.length; _i++) {
|
79
|
+
var _path = paths[_i];
|
80
|
+
|
81
|
+
_path.setScope();
|
74
82
|
|
75
|
-
|
76
|
-
path.setScope();
|
77
|
-
path.debug("Inserted.");
|
83
|
+
_path.debug("Inserted.");
|
78
84
|
|
79
|
-
for (
|
80
|
-
|
85
|
+
for (var _iterator = contexts, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
86
|
+
var _ref;
|
87
|
+
|
88
|
+
if (_isArray) {
|
89
|
+
if (_i2 >= _iterator.length) break;
|
90
|
+
_ref = _iterator[_i2++];
|
91
|
+
} else {
|
92
|
+
_i2 = _iterator.next();
|
93
|
+
if (_i2.done) break;
|
94
|
+
_ref = _i2.value;
|
95
|
+
}
|
96
|
+
|
97
|
+
var context = _ref;
|
98
|
+
context.maybeQueue(_path, true);
|
81
99
|
}
|
82
100
|
}
|
83
101
|
|
@@ -101,7 +119,7 @@ function insertAfter(nodes) {
|
|
101
119
|
return this.parentPath.insertAfter(nodes);
|
102
120
|
} else if (this.isNodeType("Expression") || this.parentPath.isForStatement() && this.key === "init") {
|
103
121
|
if (this.node) {
|
104
|
-
|
122
|
+
var temp = this.scope.generateDeclaredUidIdentifier();
|
105
123
|
nodes.unshift(t().expressionStatement(t().assignmentExpression("=", t().cloneNode(temp), this.node)));
|
106
124
|
nodes.push(t().expressionStatement(t().cloneNode(temp)));
|
107
125
|
}
|
@@ -110,7 +128,7 @@ function insertAfter(nodes) {
|
|
110
128
|
} else if (Array.isArray(this.container)) {
|
111
129
|
return this._containerInsertAfter(nodes);
|
112
130
|
} else if (this.isStatementOrBlock()) {
|
113
|
-
|
131
|
+
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
114
132
|
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
115
133
|
return this.pushContainer("body", nodes);
|
116
134
|
} else {
|
@@ -121,10 +139,10 @@ function insertAfter(nodes) {
|
|
121
139
|
function updateSiblingKeys(fromIndex, incrementBy) {
|
122
140
|
if (!this.parent) return;
|
123
141
|
|
124
|
-
|
142
|
+
var paths = _cache.path.get(this.parent);
|
125
143
|
|
126
|
-
for (
|
127
|
-
|
144
|
+
for (var i = 0; i < paths.length; i++) {
|
145
|
+
var path = paths[i];
|
128
146
|
|
129
147
|
if (path.key >= fromIndex) {
|
130
148
|
path.key += incrementBy;
|
@@ -141,9 +159,9 @@ function _verifyNodeList(nodes) {
|
|
141
159
|
nodes = [nodes];
|
142
160
|
}
|
143
161
|
|
144
|
-
for (
|
145
|
-
|
146
|
-
|
162
|
+
for (var i = 0; i < nodes.length; i++) {
|
163
|
+
var node = nodes[i];
|
164
|
+
var msg = void 0;
|
147
165
|
|
148
166
|
if (!node) {
|
149
167
|
msg = "has falsy node";
|
@@ -156,8 +174,8 @@ function _verifyNodeList(nodes) {
|
|
156
174
|
}
|
157
175
|
|
158
176
|
if (msg) {
|
159
|
-
|
160
|
-
throw new Error(
|
177
|
+
var type = Array.isArray(node) ? "array" : typeof node;
|
178
|
+
throw new Error("Node list " + msg + " with the index of " + i + " and type of " + type);
|
161
179
|
}
|
162
180
|
}
|
163
181
|
|
@@ -169,11 +187,11 @@ function unshiftContainer(listKey, nodes) {
|
|
169
187
|
|
170
188
|
nodes = this._verifyNodeList(nodes);
|
171
189
|
|
172
|
-
|
190
|
+
var path = _index.default.get({
|
173
191
|
parentPath: this,
|
174
192
|
parent: this.node,
|
175
193
|
container: this.node[listKey],
|
176
|
-
listKey,
|
194
|
+
listKey: listKey,
|
177
195
|
key: 0
|
178
196
|
});
|
179
197
|
|
@@ -184,20 +202,24 @@ function pushContainer(listKey, nodes) {
|
|
184
202
|
this._assertUnremoved();
|
185
203
|
|
186
204
|
nodes = this._verifyNodeList(nodes);
|
187
|
-
|
205
|
+
var container = this.node[listKey];
|
188
206
|
|
189
|
-
|
207
|
+
var path = _index.default.get({
|
190
208
|
parentPath: this,
|
191
209
|
parent: this.node,
|
192
210
|
container: container,
|
193
|
-
listKey,
|
211
|
+
listKey: listKey,
|
194
212
|
key: container.length
|
195
213
|
});
|
196
214
|
|
197
215
|
return path.replaceWithMultiple(nodes);
|
198
216
|
}
|
199
217
|
|
200
|
-
function hoist(scope
|
201
|
-
|
218
|
+
function hoist(scope) {
|
219
|
+
if (scope === void 0) {
|
220
|
+
scope = this.scope;
|
221
|
+
}
|
222
|
+
|
223
|
+
var hoister = new _hoister.default(this, scope);
|
202
224
|
return hoister.run();
|
203
225
|
}
|
package/lib/path/removal.js
CHANGED
@@ -33,12 +33,19 @@ function remove() {
|
|
33
33
|
}
|
34
34
|
|
35
35
|
function _removeFromScope() {
|
36
|
-
|
37
|
-
|
36
|
+
var _this = this;
|
37
|
+
|
38
|
+
var bindings = this.getBindingIdentifiers();
|
39
|
+
Object.keys(bindings).forEach(function (name) {
|
40
|
+
return _this.scope.removeBinding(name);
|
41
|
+
});
|
38
42
|
}
|
39
43
|
|
40
44
|
function _callRemovalHooks() {
|
41
|
-
|
45
|
+
var _arr = _removalHooks.hooks;
|
46
|
+
|
47
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
48
|
+
var fn = _arr[_i];
|
42
49
|
if (fn(this, this.parentPath)) return true;
|
43
50
|
}
|
44
51
|
}
|
package/lib/path/replacement.js
CHANGED
@@ -11,9 +11,9 @@ exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
|
|
11
11
|
exports.replaceInline = replaceInline;
|
12
12
|
|
13
13
|
function _codeFrame() {
|
14
|
-
|
14
|
+
var data = require("@babel/code-frame");
|
15
15
|
|
16
|
-
_codeFrame = function () {
|
16
|
+
_codeFrame = function _codeFrame() {
|
17
17
|
return data;
|
18
18
|
};
|
19
19
|
|
@@ -25,9 +25,9 @@ var _index = _interopRequireDefault(require("../index"));
|
|
25
25
|
var _index2 = _interopRequireDefault(require("./index"));
|
26
26
|
|
27
27
|
function _babylon() {
|
28
|
-
|
28
|
+
var data = require("babylon");
|
29
29
|
|
30
|
-
_babylon = function () {
|
30
|
+
_babylon = function _babylon() {
|
31
31
|
return data;
|
32
32
|
};
|
33
33
|
|
@@ -35,9 +35,9 @@ function _babylon() {
|
|
35
35
|
}
|
36
36
|
|
37
37
|
function t() {
|
38
|
-
|
38
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
39
39
|
|
40
|
-
t = function () {
|
40
|
+
t = function t() {
|
41
41
|
return data;
|
42
42
|
};
|
43
43
|
|
@@ -48,24 +48,26 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
48
48
|
|
49
49
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50
50
|
|
51
|
-
|
52
|
-
Function(path) {
|
51
|
+
var hoistVariablesVisitor = {
|
52
|
+
Function: function Function(path) {
|
53
53
|
path.skip();
|
54
54
|
},
|
55
|
-
|
56
|
-
VariableDeclaration(path) {
|
55
|
+
VariableDeclaration: function VariableDeclaration(path) {
|
57
56
|
if (path.node.kind !== "var") return;
|
58
|
-
|
57
|
+
var bindings = path.getBindingIdentifiers();
|
59
58
|
|
60
|
-
for (
|
59
|
+
for (var key in bindings) {
|
61
60
|
path.scope.push({
|
62
61
|
id: bindings[key]
|
63
62
|
});
|
64
63
|
}
|
65
64
|
|
66
|
-
|
65
|
+
var exprs = [];
|
66
|
+
var _arr = path.node.declarations;
|
67
|
+
|
68
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
69
|
+
var declar = _arr[_i];
|
67
70
|
|
68
|
-
for (const declar of path.node.declarations) {
|
69
71
|
if (declar.init) {
|
70
72
|
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init)));
|
71
73
|
}
|
@@ -73,7 +75,6 @@ const hoistVariablesVisitor = {
|
|
73
75
|
|
74
76
|
path.replaceWithMultiple(exprs);
|
75
77
|
}
|
76
|
-
|
77
78
|
};
|
78
79
|
|
79
80
|
function replaceWithMultiple(nodes) {
|
@@ -82,7 +83,7 @@ function replaceWithMultiple(nodes) {
|
|
82
83
|
t().inheritLeadingComments(nodes[0], this.node);
|
83
84
|
t().inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
84
85
|
this.node = this.container[this.key] = null;
|
85
|
-
|
86
|
+
var paths = this.insertAfter(nodes);
|
86
87
|
|
87
88
|
if (this.node) {
|
88
89
|
this.requeue();
|
@@ -97,10 +98,10 @@ function replaceWithSourceString(replacement) {
|
|
97
98
|
this.resync();
|
98
99
|
|
99
100
|
try {
|
100
|
-
replacement =
|
101
|
+
replacement = "(" + replacement + ")";
|
101
102
|
replacement = (0, _babylon().parse)(replacement);
|
102
103
|
} catch (err) {
|
103
|
-
|
104
|
+
var loc = err.loc;
|
104
105
|
|
105
106
|
if (loc) {
|
106
107
|
err.message += " - make sure this is an expression.\n" + (0, _codeFrame().codeFrameColumns)(replacement, {
|
@@ -153,7 +154,7 @@ function replaceWith(replacement) {
|
|
153
154
|
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
154
155
|
}
|
155
156
|
|
156
|
-
|
157
|
+
var nodePath = "";
|
157
158
|
|
158
159
|
if (this.isNodeType("Statement") && t().isExpression(replacement)) {
|
159
160
|
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
@@ -168,7 +169,7 @@ function replaceWith(replacement) {
|
|
168
169
|
}
|
169
170
|
}
|
170
171
|
|
171
|
-
|
172
|
+
var oldNode = this.node;
|
172
173
|
|
173
174
|
if (oldNode) {
|
174
175
|
t().inheritsComments(replacement, oldNode);
|
@@ -194,34 +195,51 @@ function _replaceWith(node) {
|
|
194
195
|
t().validate(this.parent, this.key, node);
|
195
196
|
}
|
196
197
|
|
197
|
-
this.debug(
|
198
|
+
this.debug("Replace with " + (node && node.type));
|
198
199
|
this.node = this.container[this.key] = node;
|
199
200
|
}
|
200
201
|
|
201
202
|
function replaceExpressionWithStatements(nodes) {
|
202
203
|
this.resync();
|
203
|
-
|
204
|
+
var toSequenceExpression = t().toSequenceExpression(nodes, this.scope);
|
204
205
|
|
205
206
|
if (toSequenceExpression) {
|
206
207
|
return this.replaceWith(toSequenceExpression)[0].get("expressions");
|
207
208
|
}
|
208
209
|
|
209
|
-
|
210
|
+
var container = t().arrowFunctionExpression([], t().blockStatement(nodes));
|
210
211
|
this.replaceWith(t().callExpression(container, []));
|
211
212
|
this.traverse(hoistVariablesVisitor);
|
212
|
-
|
213
|
+
var completionRecords = this.get("callee").getCompletionRecords();
|
214
|
+
|
215
|
+
for (var _iterator = completionRecords, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
216
|
+
var _ref;
|
217
|
+
|
218
|
+
if (_isArray) {
|
219
|
+
if (_i2 >= _iterator.length) break;
|
220
|
+
_ref = _iterator[_i2++];
|
221
|
+
} else {
|
222
|
+
_i2 = _iterator.next();
|
223
|
+
if (_i2.done) break;
|
224
|
+
_ref = _i2.value;
|
225
|
+
}
|
213
226
|
|
214
|
-
|
227
|
+
var path = _ref;
|
215
228
|
if (!path.isExpressionStatement()) continue;
|
216
|
-
|
229
|
+
var loop = path.findParent(function (path) {
|
230
|
+
return path.isLoop();
|
231
|
+
});
|
217
232
|
|
218
233
|
if (loop) {
|
219
|
-
|
234
|
+
var uid = loop.getData("expressionReplacementReturnUid");
|
220
235
|
|
221
236
|
if (!uid) {
|
222
|
-
|
223
|
-
|
224
|
-
|
237
|
+
var _callee = this.get("callee");
|
238
|
+
|
239
|
+
uid = _callee.scope.generateDeclaredUidIdentifier("ret");
|
240
|
+
|
241
|
+
_callee.get("body").pushContainer("body", t().returnStatement(t().cloneNode(uid)));
|
242
|
+
|
225
243
|
loop.setData("expressionReplacementReturnUid", uid);
|
226
244
|
} else {
|
227
245
|
uid = t().identifier(uid.name);
|
@@ -233,7 +251,7 @@ function replaceExpressionWithStatements(nodes) {
|
|
233
251
|
}
|
234
252
|
}
|
235
253
|
|
236
|
-
|
254
|
+
var callee = this.get("callee");
|
237
255
|
callee.arrowFunctionToExpression();
|
238
256
|
return callee.get("body.body");
|
239
257
|
}
|
@@ -245,7 +263,7 @@ function replaceInline(nodes) {
|
|
245
263
|
if (Array.isArray(this.container)) {
|
246
264
|
nodes = this._verifyNodeList(nodes);
|
247
265
|
|
248
|
-
|
266
|
+
var paths = this._containerInsertAfter(nodes);
|
249
267
|
|
250
268
|
this.remove();
|
251
269
|
return paths;
|