@babel/traverse 8.0.0-alpha.1 → 8.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +171 -160
- package/lib/index.js.map +1 -1
- package/package.json +11 -10
- package/lib/cache.js +0 -14
- package/lib/cache.js.map +0 -1
- package/lib/context.js +0 -108
- package/lib/context.js.map +0 -1
- package/lib/hub.js +0 -12
- package/lib/hub.js.map +0 -1
- package/lib/path/ancestry.js +0 -126
- package/lib/path/ancestry.js.map +0 -1
- package/lib/path/comments.js +0 -46
- package/lib/path/comments.js.map +0 -1
- package/lib/path/context.js +0 -194
- package/lib/path/context.js.map +0 -1
- package/lib/path/conversion.js +0 -453
- package/lib/path/conversion.js.map +0 -1
- package/lib/path/evaluation.js +0 -333
- package/lib/path/evaluation.js.map +0 -1
- package/lib/path/family.js +0 -322
- package/lib/path/family.js.map +0 -1
- package/lib/path/index.js +0 -185
- package/lib/path/index.js.map +0 -1
- package/lib/path/inference/index.js +0 -137
- package/lib/path/inference/index.js.map +0 -1
- package/lib/path/inference/inferer-reference.js +0 -145
- package/lib/path/inference/inferer-reference.js.map +0 -1
- package/lib/path/inference/inferers.js +0 -172
- package/lib/path/inference/inferers.js.map +0 -1
- package/lib/path/inference/util.js +0 -20
- package/lib/path/inference/util.js.map +0 -1
- package/lib/path/introspection.js +0 -360
- package/lib/path/introspection.js.map +0 -1
- package/lib/path/lib/hoister.js +0 -164
- package/lib/path/lib/hoister.js.map +0 -1
- package/lib/path/lib/removal-hooks.js +0 -31
- package/lib/path/lib/removal-hooks.js.map +0 -1
- package/lib/path/lib/virtual-types-validator.js +0 -138
- package/lib/path/lib/virtual-types-validator.js.map +0 -1
- package/lib/path/lib/virtual-types.js +0 -20
- package/lib/path/lib/virtual-types.js.map +0 -1
- package/lib/path/modification.js +0 -209
- package/lib/path/modification.js.map +0 -1
- package/lib/path/removal.js +0 -46
- package/lib/path/removal.js.map +0 -1
- package/lib/path/replacement.js +0 -192
- package/lib/path/replacement.js.map +0 -1
- package/lib/scope/binding.js +0 -78
- package/lib/scope/binding.js.map +0 -1
- package/lib/scope/index.js +0 -870
- package/lib/scope/index.js.map +0 -1
- package/lib/scope/lib/renamer.js +0 -105
- package/lib/scope/lib/renamer.js.map +0 -1
- package/lib/traverse-node.js +0 -19
- package/lib/traverse-node.js.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/visitors.js +0 -210
- package/lib/visitors.js.map +0 -1
@@ -1,360 +0,0 @@
|
|
1
|
-
import * as _t from "@babel/types";
|
2
|
-
const {
|
3
|
-
STATEMENT_OR_BLOCK_KEYS,
|
4
|
-
VISITOR_KEYS,
|
5
|
-
isBlockStatement,
|
6
|
-
isExpression,
|
7
|
-
isIdentifier,
|
8
|
-
isLiteral,
|
9
|
-
isStringLiteral,
|
10
|
-
isType,
|
11
|
-
matchesPattern: _matchesPattern
|
12
|
-
} = _t;
|
13
|
-
export function matchesPattern(pattern, allowPartial) {
|
14
|
-
return _matchesPattern(this.node, pattern, allowPartial);
|
15
|
-
}
|
16
|
-
export function has(key) {
|
17
|
-
const val = this.node && this.node[key];
|
18
|
-
if (val && Array.isArray(val)) {
|
19
|
-
return !!val.length;
|
20
|
-
} else {
|
21
|
-
return !!val;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
export function isStatic() {
|
25
|
-
return this.scope.isStatic(this.node);
|
26
|
-
}
|
27
|
-
export const is = has;
|
28
|
-
export function isnt(key) {
|
29
|
-
return !this.has(key);
|
30
|
-
}
|
31
|
-
export function equals(key, value) {
|
32
|
-
return this.node[key] === value;
|
33
|
-
}
|
34
|
-
export function isNodeType(type) {
|
35
|
-
return isType(this.type, type);
|
36
|
-
}
|
37
|
-
export function canHaveVariableDeclarationOrExpression() {
|
38
|
-
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
39
|
-
}
|
40
|
-
export function canSwapBetweenExpressionAndStatement(replacement) {
|
41
|
-
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
|
42
|
-
return false;
|
43
|
-
}
|
44
|
-
if (this.isExpression()) {
|
45
|
-
return isBlockStatement(replacement);
|
46
|
-
} else if (this.isBlockStatement()) {
|
47
|
-
return isExpression(replacement);
|
48
|
-
}
|
49
|
-
return false;
|
50
|
-
}
|
51
|
-
export function isCompletionRecord(allowInsideFunction) {
|
52
|
-
let path = this;
|
53
|
-
let first = true;
|
54
|
-
do {
|
55
|
-
const {
|
56
|
-
type,
|
57
|
-
container
|
58
|
-
} = path;
|
59
|
-
if (!first && (path.isFunction() || type === "StaticBlock")) {
|
60
|
-
return !!allowInsideFunction;
|
61
|
-
}
|
62
|
-
first = false;
|
63
|
-
if (Array.isArray(container) && path.key !== container.length - 1) {
|
64
|
-
return false;
|
65
|
-
}
|
66
|
-
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
|
67
|
-
return true;
|
68
|
-
}
|
69
|
-
export function isStatementOrBlock() {
|
70
|
-
if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {
|
71
|
-
return false;
|
72
|
-
} else {
|
73
|
-
return STATEMENT_OR_BLOCK_KEYS.includes(this.key);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
export function referencesImport(moduleSource, importName) {
|
77
|
-
if (!this.isReferencedIdentifier()) {
|
78
|
-
if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
|
79
|
-
value: importName
|
80
|
-
}) : this.node.property.name === importName)) {
|
81
|
-
const object = this.get("object");
|
82
|
-
return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
|
83
|
-
}
|
84
|
-
return false;
|
85
|
-
}
|
86
|
-
const binding = this.scope.getBinding(this.node.name);
|
87
|
-
if (!binding || binding.kind !== "module") return false;
|
88
|
-
const path = binding.path;
|
89
|
-
const parent = path.parentPath;
|
90
|
-
if (!parent.isImportDeclaration()) return false;
|
91
|
-
if (parent.node.source.value === moduleSource) {
|
92
|
-
if (!importName) return true;
|
93
|
-
} else {
|
94
|
-
return false;
|
95
|
-
}
|
96
|
-
if (path.isImportDefaultSpecifier() && importName === "default") {
|
97
|
-
return true;
|
98
|
-
}
|
99
|
-
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
100
|
-
return true;
|
101
|
-
}
|
102
|
-
if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
|
103
|
-
name: importName
|
104
|
-
})) {
|
105
|
-
return true;
|
106
|
-
}
|
107
|
-
return false;
|
108
|
-
}
|
109
|
-
export function getSource() {
|
110
|
-
const node = this.node;
|
111
|
-
if (node.end) {
|
112
|
-
const code = this.hub.getCode();
|
113
|
-
if (code) return code.slice(node.start, node.end);
|
114
|
-
}
|
115
|
-
return "";
|
116
|
-
}
|
117
|
-
export function willIMaybeExecuteBefore(target) {
|
118
|
-
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
119
|
-
}
|
120
|
-
function getOuterFunction(path) {
|
121
|
-
return path.isProgram() ? path : (path.parentPath.scope.getFunctionParent() || path.parentPath.scope.getProgramParent()).path;
|
122
|
-
}
|
123
|
-
function isExecutionUncertain(type, key) {
|
124
|
-
switch (type) {
|
125
|
-
case "LogicalExpression":
|
126
|
-
return key === "right";
|
127
|
-
case "ConditionalExpression":
|
128
|
-
case "IfStatement":
|
129
|
-
return key === "consequent" || key === "alternate";
|
130
|
-
case "WhileStatement":
|
131
|
-
case "DoWhileStatement":
|
132
|
-
case "ForInStatement":
|
133
|
-
case "ForOfStatement":
|
134
|
-
return key === "body";
|
135
|
-
case "ForStatement":
|
136
|
-
return key === "body" || key === "update";
|
137
|
-
case "SwitchStatement":
|
138
|
-
return key === "cases";
|
139
|
-
case "TryStatement":
|
140
|
-
return key === "handler";
|
141
|
-
case "AssignmentPattern":
|
142
|
-
return key === "right";
|
143
|
-
case "OptionalMemberExpression":
|
144
|
-
return key === "property";
|
145
|
-
case "OptionalCallExpression":
|
146
|
-
return key === "arguments";
|
147
|
-
default:
|
148
|
-
return false;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
function isExecutionUncertainInList(paths, maxIndex) {
|
152
|
-
for (let i = 0; i < maxIndex; i++) {
|
153
|
-
const path = paths[i];
|
154
|
-
if (isExecutionUncertain(path.parent.type, path.parentKey)) {
|
155
|
-
return true;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
return false;
|
159
|
-
}
|
160
|
-
const SYMBOL_CHECKING = Symbol();
|
161
|
-
export function _guessExecutionStatusRelativeTo(target) {
|
162
|
-
return _guessExecutionStatusRelativeToCached(this, target, new Map());
|
163
|
-
}
|
164
|
-
function _guessExecutionStatusRelativeToCached(base, target, cache) {
|
165
|
-
const funcParent = {
|
166
|
-
this: getOuterFunction(base),
|
167
|
-
target: getOuterFunction(target)
|
168
|
-
};
|
169
|
-
if (funcParent.target.node !== funcParent.this.node) {
|
170
|
-
return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
|
171
|
-
}
|
172
|
-
const paths = {
|
173
|
-
target: target.getAncestry(),
|
174
|
-
this: base.getAncestry()
|
175
|
-
};
|
176
|
-
if (paths.target.indexOf(base) >= 0) return "after";
|
177
|
-
if (paths.this.indexOf(target) >= 0) return "before";
|
178
|
-
let commonPath;
|
179
|
-
const commonIndex = {
|
180
|
-
target: 0,
|
181
|
-
this: 0
|
182
|
-
};
|
183
|
-
while (!commonPath && commonIndex.this < paths.this.length) {
|
184
|
-
const path = paths.this[commonIndex.this];
|
185
|
-
commonIndex.target = paths.target.indexOf(path);
|
186
|
-
if (commonIndex.target >= 0) {
|
187
|
-
commonPath = path;
|
188
|
-
} else {
|
189
|
-
commonIndex.this++;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
if (!commonPath) {
|
193
|
-
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
|
194
|
-
}
|
195
|
-
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
|
196
|
-
return "unknown";
|
197
|
-
}
|
198
|
-
const divergence = {
|
199
|
-
this: paths.this[commonIndex.this - 1],
|
200
|
-
target: paths.target[commonIndex.target - 1]
|
201
|
-
};
|
202
|
-
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
|
203
|
-
return divergence.target.key > divergence.this.key ? "before" : "after";
|
204
|
-
}
|
205
|
-
const keys = VISITOR_KEYS[commonPath.type];
|
206
|
-
const keyPosition = {
|
207
|
-
this: keys.indexOf(divergence.this.parentKey),
|
208
|
-
target: keys.indexOf(divergence.target.parentKey)
|
209
|
-
};
|
210
|
-
return keyPosition.target > keyPosition.this ? "before" : "after";
|
211
|
-
}
|
212
|
-
function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
|
213
|
-
if (!target.isFunctionDeclaration()) {
|
214
|
-
if (_guessExecutionStatusRelativeToCached(base, target, cache) === "before") {
|
215
|
-
return "before";
|
216
|
-
}
|
217
|
-
return "unknown";
|
218
|
-
} else if (target.parentPath.isExportDeclaration()) {
|
219
|
-
return "unknown";
|
220
|
-
}
|
221
|
-
const binding = target.scope.getBinding(target.node.id.name);
|
222
|
-
if (!binding.references) return "before";
|
223
|
-
const referencePaths = binding.referencePaths;
|
224
|
-
let allStatus;
|
225
|
-
for (const path of referencePaths) {
|
226
|
-
const childOfFunction = !!path.find(path => path.node === target.node);
|
227
|
-
if (childOfFunction) continue;
|
228
|
-
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
229
|
-
return "unknown";
|
230
|
-
}
|
231
|
-
const status = _guessExecutionStatusRelativeToCached(base, path, cache);
|
232
|
-
if (allStatus && allStatus !== status) {
|
233
|
-
return "unknown";
|
234
|
-
} else {
|
235
|
-
allStatus = status;
|
236
|
-
}
|
237
|
-
}
|
238
|
-
return allStatus;
|
239
|
-
}
|
240
|
-
function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
|
241
|
-
let nodeMap = cache.get(base.node);
|
242
|
-
let cached;
|
243
|
-
if (!nodeMap) {
|
244
|
-
cache.set(base.node, nodeMap = new Map());
|
245
|
-
} else if (cached = nodeMap.get(target.node)) {
|
246
|
-
if (cached === SYMBOL_CHECKING) {
|
247
|
-
return "unknown";
|
248
|
-
}
|
249
|
-
return cached;
|
250
|
-
}
|
251
|
-
nodeMap.set(target.node, SYMBOL_CHECKING);
|
252
|
-
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
|
253
|
-
nodeMap.set(target.node, result);
|
254
|
-
return result;
|
255
|
-
}
|
256
|
-
export function resolve(dangerous, resolved) {
|
257
|
-
return this._resolve(dangerous, resolved) || this;
|
258
|
-
}
|
259
|
-
export function _resolve(dangerous, resolved) {
|
260
|
-
if (resolved && resolved.indexOf(this) >= 0) return;
|
261
|
-
resolved = resolved || [];
|
262
|
-
resolved.push(this);
|
263
|
-
if (this.isVariableDeclarator()) {
|
264
|
-
if (this.get("id").isIdentifier()) {
|
265
|
-
return this.get("init").resolve(dangerous, resolved);
|
266
|
-
} else {}
|
267
|
-
} else if (this.isReferencedIdentifier()) {
|
268
|
-
const binding = this.scope.getBinding(this.node.name);
|
269
|
-
if (!binding) return;
|
270
|
-
if (!binding.constant) return;
|
271
|
-
if (binding.kind === "module") return;
|
272
|
-
if (binding.path !== this) {
|
273
|
-
const ret = binding.path.resolve(dangerous, resolved);
|
274
|
-
if (this.find(parent => parent.node === ret.node)) return;
|
275
|
-
return ret;
|
276
|
-
}
|
277
|
-
} else if (this.isTypeCastExpression()) {
|
278
|
-
return this.get("expression").resolve(dangerous, resolved);
|
279
|
-
} else if (dangerous && this.isMemberExpression()) {
|
280
|
-
const targetKey = this.toComputedKey();
|
281
|
-
if (!isLiteral(targetKey)) return;
|
282
|
-
const targetName = targetKey.value;
|
283
|
-
const target = this.get("object").resolve(dangerous, resolved);
|
284
|
-
if (target.isObjectExpression()) {
|
285
|
-
const props = target.get("properties");
|
286
|
-
for (const prop of props) {
|
287
|
-
if (!prop.isProperty()) continue;
|
288
|
-
const key = prop.get("key");
|
289
|
-
let match = prop.isnt("computed") && key.isIdentifier({
|
290
|
-
name: targetName
|
291
|
-
});
|
292
|
-
match = match || key.isLiteral({
|
293
|
-
value: targetName
|
294
|
-
});
|
295
|
-
if (match) return prop.get("value").resolve(dangerous, resolved);
|
296
|
-
}
|
297
|
-
} else if (target.isArrayExpression() && !isNaN(+targetName)) {
|
298
|
-
const elems = target.get("elements");
|
299
|
-
const elem = elems[targetName];
|
300
|
-
if (elem) return elem.resolve(dangerous, resolved);
|
301
|
-
}
|
302
|
-
}
|
303
|
-
}
|
304
|
-
export function isConstantExpression() {
|
305
|
-
if (this.isIdentifier()) {
|
306
|
-
const binding = this.scope.getBinding(this.node.name);
|
307
|
-
if (!binding) return false;
|
308
|
-
return binding.constant;
|
309
|
-
}
|
310
|
-
if (this.isLiteral()) {
|
311
|
-
if (this.isRegExpLiteral()) {
|
312
|
-
return false;
|
313
|
-
}
|
314
|
-
if (this.isTemplateLiteral()) {
|
315
|
-
return this.get("expressions").every(expression => expression.isConstantExpression());
|
316
|
-
}
|
317
|
-
return true;
|
318
|
-
}
|
319
|
-
if (this.isUnaryExpression()) {
|
320
|
-
if (this.node.operator !== "void") {
|
321
|
-
return false;
|
322
|
-
}
|
323
|
-
return this.get("argument").isConstantExpression();
|
324
|
-
}
|
325
|
-
if (this.isBinaryExpression()) {
|
326
|
-
const {
|
327
|
-
operator
|
328
|
-
} = this.node;
|
329
|
-
return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
|
330
|
-
}
|
331
|
-
return false;
|
332
|
-
}
|
333
|
-
export function isInStrictMode() {
|
334
|
-
const start = this.isProgram() ? this : this.parentPath;
|
335
|
-
const strictParent = start.find(path => {
|
336
|
-
if (path.isProgram({
|
337
|
-
sourceType: "module"
|
338
|
-
})) return true;
|
339
|
-
if (path.isClass()) return true;
|
340
|
-
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
341
|
-
return false;
|
342
|
-
}
|
343
|
-
let body;
|
344
|
-
if (path.isFunction()) {
|
345
|
-
body = path.node.body;
|
346
|
-
} else if (path.isProgram()) {
|
347
|
-
body = path.node;
|
348
|
-
} else {
|
349
|
-
return false;
|
350
|
-
}
|
351
|
-
for (const directive of body.directives) {
|
352
|
-
if (directive.value.value === "use strict") {
|
353
|
-
return true;
|
354
|
-
}
|
355
|
-
}
|
356
|
-
});
|
357
|
-
return !!strictParent;
|
358
|
-
}
|
359
|
-
|
360
|
-
//# sourceMappingURL=introspection.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_t","STATEMENT_OR_BLOCK_KEYS","VISITOR_KEYS","isBlockStatement","isExpression","isIdentifier","isLiteral","isStringLiteral","isType","matchesPattern","_matchesPattern","pattern","allowPartial","node","has","key","val","Array","isArray","length","isStatic","scope","is","isnt","equals","value","isNodeType","type","canHaveVariableDeclarationOrExpression","parentPath","isFor","canSwapBetweenExpressionAndStatement","replacement","isArrowFunctionExpression","isCompletionRecord","allowInsideFunction","path","first","container","isFunction","isProgram","isDoExpression","isStatementOrBlock","isLabeledStatement","includes","referencesImport","moduleSource","importName","isReferencedIdentifier","isJSXMemberExpression","property","name","isMemberExpression","isOptionalMemberExpression","computed","object","get","binding","getBinding","kind","parent","isImportDeclaration","source","isImportDefaultSpecifier","isImportNamespaceSpecifier","isImportSpecifier","imported","getSource","end","code","hub","getCode","slice","start","willIMaybeExecuteBefore","target","_guessExecutionStatusRelativeTo","getOuterFunction","getFunctionParent","getProgramParent","isExecutionUncertain","isExecutionUncertainInList","paths","maxIndex","i","parentKey","SYMBOL_CHECKING","Symbol","_guessExecutionStatusRelativeToCached","Map","base","cache","funcParent","this","_guessExecutionStatusRelativeToDifferentFunctionsCached","getAncestry","indexOf","commonPath","commonIndex","Error","divergence","listKey","keys","keyPosition","_guessExecutionStatusRelativeToDifferentFunctionsInternal","isFunctionDeclaration","isExportDeclaration","id","references","referencePaths","allStatus","childOfFunction","find","isCallExpression","status","nodeMap","cached","set","result","resolve","dangerous","resolved","_resolve","push","isVariableDeclarator","constant","ret","isTypeCastExpression","targetKey","toComputedKey","targetName","isObjectExpression","props","prop","isProperty","match","isArrayExpression","isNaN","elems","elem","isConstantExpression","isRegExpLiteral","isTemplateLiteral","every","expression","isUnaryExpression","operator","isBinaryExpression","isInStrictMode","strictParent","sourceType","isClass","body","directive","directives"],"sources":["../../src/path/introspection.ts"],"sourcesContent":["// This file contains methods responsible for introspecting the current path for certain values.\n\nimport type NodePath from \"./index\";\nimport {\n STATEMENT_OR_BLOCK_KEYS,\n VISITOR_KEYS,\n isBlockStatement,\n isExpression,\n isIdentifier,\n isLiteral,\n isStringLiteral,\n isType,\n matchesPattern as _matchesPattern,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Match the current node if it matches the provided `pattern`.\n *\n * For example, given the match `React.createClass` it would match the\n * parsed nodes of `React.createClass` and `React[\"createClass\"]`.\n */\n\nexport function matchesPattern(\n this: NodePath,\n pattern: string,\n allowPartial?: boolean,\n): boolean {\n return _matchesPattern(this.node, pattern, allowPartial);\n}\n\n/**\n * Check whether we have the input `key`. If the `key` references an array then we check\n * if the array has any items, otherwise we just check if it's falsy.\n */\n\nexport function has<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n const val = this.node && this.node[key];\n if (val && Array.isArray(val)) {\n return !!val.length;\n } else {\n return !!val;\n }\n}\n\n/**\n * Description\n */\n\nexport function isStatic(this: NodePath): boolean {\n return this.scope.isStatic(this.node);\n}\n\n/**\n * Alias of `has`.\n */\n\nexport const is = has;\n\n/**\n * Opposite of `has`.\n */\n\nexport function isnt<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n): boolean {\n return !this.has(key);\n}\n\n/**\n * Check whether the path node `key` strict equals `value`.\n */\n\nexport function equals<N extends t.Node>(\n this: NodePath<N>,\n key: keyof N,\n value: any,\n): boolean {\n return this.node[key] === value;\n}\n\n/**\n * Check the type against our stored internal type of the node. This is handy when a node has\n * been removed yet we still internally know the type and need it to calculate node replacement.\n */\n\nexport function isNodeType(this: NodePath, type: string): boolean {\n return isType(this.type, type);\n}\n\n/**\n * This checks whether or not we're in one of the following positions:\n *\n * for (KEY in right);\n * for (KEY;;);\n *\n * This is because these spots allow VariableDeclarations AND normal expressions so we need\n * to tell the path replacement that it's ok to replace this with an expression.\n */\n\nexport function canHaveVariableDeclarationOrExpression(this: NodePath) {\n return (\n (this.key === \"init\" || this.key === \"left\") && this.parentPath.isFor()\n );\n}\n\n/**\n * This checks whether we are swapping an arrow function's body between an\n * expression and a block statement (or vice versa).\n *\n * This is because arrow functions may implicitly return an expression, which\n * is the same as containing a block statement.\n */\n\nexport function canSwapBetweenExpressionAndStatement(\n this: NodePath,\n replacement: t.Node,\n): boolean {\n if (this.key !== \"body\" || !this.parentPath.isArrowFunctionExpression()) {\n return false;\n }\n\n if (this.isExpression()) {\n return isBlockStatement(replacement);\n } else if (this.isBlockStatement()) {\n return isExpression(replacement);\n }\n\n return false;\n}\n\n/**\n * Check whether the current path references a completion record\n */\n\nexport function isCompletionRecord(\n this: NodePath,\n allowInsideFunction?: boolean,\n): boolean {\n let path = this;\n let first = true;\n\n do {\n const { type, container } = path;\n\n // we're in a function so can't be a completion record\n if (!first && (path.isFunction() || type === \"StaticBlock\")) {\n return !!allowInsideFunction;\n }\n\n first = false;\n\n // check to see if we're the last item in the container and if we are\n // we're a completion record!\n if (Array.isArray(container) && path.key !== container.length - 1) {\n return false;\n }\n } while (\n (path = path.parentPath) &&\n !path.isProgram() &&\n !path.isDoExpression()\n );\n\n return true;\n}\n\n/**\n * Check whether or not the current `key` allows either a single statement or block statement\n * so we can explode it if necessary.\n */\n\nexport function isStatementOrBlock(this: NodePath): boolean {\n if (\n this.parentPath.isLabeledStatement() ||\n isBlockStatement(this.container as t.Node)\n ) {\n return false;\n } else {\n return STATEMENT_OR_BLOCK_KEYS.includes(this.key as string);\n }\n}\n\n/**\n * Check if the currently assigned path references the `importName` of `moduleSource`.\n */\n\nexport function referencesImport(\n this: NodePath,\n moduleSource: string,\n importName: string,\n): boolean {\n if (!this.isReferencedIdentifier()) {\n if (\n (this.isJSXMemberExpression() &&\n this.node.property.name === importName) ||\n ((this.isMemberExpression() || this.isOptionalMemberExpression()) &&\n (this.node.computed\n ? isStringLiteral(this.node.property, { value: importName })\n : (this.node.property as t.Identifier).name === importName))\n ) {\n const object = (\n this as NodePath<t.MemberExpression | t.OptionalMemberExpression>\n ).get(\"object\");\n return (\n object.isReferencedIdentifier() &&\n object.referencesImport(moduleSource, \"*\")\n );\n }\n\n return false;\n }\n\n const binding = this.scope.getBinding((this.node as t.Identifier).name);\n if (!binding || binding.kind !== \"module\") return false;\n\n const path = binding.path;\n const parent = path.parentPath;\n if (!parent.isImportDeclaration()) return false;\n\n // check moduleSource\n if (parent.node.source.value === moduleSource) {\n if (!importName) return true;\n } else {\n return false;\n }\n\n if (path.isImportDefaultSpecifier() && importName === \"default\") {\n return true;\n }\n\n if (path.isImportNamespaceSpecifier() && importName === \"*\") {\n return true;\n }\n\n if (\n path.isImportSpecifier() &&\n isIdentifier(path.node.imported, { name: importName })\n ) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Get the source code associated with this node.\n */\n\nexport function getSource(this: NodePath): string {\n const node = this.node;\n if (node.end) {\n const code = this.hub.getCode();\n if (code) return code.slice(node.start, node.end);\n }\n return \"\";\n}\n\nexport function willIMaybeExecuteBefore(\n this: NodePath,\n target: NodePath,\n): boolean {\n return this._guessExecutionStatusRelativeTo(target) !== \"after\";\n}\n\nfunction getOuterFunction(path: NodePath) {\n return path.isProgram()\n ? path\n : (\n path.parentPath.scope.getFunctionParent() ||\n path.parentPath.scope.getProgramParent()\n ).path;\n}\n\nfunction isExecutionUncertain(type: t.Node[\"type\"], key: string) {\n switch (type) {\n // a && FOO\n // a || FOO\n case \"LogicalExpression\":\n return key === \"right\";\n\n // a ? FOO : FOO\n // if (a) FOO; else FOO;\n case \"ConditionalExpression\":\n case \"IfStatement\":\n return key === \"consequent\" || key === \"alternate\";\n\n // while (a) FOO;\n case \"WhileStatement\":\n case \"DoWhileStatement\":\n case \"ForInStatement\":\n case \"ForOfStatement\":\n return key === \"body\";\n\n // for (a; b; FOO) FOO;\n case \"ForStatement\":\n return key === \"body\" || key === \"update\";\n\n // switch (a) { FOO }\n case \"SwitchStatement\":\n return key === \"cases\";\n\n // try { a } catch FOO finally { b }\n case \"TryStatement\":\n return key === \"handler\";\n\n // var [ x = FOO ]\n case \"AssignmentPattern\":\n return key === \"right\";\n\n // a?.[FOO]\n case \"OptionalMemberExpression\":\n return key === \"property\";\n\n // a?.(FOO)\n case \"OptionalCallExpression\":\n return key === \"arguments\";\n\n default:\n return false;\n }\n}\n\nfunction isExecutionUncertainInList(paths: NodePath[], maxIndex: number) {\n for (let i = 0; i < maxIndex; i++) {\n const path = paths[i];\n if (isExecutionUncertain(path.parent.type, path.parentKey)) {\n return true;\n }\n }\n return false;\n}\n\n// TODO(Babel 8)\n// This can be { before: boolean, after: boolean, unknown: boolean }.\n// This allows transforms like the tdz one to treat cases when the status\n// is both before and unknown/after like if it were before.\ntype RelativeExecutionStatus = \"before\" | \"after\" | \"unknown\";\n\n// Used to avoid infinite recursion in cases like\n// function f() { if (false) f(); }\n// f();\n// It also works with indirect recursion.\nconst SYMBOL_CHECKING = Symbol();\n\ntype ExecutionStatusCache = Map<\n t.Node,\n Map<t.Node, RelativeExecutionStatus | typeof SYMBOL_CHECKING>\n>;\n\n/**\n * Given a `target` check the execution status of it relative to the current path.\n *\n * \"Execution status\" simply refers to where or not we **think** this will execute\n * before or after the input `target` element.\n */\n\nexport function _guessExecutionStatusRelativeTo(\n this: NodePath,\n target: NodePath,\n): RelativeExecutionStatus {\n return _guessExecutionStatusRelativeToCached(this, target, new Map());\n}\n\nfunction _guessExecutionStatusRelativeToCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n // check if the two paths are in different functions, we can't track execution of these\n const funcParent = {\n this: getOuterFunction(base),\n target: getOuterFunction(target),\n };\n\n // here we check the `node` equality as sometimes we may have different paths for the\n // same node due to path thrashing\n if (funcParent.target.node !== funcParent.this.node) {\n return _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base,\n funcParent.target,\n cache,\n );\n }\n\n const paths = {\n target: target.getAncestry(),\n this: base.getAncestry(),\n };\n\n // If this is an ancestor of the target path,\n // e.g. f(g); where this is f and target is g.\n if (paths.target.indexOf(base) >= 0) return \"after\";\n if (paths.this.indexOf(target) >= 0) return \"before\";\n\n // get ancestor where the branches intersect\n let commonPath;\n const commonIndex = { target: 0, this: 0 };\n\n while (!commonPath && commonIndex.this < paths.this.length) {\n const path = paths.this[commonIndex.this];\n commonIndex.target = paths.target.indexOf(path);\n if (commonIndex.target >= 0) {\n commonPath = path;\n } else {\n commonIndex.this++;\n }\n }\n\n if (!commonPath) {\n throw new Error(\n \"Internal Babel error - The two compared nodes\" +\n \" don't appear to belong to the same program.\",\n );\n }\n\n if (\n isExecutionUncertainInList(paths.this, commonIndex.this - 1) ||\n isExecutionUncertainInList(paths.target, commonIndex.target - 1)\n ) {\n return \"unknown\";\n }\n\n const divergence = {\n this: paths.this[commonIndex.this - 1],\n target: paths.target[commonIndex.target - 1],\n };\n\n // container list so let's see which one is after the other\n // e.g. [ THIS, TARGET ]\n if (\n divergence.target.listKey &&\n divergence.this.listKey &&\n divergence.target.container === divergence.this.container\n ) {\n return divergence.target.key > divergence.this.key ? \"before\" : \"after\";\n }\n\n // otherwise we're associated by a parent node, check which key comes before the other\n const keys = VISITOR_KEYS[commonPath.type];\n const keyPosition = {\n this: keys.indexOf(divergence.this.parentKey),\n target: keys.indexOf(divergence.target.parentKey),\n };\n return keyPosition.target > keyPosition.this ? \"before\" : \"after\";\n}\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n if (!target.isFunctionDeclaration()) {\n if (\n _guessExecutionStatusRelativeToCached(base, target, cache) === \"before\"\n ) {\n return \"before\";\n }\n return \"unknown\";\n } else if (target.parentPath.isExportDeclaration()) {\n return \"unknown\";\n }\n\n // so we're in a completely different function, if this is a function declaration\n // then we can be a bit smarter and handle cases where the function is either\n // a. not called at all (part of an export)\n // b. called directly\n const binding = target.scope.getBinding(target.node.id.name);\n\n // no references!\n if (!binding.references) return \"before\";\n\n const referencePaths: Array<NodePath> = binding.referencePaths;\n\n let allStatus;\n\n // verify that all the calls have the same execution status\n for (const path of referencePaths) {\n // if a reference is a child of the function we're checking against then we can\n // safely ignore it\n const childOfFunction = !!path.find(path => path.node === target.node);\n if (childOfFunction) continue;\n\n if (path.key !== \"callee\" || !path.parentPath.isCallExpression()) {\n // This function is passed as a reference, so we don't\n // know when it will be called.\n return \"unknown\";\n }\n\n const status = _guessExecutionStatusRelativeToCached(base, path, cache);\n\n if (allStatus && allStatus !== status) {\n return \"unknown\";\n } else {\n allStatus = status;\n }\n }\n\n return allStatus;\n}\n\nfunction _guessExecutionStatusRelativeToDifferentFunctionsCached(\n base: NodePath,\n target: NodePath,\n cache: ExecutionStatusCache,\n): RelativeExecutionStatus {\n let nodeMap = cache.get(base.node);\n let cached;\n\n if (!nodeMap) {\n cache.set(base.node, (nodeMap = new Map()));\n } else if ((cached = nodeMap.get(target.node))) {\n if (cached === SYMBOL_CHECKING) {\n return \"unknown\";\n }\n return cached;\n }\n\n nodeMap.set(target.node, SYMBOL_CHECKING);\n\n const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(\n base,\n target,\n cache,\n );\n\n nodeMap.set(target.node, result);\n return result;\n}\n\n/**\n * Resolve a \"pointer\" `NodePath` to it's absolute path.\n */\nexport function resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n) {\n return this._resolve(dangerous, resolved) || this;\n}\n\nexport function _resolve(\n this: NodePath,\n dangerous?: boolean,\n resolved?: NodePath[],\n): NodePath | undefined | null {\n // detect infinite recursion\n // todo: possibly have a max length on this just to be safe\n if (resolved && resolved.indexOf(this) >= 0) return;\n\n // we store all the paths we've \"resolved\" in this array to prevent infinite recursion\n resolved = resolved || [];\n resolved.push(this);\n\n if (this.isVariableDeclarator()) {\n if (this.get(\"id\").isIdentifier()) {\n return this.get(\"init\").resolve(dangerous, resolved);\n } else {\n // otherwise it's a request for a pattern and that's a bit more tricky\n }\n } else if (this.isReferencedIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return;\n\n // reassigned so we can't really resolve it\n if (!binding.constant) return;\n\n // todo - lookup module in dependency graph\n if (binding.kind === \"module\") return;\n\n if (binding.path !== this) {\n const ret = binding.path.resolve(dangerous, resolved);\n // If the identifier resolves to parent node then we can't really resolve it.\n if (this.find(parent => parent.node === ret.node)) return;\n return ret;\n }\n } else if (this.isTypeCastExpression()) {\n // @ ts-ignore todo: babel-types\n return this.get(\"expression\").resolve(dangerous, resolved);\n } else if (dangerous && this.isMemberExpression()) {\n // this is dangerous, as non-direct target assignments will mutate it's state\n // making this resolution inaccurate\n\n const targetKey = this.toComputedKey();\n if (!isLiteral(targetKey)) return;\n\n // @ts-expect-error todo(flow->ts): NullLiteral\n const targetName = targetKey.value;\n\n const target = this.get(\"object\").resolve(dangerous, resolved);\n\n if (target.isObjectExpression()) {\n const props = target.get(\"properties\");\n for (const prop of props as any[]) {\n if (!prop.isProperty()) continue;\n\n const key = prop.get(\"key\");\n\n // { foo: obj }\n let match =\n prop.isnt(\"computed\") && key.isIdentifier({ name: targetName });\n\n // { \"foo\": \"obj\" } or { [\"foo\"]: \"obj\" }\n match = match || key.isLiteral({ value: targetName });\n\n if (match) return prop.get(\"value\").resolve(dangerous, resolved);\n }\n } else if (target.isArrayExpression() && !isNaN(+targetName)) {\n const elems = target.get(\"elements\");\n const elem = elems[targetName];\n if (elem) return elem.resolve(dangerous, resolved);\n }\n }\n}\n\nexport function isConstantExpression(this: NodePath): boolean {\n if (this.isIdentifier()) {\n const binding = this.scope.getBinding(this.node.name);\n if (!binding) return false;\n return binding.constant;\n }\n\n if (this.isLiteral()) {\n if (this.isRegExpLiteral()) {\n return false;\n }\n\n if (this.isTemplateLiteral()) {\n return this.get(\"expressions\").every(expression =>\n expression.isConstantExpression(),\n );\n }\n\n return true;\n }\n\n if (this.isUnaryExpression()) {\n if (this.node.operator !== \"void\") {\n return false;\n }\n\n return this.get(\"argument\").isConstantExpression();\n }\n\n if (this.isBinaryExpression()) {\n const { operator } = this.node;\n return (\n operator !== \"in\" &&\n operator !== \"instanceof\" &&\n this.get(\"left\").isConstantExpression() &&\n this.get(\"right\").isConstantExpression()\n );\n }\n\n return false;\n}\n\nexport function isInStrictMode(this: NodePath) {\n const start = this.isProgram() ? this : this.parentPath;\n\n const strictParent = start.find(path => {\n if (path.isProgram({ sourceType: \"module\" })) return true;\n\n if (path.isClass()) return true;\n\n if (\n path.isArrowFunctionExpression() &&\n !path.get(\"body\").isBlockStatement()\n ) {\n return false;\n }\n\n let body: t.BlockStatement | t.Program;\n if (path.isFunction()) {\n body = path.node.body as t.BlockStatement;\n } else if (path.isProgram()) {\n body = path.node;\n } else {\n return false;\n }\n\n for (const directive of body.directives) {\n if (directive.value.value === \"use strict\") {\n return true;\n }\n }\n });\n\n return !!strictParent;\n}\n"],"mappings":"AAGA,YAAAA,EAAA,MAUO,cAAc;AAAC;EATpBC,uBAAuB;EACvBC,YAAY;EACZC,gBAAgB;EAChBC,YAAY;EACZC,YAAY;EACZC,SAAS;EACTC,eAAe;EACfC,MAAM;EACNC,cAAc,EAAIC;AAAe,IAAAV,EAAA;AAWnC,OAAO,SAASS,cAAcA,CAE5BE,OAAe,EACfC,YAAsB,EACb;EACT,OAAOF,eAAe,CAAC,IAAI,CAACG,IAAI,EAAEF,OAAO,EAAEC,YAAY,CAAC;AAC1D;AAOA,OAAO,SAASE,GAAGA,CAEjBC,GAAY,EACH;EACT,MAAMC,GAAG,GAAG,IAAI,CAACH,IAAI,I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AEA,KAAK,MAAM4I,SAAS,IAAID,IAAI,CAACE,UAAU,EAAE;MACvC,IAAID,SAAS,CAAChI,KAAK,CAACA,KAAK,KAAK,YAAY,EAAE;QAC1C,OAAO,IAAI;MACb;IACF;EACF,CAAC,CAAC;EAEF,OAAO,CAAC,CAAC4H,YAAY;AACvB"}
|
package/lib/path/lib/hoister.js
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
import * as _t from "@babel/types";
|
2
|
-
const {
|
3
|
-
react
|
4
|
-
} = _t;
|
5
|
-
import * as _t2 from "@babel/types";
|
6
|
-
const {
|
7
|
-
cloneNode,
|
8
|
-
jsxExpressionContainer,
|
9
|
-
variableDeclaration,
|
10
|
-
variableDeclarator
|
11
|
-
} = _t2;
|
12
|
-
const referenceVisitor = {
|
13
|
-
ReferencedIdentifier(path, state) {
|
14
|
-
if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
15
|
-
return;
|
16
|
-
}
|
17
|
-
if (path.node.name === "this") {
|
18
|
-
let scope = path.scope;
|
19
|
-
do {
|
20
|
-
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
21
|
-
break;
|
22
|
-
}
|
23
|
-
} while (scope = scope.parent);
|
24
|
-
if (scope) state.breakOnScopePaths.push(scope.path);
|
25
|
-
}
|
26
|
-
const binding = path.scope.getBinding(path.node.name);
|
27
|
-
if (!binding) return;
|
28
|
-
for (const violation of binding.constantViolations) {
|
29
|
-
if (violation.scope !== binding.path.scope) {
|
30
|
-
state.mutableBinding = true;
|
31
|
-
path.stop();
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
if (binding !== state.scope.getBinding(path.node.name)) return;
|
36
|
-
state.bindings[path.node.name] = binding;
|
37
|
-
}
|
38
|
-
};
|
39
|
-
export default class PathHoister {
|
40
|
-
breakOnScopePaths;
|
41
|
-
bindings;
|
42
|
-
mutableBinding;
|
43
|
-
scopes;
|
44
|
-
scope;
|
45
|
-
path;
|
46
|
-
attachAfter;
|
47
|
-
constructor(path, scope) {
|
48
|
-
this.breakOnScopePaths = [];
|
49
|
-
this.bindings = {};
|
50
|
-
this.mutableBinding = false;
|
51
|
-
this.scopes = [];
|
52
|
-
this.scope = scope;
|
53
|
-
this.path = path;
|
54
|
-
this.attachAfter = false;
|
55
|
-
}
|
56
|
-
isCompatibleScope(scope) {
|
57
|
-
for (const key of Object.keys(this.bindings)) {
|
58
|
-
const binding = this.bindings[key];
|
59
|
-
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
60
|
-
return false;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
return true;
|
64
|
-
}
|
65
|
-
getCompatibleScopes() {
|
66
|
-
let scope = this.path.scope;
|
67
|
-
do {
|
68
|
-
if (this.isCompatibleScope(scope)) {
|
69
|
-
this.scopes.push(scope);
|
70
|
-
} else {
|
71
|
-
break;
|
72
|
-
}
|
73
|
-
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
74
|
-
break;
|
75
|
-
}
|
76
|
-
} while (scope = scope.parent);
|
77
|
-
}
|
78
|
-
getAttachmentPath() {
|
79
|
-
let path = this._getAttachmentPath();
|
80
|
-
if (!path) return;
|
81
|
-
let targetScope = path.scope;
|
82
|
-
if (targetScope.path === path) {
|
83
|
-
targetScope = path.scope.parent;
|
84
|
-
}
|
85
|
-
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
86
|
-
for (const name of Object.keys(this.bindings)) {
|
87
|
-
if (!targetScope.hasOwnBinding(name)) continue;
|
88
|
-
const binding = this.bindings[name];
|
89
|
-
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
90
|
-
continue;
|
91
|
-
}
|
92
|
-
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
93
|
-
if (bindingParentPath.key >= path.key) {
|
94
|
-
this.attachAfter = true;
|
95
|
-
path = binding.path;
|
96
|
-
for (const violationPath of binding.constantViolations) {
|
97
|
-
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
98
|
-
path = violationPath;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
}
|
104
|
-
return path;
|
105
|
-
}
|
106
|
-
_getAttachmentPath() {
|
107
|
-
const scopes = this.scopes;
|
108
|
-
const scope = scopes.pop();
|
109
|
-
if (!scope) return;
|
110
|
-
if (scope.path.isFunction()) {
|
111
|
-
if (this.hasOwnParamBindings(scope)) {
|
112
|
-
if (this.scope === scope) return;
|
113
|
-
const bodies = scope.path.get("body").get("body");
|
114
|
-
for (let i = 0; i < bodies.length; i++) {
|
115
|
-
if (bodies[i].node._blockHoist) continue;
|
116
|
-
return bodies[i];
|
117
|
-
}
|
118
|
-
} else {
|
119
|
-
return this.getNextScopeAttachmentParent();
|
120
|
-
}
|
121
|
-
} else if (scope.path.isProgram()) {
|
122
|
-
return this.getNextScopeAttachmentParent();
|
123
|
-
}
|
124
|
-
}
|
125
|
-
getNextScopeAttachmentParent() {
|
126
|
-
const scope = this.scopes.pop();
|
127
|
-
if (scope) return this.getAttachmentParentForPath(scope.path);
|
128
|
-
}
|
129
|
-
getAttachmentParentForPath(path) {
|
130
|
-
do {
|
131
|
-
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
132
|
-
return path;
|
133
|
-
}
|
134
|
-
} while (path = path.parentPath);
|
135
|
-
}
|
136
|
-
hasOwnParamBindings(scope) {
|
137
|
-
for (const name of Object.keys(this.bindings)) {
|
138
|
-
if (!scope.hasOwnBinding(name)) continue;
|
139
|
-
const binding = this.bindings[name];
|
140
|
-
if (binding.kind === "param" && binding.constant) return true;
|
141
|
-
}
|
142
|
-
return false;
|
143
|
-
}
|
144
|
-
run() {
|
145
|
-
this.path.traverse(referenceVisitor, this);
|
146
|
-
if (this.mutableBinding) return;
|
147
|
-
this.getCompatibleScopes();
|
148
|
-
const attachTo = this.getAttachmentPath();
|
149
|
-
if (!attachTo) return;
|
150
|
-
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
151
|
-
let uid = attachTo.scope.generateUidIdentifier("ref");
|
152
|
-
const declarator = variableDeclarator(uid, this.path.node);
|
153
|
-
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
154
|
-
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
|
155
|
-
const parent = this.path.parentPath;
|
156
|
-
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
157
|
-
uid = jsxExpressionContainer(uid);
|
158
|
-
}
|
159
|
-
this.path.replaceWith(cloneNode(uid));
|
160
|
-
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
161
|
-
}
|
162
|
-
}
|
163
|
-
|
164
|
-
//# sourceMappingURL=hoister.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_t","react","_t2","cloneNode","jsxExpressionContainer","variableDeclaration","variableDeclarator","referenceVisitor","ReferencedIdentifier","path","state","isJSXIdentifier","isCompatTag","node","name","parentPath","isJSXMemberExpression","scope","isFunction","isArrowFunctionExpression","parent","breakOnScopePaths","push","binding","getBinding","violation","constantViolations","mutableBinding","stop","bindings","PathHoister","scopes","attachAfter","constructor","isCompatibleScope","key","Object","keys","bindingIdentifierEquals","identifier","getCompatibleScopes","indexOf","getAttachmentPath","_getAttachmentPath","targetScope","isProgram","hasOwnBinding","kind","parentKey","bindingParentPath","getAttachmentParentForPath","violationPath","pop","hasOwnParamBindings","bodies","get","i","length","_blockHoist","getNextScopeAttachmentParent","Array","isArray","container","isStatement","constant","run","traverse","attachTo","getFunctionParent","uid","generateUidIdentifier","declarator","insertFn","attached","isVariableDeclarator","isJSXElement","children","replaceWith"],"sources":["../../../src/path/lib/hoister.ts"],"sourcesContent":["import { react } from \"@babel/types\";\nimport {\n cloneNode,\n jsxExpressionContainer,\n variableDeclaration,\n variableDeclarator,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type Scope from \"../../scope\";\nimport type NodePath from \"../index\";\nimport type Binding from \"../../scope/binding\";\nimport type { Visitor } from \"../../types\";\n\nconst referenceVisitor: Visitor<PathHoister> = {\n // This visitor looks for bindings to establish a topmost scope for hoisting.\n ReferencedIdentifier(path, state) {\n // Don't hoist regular JSX identifiers ('div', 'span', etc).\n // We do have to consider member expressions for hoisting (e.g. `this.component`)\n if (\n path.isJSXIdentifier() &&\n react.isCompatTag(path.node.name) &&\n !path.parentPath.isJSXMemberExpression()\n ) {\n return;\n }\n\n // If the identifier refers to `this`, we need to break on the closest non-arrow scope.\n if (path.node.name === \"this\") {\n let scope = path.scope;\n do {\n if (\n scope.path.isFunction() &&\n !scope.path.isArrowFunctionExpression()\n ) {\n break;\n }\n } while ((scope = scope.parent));\n if (scope) state.breakOnScopePaths.push(scope.path);\n }\n\n // direct references that we need to track to hoist this to the highest scope we can\n const binding = path.scope.getBinding(path.node.name);\n if (!binding) return;\n\n // we can handle reassignments only if they happen in the same scope as the declaration\n for (const violation of binding.constantViolations) {\n if (violation.scope !== binding.path.scope) {\n state.mutableBinding = true;\n path.stop();\n return;\n }\n }\n\n // this binding isn't accessible from the parent scope so we can safely ignore it\n // eg. it's in a closure etc\n if (binding !== state.scope.getBinding(path.node.name)) return;\n\n state.bindings[path.node.name] = binding;\n },\n};\n\nexport default class PathHoister<T extends t.Node = t.Node> {\n breakOnScopePaths: NodePath[];\n bindings: { [k: string]: Binding };\n mutableBinding: boolean;\n private scopes: Scope[];\n scope: Scope;\n private path: NodePath<T>;\n private attachAfter: boolean;\n\n constructor(path: NodePath<T>, scope: Scope) {\n // Storage for scopes we can't hoist above.\n this.breakOnScopePaths = [];\n // Storage for bindings that may affect what path we can hoist to.\n this.bindings = {};\n // \"true\" if the current path contains a reference to a binding whose\n // value can change and thus can't be safely hoisted.\n this.mutableBinding = false;\n // Storage for eligible scopes.\n this.scopes = [];\n // Our original scope and path.\n this.scope = scope;\n this.path = path;\n // By default, we attach as far up as we can; but if we're trying\n // to avoid referencing a binding, we may have to go after.\n this.attachAfter = false;\n }\n\n // A scope is compatible if all required bindings are reachable.\n isCompatibleScope(scope: Scope) {\n for (const key of Object.keys(this.bindings)) {\n const binding = this.bindings[key];\n if (!scope.bindingIdentifierEquals(key, binding.identifier)) {\n return false;\n }\n }\n\n return true;\n }\n\n // Look through all scopes and push compatible ones.\n getCompatibleScopes() {\n let scope = this.path.scope;\n do {\n if (this.isCompatibleScope(scope)) {\n this.scopes.push(scope);\n } else {\n break;\n }\n\n // deopt: These scopes are set in the visitor on const violations\n if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {\n break;\n }\n } while ((scope = scope.parent));\n }\n\n getAttachmentPath() {\n let path = this._getAttachmentPath();\n if (!path) return;\n\n let targetScope = path.scope;\n\n // don't allow paths that have their own lexical environments to pollute\n if (targetScope.path === path) {\n targetScope = path.scope.parent;\n }\n\n // avoid hoisting to a scope that contains bindings that are executed after our attachment path\n if (targetScope.path.isProgram() || targetScope.path.isFunction()) {\n for (const name of Object.keys(this.bindings)) {\n // check binding is a direct child of this paths scope\n if (!targetScope.hasOwnBinding(name)) continue;\n\n const binding = this.bindings[name];\n\n // allow parameter references and expressions in params (like destructuring rest)\n if (binding.kind === \"param\" || binding.path.parentKey === \"params\") {\n continue;\n }\n\n // For each binding, get its attachment parent. This gives us an idea of where we might\n // introduce conflicts.\n const bindingParentPath = this.getAttachmentParentForPath(binding.path);\n\n // If the binding's attachment appears at or after our attachment point, then we move after it.\n if (bindingParentPath.key >= path.key) {\n this.attachAfter = true;\n path = binding.path;\n\n // We also move past any constant violations.\n for (const violationPath of binding.constantViolations) {\n if (this.getAttachmentParentForPath(violationPath).key > path.key) {\n path = violationPath;\n }\n }\n }\n }\n }\n\n return path;\n }\n\n _getAttachmentPath() {\n const scopes = this.scopes;\n\n const scope = scopes.pop();\n // deopt: no compatible scopes\n if (!scope) return;\n\n if (scope.path.isFunction()) {\n if (this.hasOwnParamBindings(scope)) {\n // deopt: should ignore this scope since it's ourselves\n if (this.scope === scope) return;\n\n // needs to be attached to the body\n const bodies = scope.path.get(\"body\").get(\"body\") as NodePath[];\n for (let i = 0; i < bodies.length; i++) {\n // Don't attach to something that's going to get hoisted,\n // like a default parameter\n // @ts-expect-error todo(flow->ts): avoid mutating the node, introducing new fields\n if (bodies[i].node._blockHoist) continue;\n return bodies[i];\n }\n // deopt: If here, no attachment path found\n } else {\n // doesn't need to be be attached to this scope\n return this.getNextScopeAttachmentParent();\n }\n } else if (scope.path.isProgram()) {\n return this.getNextScopeAttachmentParent();\n }\n }\n\n getNextScopeAttachmentParent() {\n const scope = this.scopes.pop();\n if (scope) return this.getAttachmentParentForPath(scope.path);\n }\n\n // Find an attachment for this path.\n getAttachmentParentForPath(path: NodePath) {\n do {\n if (\n // Beginning of the scope\n !path.parentPath ||\n // Has siblings and is a statement\n (Array.isArray(path.container) && path.isStatement())\n ) {\n return path;\n }\n } while ((path = path.parentPath));\n }\n\n // Returns true if a scope has param bindings.\n hasOwnParamBindings(scope: Scope) {\n for (const name of Object.keys(this.bindings)) {\n if (!scope.hasOwnBinding(name)) continue;\n\n const binding = this.bindings[name];\n // Ensure constant; without it we could place behind a reassignment\n if (binding.kind === \"param\" && binding.constant) return true;\n }\n return false;\n }\n\n run(): NodePath<t.Expression> | undefined {\n this.path.traverse(referenceVisitor, this);\n\n if (this.mutableBinding) return;\n\n this.getCompatibleScopes();\n\n const attachTo = this.getAttachmentPath();\n if (!attachTo) return;\n\n // don't bother hoisting to the same function as this will cause multiple branches to be\n // evaluated more than once leading to a bad optimisation\n if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;\n\n // generate declaration and insert it to our point\n let uid: t.Identifier | t.JSXExpressionContainer =\n attachTo.scope.generateUidIdentifier(\"ref\");\n\n // @ts-expect-error todo(flow->ts): more specific type for this.path\n const declarator = variableDeclarator(uid, this.path.node);\n\n const insertFn = this.attachAfter ? \"insertAfter\" : \"insertBefore\";\n const [attached] = attachTo[insertFn]([\n attachTo.isVariableDeclarator()\n ? declarator\n : variableDeclaration(\"var\", [declarator]),\n ]);\n\n const parent = this.path.parentPath;\n if (parent.isJSXElement() && this.path.container === parent.node.children) {\n // turning the `span` in `<div><span /></div>` to an expression so we need to wrap it with\n // an expression container\n uid = jsxExpressionContainer(uid);\n }\n\n this.path.replaceWith(cloneNode(uid));\n\n return attachTo.isVariableDeclarator()\n ? attached.get(\"init\")\n : attached.get(\"declarations.0.init\");\n }\n}\n"],"mappings":"AAAA,YAAAA,EAAA,MAAsB,cAAc;AAAC;EAA5BC;AAAK,IAAAD,EAAA;AACd,YAAAE,GAAA,MAKO,cAAc;AAAC;EAJpBC,SAAS;EACTC,sBAAsB;EACtBC,mBAAmB;EACnBC;AAAkB,IAAAJ,GAAA;AAQpB,MAAMK,gBAAsC,GAAG;EAE7CC,oBAAoBA,CAACC,IAAI,EAAEC,KAAK,EAAE;IAGhC,IACED,IAAI,CAACE,eAAe,CAAC,CAAC,IACtBV,KAAK,CAACW,WAAW,CAACH,IAAI,CAACI,IAAI,CAACC,IAAI,CAAC,IACjC,CAACL,IAAI,CAACM,UAAU,CAACC,qBAAqB,CAAC,CAAC,EACxC;MACA;IACF;IAGA,IAAIP,IAAI,CAACI,IAAI,CAACC,IAAI,KAAK,MAAM,EAAE;MAC7B,IAAIG,KAAK,GAAGR,IAAI,CAACQ,KAAK;MACtB,GAAG;QACD,IACEA,KAAK,CAACR,IAAI,CAACS,UAAU,CAAC,CAAC,IACvB,CAACD,KAAK,CAACR,IAAI,CAACU,yBAAyB,CAAC,CAAC,EACvC;UACA;QACF;MACF,CAAC,QAASF,KAAK,GAAGA,KAAK,CAACG,MAAM;MAC9B,IAAIH,KAAK,EAAEP,KAAK,CAACW,iBAAiB,CAACC,IAAI,CAACL,KAAK,CAACR,IAAI,CAAC;IACrD;IAGA,MAAMc,OAAO,GAAGd,IAAI,CAACQ,KAAK,CAACO,UAAU,CAACf,IAAI,CAACI,IAAI,CAACC,IAAI,CAAC;IACrD,IAAI,CAACS,OAAO,EAAE;IAGd,KAAK,MAAME,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