@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
package/lib/path/family.js
DELETED
@@ -1,322 +0,0 @@
|
|
1
|
-
import NodePath from "./index.js";
|
2
|
-
import * as _t from "@babel/types";
|
3
|
-
const {
|
4
|
-
getBindingIdentifiers: _getBindingIdentifiers,
|
5
|
-
getOuterBindingIdentifiers: _getOuterBindingIdentifiers,
|
6
|
-
isDeclaration,
|
7
|
-
numericLiteral,
|
8
|
-
unaryExpression
|
9
|
-
} = _t;
|
10
|
-
const NORMAL_COMPLETION = 0;
|
11
|
-
const BREAK_COMPLETION = 1;
|
12
|
-
function NormalCompletion(path) {
|
13
|
-
return {
|
14
|
-
type: NORMAL_COMPLETION,
|
15
|
-
path
|
16
|
-
};
|
17
|
-
}
|
18
|
-
function BreakCompletion(path) {
|
19
|
-
return {
|
20
|
-
type: BREAK_COMPLETION,
|
21
|
-
path
|
22
|
-
};
|
23
|
-
}
|
24
|
-
export function getOpposite() {
|
25
|
-
if (this.key === "left") {
|
26
|
-
return this.getSibling("right");
|
27
|
-
} else if (this.key === "right") {
|
28
|
-
return this.getSibling("left");
|
29
|
-
}
|
30
|
-
return null;
|
31
|
-
}
|
32
|
-
function addCompletionRecords(path, records, context) {
|
33
|
-
if (path) {
|
34
|
-
records.push(..._getCompletionRecords(path, context));
|
35
|
-
}
|
36
|
-
return records;
|
37
|
-
}
|
38
|
-
function completionRecordForSwitch(cases, records, context) {
|
39
|
-
let lastNormalCompletions = [];
|
40
|
-
for (let i = 0; i < cases.length; i++) {
|
41
|
-
const casePath = cases[i];
|
42
|
-
const caseCompletions = _getCompletionRecords(casePath, context);
|
43
|
-
const normalCompletions = [];
|
44
|
-
const breakCompletions = [];
|
45
|
-
for (const c of caseCompletions) {
|
46
|
-
if (c.type === NORMAL_COMPLETION) {
|
47
|
-
normalCompletions.push(c);
|
48
|
-
}
|
49
|
-
if (c.type === BREAK_COMPLETION) {
|
50
|
-
breakCompletions.push(c);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
if (normalCompletions.length) {
|
54
|
-
lastNormalCompletions = normalCompletions;
|
55
|
-
}
|
56
|
-
records.push(...breakCompletions);
|
57
|
-
}
|
58
|
-
records.push(...lastNormalCompletions);
|
59
|
-
return records;
|
60
|
-
}
|
61
|
-
function normalCompletionToBreak(completions) {
|
62
|
-
completions.forEach(c => {
|
63
|
-
c.type = BREAK_COMPLETION;
|
64
|
-
});
|
65
|
-
}
|
66
|
-
function replaceBreakStatementInBreakCompletion(completions, reachable) {
|
67
|
-
completions.forEach(c => {
|
68
|
-
if (c.path.isBreakStatement({
|
69
|
-
label: null
|
70
|
-
})) {
|
71
|
-
if (reachable) {
|
72
|
-
c.path.replaceWith(unaryExpression("void", numericLiteral(0)));
|
73
|
-
} else {
|
74
|
-
c.path.remove();
|
75
|
-
}
|
76
|
-
}
|
77
|
-
});
|
78
|
-
}
|
79
|
-
function getStatementListCompletion(paths, context) {
|
80
|
-
const completions = [];
|
81
|
-
if (context.canHaveBreak) {
|
82
|
-
let lastNormalCompletions = [];
|
83
|
-
for (let i = 0; i < paths.length; i++) {
|
84
|
-
const path = paths[i];
|
85
|
-
const newContext = Object.assign({}, context, {
|
86
|
-
inCaseClause: false
|
87
|
-
});
|
88
|
-
if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
|
89
|
-
newContext.shouldPopulateBreak = true;
|
90
|
-
} else {
|
91
|
-
newContext.shouldPopulateBreak = false;
|
92
|
-
}
|
93
|
-
const statementCompletions = _getCompletionRecords(path, newContext);
|
94
|
-
if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
|
95
|
-
if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({
|
96
|
-
label: null
|
97
|
-
}))) {
|
98
|
-
normalCompletionToBreak(lastNormalCompletions);
|
99
|
-
completions.push(...lastNormalCompletions);
|
100
|
-
if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
|
101
|
-
completions.push(...statementCompletions);
|
102
|
-
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
103
|
-
}
|
104
|
-
replaceBreakStatementInBreakCompletion(statementCompletions, false);
|
105
|
-
} else {
|
106
|
-
completions.push(...statementCompletions);
|
107
|
-
if (!context.shouldPopulateBreak) {
|
108
|
-
replaceBreakStatementInBreakCompletion(statementCompletions, true);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
break;
|
112
|
-
}
|
113
|
-
if (i === paths.length - 1) {
|
114
|
-
completions.push(...statementCompletions);
|
115
|
-
} else {
|
116
|
-
lastNormalCompletions = [];
|
117
|
-
for (let i = 0; i < statementCompletions.length; i++) {
|
118
|
-
const c = statementCompletions[i];
|
119
|
-
if (c.type === BREAK_COMPLETION) {
|
120
|
-
completions.push(c);
|
121
|
-
}
|
122
|
-
if (c.type === NORMAL_COMPLETION) {
|
123
|
-
lastNormalCompletions.push(c);
|
124
|
-
}
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
} else if (paths.length) {
|
129
|
-
for (let i = paths.length - 1; i >= 0; i--) {
|
130
|
-
const pathCompletions = _getCompletionRecords(paths[i], context);
|
131
|
-
if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) {
|
132
|
-
completions.push(...pathCompletions);
|
133
|
-
break;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
return completions;
|
138
|
-
}
|
139
|
-
function _getCompletionRecords(path, context) {
|
140
|
-
let records = [];
|
141
|
-
if (path.isIfStatement()) {
|
142
|
-
records = addCompletionRecords(path.get("consequent"), records, context);
|
143
|
-
records = addCompletionRecords(path.get("alternate"), records, context);
|
144
|
-
} else if (path.isDoExpression() || path.isFor() || path.isWhile() || path.isLabeledStatement()) {
|
145
|
-
return addCompletionRecords(path.get("body"), records, context);
|
146
|
-
} else if (path.isProgram() || path.isBlockStatement()) {
|
147
|
-
return getStatementListCompletion(path.get("body"), context);
|
148
|
-
} else if (path.isFunction()) {
|
149
|
-
return _getCompletionRecords(path.get("body"), context);
|
150
|
-
} else if (path.isTryStatement()) {
|
151
|
-
records = addCompletionRecords(path.get("block"), records, context);
|
152
|
-
records = addCompletionRecords(path.get("handler"), records, context);
|
153
|
-
} else if (path.isCatchClause()) {
|
154
|
-
return addCompletionRecords(path.get("body"), records, context);
|
155
|
-
} else if (path.isSwitchStatement()) {
|
156
|
-
return completionRecordForSwitch(path.get("cases"), records, context);
|
157
|
-
} else if (path.isSwitchCase()) {
|
158
|
-
return getStatementListCompletion(path.get("consequent"), {
|
159
|
-
canHaveBreak: true,
|
160
|
-
shouldPopulateBreak: false,
|
161
|
-
inCaseClause: true
|
162
|
-
});
|
163
|
-
} else if (path.isBreakStatement()) {
|
164
|
-
records.push(BreakCompletion(path));
|
165
|
-
} else {
|
166
|
-
records.push(NormalCompletion(path));
|
167
|
-
}
|
168
|
-
return records;
|
169
|
-
}
|
170
|
-
export function getCompletionRecords() {
|
171
|
-
const records = _getCompletionRecords(this, {
|
172
|
-
canHaveBreak: false,
|
173
|
-
shouldPopulateBreak: false,
|
174
|
-
inCaseClause: false
|
175
|
-
});
|
176
|
-
return records.map(r => r.path);
|
177
|
-
}
|
178
|
-
export function getSibling(key) {
|
179
|
-
return NodePath.get({
|
180
|
-
parentPath: this.parentPath,
|
181
|
-
parent: this.parent,
|
182
|
-
container: this.container,
|
183
|
-
listKey: this.listKey,
|
184
|
-
key: key
|
185
|
-
}).setContext(this.context);
|
186
|
-
}
|
187
|
-
export function getPrevSibling() {
|
188
|
-
return this.getSibling(this.key - 1);
|
189
|
-
}
|
190
|
-
export function getNextSibling() {
|
191
|
-
return this.getSibling(this.key + 1);
|
192
|
-
}
|
193
|
-
export function getAllNextSiblings() {
|
194
|
-
let _key = this.key;
|
195
|
-
let sibling = this.getSibling(++_key);
|
196
|
-
const siblings = [];
|
197
|
-
while (sibling.node) {
|
198
|
-
siblings.push(sibling);
|
199
|
-
sibling = this.getSibling(++_key);
|
200
|
-
}
|
201
|
-
return siblings;
|
202
|
-
}
|
203
|
-
export function getAllPrevSiblings() {
|
204
|
-
let _key = this.key;
|
205
|
-
let sibling = this.getSibling(--_key);
|
206
|
-
const siblings = [];
|
207
|
-
while (sibling.node) {
|
208
|
-
siblings.push(sibling);
|
209
|
-
sibling = this.getSibling(--_key);
|
210
|
-
}
|
211
|
-
return siblings;
|
212
|
-
}
|
213
|
-
function get(key, context = true) {
|
214
|
-
if (context === true) context = this.context;
|
215
|
-
const parts = key.split(".");
|
216
|
-
if (parts.length === 1) {
|
217
|
-
return this._getKey(key, context);
|
218
|
-
} else {
|
219
|
-
return this._getPattern(parts, context);
|
220
|
-
}
|
221
|
-
}
|
222
|
-
export { get };
|
223
|
-
export function _getKey(key, context) {
|
224
|
-
const node = this.node;
|
225
|
-
const container = node[key];
|
226
|
-
if (Array.isArray(container)) {
|
227
|
-
return container.map((_, i) => {
|
228
|
-
return NodePath.get({
|
229
|
-
listKey: key,
|
230
|
-
parentPath: this,
|
231
|
-
parent: node,
|
232
|
-
container: container,
|
233
|
-
key: i
|
234
|
-
}).setContext(context);
|
235
|
-
});
|
236
|
-
} else {
|
237
|
-
return NodePath.get({
|
238
|
-
parentPath: this,
|
239
|
-
parent: node,
|
240
|
-
container: node,
|
241
|
-
key: key
|
242
|
-
}).setContext(context);
|
243
|
-
}
|
244
|
-
}
|
245
|
-
export function _getPattern(parts, context) {
|
246
|
-
let path = this;
|
247
|
-
for (const part of parts) {
|
248
|
-
if (part === ".") {
|
249
|
-
path = path.parentPath;
|
250
|
-
} else {
|
251
|
-
if (Array.isArray(path)) {
|
252
|
-
path = path[part];
|
253
|
-
} else {
|
254
|
-
path = path.get(part, context);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
}
|
258
|
-
return path;
|
259
|
-
}
|
260
|
-
function getBindingIdentifiers(duplicates) {
|
261
|
-
return _getBindingIdentifiers(this.node, duplicates);
|
262
|
-
}
|
263
|
-
export { getBindingIdentifiers };
|
264
|
-
function getOuterBindingIdentifiers(duplicates) {
|
265
|
-
return _getOuterBindingIdentifiers(this.node, duplicates);
|
266
|
-
}
|
267
|
-
export { getOuterBindingIdentifiers };
|
268
|
-
function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
|
269
|
-
const path = this;
|
270
|
-
const search = [path];
|
271
|
-
const ids = Object.create(null);
|
272
|
-
while (search.length) {
|
273
|
-
const id = search.shift();
|
274
|
-
if (!id) continue;
|
275
|
-
if (!id.node) continue;
|
276
|
-
const keys = _getBindingIdentifiers.keys[id.node.type];
|
277
|
-
if (id.isIdentifier()) {
|
278
|
-
if (duplicates) {
|
279
|
-
const _ids = ids[id.node.name] = ids[id.node.name] || [];
|
280
|
-
_ids.push(id);
|
281
|
-
} else {
|
282
|
-
ids[id.node.name] = id;
|
283
|
-
}
|
284
|
-
continue;
|
285
|
-
}
|
286
|
-
if (id.isExportDeclaration()) {
|
287
|
-
const declaration = id.get("declaration");
|
288
|
-
if (isDeclaration(declaration)) {
|
289
|
-
search.push(declaration);
|
290
|
-
}
|
291
|
-
continue;
|
292
|
-
}
|
293
|
-
if (outerOnly) {
|
294
|
-
if (id.isFunctionDeclaration()) {
|
295
|
-
search.push(id.get("id"));
|
296
|
-
continue;
|
297
|
-
}
|
298
|
-
if (id.isFunctionExpression()) {
|
299
|
-
continue;
|
300
|
-
}
|
301
|
-
}
|
302
|
-
if (keys) {
|
303
|
-
for (let i = 0; i < keys.length; i++) {
|
304
|
-
const key = keys[i];
|
305
|
-
const child = id.get(key);
|
306
|
-
if (Array.isArray(child)) {
|
307
|
-
search.push(...child);
|
308
|
-
} else if (child.node) {
|
309
|
-
search.push(child);
|
310
|
-
}
|
311
|
-
}
|
312
|
-
}
|
313
|
-
}
|
314
|
-
return ids;
|
315
|
-
}
|
316
|
-
export { getBindingIdentifierPaths };
|
317
|
-
function getOuterBindingIdentifierPaths(duplicates = false) {
|
318
|
-
return this.getBindingIdentifierPaths(duplicates, true);
|
319
|
-
}
|
320
|
-
export { getOuterBindingIdentifierPaths };
|
321
|
-
|
322
|
-
//# sourceMappingURL=family.js.map
|
package/lib/path/family.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["NodePath","_t","getBindingIdentifiers","_getBindingIdentifiers","getOuterBindingIdentifiers","_getOuterBindingIdentifiers","isDeclaration","numericLiteral","unaryExpression","NORMAL_COMPLETION","BREAK_COMPLETION","NormalCompletion","path","type","BreakCompletion","getOpposite","key","getSibling","addCompletionRecords","records","context","push","_getCompletionRecords","completionRecordForSwitch","cases","lastNormalCompletions","i","length","casePath","caseCompletions","normalCompletions","breakCompletions","c","normalCompletionToBreak","completions","forEach","replaceBreakStatementInBreakCompletion","reachable","isBreakStatement","label","replaceWith","remove","getStatementListCompletion","paths","canHaveBreak","newContext","Object","assign","inCaseClause","isBlockStatement","shouldPopulateBreak","statementCompletions","every","some","pathCompletions","isVariableDeclaration","isIfStatement","get","isDoExpression","isFor","isWhile","isLabeledStatement","isProgram","isFunction","isTryStatement","isCatchClause","isSwitchStatement","isSwitchCase","getCompletionRecords","map","r","parentPath","parent","container","listKey","setContext","getPrevSibling","getNextSibling","getAllNextSiblings","_key","sibling","siblings","node","getAllPrevSiblings","parts","split","_getKey","_getPattern","Array","isArray","_","part","duplicates","getBindingIdentifierPaths","outerOnly","search","ids","create","id","shift","keys","isIdentifier","_ids","name","isExportDeclaration","declaration","isFunctionDeclaration","isFunctionExpression","child","getOuterBindingIdentifierPaths"],"sources":["../../src/path/family.ts"],"sourcesContent":["// This file contains methods responsible for dealing with/retrieving children or siblings.\n\nimport type TraversalContext from \"../context\";\nimport NodePath from \"./index\";\nimport {\n getBindingIdentifiers as _getBindingIdentifiers,\n getOuterBindingIdentifiers as _getOuterBindingIdentifiers,\n isDeclaration,\n numericLiteral,\n unaryExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nconst NORMAL_COMPLETION = 0 as const;\nconst BREAK_COMPLETION = 1 as const;\n\ntype Completion = {\n path: NodePath;\n type: 0 | 1;\n};\n\ntype CompletionContext = {\n // whether the current context allows `break` statement. When it allows, we have\n // to search all the statements for potential `break`\n canHaveBreak: boolean;\n // whether the statement is an immediate descendant of a switch case clause\n inCaseClause: boolean;\n // whether the `break` statement record should be populated to upper level\n // when a `break` statement is an immediate descendant of a block statement, e.g.\n // `{ break }`, it can influence the control flow in the upper levels.\n shouldPopulateBreak: boolean;\n};\n\nfunction NormalCompletion(path: NodePath) {\n return { type: NORMAL_COMPLETION, path };\n}\n\nfunction BreakCompletion(path: NodePath) {\n return { type: BREAK_COMPLETION, path };\n}\n\nexport function getOpposite(this: NodePath): NodePath | null {\n if (this.key === \"left\") {\n return this.getSibling(\"right\");\n } else if (this.key === \"right\") {\n return this.getSibling(\"left\");\n }\n return null;\n}\n\nfunction addCompletionRecords(\n path: NodePath | null | undefined,\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n if (path) {\n records.push(..._getCompletionRecords(path, context));\n }\n return records;\n}\n\nfunction completionRecordForSwitch(\n cases: NodePath<t.SwitchCase>[],\n records: Completion[],\n context: CompletionContext,\n): Completion[] {\n // https://tc39.es/ecma262/#sec-runtime-semantics-caseblockevaluation\n let lastNormalCompletions: Completion[] = [];\n for (let i = 0; i < cases.length; i++) {\n const casePath = cases[i];\n const caseCompletions = _getCompletionRecords(casePath, context);\n const normalCompletions = [];\n const breakCompletions = [];\n for (const c of caseCompletions) {\n if (c.type === NORMAL_COMPLETION) {\n normalCompletions.push(c);\n }\n if (c.type === BREAK_COMPLETION) {\n breakCompletions.push(c);\n }\n }\n if (normalCompletions.length) {\n lastNormalCompletions = normalCompletions;\n }\n records.push(...breakCompletions);\n }\n records.push(...lastNormalCompletions);\n return records;\n}\n\nfunction normalCompletionToBreak(completions: Completion[]) {\n completions.forEach(c => {\n c.type = BREAK_COMPLETION;\n });\n}\n\n/**\n * Determine how we should handle the break statement for break completions\n *\n * @param {Completion[]} completions\n * @param {boolean} reachable Whether the break statement is reachable after\n we mark the normal completions _before_ the given break completions as the final\n completions. For example,\n `{ 0 }; break;` is transformed to `{ return 0 }; break;`, the `break` here is unreachable\n and thus can be removed without consequences. We may in the future reserve them instead since\n we do not consistently remove unreachable statements _after_ break\n `{ var x = 0 }; break;` is transformed to `{ var x = 0 }; return void 0;`, the `break` is reachable\n because we can not wrap variable declaration under a return statement\n */\nfunction replaceBreakStatementInBreakCompletion(\n completions: Completion[],\n reachable: boolean,\n) {\n completions.forEach(c => {\n if (c.path.isBreakStatement({ label: null })) {\n if (reachable) {\n c.path.replaceWith(unaryExpression(\"void\", numericLiteral(0)));\n } else {\n c.path.remove();\n }\n }\n });\n}\n\nfunction getStatementListCompletion(\n paths: NodePath[],\n context: CompletionContext,\n): Completion[] {\n const completions = [];\n if (context.canHaveBreak) {\n let lastNormalCompletions = [];\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n const newContext = { ...context, inCaseClause: false };\n if (\n path.isBlockStatement() &&\n (context.inCaseClause || // case test: { break }\n context.shouldPopulateBreak) // case test: { { break } }\n ) {\n newContext.shouldPopulateBreak = true;\n } else {\n newContext.shouldPopulateBreak = false;\n }\n const statementCompletions = _getCompletionRecords(path, newContext);\n if (\n statementCompletions.length > 0 &&\n // we can stop search `paths` when we have seen a `path` that is\n // effectively a `break` statement. Examples are\n // - `break`\n // - `if (true) { 1; break } else { 2; break }`\n // - `{ break }```\n // In other words, the paths after this `path` are unreachable\n statementCompletions.every(c => c.type === BREAK_COMPLETION)\n ) {\n if (\n lastNormalCompletions.length > 0 &&\n statementCompletions.every(c =>\n c.path.isBreakStatement({ label: null }),\n )\n ) {\n // when a break completion has a path as BreakStatement, it must be `{ break }`\n // whose completion value we can not determine, otherwise it would have been\n // replaced by `replaceBreakStatementInBreakCompletion`\n // When we have seen normal completions from the last statement\n // it is safe to stop populating break and mark normal completions as break\n normalCompletionToBreak(lastNormalCompletions);\n completions.push(...lastNormalCompletions);\n // Declarations have empty completion record, however they can not be nested\n // directly in return statement, i.e. `return (var a = 1)` is invalid.\n if (lastNormalCompletions.some(c => c.path.isDeclaration())) {\n completions.push(...statementCompletions);\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ false,\n );\n } else {\n completions.push(...statementCompletions);\n if (!context.shouldPopulateBreak) {\n replaceBreakStatementInBreakCompletion(\n statementCompletions,\n /* reachable */ true,\n );\n }\n }\n break;\n }\n if (i === paths.length - 1) {\n completions.push(...statementCompletions);\n } else {\n lastNormalCompletions = [];\n for (let i = 0; i < statementCompletions.length; i++) {\n const c = statementCompletions[i];\n if (c.type === BREAK_COMPLETION) {\n completions.push(c);\n }\n if (c.type === NORMAL_COMPLETION) {\n lastNormalCompletions.push(c);\n }\n }\n }\n }\n } else if (paths.length) {\n // When we are in a context where `break` must not exist, we can skip linear\n // search on statement lists and assume that the last\n // non-variable-declaration statement determines the completion.\n for (let i = paths.length - 1; i >= 0; i--) {\n const pathCompletions = _getCompletionRecords(paths[i], context);\n if (\n pathCompletions.length > 1 ||\n (pathCompletions.length === 1 &&\n !pathCompletions[0].path.isVariableDeclaration())\n ) {\n completions.push(...pathCompletions);\n break;\n }\n }\n }\n return completions;\n}\n\nfunction _getCompletionRecords(\n path: NodePath,\n context: CompletionContext,\n): Completion[] {\n let records: Completion[] = [];\n if (path.isIfStatement()) {\n records = addCompletionRecords(path.get(\"consequent\"), records, context);\n records = addCompletionRecords(path.get(\"alternate\"), records, context);\n } else if (\n path.isDoExpression() ||\n path.isFor() ||\n path.isWhile() ||\n path.isLabeledStatement()\n ) {\n // @ts-expect-error(flow->ts): todo\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isProgram() || path.isBlockStatement()) {\n // @ts-expect-error(flow->ts): todo\n return getStatementListCompletion(path.get(\"body\"), context);\n } else if (path.isFunction()) {\n return _getCompletionRecords(path.get(\"body\"), context);\n } else if (path.isTryStatement()) {\n records = addCompletionRecords(path.get(\"block\"), records, context);\n records = addCompletionRecords(path.get(\"handler\"), records, context);\n } else if (path.isCatchClause()) {\n return addCompletionRecords(path.get(\"body\"), records, context);\n } else if (path.isSwitchStatement()) {\n return completionRecordForSwitch(path.get(\"cases\"), records, context);\n } else if (path.isSwitchCase()) {\n return getStatementListCompletion(path.get(\"consequent\"), {\n canHaveBreak: true,\n shouldPopulateBreak: false,\n inCaseClause: true,\n });\n } else if (path.isBreakStatement()) {\n records.push(BreakCompletion(path));\n } else {\n records.push(NormalCompletion(path));\n }\n\n return records;\n}\n\n/**\n * Retrieve the completion records of a given path.\n * Note: to ensure proper support on `break` statement, this method\n * will manipulate the AST around the break statement. Do not call the method\n * twice for the same path.\n *\n * @export\n * @param {NodePath} this\n * @returns {NodePath[]} Completion records\n */\nexport function getCompletionRecords(this: NodePath): NodePath[] {\n const records = _getCompletionRecords(this, {\n canHaveBreak: false,\n shouldPopulateBreak: false,\n inCaseClause: false,\n });\n return records.map(r => r.path);\n}\n\nexport function getSibling(this: NodePath, key: string | number): NodePath {\n return NodePath.get({\n parentPath: this.parentPath,\n parent: this.parent,\n container: this.container,\n listKey: this.listKey,\n key: key,\n }).setContext(this.context);\n}\n\nexport function getPrevSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key - 1);\n}\n\nexport function getNextSibling(this: NodePath): NodePath {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n return this.getSibling(this.key + 1);\n}\n\nexport function getAllNextSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(++_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(++_key);\n }\n return siblings;\n}\n\nexport function getAllPrevSiblings(this: NodePath): NodePath[] {\n // @ts-expect-error todo(flow->ts) this.key could be a string\n let _key: number = this.key;\n let sibling = this.getSibling(--_key);\n const siblings = [];\n while (sibling.node) {\n siblings.push(sibling);\n sibling = this.getSibling(--_key);\n }\n return siblings;\n}\n\n// convert \"1\" to 1 (string index to number index)\ntype MaybeToIndex<T extends string> = T extends `${bigint}` ? number : T;\n\ntype Pattern<Obj extends string, Prop extends string> = `${Obj}.${Prop}`;\n\n// split \"body.body.1\" to [\"body\", \"body\", 1]\ntype Split<P extends string> = P extends Pattern<infer O, infer U>\n ? [MaybeToIndex<O>, ...Split<U>]\n : [MaybeToIndex<P>];\n\n// get all K with Node[K] is t.Node | t.Node[]\ntype NodeKeyOf<Node extends t.Node | t.Node[]> = keyof Pick<\n Node,\n {\n [Key in keyof Node]-?: Node[Key] extends t.Node | t.Node[] ? Key : never;\n }[keyof Node]\n>;\n\n// traverse the Node with tuple path [\"body\", \"body\", 1]\n// Path should be created with Split\ntype Trav<\n Node extends t.Node | t.Node[],\n Path extends unknown[],\n> = Path extends [infer K, ...infer R]\n ? K extends NodeKeyOf<Node>\n ? R extends []\n ? Node[K]\n : // @ts-expect-error ignore since TS is not smart enough\n Trav<Node[K], R>\n : never\n : never;\n\ntype ToNodePath<T> = T extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[number]>>\n : T extends t.Node | null | undefined\n ? NodePath<T>\n : never;\n\nfunction get<T extends t.Node, K extends keyof T>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): T[K] extends Array<t.Node | null | undefined>\n ? Array<NodePath<T[K][number]>>\n : T[K] extends t.Node | null | undefined\n ? NodePath<T[K]>\n : never;\n\nfunction get<T extends t.Node, K extends string>(\n this: NodePath<T>,\n key: K,\n context?: boolean | TraversalContext,\n): ToNodePath<Trav<T, Split<K>>>;\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context?: true | TraversalContext,\n): NodePath | NodePath[];\n\nfunction get<T extends t.Node>(\n this: NodePath<T>,\n key: string,\n context: true | TraversalContext = true,\n): NodePath | NodePath[] {\n if (context === true) context = this.context;\n const parts = key.split(\".\");\n if (parts.length === 1) {\n // \"foo\"\n // @ts-expect-error key may not index T\n return this._getKey(key, context);\n } else {\n // \"foo.bar\"\n return this._getPattern(parts, context);\n }\n}\n\nexport { get };\n\nexport function _getKey<T extends t.Node>(\n this: NodePath<T>,\n key: keyof T & string,\n context?: TraversalContext,\n): NodePath | NodePath[] {\n const node = this.node;\n const container = node[key];\n\n if (Array.isArray(container)) {\n // requested a container so give them all the paths\n return container.map((_, i) => {\n return NodePath.get({\n listKey: key,\n parentPath: this,\n parent: node,\n container: container,\n key: i,\n }).setContext(context);\n });\n } else {\n return NodePath.get({\n parentPath: this,\n parent: node,\n container: node,\n key: key,\n }).setContext(context);\n }\n}\n\nexport function _getPattern(\n this: NodePath,\n parts: string[],\n context?: TraversalContext,\n): NodePath | NodePath[] {\n let path: NodePath | NodePath[] = this;\n for (const part of parts) {\n if (part === \".\") {\n // @ts-expect-error todo(flow-ts): Can path be an array here?\n path = path.parentPath;\n } else {\n if (Array.isArray(path)) {\n // @ts-expect-error part may not index path\n path = path[part];\n } else {\n path = path.get(part, context);\n }\n }\n }\n return path;\n}\n\nfunction getBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getBindingIdentifiers };\n\nfunction getOuterBindingIdentifiers(\n duplicates: true,\n): Record<string, t.Identifier[]>;\nfunction getOuterBindingIdentifiers(\n duplicates?: false,\n): Record<string, t.Identifier>;\nfunction getOuterBindingIdentifiers(\n duplicates: boolean,\n): Record<string, t.Identifier[] | t.Identifier>;\n\nfunction getOuterBindingIdentifiers(\n this: NodePath,\n duplicates?: boolean,\n): Record<string, t.Identifier[] | t.Identifier> {\n return _getOuterBindingIdentifiers(this.node, duplicates);\n}\n\nexport { getOuterBindingIdentifiers };\n\nfunction getBindingIdentifierPaths(\n duplicates: true,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getBindingIdentifierPaths(\n duplicates: false,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier>>;\nfunction getBindingIdentifierPaths(\n duplicates?: boolean,\n outerOnly?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\n// original source - https://github.com/babel/babel/blob/main/packages/babel-types/src/retrievers/getBindingIdentifiers.js\n// path.getBindingIdentifiers returns nodes where the following re-implementation returns paths\nfunction getBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n outerOnly: boolean = false,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]> {\n const path = this;\n const search = [path];\n const ids = Object.create(null);\n\n while (search.length) {\n const id = search.shift();\n if (!id) continue;\n if (!id.node) continue;\n\n const keys =\n // @ts-expect-error _getBindingIdentifiers.keys do not cover all node types\n _getBindingIdentifiers.keys[id.node.type];\n\n if (id.isIdentifier()) {\n if (duplicates) {\n const _ids = (ids[id.node.name] = ids[id.node.name] || []);\n _ids.push(id);\n } else {\n ids[id.node.name] = id;\n }\n continue;\n }\n\n if (id.isExportDeclaration()) {\n const declaration = id.get(\"declaration\");\n if (isDeclaration(declaration)) {\n search.push(declaration);\n }\n continue;\n }\n\n if (outerOnly) {\n if (id.isFunctionDeclaration()) {\n search.push(id.get(\"id\"));\n continue;\n }\n if (id.isFunctionExpression()) {\n continue;\n }\n }\n\n if (keys) {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const child = id.get(key);\n if (Array.isArray(child)) {\n search.push(...child);\n } else if (child.node) {\n search.push(child);\n }\n }\n }\n }\n\n return ids;\n}\n\nexport { getBindingIdentifierPaths };\n\nfunction getOuterBindingIdentifierPaths(\n duplicates: true,\n): Record<string, NodePath<t.Identifier>[]>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: false,\n): Record<string, NodePath<t.Identifier>>;\nfunction getOuterBindingIdentifierPaths(\n duplicates?: boolean,\n): Record<string, NodePath<t.Identifier> | NodePath<t.Identifier>[]>;\n\nfunction getOuterBindingIdentifierPaths(\n this: NodePath,\n duplicates: boolean = false,\n) {\n return this.getBindingIdentifierPaths(duplicates, true);\n}\n\nexport { getOuterBindingIdentifierPaths };\n"],"mappings":"AAGA,OAAOA,QAAQ,MAAM,YAAS;AAC9B,YAAAC,EAAA,MAMO,cAAc;AAAC;EALpBC,qBAAqB,EAAIC,sBAAsB;EAC/CC,0BAA0B,EAAIC,2BAA2B;EACzDC,aAAa;EACbC,cAAc;EACdC;AAAe,IAAAP,EAAA;AAIjB,MAAMQ,iBAAiB,GAAG,CAAU;AACpC,MAAMC,gBAAgB,GAAG,CAAU;AAmBnC,SAASC,gBAAgBA,CAACC,IAAc,EAAE;EACxC,OAAO;IAAEC,IAAI,EAAEJ,iBAAiB;IAAEG;EAAK,CAAC;AAC1C;AAEA,SAASE,eAAeA,CAACF,IAAc,EAAE;EACvC,OAAO;IAAEC,IAAI,EAAEH,gBAAgB;IAAEE;EAAK,CAAC;AACzC;AAEA,OAAO,SAASG,WAAWA,CAAA,EAAkC;EAC3D,IAAI,IAAI,CAACC,GAAG,KAAK,MAAM,EAAE;IACvB,OAAO,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC;EACjC,CAAC,MAAM,IAAI,IAAI,CAACD,GAAG,KAAK,OAAO,EAAE;IAC/B,OAAO,IAAI,CAACC,UAAU,CAAC,MAAM,CAAC;EAChC;EACA,OAAO,IAAI;AACb;AAEA,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AACQ,qBAAqB,CAAC,CAAC,EAAE;QAC9BX,MAAM,CAAC1E,IAAI,CAAC6E,EAAE,CAACzC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzB;MACF;MACA,IAAIyC,EAAE,CAACS,oBAAoB,CAAC,CAAC,EAAE;QAC7B;MACF;IACF;IAEA,IAAIP,IAAI,EAAE;MACR,KAAK,IAAI1E,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG0E,IAAI,CAACzE,MAAM,EAAED,CAAC,EAAE,EAAE;QACpC,MAAMV,GAAG,GAAGoF,IAAI,CAAC1E,CAAC,CAAC;QACnB,MAAMkF,KAAK,GAAGV,EAAE,CAACzC,GAAG,CAACzC,GAAG,CAAC;QACzB,IAAIwE,KAAK,CAACC,OAAO,CAACmB,KAAK,CAAC,EAAE;UACxBb,MAAM,CAAC1E,IAAI,CAAC,GAAGuF,KAAK,CAAC;QACvB,CAAC,MAAM,IAAIA,KAAK,CAAC1B,IAAI,EAAE;UACrBa,MAAM,CAAC1E,IAAI,CAACuF,KAAK,CAAC;QACpB;MACF;IACF;EACF;EAEA,OAAOZ,GAAG;AACZ;AAEA,SAASH,yBAAyB;AAYlC,SAASgB,8BAA8BA,CAErCjB,UAAmB,GAAG,KAAK,EAC3B;EACA,OAAO,IAAI,CAACC,yBAAyB,CAACD,UAAU,EAAE,IAAI,CAAC;AACzD;AAEA,SAASiB,8BAA8B"}
|
package/lib/path/index.js
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
import * as virtualTypes from "./lib/virtual-types.js";
|
2
|
-
import buildDebug from "debug";
|
3
|
-
import traverse from "../index.js";
|
4
|
-
import Scope from "../scope/index.js";
|
5
|
-
import * as _t from "@babel/types";
|
6
|
-
const {
|
7
|
-
validate
|
8
|
-
} = _t;
|
9
|
-
import * as t from "@babel/types";
|
10
|
-
import { path as pathCache } from "../cache.js";
|
11
|
-
import generator from "@babel/generator";
|
12
|
-
import * as NodePath_ancestry from "./ancestry.js";
|
13
|
-
import * as NodePath_inference from "./inference/index.js";
|
14
|
-
import * as NodePath_replacement from "./replacement.js";
|
15
|
-
import * as NodePath_evaluation from "./evaluation.js";
|
16
|
-
import * as NodePath_conversion from "./conversion.js";
|
17
|
-
import * as NodePath_introspection from "./introspection.js";
|
18
|
-
import * as NodePath_context from "./context.js";
|
19
|
-
import * as NodePath_removal from "./removal.js";
|
20
|
-
import * as NodePath_modification from "./modification.js";
|
21
|
-
import * as NodePath_family from "./family.js";
|
22
|
-
import * as NodePath_comments from "./comments.js";
|
23
|
-
import * as NodePath_virtual_types_validator from "./lib/virtual-types-validator.js";
|
24
|
-
const debug = buildDebug("babel");
|
25
|
-
export const REMOVED = 1 << 0;
|
26
|
-
export const SHOULD_STOP = 1 << 1;
|
27
|
-
export const SHOULD_SKIP = 1 << 2;
|
28
|
-
class NodePath {
|
29
|
-
constructor(hub, parent) {
|
30
|
-
this.parent = parent;
|
31
|
-
this.hub = hub;
|
32
|
-
this.data = null;
|
33
|
-
this.context = null;
|
34
|
-
this.scope = null;
|
35
|
-
}
|
36
|
-
contexts = [];
|
37
|
-
state = null;
|
38
|
-
opts = null;
|
39
|
-
_traverseFlags = 0;
|
40
|
-
skipKeys = null;
|
41
|
-
parentPath = null;
|
42
|
-
container = null;
|
43
|
-
listKey = null;
|
44
|
-
key = null;
|
45
|
-
node = null;
|
46
|
-
type = null;
|
47
|
-
static get({
|
48
|
-
hub,
|
49
|
-
parentPath,
|
50
|
-
parent,
|
51
|
-
container,
|
52
|
-
listKey,
|
53
|
-
key
|
54
|
-
}) {
|
55
|
-
if (!hub && parentPath) {
|
56
|
-
hub = parentPath.hub;
|
57
|
-
}
|
58
|
-
if (!parent) {
|
59
|
-
throw new Error("To get a node path the parent needs to exist");
|
60
|
-
}
|
61
|
-
const targetNode = container[key];
|
62
|
-
let paths = pathCache.get(parent);
|
63
|
-
if (!paths) {
|
64
|
-
paths = new Map();
|
65
|
-
pathCache.set(parent, paths);
|
66
|
-
}
|
67
|
-
let path = paths.get(targetNode);
|
68
|
-
if (!path) {
|
69
|
-
path = new NodePath(hub, parent);
|
70
|
-
if (targetNode) paths.set(targetNode, path);
|
71
|
-
}
|
72
|
-
path.setup(parentPath, container, listKey, key);
|
73
|
-
return path;
|
74
|
-
}
|
75
|
-
getScope(scope) {
|
76
|
-
return this.isScope() ? new Scope(this) : scope;
|
77
|
-
}
|
78
|
-
setData(key, val) {
|
79
|
-
if (this.data == null) {
|
80
|
-
this.data = Object.create(null);
|
81
|
-
}
|
82
|
-
return this.data[key] = val;
|
83
|
-
}
|
84
|
-
getData(key, def) {
|
85
|
-
if (this.data == null) {
|
86
|
-
this.data = Object.create(null);
|
87
|
-
}
|
88
|
-
let val = this.data[key];
|
89
|
-
if (val === undefined && def !== undefined) val = this.data[key] = def;
|
90
|
-
return val;
|
91
|
-
}
|
92
|
-
hasNode() {
|
93
|
-
return this.node != null;
|
94
|
-
}
|
95
|
-
buildCodeFrameError(msg, Error = SyntaxError) {
|
96
|
-
return this.hub.buildError(this.node, msg, Error);
|
97
|
-
}
|
98
|
-
traverse(visitor, state) {
|
99
|
-
traverse(this.node, visitor, this.scope, state, this);
|
100
|
-
}
|
101
|
-
set(key, node) {
|
102
|
-
validate(this.node, key, node);
|
103
|
-
this.node[key] = node;
|
104
|
-
}
|
105
|
-
getPathLocation() {
|
106
|
-
const parts = [];
|
107
|
-
let path = this;
|
108
|
-
do {
|
109
|
-
let key = path.key;
|
110
|
-
if (path.inList) key = `${path.listKey}[${key}]`;
|
111
|
-
parts.unshift(key);
|
112
|
-
} while (path = path.parentPath);
|
113
|
-
return parts.join(".");
|
114
|
-
}
|
115
|
-
debug(message) {
|
116
|
-
if (!debug.enabled) return;
|
117
|
-
debug(`${this.getPathLocation()} ${this.type}: ${message}`);
|
118
|
-
}
|
119
|
-
toString() {
|
120
|
-
return generator(this.node).code;
|
121
|
-
}
|
122
|
-
get inList() {
|
123
|
-
return !!this.listKey;
|
124
|
-
}
|
125
|
-
set inList(inList) {
|
126
|
-
if (!inList) {
|
127
|
-
this.listKey = null;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
get parentKey() {
|
131
|
-
return this.listKey || this.key;
|
132
|
-
}
|
133
|
-
get shouldSkip() {
|
134
|
-
return !!(this._traverseFlags & SHOULD_SKIP);
|
135
|
-
}
|
136
|
-
set shouldSkip(v) {
|
137
|
-
if (v) {
|
138
|
-
this._traverseFlags |= SHOULD_SKIP;
|
139
|
-
} else {
|
140
|
-
this._traverseFlags &= ~SHOULD_SKIP;
|
141
|
-
}
|
142
|
-
}
|
143
|
-
get shouldStop() {
|
144
|
-
return !!(this._traverseFlags & SHOULD_STOP);
|
145
|
-
}
|
146
|
-
set shouldStop(v) {
|
147
|
-
if (v) {
|
148
|
-
this._traverseFlags |= SHOULD_STOP;
|
149
|
-
} else {
|
150
|
-
this._traverseFlags &= ~SHOULD_STOP;
|
151
|
-
}
|
152
|
-
}
|
153
|
-
get removed() {
|
154
|
-
return !!(this._traverseFlags & REMOVED);
|
155
|
-
}
|
156
|
-
set removed(v) {
|
157
|
-
if (v) {
|
158
|
-
this._traverseFlags |= REMOVED;
|
159
|
-
} else {
|
160
|
-
this._traverseFlags &= ~REMOVED;
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
165
|
-
;
|
166
|
-
for (const type of t.TYPES) {
|
167
|
-
const typeKey = `is${type}`;
|
168
|
-
const fn = t[typeKey];
|
169
|
-
NodePath.prototype[typeKey] = function (opts) {
|
170
|
-
return fn(this.node, opts);
|
171
|
-
};
|
172
|
-
NodePath.prototype[`assert${type}`] = function (opts) {
|
173
|
-
if (!fn(this.node, opts)) {
|
174
|
-
throw new TypeError(`Expected node path of type ${type}`);
|
175
|
-
}
|
176
|
-
};
|
177
|
-
}
|
178
|
-
Object.assign(NodePath.prototype, NodePath_virtual_types_validator);
|
179
|
-
for (const type of Object.keys(virtualTypes)) {
|
180
|
-
if (type[0] === "_") continue;
|
181
|
-
if (!t.TYPES.includes(type)) t.TYPES.push(type);
|
182
|
-
}
|
183
|
-
export default NodePath;
|
184
|
-
|
185
|
-
//# sourceMappingURL=index.js.map
|
package/lib/path/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["virtualTypes","buildDebug","traverse","Scope","_t","validate","t","path","pathCache","generator","NodePath_ancestry","NodePath_inference","NodePath_replacement","NodePath_evaluation","NodePath_conversion","NodePath_introspection","NodePath_context","NodePath_removal","NodePath_modification","NodePath_family","NodePath_comments","NodePath_virtual_types_validator","debug","REMOVED","SHOULD_STOP","SHOULD_SKIP","NodePath","constructor","hub","parent","data","context","scope","contexts","state","opts","_traverseFlags","skipKeys","parentPath","container","listKey","key","node","type","get","Error","targetNode","paths","Map","set","setup","getScope","isScope","setData","val","Object","create","getData","def","undefined","hasNode","buildCodeFrameError","msg","SyntaxError","buildError","visitor","getPathLocation","parts","inList","unshift","join","message","enabled","toString","code","parentKey","shouldSkip","v","shouldStop","removed","assign","prototype","TYPES","typeKey","fn","TypeError","keys","includes","push"],"sources":["../../src/path/index.ts"],"sourcesContent":["import type { HubInterface } from \"../hub\";\nimport type TraversalContext from \"../context\";\nimport type { ExplodedTraverseOptions } from \"..\";\nimport * as virtualTypes from \"./lib/virtual-types\";\nimport buildDebug from \"debug\";\nimport traverse from \"../index\";\nimport type { Visitor } from \"../types\";\nimport Scope from \"../scope\";\nimport { validate } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport { path as pathCache } from \"../cache\";\nimport generator from \"@babel/generator\";\n\n// NodePath is split across many files.\nimport * as NodePath_ancestry from \"./ancestry\";\nimport * as NodePath_inference from \"./inference\";\nimport * as NodePath_replacement from \"./replacement\";\nimport * as NodePath_evaluation from \"./evaluation\";\nimport * as NodePath_conversion from \"./conversion\";\nimport * as NodePath_introspection from \"./introspection\";\nimport * as NodePath_context from \"./context\";\nimport * as NodePath_removal from \"./removal\";\nimport * as NodePath_modification from \"./modification\";\nimport * as NodePath_family from \"./family\";\nimport * as NodePath_comments from \"./comments\";\nimport * as NodePath_virtual_types_validator from \"./lib/virtual-types-validator\";\nimport type { NodePathAssertions } from \"./generated/asserts\";\nimport type { NodePathValidators } from \"./generated/validators\";\n\nconst debug = buildDebug(\"babel\");\n\nexport const REMOVED = 1 << 0;\nexport const SHOULD_STOP = 1 << 1;\nexport const SHOULD_SKIP = 1 << 2;\n\nclass NodePath<T extends t.Node = t.Node> {\n constructor(hub: HubInterface, parent: t.ParentMaps[T[\"type\"]]) {\n this.parent = parent;\n this.hub = hub;\n this.data = null;\n\n this.context = null;\n this.scope = null;\n }\n\n declare parent: t.ParentMaps[T[\"type\"]];\n declare hub: HubInterface;\n declare data: Record<string | symbol, unknown>;\n // TraversalContext is configured by setContext\n declare context: TraversalContext;\n declare scope: Scope;\n\n contexts: Array<TraversalContext> = [];\n state: any = null;\n opts: ExplodedTraverseOptions | null = null;\n // this.shouldSkip = false; this.shouldStop = false; this.removed = false;\n _traverseFlags: number = 0;\n skipKeys: Record<string, boolean> | null = null;\n parentPath: t.ParentMaps[T[\"type\"]] extends null\n ? null\n : NodePath<t.ParentMaps[T[\"type\"]]> | null = null;\n container: t.Node | Array<t.Node> | null = null;\n listKey: string | null = null;\n key: string | number | null = null;\n node: T = null;\n type: T[\"type\"] | null = null;\n\n static get({\n hub,\n parentPath,\n parent,\n container,\n listKey,\n key,\n }: {\n hub?: HubInterface;\n parentPath: NodePath | null;\n parent: t.Node;\n container: t.Node | t.Node[];\n listKey?: string;\n key: string | number;\n }): NodePath {\n if (!hub && parentPath) {\n hub = parentPath.hub;\n }\n\n if (!parent) {\n throw new Error(\"To get a node path the parent needs to exist\");\n }\n\n const targetNode =\n // @ts-expect-error key must present in container\n container[key];\n\n let paths = pathCache.get(parent);\n if (!paths) {\n paths = new Map();\n pathCache.set(parent, paths);\n }\n\n let path = paths.get(targetNode);\n if (!path) {\n path = new NodePath(hub, parent);\n if (targetNode) paths.set(targetNode, path);\n }\n\n path.setup(parentPath, container, listKey, key);\n\n return path;\n }\n\n getScope(scope: Scope): Scope {\n return this.isScope() ? new Scope(this) : scope;\n }\n\n setData(key: string | symbol, val: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n return (this.data[key] = val);\n }\n\n getData(key: string | symbol, def?: any): any {\n if (this.data == null) {\n this.data = Object.create(null);\n }\n let val = this.data[key];\n if (val === undefined && def !== undefined) val = this.data[key] = def;\n return val;\n }\n\n hasNode(): this is NodePath<NonNullable<this[\"node\"]>> {\n return this.node != null;\n }\n\n buildCodeFrameError(\n msg: string,\n Error: new () => Error = SyntaxError,\n ): Error {\n return this.hub.buildError(this.node, msg, Error);\n }\n\n traverse<T>(visitor: Visitor<T>, state: T): void;\n traverse(visitor: Visitor): void;\n traverse(visitor: any, state?: any) {\n traverse(this.node, visitor, this.scope, state, this);\n }\n\n set(key: string, node: any) {\n validate(this.node, key, node);\n // @ts-expect-error key must present in this.node\n this.node[key] = node;\n }\n\n getPathLocation(): string {\n const parts = [];\n let path: NodePath = this;\n do {\n let key = path.key;\n if (path.inList) key = `${path.listKey}[${key}]`;\n parts.unshift(key);\n } while ((path = path.parentPath));\n return parts.join(\".\");\n }\n\n debug(message: string) {\n if (!debug.enabled) return;\n debug(`${this.getPathLocation()} ${this.type}: ${message}`);\n }\n\n toString() {\n return generator(this.node).code;\n }\n\n get inList() {\n return !!this.listKey;\n }\n\n set inList(inList) {\n if (!inList) {\n this.listKey = null;\n }\n // ignore inList = true as it should depend on `listKey`\n }\n\n get parentKey(): string {\n return (this.listKey || this.key) as string;\n }\n\n get shouldSkip() {\n return !!(this._traverseFlags & SHOULD_SKIP);\n }\n\n set shouldSkip(v) {\n if (v) {\n this._traverseFlags |= SHOULD_SKIP;\n } else {\n this._traverseFlags &= ~SHOULD_SKIP;\n }\n }\n\n get shouldStop() {\n return !!(this._traverseFlags & SHOULD_STOP);\n }\n\n set shouldStop(v) {\n if (v) {\n this._traverseFlags |= SHOULD_STOP;\n } else {\n this._traverseFlags &= ~SHOULD_STOP;\n }\n }\n\n get removed() {\n return !!(this._traverseFlags & REMOVED);\n }\n set removed(v) {\n if (v) {\n this._traverseFlags |= REMOVED;\n } else {\n this._traverseFlags &= ~REMOVED;\n }\n }\n}\n\nObject.assign(\n NodePath.prototype,\n NodePath_ancestry,\n NodePath_inference,\n NodePath_replacement,\n NodePath_evaluation,\n NodePath_conversion,\n NodePath_introspection,\n NodePath_context,\n NodePath_removal,\n NodePath_modification,\n NodePath_family,\n NodePath_comments,\n);\n\nif (!process.env.BABEL_8_BREAKING) {\n // @ts-expect-error The original _guessExecutionStatusRelativeToDifferentFunctions only worked for paths in\n // different functions, but _guessExecutionStatusRelativeTo works as a replacement in those cases.\n NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions =\n NodePath_introspection._guessExecutionStatusRelativeTo;\n}\n\n// we can not use `import { TYPES } from \"@babel/types\"` here\n// because the transformNamedBabelTypesImportToDestructuring plugin in babel.config.js\n// does not offer live bindings for `TYPES`\n// we can change to `import { TYPES }` when we are publishing ES modules only\nfor (const type of t.TYPES) {\n const typeKey = `is${type}`;\n // @ts-expect-error typeKey must present in t\n const fn = t[typeKey];\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[typeKey] = function (opts: any) {\n return fn(this.node, opts);\n };\n\n // @ts-expect-error augmenting NodePath prototype\n NodePath.prototype[`assert${type}`] = function (opts: any) {\n if (!fn(this.node, opts)) {\n throw new TypeError(`Expected node path of type ${type}`);\n }\n };\n}\n\n// Register virtual types validators after base types validators\nObject.assign(NodePath.prototype, NodePath_virtual_types_validator);\n\nfor (const type of Object.keys(virtualTypes) as (keyof typeof virtualTypes)[]) {\n if (type[0] === \"_\") continue;\n if (!t.TYPES.includes(type)) t.TYPES.push(type);\n}\n\ntype NodePathMixins = typeof NodePath_ancestry &\n typeof NodePath_inference &\n typeof NodePath_replacement &\n typeof NodePath_evaluation &\n typeof NodePath_conversion &\n typeof NodePath_introspection &\n typeof NodePath_context &\n typeof NodePath_removal &\n typeof NodePath_modification &\n typeof NodePath_family &\n typeof NodePath_comments;\n\n// @ts-expect-error TS throws because ensureBlock returns the body node path\n// however, we don't use the return value and treat it as a transform and\n// assertion utilities. For better type inference we annotate it as an\n// assertion method\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ninterface NodePath<T>\n extends NodePathAssertions,\n NodePathValidators,\n NodePathMixins {\n /**\n * @see ./conversion.ts for implementation\n */\n ensureBlock<\n T extends\n | t.Loop\n | t.WithStatement\n | t.Function\n | t.LabeledStatement\n | t.CatchClause,\n >(\n this: NodePath<T>,\n ): asserts this is NodePath<T & { body: t.BlockStatement }>;\n}\n\nexport default NodePath;\n"],"mappings":"AAGA,OAAO,KAAKA,YAAY,MAAM,wBAAqB;AACnD,OAAOC,UAAU,MAAM,OAAO;AAC9B,OAAOC,QAAQ,MAAM,aAAU;AAE/B,OAAOC,KAAK,MAAM,mBAAU;AAC5B,YAAAC,EAAA,MAAyB,cAAc;AAAC;EAA/BC;AAAQ,IAAAD,EAAA;AACjB,OAAO,KAAKE,CAAC,MAAM,cAAc;AACjC,SAASC,IAAI,IAAIC,SAAS,QAAQ,aAAU;AAC5C,OAAOC,SAAS,MAAM,kBAAkB;AAGxC,OAAO,KAAKC,iBAAiB,MAAM,eAAY;AAC/C,OAAO,KAAKC,kBAAkB,MAAM,sBAAa;AACjD,OAAO,KAAKC,oBAAoB,MAAM,kBAAe;AACrD,OAAO,KAAKC,mBAAmB,MAAM,iBAAc;AACnD,OAAO,KAAKC,mBAAmB,MAAM,iBAAc;AACnD,OAAO,KAAKC,sBAAsB,MAAM,oBAAiB;AACzD,OAAO,KAAKC,gBAAgB,MAAM,cAAW;AAC7C,OAAO,KAAKC,gBAAgB,MAAM,cAAW;AAC7C,OAAO,KAAKC,qBAAqB,MAAM,mBAAgB;AACvD,OAAO,KAAKC,eAAe,MAAM,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