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