vue-hook-optimizer 0.0.77 → 0.0.79
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/dist/index.cjs +2016 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +82 -71
- package/dist/index.js +1874 -2442
- package/dist/index.js.map +1 -1
- package/package.json +11 -23
- package/README.md +0 -59
- package/dist/index.d.mts +0 -98
- package/dist/index.mjs +0 -2500
- package/dist/index.mjs.map +0 -1
- package/license +0 -1
package/dist/index.js
CHANGED
@@ -1,2547 +1,1979 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
|
30
|
-
// src/index.ts
|
31
|
-
var src_exports = {};
|
32
|
-
__export(src_exports, {
|
33
|
-
NodeType: () => NodeType,
|
34
|
-
SuggestionType: () => SuggestionType,
|
35
|
-
analyzeOptions: () => analyze2,
|
36
|
-
analyzeSetupScript: () => analyze,
|
37
|
-
analyzeStyle: () => analyze3,
|
38
|
-
analyzeTemplate: () => analyze4,
|
39
|
-
analyzeTsx: () => analyze5,
|
40
|
-
gen: () => gen,
|
41
|
-
getMermaidText: () => getMermaidText,
|
42
|
-
getVisData: () => getVisData,
|
43
|
-
parse: () => import_compiler_sfc5.parse
|
44
|
-
});
|
45
|
-
module.exports = __toCommonJS(src_exports);
|
1
|
+
import _traverse from "@babel/traverse";
|
2
|
+
import { babelParse, compileTemplate, parse } from "@vue/compiler-sfc";
|
46
3
|
|
47
|
-
|
48
|
-
|
49
|
-
var
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
var import_compiler_sfc = require("@vue/compiler-sfc");
|
54
|
-
|
55
|
-
// src/analyze/utils.ts
|
56
|
-
var NodeType = /* @__PURE__ */ ((NodeType3) => {
|
57
|
-
NodeType3["var"] = "var";
|
58
|
-
NodeType3["fun"] = "fun";
|
59
|
-
return NodeType3;
|
60
|
-
})(NodeType || {});
|
4
|
+
//#region src/analyze/utils.ts
|
5
|
+
let NodeType = /* @__PURE__ */ function(NodeType$1) {
|
6
|
+
NodeType$1["var"] = "var";
|
7
|
+
NodeType$1["fun"] = "fun";
|
8
|
+
return NodeType$1;
|
9
|
+
}({});
|
61
10
|
var NodeCollection = class {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
}
|
136
|
-
}
|
137
|
-
const items = Array.from(labelMap.values());
|
138
|
-
return [this.nodes.get(from), new Set(items)];
|
139
|
-
}));
|
140
|
-
return {
|
141
|
-
nodes,
|
142
|
-
edges
|
143
|
-
};
|
144
|
-
}
|
11
|
+
constructor(_lineOffset = 0, _addInfo = true) {
|
12
|
+
this.lineOffset = 0;
|
13
|
+
this.addInfo = true;
|
14
|
+
this.nodes = /* @__PURE__ */ new Map();
|
15
|
+
this.lineOffset = _lineOffset;
|
16
|
+
this.addInfo = _addInfo;
|
17
|
+
}
|
18
|
+
addNode(label, node, options = {
|
19
|
+
isComputed: false,
|
20
|
+
isMethod: false,
|
21
|
+
comment: ""
|
22
|
+
}) {
|
23
|
+
if (this.nodes.has(label)) return;
|
24
|
+
if (!options.isComputed && (node.type === "VariableDeclarator" && [
|
25
|
+
"ArrowFunctionExpression",
|
26
|
+
"FunctionDeclaration",
|
27
|
+
"FunctionExpression"
|
28
|
+
].includes(node.init?.type || "") || node.type === "ObjectProperty" && [
|
29
|
+
"ArrowFunctionExpression",
|
30
|
+
"FunctionDeclaration",
|
31
|
+
"FunctionExpression"
|
32
|
+
].includes(node.value?.type || "") || node.type === "FunctionDeclaration" || node.type === "ObjectMethod" || node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") || options.isMethod) this.nodes.set(label, {
|
33
|
+
label,
|
34
|
+
type: NodeType.fun,
|
35
|
+
...this.addInfo ? { info: {
|
36
|
+
line: (node.loc?.start.line || 1) - 1 + this.lineOffset,
|
37
|
+
column: node.loc?.start.column || 0,
|
38
|
+
...options.comment ? { comment: options.comment } : {}
|
39
|
+
} } : {}
|
40
|
+
});
|
41
|
+
else this.nodes.set(label, {
|
42
|
+
label,
|
43
|
+
type: NodeType.var,
|
44
|
+
...this.addInfo ? { info: {
|
45
|
+
line: (node.loc?.start.line || 1) - 1 + this.lineOffset,
|
46
|
+
column: node.loc?.start.column || 0,
|
47
|
+
...options.comment ? { comment: options.comment } : {}
|
48
|
+
} } : {}
|
49
|
+
});
|
50
|
+
}
|
51
|
+
addTypedNode(label, node) {
|
52
|
+
this.nodes.set(label, {
|
53
|
+
label,
|
54
|
+
type: node.type,
|
55
|
+
...this.addInfo ? { info: { ...node.info || {} } } : {}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
getNode(label) {
|
59
|
+
return this.nodes.get(label);
|
60
|
+
}
|
61
|
+
map(graph) {
|
62
|
+
const nodes = new Set(Array.from(graph.nodes).map((node) => {
|
63
|
+
return this.nodes.get(node);
|
64
|
+
}).filter((node) => !!node));
|
65
|
+
const edges = new Map(Array.from(graph.edges).map(([from, to]) => {
|
66
|
+
const labelMap = /* @__PURE__ */ new Map();
|
67
|
+
for (const item of to) {
|
68
|
+
const node = this.nodes.get(item.label);
|
69
|
+
if (!node) continue;
|
70
|
+
const existing = labelMap.get(item.label);
|
71
|
+
if (!existing || existing.type === "get" && item.type === "set") labelMap.set(item.label, {
|
72
|
+
node,
|
73
|
+
type: item.type
|
74
|
+
});
|
75
|
+
}
|
76
|
+
const items = Array.from(labelMap.values());
|
77
|
+
return [this.nodes.get(from), new Set(items)];
|
78
|
+
}));
|
79
|
+
return {
|
80
|
+
nodes,
|
81
|
+
edges
|
82
|
+
};
|
83
|
+
}
|
145
84
|
};
|
146
85
|
function getComment(node) {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
`;
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
if (_comment.loc.end.line > node.loc.start.line) {
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
if (_comment.value.trim().startsWith("*")) {
|
162
|
-
comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
|
163
|
-
`;
|
164
|
-
} else {
|
165
|
-
comment += `${_comment.value.trim()}
|
166
|
-
`;
|
167
|
-
}
|
168
|
-
});
|
169
|
-
return comment.trim();
|
86
|
+
let comment = "";
|
87
|
+
node.leadingComments?.forEach((_comment) => {
|
88
|
+
if (_comment.loc.end.line > node.loc.start.line) return;
|
89
|
+
if (_comment.value.trim().startsWith("*")) comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}\n`;
|
90
|
+
});
|
91
|
+
node.trailingComments?.forEach((_comment) => {
|
92
|
+
if (_comment.loc.end.line > node.loc.start.line) return;
|
93
|
+
if (_comment.value.trim().startsWith("*")) comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}\n`;
|
94
|
+
else comment += `${_comment.value.trim()}\n`;
|
95
|
+
});
|
96
|
+
return comment.trim();
|
170
97
|
}
|
171
98
|
function isWritingNode(path) {
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
return true;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
return false;
|
99
|
+
const assignParent = path.findParent((p) => p.isAssignmentExpression());
|
100
|
+
if (assignParent) {
|
101
|
+
const leftNode = assignParent.node.left;
|
102
|
+
if (leftNode.start != null && path.node.start >= leftNode.start && path.node.end <= leftNode.end) return true;
|
103
|
+
}
|
104
|
+
const updateParent = path.findParent((p) => p.isUpdateExpression());
|
105
|
+
if (updateParent) {
|
106
|
+
const argNode = updateParent.node.argument;
|
107
|
+
if (argNode.start != null && path.node.start >= argNode.start && path.node.end <= argNode.end) return true;
|
108
|
+
}
|
109
|
+
return false;
|
187
110
|
}
|
188
111
|
function isCallingNode(path) {
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
}
|
193
|
-
return false;
|
112
|
+
const parent = path.parentPath;
|
113
|
+
if (parent && parent.isCallExpression()) return parent.node.callee === path.node;
|
114
|
+
return false;
|
194
115
|
}
|
195
116
|
function getRelationType(path) {
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
if (isWritingNode(path)) {
|
200
|
-
return "set";
|
201
|
-
}
|
202
|
-
return "get";
|
117
|
+
if (path.node.type === "Identifier" && isCallingNode(path)) return "call";
|
118
|
+
if (isWritingNode(path)) return "set";
|
119
|
+
return "get";
|
203
120
|
}
|
204
121
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
122
|
+
//#endregion
|
123
|
+
//#region src/analyze/setupScript.ts
|
124
|
+
const traverse$3 = _traverse.default?.default || _traverse.default || _traverse;
|
125
|
+
const ignoreFunctionsName = [
|
126
|
+
"defineProps",
|
127
|
+
"defineEmits",
|
128
|
+
"withDefaults"
|
129
|
+
];
|
130
|
+
const watchHooks = [
|
131
|
+
"watch",
|
132
|
+
"watchArray",
|
133
|
+
"watchAtMost",
|
134
|
+
"watchDebounced",
|
135
|
+
"watchDeep",
|
136
|
+
"watchIgnorable",
|
137
|
+
"watchImmediate",
|
138
|
+
"watchOnce",
|
139
|
+
"watchPausable",
|
140
|
+
"watchThrottled",
|
141
|
+
"watchTriggerable",
|
142
|
+
"watchWithFilter"
|
222
143
|
];
|
223
144
|
function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
const binding = path1.scope.getBinding(path1.node.object.name);
|
571
|
-
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
572
|
-
graph.edges.get(name)?.add({
|
573
|
-
label: path1.node.property.name,
|
574
|
-
type: getRelationType(path1)
|
575
|
-
});
|
576
|
-
}
|
577
|
-
}
|
578
|
-
}
|
579
|
-
}, path.scope, path);
|
580
|
-
}
|
581
|
-
}
|
582
|
-
});
|
583
|
-
} else if ([
|
584
|
-
"CallExpression",
|
585
|
-
"ArrowFunctionExpression",
|
586
|
-
"FunctionDeclaration"
|
587
|
-
].includes(path.node.init.type) && path.node.id.type === "Identifier") {
|
588
|
-
if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && [...watchHooks, "watchEffect"].includes(path.node.init.callee.name)) {
|
589
|
-
traverseHooks(path.node.init, path.scope);
|
590
|
-
}
|
591
|
-
const name = path.node.id?.name;
|
592
|
-
if (name && graph.nodes.has(name)) {
|
593
|
-
traverse(path.node.init, {
|
594
|
-
Identifier(path1) {
|
595
|
-
const binding = path1.scope.getBinding(path1.node.name);
|
596
|
-
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
597
|
-
graph.edges.get(name)?.add({
|
598
|
-
label: path1.node.name,
|
599
|
-
type: getRelationType(path1)
|
600
|
-
});
|
601
|
-
}
|
602
|
-
},
|
603
|
-
MemberExpression(path1) {
|
604
|
-
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
605
|
-
const binding = path1.scope.getBinding(path1.node.object.name);
|
606
|
-
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
607
|
-
graph.edges.get(name)?.add({
|
608
|
-
label: path1.node.property.name,
|
609
|
-
type: getRelationType(path1)
|
610
|
-
});
|
611
|
-
}
|
612
|
-
}
|
613
|
-
}
|
614
|
-
}, path.scope, path);
|
615
|
-
}
|
616
|
-
} else if (path.node.id.type === "Identifier") {
|
617
|
-
const name = path.node.id.name;
|
618
|
-
if (path.node.init.type === "Identifier") {
|
619
|
-
const binding = path.scope.getBinding(path.node.init.name);
|
620
|
-
if (graph.nodes.has(path.node.init.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
621
|
-
graph.edges.get(name)?.add({
|
622
|
-
label: path.node.init.name,
|
623
|
-
type: getRelationType(path)
|
624
|
-
});
|
625
|
-
}
|
626
|
-
} else {
|
627
|
-
traverse(path.node.init, {
|
628
|
-
Identifier(path1) {
|
629
|
-
const binding = path1.scope.getBinding(path1.node.name);
|
630
|
-
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
631
|
-
graph.edges.get(name)?.add({
|
632
|
-
label: path1.node.name,
|
633
|
-
type: getRelationType(path1)
|
634
|
-
});
|
635
|
-
}
|
636
|
-
}
|
637
|
-
}, path.scope, path);
|
638
|
-
}
|
639
|
-
}
|
640
|
-
}
|
641
|
-
},
|
642
|
-
ObjectMethod(path) {
|
643
|
-
if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
|
644
|
-
const name = path.node.key.name;
|
645
|
-
traverse(path.node.body, {
|
646
|
-
Identifier(path1) {
|
647
|
-
const binding = path1.scope.getBinding(path1.node.name);
|
648
|
-
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
649
|
-
graph.edges.get(name)?.add({
|
650
|
-
label: path1.node.name,
|
651
|
-
type: getRelationType(path1)
|
652
|
-
});
|
653
|
-
}
|
654
|
-
},
|
655
|
-
MemberExpression(path1) {
|
656
|
-
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
657
|
-
const binding = path1.scope.getBinding(path1.node.object.name);
|
658
|
-
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
659
|
-
graph.edges.get(name)?.add({
|
660
|
-
label: path1.node.property.name,
|
661
|
-
type: getRelationType(path1)
|
662
|
-
});
|
663
|
-
}
|
664
|
-
}
|
665
|
-
}
|
666
|
-
}, path.scope, path);
|
667
|
-
}
|
668
|
-
},
|
669
|
-
ObjectProperty(path) {
|
670
|
-
if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
|
671
|
-
const name = path.node.key.name;
|
672
|
-
traverse(path.node.value, {
|
673
|
-
MemberExpression(path1) {
|
674
|
-
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
675
|
-
const binding = path1.scope.getBinding(path1.node.object.name);
|
676
|
-
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
677
|
-
graph.edges.get(name)?.add({
|
678
|
-
label: path1.node.property.name,
|
679
|
-
type: getRelationType(path1)
|
680
|
-
});
|
681
|
-
}
|
682
|
-
}
|
683
|
-
}
|
684
|
-
}, path.scope, path);
|
685
|
-
}
|
686
|
-
},
|
687
|
-
ExpressionStatement(path) {
|
688
|
-
if (path.type === "ExpressionStatement" && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "Identifier") {
|
689
|
-
const name = path.node.expression.callee.name;
|
690
|
-
if (graph.nodes.has(name) && path.scope.block.type === "Program") {
|
691
|
-
const _node = nodeCollection.getNode(name);
|
692
|
-
if (_node?.info?.used) {
|
693
|
-
_node?.info?.used?.add("Call Expression");
|
694
|
-
} else if (_node) {
|
695
|
-
_node.info = {
|
696
|
-
..._node?.info,
|
697
|
-
used: /* @__PURE__ */ new Set(["Call Expression"])
|
698
|
-
};
|
699
|
-
}
|
700
|
-
} else {
|
701
|
-
traverseHooks(path.node.expression, path.scope);
|
702
|
-
}
|
703
|
-
}
|
704
|
-
if (path.type === "ExpressionStatement" && path.node.expression.type === "AssignmentExpression" && path.node.expression.right.type === "CallExpression" && path.node.expression.right.callee.type === "Identifier") {
|
705
|
-
traverseHooks(path.node.expression.right, path.scope);
|
706
|
-
}
|
707
|
-
}
|
708
|
-
}, parentScope, parentPath);
|
709
|
-
return {
|
710
|
-
graph,
|
711
|
-
nodeCollection
|
712
|
-
};
|
145
|
+
const spread = _spread || [];
|
146
|
+
const nodeCollection = new NodeCollection(_lineOffset);
|
147
|
+
const graph = {
|
148
|
+
nodes: /* @__PURE__ */ new Set(),
|
149
|
+
edges: /* @__PURE__ */ new Map(),
|
150
|
+
spread: /* @__PURE__ */ new Map()
|
151
|
+
};
|
152
|
+
traverse$3(ast, {
|
153
|
+
VariableDeclaration(path) {
|
154
|
+
path.node.declarations.forEach((declaration) => {
|
155
|
+
if (declaration.id.type === "ArrayPattern") declaration.id.elements.forEach((element) => {
|
156
|
+
if (element?.type === "Identifier") {
|
157
|
+
const name = element.name;
|
158
|
+
const binding = path.scope.getBinding(name);
|
159
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ignoreFunctionsName.includes(declaration.init?.callee.name))) {
|
160
|
+
graph.nodes.add(name);
|
161
|
+
nodeCollection.addNode(name, element, { comment: getComment(path.node) });
|
162
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
163
|
+
}
|
164
|
+
}
|
165
|
+
if (element?.type === "RestElement" && element.argument.type === "Identifier") {
|
166
|
+
const name = element.argument.name;
|
167
|
+
const binding = path.scope.getBinding(name);
|
168
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ignoreFunctionsName.includes(declaration.init?.callee.name))) {
|
169
|
+
graph.nodes.add(name);
|
170
|
+
nodeCollection.addNode(name, element.argument, { comment: getComment(path.node) });
|
171
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
172
|
+
}
|
173
|
+
}
|
174
|
+
});
|
175
|
+
if (declaration.id.type === "ObjectPattern") declaration.id.properties.forEach((property) => {
|
176
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
177
|
+
const name = property.value.name;
|
178
|
+
const binding = path.scope.getBinding(name);
|
179
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ignoreFunctionsName.includes(declaration.init?.callee.name))) {
|
180
|
+
graph.nodes.add(name);
|
181
|
+
nodeCollection.addNode(name, property.value, { comment: getComment(property) });
|
182
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
183
|
+
}
|
184
|
+
}
|
185
|
+
if (property.type === "RestElement" && property.argument.type === "Identifier") {
|
186
|
+
const name = property.argument.name;
|
187
|
+
const binding = path.scope.getBinding(name);
|
188
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ignoreFunctionsName.includes(declaration.init?.callee.name))) {
|
189
|
+
graph.nodes.add(name);
|
190
|
+
nodeCollection.addNode(name, property.argument, { comment: getComment(property) });
|
191
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
192
|
+
}
|
193
|
+
}
|
194
|
+
});
|
195
|
+
if (declaration.id?.type === "Identifier") {
|
196
|
+
const name = declaration.id.name;
|
197
|
+
const binding = path.scope.getBinding(name);
|
198
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ignoreFunctionsName.includes(declaration.init?.callee.name))) {
|
199
|
+
graph.nodes.add(name);
|
200
|
+
nodeCollection.addNode(name, declaration, { comment: getComment(path.node) });
|
201
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
202
|
+
if (spread.includes(name)) {
|
203
|
+
if (declaration.init?.type === "ObjectExpression") declaration.init?.properties.forEach((prop) => {
|
204
|
+
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
205
|
+
const keyName = prop.key.name;
|
206
|
+
graph.nodes.add(keyName);
|
207
|
+
nodeCollection.addNode(keyName, prop, { comment: getComment(prop) });
|
208
|
+
if (!graph.edges.get(keyName)) graph.edges.set(keyName, /* @__PURE__ */ new Set());
|
209
|
+
if (graph.spread.has(name)) graph.spread.get(name)?.add(keyName);
|
210
|
+
else graph.spread.set(name, new Set([keyName]));
|
211
|
+
} else if (prop.type === "SpreadElement") console.warn("not support spread in spread");
|
212
|
+
});
|
213
|
+
if (declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && declaration.init?.callee.name === "reactive") {
|
214
|
+
const arg = declaration.init?.arguments[0];
|
215
|
+
if (arg.type === "ObjectExpression") arg.properties.forEach((prop) => {
|
216
|
+
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
217
|
+
const keyName = prop.key.name;
|
218
|
+
graph.nodes.add(keyName);
|
219
|
+
nodeCollection.addNode(keyName, prop, { comment: getComment(prop) });
|
220
|
+
if (!graph.edges.get(keyName)) graph.edges.set(keyName, /* @__PURE__ */ new Set());
|
221
|
+
if (graph.spread.has(name)) graph.spread.get(name)?.add(keyName);
|
222
|
+
else graph.spread.set(name, new Set([keyName]));
|
223
|
+
} else if (prop.type === "SpreadElement") console.warn("not support spread in spread");
|
224
|
+
});
|
225
|
+
}
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
});
|
230
|
+
},
|
231
|
+
FunctionDeclaration(path) {
|
232
|
+
const name = path.node.id?.name;
|
233
|
+
if (name) {
|
234
|
+
const binding = path.scope.getBinding(name);
|
235
|
+
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent)) {
|
236
|
+
graph.nodes.add(name);
|
237
|
+
nodeCollection.addNode(name, path.node.id, {
|
238
|
+
isMethod: true,
|
239
|
+
comment: getComment(path.node)
|
240
|
+
});
|
241
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}, parentScope, parentPath);
|
246
|
+
function traverseHooks(node, patentScope) {
|
247
|
+
if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" || node.type === "CallExpression" && node.callee.type === "Identifier") {
|
248
|
+
const hookName = (() => {
|
249
|
+
if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier") return node.expression.callee.name;
|
250
|
+
if (node.type === "CallExpression" && node.callee.type === "Identifier") return node.callee.name;
|
251
|
+
})() || "";
|
252
|
+
if (!hookName) return;
|
253
|
+
const hookBinding = patentScope.getBinding(hookName);
|
254
|
+
if (!(hookBinding === void 0 || hookBinding?.scope.block.type === "Program" || parentScope === hookBinding?.scope)) return;
|
255
|
+
const expression = node.type === "ExpressionStatement" ? node.expression : node;
|
256
|
+
const watchArgs = /* @__PURE__ */ new Set();
|
257
|
+
if (hookName === "provide") traverse$3(expression, { Identifier(path1) {
|
258
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
259
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
260
|
+
const _node = nodeCollection.getNode(path1.node.name);
|
261
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
262
|
+
else if (_node) _node.info = {
|
263
|
+
..._node?.info,
|
264
|
+
used: new Set([hookName])
|
265
|
+
};
|
266
|
+
}
|
267
|
+
} }, patentScope, node);
|
268
|
+
else if (watchHooks.includes(hookName)) if (expression.arguments[0].type === "Identifier") {
|
269
|
+
const binding = patentScope.getBinding(expression.arguments[0].name);
|
270
|
+
if (graph.nodes.has(expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) watchArgs.add(expression.arguments[0]);
|
271
|
+
} else traverse$3(expression.arguments[0], { Identifier(path1) {
|
272
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
273
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) watchArgs.add(path1.node);
|
274
|
+
} }, patentScope, node);
|
275
|
+
else if (hookName === "useEffect" && expression.arguments[1].type === "ArrayExpression") traverse$3(expression.arguments[1], { Identifier(path1) {
|
276
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
277
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) watchArgs.add(path1.node);
|
278
|
+
} }, patentScope, node);
|
279
|
+
expression.arguments.forEach((argNode, index) => {
|
280
|
+
if (watchHooks.includes(hookName) && index === 0 && argNode.type === "Identifier") {
|
281
|
+
const _node = nodeCollection.getNode(argNode.name);
|
282
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
283
|
+
else if (_node) _node.info = {
|
284
|
+
..._node?.info,
|
285
|
+
used: new Set([hookName])
|
286
|
+
};
|
287
|
+
return;
|
288
|
+
}
|
289
|
+
if (argNode.type === "Identifier") {
|
290
|
+
const binding = patentScope.getBinding(argNode.name);
|
291
|
+
if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
292
|
+
const _node = nodeCollection.getNode(argNode.name);
|
293
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
294
|
+
else if (_node) _node.info = {
|
295
|
+
..._node?.info,
|
296
|
+
used: new Set([hookName])
|
297
|
+
};
|
298
|
+
}
|
299
|
+
} else traverse$3(argNode, { Identifier(path1) {
|
300
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
301
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
302
|
+
if ([...watchHooks, "useEffect"].includes(hookName) && watchArgs.size > 0) {
|
303
|
+
const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
|
304
|
+
watchArgs.forEach((watchArg) => {
|
305
|
+
if (!watchArgsNames.includes(path1.node.name)) graph.edges.get(watchArg.name)?.add({
|
306
|
+
label: path1.node.name,
|
307
|
+
type: getRelationType(path1)
|
308
|
+
});
|
309
|
+
});
|
310
|
+
}
|
311
|
+
const _node = nodeCollection.getNode(path1.node.name);
|
312
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
313
|
+
else if (_node) _node.info = {
|
314
|
+
..._node?.info,
|
315
|
+
used: new Set([hookName])
|
316
|
+
};
|
317
|
+
}
|
318
|
+
} }, patentScope, node);
|
319
|
+
});
|
320
|
+
}
|
321
|
+
}
|
322
|
+
traverse$3(ast, {
|
323
|
+
FunctionDeclaration(path) {
|
324
|
+
const name = path.node.id?.name;
|
325
|
+
if (name && graph.nodes.has(name)) traverse$3(path.node.body, {
|
326
|
+
Identifier(path1) {
|
327
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
328
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
329
|
+
label: path1.node.name,
|
330
|
+
type: getRelationType(path1)
|
331
|
+
});
|
332
|
+
},
|
333
|
+
MemberExpression(path1) {
|
334
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
335
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
336
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
337
|
+
label: path1.node.property.name,
|
338
|
+
type: getRelationType(path1)
|
339
|
+
});
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}, path.scope, path);
|
343
|
+
},
|
344
|
+
VariableDeclarator(path) {
|
345
|
+
if (path.node.init) {
|
346
|
+
if (path.node.id.type === "ArrayPattern") path.node.id.elements.forEach((element) => {
|
347
|
+
if (element?.type === "Identifier") {
|
348
|
+
const name = element.name;
|
349
|
+
if (name && graph.nodes.has(name) && path.node.init?.type === "CallExpression") traverse$3(path.node.init, {
|
350
|
+
Identifier(path1) {
|
351
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
352
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
353
|
+
label: path1.node.name,
|
354
|
+
type: getRelationType(path1)
|
355
|
+
});
|
356
|
+
},
|
357
|
+
MemberExpression(path1) {
|
358
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
359
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
360
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
361
|
+
label: path1.node.property.name,
|
362
|
+
type: getRelationType(path1)
|
363
|
+
});
|
364
|
+
}
|
365
|
+
}
|
366
|
+
}, path.scope, path);
|
367
|
+
}
|
368
|
+
});
|
369
|
+
else if (path.node.id.type === "ObjectPattern") path.node.id.properties.forEach((property) => {
|
370
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
371
|
+
const name = property.value.name;
|
372
|
+
if (name && graph.nodes.has(name) && path.node.init) traverse$3(path.node.init, {
|
373
|
+
Identifier(path1) {
|
374
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
375
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
376
|
+
label: path1.node.name,
|
377
|
+
type: getRelationType(path1)
|
378
|
+
});
|
379
|
+
},
|
380
|
+
MemberExpression(path1) {
|
381
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
382
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
383
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
384
|
+
label: path1.node.property.name,
|
385
|
+
type: getRelationType(path1)
|
386
|
+
});
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}, path.scope, path);
|
390
|
+
}
|
391
|
+
});
|
392
|
+
else if ([
|
393
|
+
"CallExpression",
|
394
|
+
"ArrowFunctionExpression",
|
395
|
+
"FunctionDeclaration"
|
396
|
+
].includes(path.node.init.type) && path.node.id.type === "Identifier") {
|
397
|
+
if (path.node.init.type === "CallExpression" && path.node.init.callee.type === "Identifier" && [...watchHooks, "watchEffect"].includes(path.node.init.callee.name)) traverseHooks(path.node.init, path.scope);
|
398
|
+
const name = path.node.id?.name;
|
399
|
+
if (name && graph.nodes.has(name)) traverse$3(path.node.init, {
|
400
|
+
Identifier(path1) {
|
401
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
402
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
403
|
+
label: path1.node.name,
|
404
|
+
type: getRelationType(path1)
|
405
|
+
});
|
406
|
+
},
|
407
|
+
MemberExpression(path1) {
|
408
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
409
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
410
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
411
|
+
label: path1.node.property.name,
|
412
|
+
type: getRelationType(path1)
|
413
|
+
});
|
414
|
+
}
|
415
|
+
}
|
416
|
+
}, path.scope, path);
|
417
|
+
} else if (path.node.id.type === "Identifier") {
|
418
|
+
const name = path.node.id.name;
|
419
|
+
if (path.node.init.type === "Identifier") {
|
420
|
+
const binding = path.scope.getBinding(path.node.init.name);
|
421
|
+
if (graph.nodes.has(path.node.init.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
422
|
+
label: path.node.init.name,
|
423
|
+
type: getRelationType(path)
|
424
|
+
});
|
425
|
+
} else traverse$3(path.node.init, { Identifier(path1) {
|
426
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
427
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
428
|
+
label: path1.node.name,
|
429
|
+
type: getRelationType(path1)
|
430
|
+
});
|
431
|
+
} }, path.scope, path);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
},
|
435
|
+
ObjectMethod(path) {
|
436
|
+
if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
|
437
|
+
const name = path.node.key.name;
|
438
|
+
traverse$3(path.node.body, {
|
439
|
+
Identifier(path1) {
|
440
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
441
|
+
if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
442
|
+
label: path1.node.name,
|
443
|
+
type: getRelationType(path1)
|
444
|
+
});
|
445
|
+
},
|
446
|
+
MemberExpression(path1) {
|
447
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
448
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
449
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
450
|
+
label: path1.node.property.name,
|
451
|
+
type: getRelationType(path1)
|
452
|
+
});
|
453
|
+
}
|
454
|
+
}
|
455
|
+
}, path.scope, path);
|
456
|
+
}
|
457
|
+
},
|
458
|
+
ObjectProperty(path) {
|
459
|
+
if (path.node.key.type === "Identifier" && graph.nodes.has(path.node.key.name)) {
|
460
|
+
const name = path.node.key.name;
|
461
|
+
traverse$3(path.node.value, { MemberExpression(path1) {
|
462
|
+
if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
|
463
|
+
const binding = path1.scope.getBinding(path1.node.object.name);
|
464
|
+
if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) graph.edges.get(name)?.add({
|
465
|
+
label: path1.node.property.name,
|
466
|
+
type: getRelationType(path1)
|
467
|
+
});
|
468
|
+
}
|
469
|
+
} }, path.scope, path);
|
470
|
+
}
|
471
|
+
},
|
472
|
+
ExpressionStatement(path) {
|
473
|
+
if (path.type === "ExpressionStatement" && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "Identifier") {
|
474
|
+
const name = path.node.expression.callee.name;
|
475
|
+
if (graph.nodes.has(name) && path.scope.block.type === "Program") {
|
476
|
+
const _node = nodeCollection.getNode(name);
|
477
|
+
if (_node?.info?.used) _node?.info?.used?.add("Call Expression");
|
478
|
+
else if (_node) _node.info = {
|
479
|
+
..._node?.info,
|
480
|
+
used: new Set(["Call Expression"])
|
481
|
+
};
|
482
|
+
} else traverseHooks(path.node.expression, path.scope);
|
483
|
+
}
|
484
|
+
if (path.type === "ExpressionStatement" && path.node.expression.type === "AssignmentExpression" && path.node.expression.right.type === "CallExpression" && path.node.expression.right.callee.type === "Identifier") traverseHooks(path.node.expression.right, path.scope);
|
485
|
+
}
|
486
|
+
}, parentScope, parentPath);
|
487
|
+
return {
|
488
|
+
graph,
|
489
|
+
nodeCollection
|
490
|
+
};
|
713
491
|
}
|
714
|
-
function analyze(content, lineOffset = 0, jsx = false) {
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
492
|
+
function analyze$1(content, lineOffset = 0, jsx = false) {
|
493
|
+
const ast = babelParse(content, {
|
494
|
+
sourceType: "module",
|
495
|
+
plugins: ["typescript", ...jsx ? ["jsx"] : []]
|
496
|
+
});
|
497
|
+
const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
|
498
|
+
return nodeCollection.map(graph);
|
721
499
|
}
|
722
500
|
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
501
|
+
//#endregion
|
502
|
+
//#region src/analyze/options.ts
|
503
|
+
const traverse$2 = _traverse.default?.default || _traverse.default || _traverse;
|
504
|
+
const vueLifeCycleHooks = [
|
505
|
+
"beforeCreate",
|
506
|
+
"created",
|
507
|
+
"beforeMount",
|
508
|
+
"mounted",
|
509
|
+
"beforeUpdate",
|
510
|
+
"updated",
|
511
|
+
"beforeDestroy",
|
512
|
+
"destroyed",
|
513
|
+
"activated",
|
514
|
+
"deactivated",
|
515
|
+
"errorCaptured",
|
516
|
+
"renderTracked",
|
517
|
+
"renderTriggered",
|
518
|
+
"provide"
|
740
519
|
];
|
741
|
-
function
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
traverse2(prop, {
|
1042
|
-
MemberExpression(path2) {
|
1043
|
-
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
1044
|
-
graph.edges.get(name)?.add({
|
1045
|
-
label: path2.node.property.name,
|
1046
|
-
type: getRelationType(path2)
|
1047
|
-
});
|
1048
|
-
}
|
1049
|
-
}
|
1050
|
-
}, path1.scope, path1);
|
1051
|
-
}
|
1052
|
-
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.value.type === "ObjectExpression") {
|
1053
|
-
const name = prop.key.name;
|
1054
|
-
prop.value.properties.forEach((prop1) => {
|
1055
|
-
if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
|
1056
|
-
traverse2(prop1, {
|
1057
|
-
MemberExpression(path2) {
|
1058
|
-
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
1059
|
-
graph.edges.get(name)?.add({
|
1060
|
-
label: path2.node.property.name,
|
1061
|
-
type: getRelationType(path2)
|
1062
|
-
});
|
1063
|
-
}
|
1064
|
-
}
|
1065
|
-
}, path1.scope, path1);
|
1066
|
-
}
|
1067
|
-
});
|
1068
|
-
}
|
1069
|
-
});
|
1070
|
-
}
|
1071
|
-
}
|
1072
|
-
if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
|
1073
|
-
const methodsNode = path1.node;
|
1074
|
-
if (methodsNode.value.type === "ObjectExpression") {
|
1075
|
-
methodsNode.value.properties.forEach((prop) => {
|
1076
|
-
if ((prop.type === "ObjectMethod" || prop.type === "ObjectProperty") && prop.key.type === "Identifier") {
|
1077
|
-
const name = prop.key.name;
|
1078
|
-
traverse2(prop, {
|
1079
|
-
MemberExpression(path2) {
|
1080
|
-
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
1081
|
-
graph.edges.get(name)?.add({
|
1082
|
-
label: path2.node.property.name,
|
1083
|
-
type: getRelationType(path2)
|
1084
|
-
});
|
1085
|
-
}
|
1086
|
-
}
|
1087
|
-
}, path1.scope, path1);
|
1088
|
-
}
|
1089
|
-
});
|
1090
|
-
}
|
1091
|
-
}
|
1092
|
-
if (path1.node.key.type === "Identifier" && [...watchHooks, ...vueLifeCycleHooks].includes(path1.node.key.name)) {
|
1093
|
-
const hookName = path1.node.key.name;
|
1094
|
-
if (watchHooks.includes(hookName) && path1.node.value.type === "ObjectExpression") {
|
1095
|
-
path1.node.value.properties.forEach((prop) => {
|
1096
|
-
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
|
1097
|
-
const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";
|
1098
|
-
const watchArg = tNodes.get(keyName);
|
1099
|
-
const _node = nodeCollection.getNode(keyName);
|
1100
|
-
if (_node?.info?.used) {
|
1101
|
-
_node?.info?.used?.add(hookName);
|
1102
|
-
} else if (_node) {
|
1103
|
-
_node.info = {
|
1104
|
-
..._node?.info,
|
1105
|
-
used: /* @__PURE__ */ new Set([hookName])
|
1106
|
-
};
|
1107
|
-
}
|
1108
|
-
traverse2(path1.node.value, {
|
1109
|
-
MemberExpression(path2) {
|
1110
|
-
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
1111
|
-
if (watchArg && watchArg.name !== path2.node.property.name) {
|
1112
|
-
graph.edges.get(watchArg.name)?.add({
|
1113
|
-
label: path2.node.property.name,
|
1114
|
-
type: getRelationType(path2)
|
1115
|
-
});
|
1116
|
-
}
|
1117
|
-
}
|
1118
|
-
}
|
1119
|
-
}, path1.scope, path1);
|
1120
|
-
}
|
1121
|
-
});
|
1122
|
-
} else {
|
1123
|
-
traverse2(path1.node.value, {
|
1124
|
-
MemberExpression(path2) {
|
1125
|
-
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
1126
|
-
const _node = nodeCollection.getNode(path2.node.property.name);
|
1127
|
-
if (_node?.info?.used) {
|
1128
|
-
_node?.info?.used?.add(hookName);
|
1129
|
-
} else if (_node) {
|
1130
|
-
_node.info = {
|
1131
|
-
..._node?.info,
|
1132
|
-
used: /* @__PURE__ */ new Set([hookName])
|
1133
|
-
};
|
1134
|
-
}
|
1135
|
-
}
|
1136
|
-
}
|
1137
|
-
}, path1.scope, path1);
|
1138
|
-
}
|
1139
|
-
}
|
1140
|
-
}
|
1141
|
-
}
|
1142
|
-
}, path.scope, path);
|
1143
|
-
}
|
1144
|
-
traverse2(ast, {
|
1145
|
-
ExportDefaultDeclaration(path) {
|
1146
|
-
if (path.node.declaration.type === "ObjectExpression") {
|
1147
|
-
process(path.node.declaration, path);
|
1148
|
-
} else if (path.node.declaration.type === "CallExpression" && path.node.declaration.callee.type === "Identifier" && path.node.declaration.callee.name === "defineComponent" && path.node.declaration.arguments[0].type === "ObjectExpression") {
|
1149
|
-
process(path.node.declaration.arguments[0], path);
|
1150
|
-
}
|
1151
|
-
}
|
1152
|
-
});
|
1153
|
-
return {
|
1154
|
-
graph: nodeCollection.map(graph),
|
1155
|
-
nodesUsedInTemplate
|
1156
|
-
};
|
520
|
+
function analyze(content, lineOffset = 0, jsx = false) {
|
521
|
+
const ast = babelParse(content, {
|
522
|
+
sourceType: "module",
|
523
|
+
plugins: ["typescript", ...jsx ? ["jsx"] : []]
|
524
|
+
});
|
525
|
+
let nodeCollection = new NodeCollection(lineOffset);
|
526
|
+
const tNodes = /* @__PURE__ */ new Map();
|
527
|
+
const graph = {
|
528
|
+
nodes: /* @__PURE__ */ new Set(),
|
529
|
+
edges: /* @__PURE__ */ new Map()
|
530
|
+
};
|
531
|
+
/** used in render block or setup return */
|
532
|
+
const nodesUsedInTemplate = /* @__PURE__ */ new Set();
|
533
|
+
function process(node, path) {
|
534
|
+
traverse$2(node, {
|
535
|
+
ObjectProperty(path1) {
|
536
|
+
if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
|
537
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
|
538
|
+
const dataNode = path1.node.value;
|
539
|
+
traverse$2(dataNode, { ReturnStatement(path2) {
|
540
|
+
if (path2.parent === dataNode.body) {
|
541
|
+
if (path2.node.argument?.type === "ObjectExpression") path2.node.argument.properties.forEach((prop) => {
|
542
|
+
if (prop.type === "ObjectProperty") {
|
543
|
+
if (prop.key.type === "Identifier") {
|
544
|
+
const name = prop.key.name;
|
545
|
+
graph.nodes.add(name);
|
546
|
+
tNodes.set(name, prop.key);
|
547
|
+
nodeCollection.addNode(name, prop, { comment: getComment(prop) });
|
548
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
549
|
+
}
|
550
|
+
}
|
551
|
+
});
|
552
|
+
}
|
553
|
+
} }, path1.scope, path1);
|
554
|
+
}
|
555
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
|
556
|
+
const computedNode = path1.node;
|
557
|
+
if (computedNode.value.type === "ObjectExpression") computedNode.value.properties.forEach((prop) => {
|
558
|
+
if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
|
559
|
+
if (prop.key.type === "Identifier") {
|
560
|
+
const name = prop.key.name;
|
561
|
+
graph.nodes.add(name);
|
562
|
+
tNodes.set(name, prop.key);
|
563
|
+
nodeCollection.addNode(name, prop, {
|
564
|
+
isComputed: true,
|
565
|
+
comment: getComment(prop)
|
566
|
+
});
|
567
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
568
|
+
}
|
569
|
+
}
|
570
|
+
});
|
571
|
+
}
|
572
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
|
573
|
+
const methodsNode = path1.node;
|
574
|
+
if (methodsNode.value.type === "ObjectExpression") methodsNode.value.properties.forEach((prop) => {
|
575
|
+
if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
|
576
|
+
if (prop.key.type === "Identifier") {
|
577
|
+
const name = prop.key.name;
|
578
|
+
graph.nodes.add(name);
|
579
|
+
tNodes.set(name, prop.key);
|
580
|
+
nodeCollection.addNode(name, prop, {
|
581
|
+
isMethod: true,
|
582
|
+
comment: getComment(prop)
|
583
|
+
});
|
584
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
585
|
+
}
|
586
|
+
}
|
587
|
+
});
|
588
|
+
}
|
589
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "render" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) traverse$2(path1.node.value, { ReturnStatement(path2) {
|
590
|
+
const templateNode = path2.node;
|
591
|
+
traverse$2(templateNode, { MemberExpression(path3) {
|
592
|
+
if (path3.node.object && path3.node.object.type === "ThisExpression") {
|
593
|
+
if (path3.node.property && path3.node.property.type === "Identifier") nodesUsedInTemplate.add(path3.node.property.name);
|
594
|
+
}
|
595
|
+
} }, path2.scope, path2);
|
596
|
+
} }, path1.scope, path1);
|
597
|
+
}
|
598
|
+
},
|
599
|
+
ObjectMethod(path1) {
|
600
|
+
if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
|
601
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
|
602
|
+
const setupNode = path1.node;
|
603
|
+
const spread = [];
|
604
|
+
traverse$2(setupNode, { ReturnStatement(path2) {
|
605
|
+
if (path2.node.argument?.type === "ObjectExpression") {
|
606
|
+
const returnNode = path2.node.argument;
|
607
|
+
traverse$2(returnNode, { SpreadElement(path3) {
|
608
|
+
if (path3.node.argument.type === "CallExpression" && path3.node.argument.callee.type === "Identifier" && path3.node.argument.callee.name === "toRefs" && path3.node.argument.arguments[0].type === "Identifier") spread.push(path3.node.argument.arguments[0].name);
|
609
|
+
else if (path3.node.argument.type === "Identifier") spread.push(path3.node.argument.name);
|
610
|
+
} }, path2.scope, path2);
|
611
|
+
}
|
612
|
+
if (path2.node.argument?.type === "FunctionExpression" || path2.node.argument?.type === "ArrowFunctionExpression") {
|
613
|
+
const templateNode = path2.node.argument.body;
|
614
|
+
traverse$2(templateNode, {
|
615
|
+
Identifier(path3) {
|
616
|
+
const binding = path3.scope.getBinding(path3.node.name);
|
617
|
+
if (binding?.scope === path1.scope) nodesUsedInTemplate.add(path3.node.name);
|
618
|
+
},
|
619
|
+
JSXIdentifier(path3) {
|
620
|
+
const binding = path3.scope.getBinding(path3.node.name);
|
621
|
+
if (binding?.scope === path1.scope) nodesUsedInTemplate.add(path3.node.name);
|
622
|
+
}
|
623
|
+
}, path2.scope, path2);
|
624
|
+
}
|
625
|
+
} }, path1.scope, path1);
|
626
|
+
const { graph: { nodes: tempNodes, edges: tempEdges, spread: tempSpread }, nodeCollection: tempNodeCollection } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
|
627
|
+
traverse$2(setupNode, { ReturnStatement(path2) {
|
628
|
+
if (path2.scope !== path1.scope) return;
|
629
|
+
if (path2.node.argument?.type === "ObjectExpression") {
|
630
|
+
const returnNode = path2.node.argument;
|
631
|
+
traverse$2(returnNode, {
|
632
|
+
ObjectProperty(path3) {
|
633
|
+
if (path3.parent === returnNode) {
|
634
|
+
if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier" && tempNodes.has(path3.node.value.name)) {
|
635
|
+
const valName = path3.node.value.name;
|
636
|
+
if (!graph.nodes.has(valName)) {
|
637
|
+
graph.nodes.add(valName);
|
638
|
+
tNodes.set(valName, path3.node.value);
|
639
|
+
nodeCollection.addTypedNode(valName, tempNodeCollection.nodes.get(valName));
|
640
|
+
}
|
641
|
+
if (!graph.edges.has(valName)) graph.edges.set(valName, new Set([...Array.from(tempEdges.get(valName) || /* @__PURE__ */ new Set())]));
|
642
|
+
const name = path3.node.key.name;
|
643
|
+
if (name !== valName) {
|
644
|
+
graph.nodes.add(name);
|
645
|
+
tNodes.set(name, path3.node.key);
|
646
|
+
nodeCollection.addNode(name, path3.node.key, { comment: getComment(path3.node) });
|
647
|
+
graph.edges.set(name, new Set([{
|
648
|
+
label: valName,
|
649
|
+
type: getRelationType(path3)
|
650
|
+
}]));
|
651
|
+
}
|
652
|
+
}
|
653
|
+
}
|
654
|
+
},
|
655
|
+
SpreadElement(path3) {
|
656
|
+
if (path3.node.argument.type === "CallExpression" && path3.node.argument.callee.type === "Identifier" && path3.node.argument.callee.name === "toRefs" && path3.node.argument.arguments[0].type === "Identifier" && tempSpread.get(path3.node.argument.arguments[0].name)) tempSpread.get(path3.node.argument.arguments[0].name)?.forEach((name) => {
|
657
|
+
graph.nodes.add(name);
|
658
|
+
tNodes.set(name, path3.node.argument.arguments[0]);
|
659
|
+
nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
|
660
|
+
if (!graph.edges.get(name)) {
|
661
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
662
|
+
tempEdges.get(name)?.forEach((edge) => {
|
663
|
+
graph.edges.get(name)?.add(edge);
|
664
|
+
});
|
665
|
+
}
|
666
|
+
});
|
667
|
+
else if (path3.node.argument.type === "Identifier" && tempSpread.get(path3.node.argument.name)) tempSpread.get(path3.node.argument.name)?.forEach((name) => {
|
668
|
+
graph.nodes.add(name);
|
669
|
+
tNodes.set(name, path3.node.argument);
|
670
|
+
nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
|
671
|
+
if (!graph.edges.get(name)) {
|
672
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
673
|
+
tempEdges.get(name)?.forEach((edge) => {
|
674
|
+
graph.edges.get(name)?.add(edge);
|
675
|
+
});
|
676
|
+
}
|
677
|
+
});
|
678
|
+
}
|
679
|
+
}, path2.scope, path2);
|
680
|
+
} else {
|
681
|
+
graph.edges = tempEdges;
|
682
|
+
graph.nodes = tempNodes;
|
683
|
+
nodeCollection = tempNodeCollection;
|
684
|
+
}
|
685
|
+
} }, path1.scope, path1);
|
686
|
+
}
|
687
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
|
688
|
+
const dataNode = path1.node;
|
689
|
+
traverse$2(dataNode, { ReturnStatement(path2) {
|
690
|
+
if (path2.parent === dataNode.body) {
|
691
|
+
if (path2.node.argument?.type === "ObjectExpression") path2.node.argument.properties.forEach((prop) => {
|
692
|
+
if (prop.type === "ObjectProperty") {
|
693
|
+
if (prop.key.type === "Identifier") {
|
694
|
+
const name = prop.key.name;
|
695
|
+
graph.nodes.add(name);
|
696
|
+
tNodes.set(name, prop.key);
|
697
|
+
nodeCollection.addNode(name, prop, { comment: getComment(prop) });
|
698
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
699
|
+
}
|
700
|
+
}
|
701
|
+
});
|
702
|
+
}
|
703
|
+
} }, path1.scope, path1);
|
704
|
+
}
|
705
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "render") traverse$2(path1.node, { ReturnStatement(path2) {
|
706
|
+
const templateNode = path2.node;
|
707
|
+
traverse$2(templateNode, { MemberExpression(path3) {
|
708
|
+
if (path3.node.object && path3.node.object.type === "ThisExpression") {
|
709
|
+
if (path3.node.property && path3.node.property.type === "Identifier") nodesUsedInTemplate.add(path3.node.property.name);
|
710
|
+
}
|
711
|
+
} }, path2.scope, path2);
|
712
|
+
} }, path1.scope, path1);
|
713
|
+
}
|
714
|
+
}
|
715
|
+
}, path.scope, path);
|
716
|
+
traverse$2(node, {
|
717
|
+
ObjectMethod(path1) {
|
718
|
+
if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
|
719
|
+
if (path1.node.key.type === "Identifier" && vueLifeCycleHooks.includes(path1.node.key.name)) {
|
720
|
+
const hookName = path1.node.key.name;
|
721
|
+
traverse$2(path1.node.body, { MemberExpression(path2) {
|
722
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
723
|
+
const _node = nodeCollection.getNode(path2.node.property.name);
|
724
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
725
|
+
else if (_node) _node.info = {
|
726
|
+
..._node?.info,
|
727
|
+
used: new Set([hookName])
|
728
|
+
};
|
729
|
+
}
|
730
|
+
} }, path1.scope, path1);
|
731
|
+
}
|
732
|
+
}
|
733
|
+
},
|
734
|
+
ObjectProperty(path1) {
|
735
|
+
if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
|
736
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
|
737
|
+
const computedNode = path1.node;
|
738
|
+
if (computedNode.value.type === "ObjectExpression") computedNode.value.properties.forEach((prop) => {
|
739
|
+
if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
|
740
|
+
const name = prop.key.name;
|
741
|
+
traverse$2(prop, { MemberExpression(path2) {
|
742
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") graph.edges.get(name)?.add({
|
743
|
+
label: path2.node.property.name,
|
744
|
+
type: getRelationType(path2)
|
745
|
+
});
|
746
|
+
} }, path1.scope, path1);
|
747
|
+
}
|
748
|
+
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.value.type === "ObjectExpression") {
|
749
|
+
const name = prop.key.name;
|
750
|
+
prop.value.properties.forEach((prop1) => {
|
751
|
+
if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") traverse$2(prop1, { MemberExpression(path2) {
|
752
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") graph.edges.get(name)?.add({
|
753
|
+
label: path2.node.property.name,
|
754
|
+
type: getRelationType(path2)
|
755
|
+
});
|
756
|
+
} }, path1.scope, path1);
|
757
|
+
});
|
758
|
+
}
|
759
|
+
});
|
760
|
+
}
|
761
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
|
762
|
+
const methodsNode = path1.node;
|
763
|
+
if (methodsNode.value.type === "ObjectExpression") methodsNode.value.properties.forEach((prop) => {
|
764
|
+
if ((prop.type === "ObjectMethod" || prop.type === "ObjectProperty") && prop.key.type === "Identifier") {
|
765
|
+
const name = prop.key.name;
|
766
|
+
traverse$2(prop, { MemberExpression(path2) {
|
767
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") graph.edges.get(name)?.add({
|
768
|
+
label: path2.node.property.name,
|
769
|
+
type: getRelationType(path2)
|
770
|
+
});
|
771
|
+
} }, path1.scope, path1);
|
772
|
+
}
|
773
|
+
});
|
774
|
+
}
|
775
|
+
if (path1.node.key.type === "Identifier" && [...watchHooks, ...vueLifeCycleHooks].includes(path1.node.key.name)) {
|
776
|
+
const hookName = path1.node.key.name;
|
777
|
+
if (watchHooks.includes(hookName) && path1.node.value.type === "ObjectExpression") path1.node.value.properties.forEach((prop) => {
|
778
|
+
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && (prop.key.type === "Identifier" || prop.key.type === "StringLiteral")) {
|
779
|
+
const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "StringLiteral" ? prop.key.value.split(".")[0] : "";
|
780
|
+
const watchArg = tNodes.get(keyName);
|
781
|
+
const _node = nodeCollection.getNode(keyName);
|
782
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
783
|
+
else if (_node) _node.info = {
|
784
|
+
..._node?.info,
|
785
|
+
used: new Set([hookName])
|
786
|
+
};
|
787
|
+
traverse$2(path1.node.value, { MemberExpression(path2) {
|
788
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
789
|
+
if (watchArg && watchArg.name !== path2.node.property.name) graph.edges.get(watchArg.name)?.add({
|
790
|
+
label: path2.node.property.name,
|
791
|
+
type: getRelationType(path2)
|
792
|
+
});
|
793
|
+
}
|
794
|
+
} }, path1.scope, path1);
|
795
|
+
}
|
796
|
+
});
|
797
|
+
else traverse$2(path1.node.value, { MemberExpression(path2) {
|
798
|
+
if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
|
799
|
+
const _node = nodeCollection.getNode(path2.node.property.name);
|
800
|
+
if (_node?.info?.used) _node?.info?.used?.add(hookName);
|
801
|
+
else if (_node) _node.info = {
|
802
|
+
..._node?.info,
|
803
|
+
used: new Set([hookName])
|
804
|
+
};
|
805
|
+
}
|
806
|
+
} }, path1.scope, path1);
|
807
|
+
}
|
808
|
+
}
|
809
|
+
}
|
810
|
+
}, path.scope, path);
|
811
|
+
}
|
812
|
+
traverse$2(ast, { ExportDefaultDeclaration(path) {
|
813
|
+
if (path.node.declaration.type === "ObjectExpression") process(path.node.declaration, path);
|
814
|
+
else if (path.node.declaration.type === "CallExpression" && path.node.declaration.callee.type === "Identifier" && path.node.declaration.callee.name === "defineComponent" && path.node.declaration.arguments[0].type === "ObjectExpression") process(path.node.declaration.arguments[0], path);
|
815
|
+
} });
|
816
|
+
return {
|
817
|
+
graph: nodeCollection.map(graph),
|
818
|
+
nodesUsedInTemplate
|
819
|
+
};
|
1157
820
|
}
|
1158
821
|
|
1159
|
-
|
822
|
+
//#endregion
|
823
|
+
//#region src/analyze/style.ts
|
824
|
+
var LexerState = /* @__PURE__ */ function(LexerState$1) {
|
825
|
+
LexerState$1[LexerState$1["inParens"] = 0] = "inParens";
|
826
|
+
LexerState$1[LexerState$1["inSingleQuoteString"] = 1] = "inSingleQuoteString";
|
827
|
+
LexerState$1[LexerState$1["inDoubleQuoteString"] = 2] = "inDoubleQuoteString";
|
828
|
+
return LexerState$1;
|
829
|
+
}(LexerState || {});
|
1160
830
|
function lexBinding(content, start) {
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
if (char === "'") {
|
1183
|
-
state = 0 /* inParens */;
|
1184
|
-
}
|
1185
|
-
break;
|
1186
|
-
case 2 /* inDoubleQuoteString */:
|
1187
|
-
if (char === '"') {
|
1188
|
-
state = 0 /* inParens */;
|
1189
|
-
}
|
1190
|
-
break;
|
1191
|
-
}
|
1192
|
-
}
|
1193
|
-
return null;
|
831
|
+
let state = LexerState.inParens;
|
832
|
+
let parenDepth = 0;
|
833
|
+
for (let i = start; i < content.length; i++) {
|
834
|
+
const char = content.charAt(i);
|
835
|
+
switch (state) {
|
836
|
+
case LexerState.inParens:
|
837
|
+
if (char === "'") state = LexerState.inSingleQuoteString;
|
838
|
+
else if (char === "\"") state = LexerState.inDoubleQuoteString;
|
839
|
+
else if (char === "(") parenDepth++;
|
840
|
+
else if (char === ")") if (parenDepth > 0) parenDepth--;
|
841
|
+
else return i;
|
842
|
+
break;
|
843
|
+
case LexerState.inSingleQuoteString:
|
844
|
+
if (char === "'") state = LexerState.inParens;
|
845
|
+
break;
|
846
|
+
case LexerState.inDoubleQuoteString:
|
847
|
+
if (char === "\"") state = LexerState.inParens;
|
848
|
+
break;
|
849
|
+
}
|
850
|
+
}
|
851
|
+
return null;
|
1194
852
|
}
|
1195
853
|
function normalizeExpression(exp) {
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
}
|
1200
|
-
return exp;
|
854
|
+
exp = exp.trim();
|
855
|
+
if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === "\"" && exp[exp.length - 1] === "\"") return exp.slice(1, -1);
|
856
|
+
return exp;
|
1201
857
|
}
|
1202
|
-
|
1203
|
-
function
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
858
|
+
const vBindRE = /v-bind\s*\(/g;
|
859
|
+
function analyze$2(styles) {
|
860
|
+
const nodes = /* @__PURE__ */ new Set();
|
861
|
+
styles.forEach((style) => {
|
862
|
+
let match;
|
863
|
+
const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
|
864
|
+
while (match = vBindRE.exec(content)) {
|
865
|
+
const start = match.index + match[0].length;
|
866
|
+
const end = lexBinding(content, start);
|
867
|
+
if (end !== null) {
|
868
|
+
const variable = normalizeExpression(content.slice(start, end));
|
869
|
+
nodes.add(variable);
|
870
|
+
}
|
871
|
+
}
|
872
|
+
});
|
873
|
+
return nodes;
|
1218
874
|
}
|
1219
875
|
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
nodes.add(name);
|
1262
|
-
}
|
1263
|
-
}
|
1264
|
-
}
|
1265
|
-
}
|
1266
|
-
});
|
1267
|
-
return nodes;
|
876
|
+
//#endregion
|
877
|
+
//#region src/analyze/template.ts
|
878
|
+
const traverse$1 = _traverse.default?.default || _traverse.default || _traverse;
|
879
|
+
function analyze$3(content) {
|
880
|
+
const id = "template";
|
881
|
+
const { code } = compileTemplate({
|
882
|
+
id,
|
883
|
+
source: content,
|
884
|
+
filename: `${id}.js`
|
885
|
+
});
|
886
|
+
const ast = babelParse(code, {
|
887
|
+
sourceType: "module",
|
888
|
+
plugins: ["typescript"]
|
889
|
+
});
|
890
|
+
const nodes = /* @__PURE__ */ new Set();
|
891
|
+
traverse$1(ast, {
|
892
|
+
MemberExpression(path) {
|
893
|
+
if (path.type === "MemberExpression") {
|
894
|
+
if (path.node.object && path.node.object.type === "Identifier" && path.node.object.name === "_ctx") {
|
895
|
+
if (path.node.property && path.node.property.type === "Identifier") nodes.add(path.node.property.name);
|
896
|
+
}
|
897
|
+
}
|
898
|
+
},
|
899
|
+
ObjectProperty(path) {
|
900
|
+
if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
|
901
|
+
if (path.node.value.type === "StringLiteral") {
|
902
|
+
const name = path.node.value.value;
|
903
|
+
if (name) nodes.add(name);
|
904
|
+
}
|
905
|
+
}
|
906
|
+
},
|
907
|
+
CallExpression(path) {
|
908
|
+
if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
|
909
|
+
if (path.node.arguments[0].type === "StringLiteral") {
|
910
|
+
const name = path.node.arguments[0].value;
|
911
|
+
if (name) nodes.add(name);
|
912
|
+
}
|
913
|
+
}
|
914
|
+
}
|
915
|
+
});
|
916
|
+
return nodes;
|
1268
917
|
}
|
1269
918
|
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
919
|
+
//#endregion
|
920
|
+
//#region src/utils/traverse.ts
|
921
|
+
const traverse = _traverse.default?.default || _traverse.default || _traverse;
|
922
|
+
/**
|
923
|
+
* 递归遍历如下结构:
|
924
|
+
* let { loc, loc: locd, loc: { start, end }, loc: { start: { line: { deep } }} } = node;
|
925
|
+
* 解出 loc, locd, start, end, deep
|
926
|
+
*/
|
1276
927
|
function rescureObjectPattern({ node, rootScope, res, parentScope, parentPath }) {
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
if (_scope && _scope === rootScope) {
|
1300
|
-
res.push(path1.node.argument);
|
1301
|
-
}
|
1302
|
-
}
|
1303
|
-
}
|
1304
|
-
}, parentScope, parentPath);
|
928
|
+
traverse(node, {
|
929
|
+
ObjectProperty(path1) {
|
930
|
+
if (path1.node.type === "ObjectProperty" && path1.node.key.type === "Identifier" && path1.node.value.type === "Identifier") {
|
931
|
+
const name = path1.node.value.name;
|
932
|
+
const _scope = path1.scope.getBinding(name)?.scope;
|
933
|
+
if (_scope && _scope === rootScope) res.push(path1.node.value);
|
934
|
+
} else if (path1.node.type === "ObjectProperty" && path1.node.key.type === "Identifier" && path1.node.value.type === "ObjectPattern") rescureObjectPattern({
|
935
|
+
node: path1.node.value,
|
936
|
+
rootScope,
|
937
|
+
res,
|
938
|
+
parentScope: path1.scope,
|
939
|
+
parentPath: path1
|
940
|
+
});
|
941
|
+
},
|
942
|
+
RestElement(path1) {
|
943
|
+
if (path1.node.argument.type === "Identifier") {
|
944
|
+
const name = path1.node.argument.name;
|
945
|
+
const _scope = path1.scope.getBinding(name)?.scope;
|
946
|
+
if (_scope && _scope === rootScope) res.push(path1.node.argument);
|
947
|
+
}
|
948
|
+
}
|
949
|
+
}, parentScope, parentPath);
|
1305
950
|
}
|
951
|
+
/**
|
952
|
+
* 递归遍历如下结构:
|
953
|
+
* let [foo, [bar, baz]] = [1, [[2], 3]];
|
954
|
+
* 解出 foo, bar, baz
|
955
|
+
*/
|
1306
956
|
function rescureArrayPattern({ node, rootScope, res, parentScope, parentPath }) {
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
});
|
1326
|
-
}
|
1327
|
-
}
|
1328
|
-
}, parentScope, parentPath);
|
957
|
+
traverse(node, {
|
958
|
+
Identifier(path1) {
|
959
|
+
if (path1.node.type === "Identifier") {
|
960
|
+
const name = path1.node.name;
|
961
|
+
const _scope = path1.scope.getBinding(name)?.scope;
|
962
|
+
if (_scope && _scope === rootScope) res.push(path1.node);
|
963
|
+
}
|
964
|
+
},
|
965
|
+
ArrayPattern(path1) {
|
966
|
+
if (path1.node.type === "ArrayPattern") rescureArrayPattern({
|
967
|
+
node: path1.node,
|
968
|
+
rootScope,
|
969
|
+
res,
|
970
|
+
parentScope: path1.scope,
|
971
|
+
parentPath: path1
|
972
|
+
});
|
973
|
+
}
|
974
|
+
}, parentScope, parentPath);
|
1329
975
|
}
|
1330
|
-
function parseNodeIdentifierPattern({
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
});
|
1345
|
-
} else {
|
1346
|
-
cb?.({
|
1347
|
-
name: path.node.id.name,
|
1348
|
-
node: path.node,
|
1349
|
-
path,
|
1350
|
-
scope: rootScope
|
1351
|
-
});
|
1352
|
-
}
|
976
|
+
function parseNodeIdentifierPattern({ path, rootScope, cb }) {
|
977
|
+
if (path.node.id.type !== "Identifier") return;
|
978
|
+
if (path.node.init?.type === "ArrowFunctionExpression" || path.node.init?.type === "FunctionExpression") cb?.({
|
979
|
+
name: path.node.id.name,
|
980
|
+
node: path.node,
|
981
|
+
path,
|
982
|
+
scope: rootScope
|
983
|
+
});
|
984
|
+
else cb?.({
|
985
|
+
name: path.node.id.name,
|
986
|
+
node: path.node,
|
987
|
+
path,
|
988
|
+
scope: rootScope
|
989
|
+
});
|
1353
990
|
}
|
1354
991
|
function parseNodeObjectPattern({ path, rootScope, cb }) {
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
path,
|
1393
|
-
scope: rootScope
|
1394
|
-
}));
|
1395
|
-
}
|
1396
|
-
});
|
992
|
+
if (path.node.id.type !== "ObjectPattern") return;
|
993
|
+
path.node.id.properties.forEach((property) => {
|
994
|
+
if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "Identifier") cb?.({
|
995
|
+
name: property.value.name,
|
996
|
+
node: property,
|
997
|
+
path,
|
998
|
+
scope: rootScope
|
999
|
+
});
|
1000
|
+
else if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "AssignmentPattern") cb?.({
|
1001
|
+
name: property.key.name,
|
1002
|
+
node: property,
|
1003
|
+
path,
|
1004
|
+
scope: rootScope
|
1005
|
+
});
|
1006
|
+
else if (property.type === "RestElement" && property.argument.type === "Identifier") cb?.({
|
1007
|
+
name: property.argument.name,
|
1008
|
+
node: property,
|
1009
|
+
path,
|
1010
|
+
scope: rootScope
|
1011
|
+
});
|
1012
|
+
else if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "ObjectPattern") {
|
1013
|
+
const res = [];
|
1014
|
+
rescureObjectPattern({
|
1015
|
+
node: property.value,
|
1016
|
+
rootScope,
|
1017
|
+
res,
|
1018
|
+
parentScope: path.scope,
|
1019
|
+
parentPath: path
|
1020
|
+
});
|
1021
|
+
res.forEach((r) => cb?.({
|
1022
|
+
name: r.name,
|
1023
|
+
node: r,
|
1024
|
+
path,
|
1025
|
+
scope: rootScope
|
1026
|
+
}));
|
1027
|
+
}
|
1028
|
+
});
|
1397
1029
|
}
|
1398
1030
|
function parseNodeArrayPattern({ path, rootScope, cb }) {
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
node: ele,
|
1439
|
-
path,
|
1440
|
-
scope: rootScope
|
1441
|
-
});
|
1442
|
-
}
|
1443
|
-
}
|
1444
|
-
});
|
1031
|
+
if (path.node.id.type !== "ArrayPattern") return;
|
1032
|
+
path.node.id.elements.forEach((ele) => {
|
1033
|
+
if (ele?.type === "Identifier") cb?.({
|
1034
|
+
name: ele.name,
|
1035
|
+
node: ele,
|
1036
|
+
path,
|
1037
|
+
scope: rootScope
|
1038
|
+
});
|
1039
|
+
else if (ele?.type === "ArrayPattern") {
|
1040
|
+
const res = [];
|
1041
|
+
rescureArrayPattern({
|
1042
|
+
node: ele,
|
1043
|
+
rootScope,
|
1044
|
+
res,
|
1045
|
+
parentScope: path.scope,
|
1046
|
+
parentPath: path
|
1047
|
+
});
|
1048
|
+
res.forEach((r) => cb?.({
|
1049
|
+
name: r.name,
|
1050
|
+
node: r,
|
1051
|
+
path,
|
1052
|
+
scope: rootScope
|
1053
|
+
}));
|
1054
|
+
} else if (ele?.type === "AssignmentPattern") {
|
1055
|
+
if (ele.left.type === "Identifier") cb?.({
|
1056
|
+
name: ele.left.name,
|
1057
|
+
node: ele,
|
1058
|
+
path,
|
1059
|
+
scope: rootScope
|
1060
|
+
});
|
1061
|
+
} else if (ele?.type === "RestElement") {
|
1062
|
+
if (ele.argument.type === "Identifier") cb?.({
|
1063
|
+
name: ele.argument.name,
|
1064
|
+
node: ele,
|
1065
|
+
path,
|
1066
|
+
scope: rootScope
|
1067
|
+
});
|
1068
|
+
}
|
1069
|
+
});
|
1445
1070
|
}
|
1446
1071
|
function parseNodeFunctionPattern({ path, rootScope, cb }) {
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
path,
|
1455
|
-
scope: rootScope
|
1456
|
-
});
|
1457
|
-
}
|
1072
|
+
if (path.node.type !== "FunctionDeclaration") return;
|
1073
|
+
if (path.node.id?.type === "Identifier") cb?.({
|
1074
|
+
name: path.node.id.name,
|
1075
|
+
node: path.node,
|
1076
|
+
path,
|
1077
|
+
scope: rootScope
|
1078
|
+
});
|
1458
1079
|
}
|
1459
1080
|
function parseEdgeLeftIdentifierPattern({ path, rootScope, cb, collectionNodes, spread }) {
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
});
|
1495
|
-
}
|
1496
|
-
}
|
1497
|
-
}, path.scope, path);
|
1498
|
-
}
|
1499
|
-
}
|
1081
|
+
if (!path.node.id || path.node.id.type !== "Identifier") return;
|
1082
|
+
if (path.node.init?.type && [
|
1083
|
+
"ArrowFunctionExpression",
|
1084
|
+
"FunctionExpression",
|
1085
|
+
"CallExpression",
|
1086
|
+
"ObjectExpression",
|
1087
|
+
"ArrayExpression"
|
1088
|
+
].includes(path.node.init.type)) {
|
1089
|
+
if (collectionNodes.has(path.node.id.name) && path.scope.getBinding(path.node.id.name)?.scope === rootScope) {
|
1090
|
+
const name = path.node.id.name;
|
1091
|
+
traverse(path.node.init, {
|
1092
|
+
Identifier(path1) {
|
1093
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
1094
|
+
if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) cb?.({
|
1095
|
+
fromName: name,
|
1096
|
+
toName: path1.node.name,
|
1097
|
+
path: path1,
|
1098
|
+
scope: rootScope,
|
1099
|
+
collectionNodes
|
1100
|
+
});
|
1101
|
+
},
|
1102
|
+
MemberExpression(path1) {
|
1103
|
+
if (spread?.length && path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier") cb?.({
|
1104
|
+
fromName: name,
|
1105
|
+
toName: path1.node.property.name,
|
1106
|
+
toScope: path1.scope.getBinding(path1.node.object.name)?.scope,
|
1107
|
+
path: path1,
|
1108
|
+
scope: rootScope,
|
1109
|
+
collectionNodes
|
1110
|
+
});
|
1111
|
+
}
|
1112
|
+
}, path.scope, path);
|
1113
|
+
}
|
1114
|
+
}
|
1500
1115
|
}
|
1501
1116
|
function parseEdgeLeftObjectPattern({ path, rootScope, cb, collectionNodes }) {
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
});
|
1533
|
-
});
|
1534
|
-
}
|
1535
|
-
}
|
1536
|
-
}, path.scope, path);
|
1537
|
-
}
|
1117
|
+
if (!path.node.id || path.node.id.type !== "ObjectPattern") return;
|
1118
|
+
if (path.node.init?.type && [
|
1119
|
+
"ArrowFunctionExpression",
|
1120
|
+
"FunctionExpression",
|
1121
|
+
"CallExpression",
|
1122
|
+
"ObjectExpression",
|
1123
|
+
"ArrayExpression"
|
1124
|
+
].includes(path.node.init.type)) {
|
1125
|
+
const res = [];
|
1126
|
+
rescureObjectPattern({
|
1127
|
+
node: path.node.id,
|
1128
|
+
rootScope,
|
1129
|
+
res,
|
1130
|
+
parentScope: path.scope,
|
1131
|
+
parentPath: path
|
1132
|
+
});
|
1133
|
+
res.filter((r) => collectionNodes.has(r.name) && path.scope.getBinding(r.name)?.scope === rootScope);
|
1134
|
+
traverse(path.node.init, { Identifier(path1) {
|
1135
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
1136
|
+
if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) res.forEach((r) => {
|
1137
|
+
cb?.({
|
1138
|
+
fromName: r.name,
|
1139
|
+
toName: path1.node.name,
|
1140
|
+
path: path1,
|
1141
|
+
scope: rootScope,
|
1142
|
+
collectionNodes
|
1143
|
+
});
|
1144
|
+
});
|
1145
|
+
} }, path.scope, path);
|
1146
|
+
}
|
1538
1147
|
}
|
1539
1148
|
function parseEdgeLeftArrayPattern({ path, rootScope, cb, collectionNodes }) {
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
});
|
1571
|
-
});
|
1572
|
-
}
|
1573
|
-
}
|
1574
|
-
}, path.scope, path);
|
1575
|
-
}
|
1149
|
+
if (!path.node.id || path.node.id.type !== "ArrayPattern") return;
|
1150
|
+
if (path.node.init?.type && [
|
1151
|
+
"ArrowFunctionExpression",
|
1152
|
+
"FunctionExpression",
|
1153
|
+
"CallExpression",
|
1154
|
+
"ObjectExpression",
|
1155
|
+
"ArrayExpression"
|
1156
|
+
].includes(path.node.init.type)) {
|
1157
|
+
const res = [];
|
1158
|
+
rescureArrayPattern({
|
1159
|
+
node: path.node.id,
|
1160
|
+
rootScope,
|
1161
|
+
res,
|
1162
|
+
parentScope: path.scope,
|
1163
|
+
parentPath: path
|
1164
|
+
});
|
1165
|
+
res.filter((r) => collectionNodes.has(r.name) && path.scope.getBinding(r.name)?.scope === rootScope);
|
1166
|
+
traverse(path.node.init, { Identifier(path1) {
|
1167
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
1168
|
+
if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) res.forEach((r) => {
|
1169
|
+
cb?.({
|
1170
|
+
fromName: r.name,
|
1171
|
+
toName: path1.node.name,
|
1172
|
+
path: path1,
|
1173
|
+
scope: rootScope,
|
1174
|
+
collectionNodes
|
1175
|
+
});
|
1176
|
+
});
|
1177
|
+
} }, path.scope, path);
|
1178
|
+
}
|
1576
1179
|
}
|
1577
1180
|
function parseEdgeFunctionPattern({ path, rootScope, cb, collectionNodes }) {
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
collectionNodes
|
1593
|
-
});
|
1594
|
-
}
|
1595
|
-
}
|
1596
|
-
}, path.scope, path);
|
1597
|
-
}
|
1181
|
+
if (!path.node.id) return;
|
1182
|
+
if (collectionNodes.has(path.node.id.name) && path.scope.getBinding(path.node.id.name)?.scope === rootScope) {
|
1183
|
+
const name = path.node.id.name;
|
1184
|
+
traverse(path.node.body, { Identifier(path1) {
|
1185
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
1186
|
+
if (binding?.scope === rootScope && collectionNodes.has(path1.node.name)) cb?.({
|
1187
|
+
fromName: name,
|
1188
|
+
toName: path1.node.name,
|
1189
|
+
path: path1,
|
1190
|
+
scope: rootScope,
|
1191
|
+
collectionNodes
|
1192
|
+
});
|
1193
|
+
} }, path.scope, path);
|
1194
|
+
}
|
1598
1195
|
}
|
1599
1196
|
function parseReturnJsxPattern({ path, parentPath, cb }) {
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
path: path1,
|
1608
|
-
parentPath
|
1609
|
-
});
|
1610
|
-
}
|
1611
|
-
});
|
1612
|
-
}
|
1197
|
+
if (path.node.argument && ((path.node.argument.type === "ArrowFunctionExpression" || path.node.argument.type === "FunctionExpression") && (path.node.argument.body.type === "JSXElement" || path.node.argument.body.type === "JSXFragment") || path.node.argument.type === "JSXElement" || path.node.argument.type === "JSXFragment")) path.traverse({ Identifier(path1) {
|
1198
|
+
cb?.({
|
1199
|
+
name: path1.node.name,
|
1200
|
+
path: path1,
|
1201
|
+
parentPath
|
1202
|
+
});
|
1203
|
+
} });
|
1613
1204
|
}
|
1614
1205
|
function traverseSetup({ node, parentScope, parentPath }) {
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
}
|
1623
|
-
}
|
1624
|
-
}, parentScope, parentPath);
|
1625
|
-
return path;
|
1206
|
+
let path;
|
1207
|
+
traverse(node, { ObjectMethod(path1) {
|
1208
|
+
if (parentPath.node.declaration.type === "ObjectExpression" && path1.parent === parentPath.node.declaration || parentPath.node.declaration.type === "CallExpression" && path1.parent === parentPath.node.declaration.arguments[0]) {
|
1209
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") path = path1;
|
1210
|
+
}
|
1211
|
+
} }, parentScope, parentPath);
|
1212
|
+
return path;
|
1626
1213
|
}
|
1627
1214
|
function collectionSpread({ path: path1, spread }) {
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
spread.push(path3.node.argument.name);
|
1638
|
-
}
|
1639
|
-
}
|
1640
|
-
}, path2.scope, path2);
|
1641
|
-
}
|
1642
|
-
}
|
1643
|
-
});
|
1215
|
+
path1.traverse({ ReturnStatement(path2) {
|
1216
|
+
if (path2.node.argument?.type === "ObjectExpression") {
|
1217
|
+
const returnNode = path2.node.argument;
|
1218
|
+
traverse(returnNode, { SpreadElement(path3) {
|
1219
|
+
if (path3.node.argument.type === "CallExpression" && path3.node.argument.callee.type === "Identifier" && path3.node.argument.callee.name === "toRefs" && path3.node.argument.arguments[0].type === "Identifier") spread.push(path3.node.argument.arguments[0].name);
|
1220
|
+
else if (path3.node.argument.type === "Identifier") spread.push(path3.node.argument.name);
|
1221
|
+
} }, path2.scope, path2);
|
1222
|
+
}
|
1223
|
+
} });
|
1644
1224
|
}
|
1645
1225
|
function addIdentifiesToGraphByScanReturn({ path: path1, graph, nodeCollection, tempNodeCollection, tempEdges }) {
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
});
|
1673
|
-
graph.edges.set(name, /* @__PURE__ */ new Set([{
|
1674
|
-
label: valName,
|
1675
|
-
type: getRelationType(path3)
|
1676
|
-
}]));
|
1677
|
-
}
|
1678
|
-
}
|
1679
|
-
}
|
1680
|
-
}
|
1681
|
-
}, path2.scope, path2);
|
1682
|
-
}
|
1683
|
-
}
|
1684
|
-
});
|
1226
|
+
path1.traverse({ ReturnStatement(path2) {
|
1227
|
+
if (path2.node.argument?.type === "ObjectExpression") {
|
1228
|
+
const returnNode = path2.node.argument;
|
1229
|
+
traverse(returnNode, { ObjectProperty(path3) {
|
1230
|
+
if (path3.parent === returnNode) {
|
1231
|
+
if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier") {
|
1232
|
+
const valName = path3.node.value.name;
|
1233
|
+
if (!graph.nodes.has(valName)) {
|
1234
|
+
graph.nodes.add(valName);
|
1235
|
+
nodeCollection.addTypedNode(valName, tempNodeCollection.nodes.get(valName));
|
1236
|
+
}
|
1237
|
+
if (!graph.edges.has(valName)) graph.edges.set(valName, new Set([...Array.from(tempEdges.get(valName) || /* @__PURE__ */ new Set())]));
|
1238
|
+
const name = path3.node.key.name;
|
1239
|
+
if (name !== valName) {
|
1240
|
+
graph.nodes.add(name);
|
1241
|
+
nodeCollection.addNode(name, path3.node.key, { comment: getComment(path3.node) });
|
1242
|
+
graph.edges.set(name, new Set([{
|
1243
|
+
label: valName,
|
1244
|
+
type: getRelationType(path3)
|
1245
|
+
}]));
|
1246
|
+
}
|
1247
|
+
}
|
1248
|
+
}
|
1249
|
+
} }, path2.scope, path2);
|
1250
|
+
}
|
1251
|
+
} });
|
1685
1252
|
}
|
1686
1253
|
function addSpreadToGraphByScanReturn({ path: path1, graph, nodeCollection, tempNodeCollection, tempEdges, tempSpread }) {
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
});
|
1715
|
-
}
|
1716
|
-
}
|
1717
|
-
}, path2.scope, path2);
|
1718
|
-
}
|
1719
|
-
}
|
1720
|
-
});
|
1254
|
+
path1.traverse({ ReturnStatement(path2) {
|
1255
|
+
if (path2.node.argument?.type === "ObjectExpression") {
|
1256
|
+
const returnNode = path2.node.argument;
|
1257
|
+
traverse(returnNode, { SpreadElement(path3) {
|
1258
|
+
if (path3.node.argument.type === "CallExpression" && path3.node.argument.callee.type === "Identifier" && path3.node.argument.callee.name === "toRefs" && path3.node.argument.arguments[0].type === "Identifier" && tempSpread.get(path3.node.argument.arguments[0].name)) tempSpread.get(path3.node.argument.arguments[0].name)?.forEach((name) => {
|
1259
|
+
graph.nodes.add(name);
|
1260
|
+
nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
|
1261
|
+
if (!graph.edges.get(name)) {
|
1262
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
1263
|
+
tempEdges.get(name)?.forEach((edge) => {
|
1264
|
+
graph.edges.get(name)?.add(edge);
|
1265
|
+
});
|
1266
|
+
}
|
1267
|
+
});
|
1268
|
+
else if (path3.node.argument.type === "Identifier" && tempSpread.get(path3.node.argument.name)) tempSpread.get(path3.node.argument.name)?.forEach((name) => {
|
1269
|
+
graph.nodes.add(name);
|
1270
|
+
nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
|
1271
|
+
if (!graph.edges.get(name)) {
|
1272
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
1273
|
+
tempEdges.get(name)?.forEach((edge) => {
|
1274
|
+
graph.edges.get(name)?.add(edge);
|
1275
|
+
});
|
1276
|
+
}
|
1277
|
+
});
|
1278
|
+
} }, path2.scope, path2);
|
1279
|
+
}
|
1280
|
+
} });
|
1721
1281
|
}
|
1722
1282
|
function addGraphBySpreadIdentifier({ path: path1, graph, nodeCollection, iname }) {
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
if (arg.type === "ObjectExpression") {
|
1747
|
-
arg.properties.forEach((prop) => {
|
1748
|
-
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
1749
|
-
const keyName = prop.key.name;
|
1750
|
-
graph.nodes.add(keyName);
|
1751
|
-
nodeCollection.addNode(keyName, prop, {
|
1752
|
-
comment: getComment(prop)
|
1753
|
-
});
|
1754
|
-
if (!graph.edges.get(keyName)) {
|
1755
|
-
graph.edges.set(keyName, /* @__PURE__ */ new Set());
|
1756
|
-
}
|
1757
|
-
if (graph.spread.has(iname)) {
|
1758
|
-
graph.spread.get(iname)?.add(keyName);
|
1759
|
-
} else {
|
1760
|
-
graph.spread.set(iname, /* @__PURE__ */ new Set([keyName]));
|
1761
|
-
}
|
1762
|
-
} else if (prop.type === "SpreadElement") {
|
1763
|
-
console.warn("not support spread in spread");
|
1764
|
-
}
|
1765
|
-
});
|
1766
|
-
}
|
1767
|
-
}
|
1283
|
+
if (path1.node.init?.type === "ObjectExpression") path1.node.init?.properties.forEach((prop) => {
|
1284
|
+
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
1285
|
+
const keyName = prop.key.name;
|
1286
|
+
graph.nodes.add(keyName);
|
1287
|
+
nodeCollection.addNode(keyName, prop, { comment: getComment(prop) });
|
1288
|
+
if (!graph.edges.get(keyName)) graph.edges.set(keyName, /* @__PURE__ */ new Set());
|
1289
|
+
if (graph.spread.has(iname)) graph.spread.get(iname)?.add(keyName);
|
1290
|
+
else graph.spread.set(iname, new Set([keyName]));
|
1291
|
+
} else if (prop.type === "SpreadElement") console.warn("not support spread in spread");
|
1292
|
+
});
|
1293
|
+
if (path1.node.init?.type === "CallExpression" && path1.node.init?.callee.type === "Identifier" && path1.node.init?.callee.name === "reactive") {
|
1294
|
+
const arg = path1.node.init?.arguments[0];
|
1295
|
+
if (arg.type === "ObjectExpression") arg.properties.forEach((prop) => {
|
1296
|
+
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
1297
|
+
const keyName = prop.key.name;
|
1298
|
+
graph.nodes.add(keyName);
|
1299
|
+
nodeCollection.addNode(keyName, prop, { comment: getComment(prop) });
|
1300
|
+
if (!graph.edges.get(keyName)) graph.edges.set(keyName, /* @__PURE__ */ new Set());
|
1301
|
+
if (graph.spread.has(iname)) graph.spread.get(iname)?.add(keyName);
|
1302
|
+
else graph.spread.set(iname, new Set([keyName]));
|
1303
|
+
} else if (prop.type === "SpreadElement") console.warn("not support spread in spread");
|
1304
|
+
});
|
1305
|
+
}
|
1768
1306
|
}
|
1769
1307
|
|
1770
|
-
|
1308
|
+
//#endregion
|
1309
|
+
//#region src/analyze/tsx.ts
|
1771
1310
|
function processByReturnNotJSX(params) {
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1311
|
+
const { node, parentPath, lineOffset, addInfo } = params;
|
1312
|
+
const spread = [];
|
1313
|
+
const nodeCollection = new NodeCollection(lineOffset, addInfo);
|
1314
|
+
const graph = {
|
1315
|
+
nodes: /* @__PURE__ */ new Set(),
|
1316
|
+
edges: /* @__PURE__ */ new Map()
|
1317
|
+
};
|
1318
|
+
const setupPath = traverseSetup({
|
1319
|
+
node,
|
1320
|
+
parentScope: parentPath.scope,
|
1321
|
+
parentPath
|
1322
|
+
});
|
1323
|
+
collectionSpread({
|
1324
|
+
path: setupPath,
|
1325
|
+
spread
|
1326
|
+
});
|
1327
|
+
const { graph: { nodes: tempNodes, edges: tempEdges, spread: tempSpread }, nodeCollection: tempNodeCollection, nodesUsedInTemplate } = processByReturnJSX({
|
1328
|
+
node,
|
1329
|
+
parentPath,
|
1330
|
+
spread,
|
1331
|
+
lineOffset,
|
1332
|
+
addInfo
|
1333
|
+
});
|
1334
|
+
addIdentifiesToGraphByScanReturn({
|
1335
|
+
path: setupPath,
|
1336
|
+
graph,
|
1337
|
+
nodeCollection,
|
1338
|
+
tempNodeCollection,
|
1339
|
+
tempEdges
|
1340
|
+
});
|
1341
|
+
addSpreadToGraphByScanReturn({
|
1342
|
+
path: setupPath,
|
1343
|
+
graph,
|
1344
|
+
nodeCollection,
|
1345
|
+
tempNodeCollection,
|
1346
|
+
tempEdges,
|
1347
|
+
tempSpread
|
1348
|
+
});
|
1349
|
+
return {
|
1350
|
+
graph,
|
1351
|
+
nodeCollection,
|
1352
|
+
nodesUsedInTemplate
|
1353
|
+
};
|
1810
1354
|
}
|
1811
1355
|
function processByReturnJSX(params) {
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
cb: addEdge
|
1924
|
-
});
|
1925
|
-
}
|
1926
|
-
}, setupScope, setupPath);
|
1927
|
-
return {
|
1928
|
-
graph,
|
1929
|
-
nodeCollection,
|
1930
|
-
nodesUsedInTemplate
|
1931
|
-
};
|
1356
|
+
const { node, parentPath, spread = [], lineOffset, addInfo } = params;
|
1357
|
+
const nodeCollection = new NodeCollection(lineOffset, addInfo);
|
1358
|
+
const nodesUsedInTemplate = /* @__PURE__ */ new Set();
|
1359
|
+
const graph = {
|
1360
|
+
nodes: /* @__PURE__ */ new Set(),
|
1361
|
+
edges: /* @__PURE__ */ new Map(),
|
1362
|
+
spread: /* @__PURE__ */ new Map()
|
1363
|
+
};
|
1364
|
+
function addNode({ name, node: node$1, path, scope }, commentParentNode) {
|
1365
|
+
const binding = path.scope.getBinding(name);
|
1366
|
+
if (scope === binding?.scope) {
|
1367
|
+
graph.nodes.add(name);
|
1368
|
+
nodeCollection.addNode(name, node$1, { comment: commentParentNode ? getComment(commentParentNode) : "" });
|
1369
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
1370
|
+
}
|
1371
|
+
}
|
1372
|
+
function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
|
1373
|
+
const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
|
1374
|
+
if (scope === bindingScope && collectionNodes.has(toName)) graph.edges.get(fromName)?.add({
|
1375
|
+
label: toName,
|
1376
|
+
type: getRelationType(path)
|
1377
|
+
});
|
1378
|
+
}
|
1379
|
+
function addUsed({ name, path, parentPath: parentPath$1 }) {
|
1380
|
+
const binding = path.scope.getBinding(name);
|
1381
|
+
if (binding?.scope === parentPath$1.scope) nodesUsedInTemplate.add(name);
|
1382
|
+
}
|
1383
|
+
const setupPath = traverseSetup({
|
1384
|
+
node,
|
1385
|
+
parentScope: parentPath.scope,
|
1386
|
+
parentPath
|
1387
|
+
});
|
1388
|
+
const setupScope = setupPath.scope;
|
1389
|
+
const setupNode = setupPath.node;
|
1390
|
+
traverse(setupNode, {
|
1391
|
+
VariableDeclarator(path1) {
|
1392
|
+
parseNodeIdentifierPattern({
|
1393
|
+
path: path1,
|
1394
|
+
rootScope: setupScope,
|
1395
|
+
cb: (params$1) => {
|
1396
|
+
if (!spread.includes(params$1.name)) addNode(params$1, path1.node);
|
1397
|
+
else addGraphBySpreadIdentifier({
|
1398
|
+
path: path1,
|
1399
|
+
graph,
|
1400
|
+
nodeCollection,
|
1401
|
+
iname: params$1.name
|
1402
|
+
});
|
1403
|
+
}
|
1404
|
+
});
|
1405
|
+
parseNodeObjectPattern({
|
1406
|
+
path: path1,
|
1407
|
+
rootScope: setupScope,
|
1408
|
+
cb: addNode
|
1409
|
+
});
|
1410
|
+
parseNodeArrayPattern({
|
1411
|
+
path: path1,
|
1412
|
+
rootScope: setupScope,
|
1413
|
+
cb: addNode
|
1414
|
+
});
|
1415
|
+
},
|
1416
|
+
FunctionDeclaration(path1) {
|
1417
|
+
parseNodeFunctionPattern({
|
1418
|
+
path: path1,
|
1419
|
+
rootScope: setupScope,
|
1420
|
+
cb: addNode
|
1421
|
+
});
|
1422
|
+
}
|
1423
|
+
}, setupScope, setupPath);
|
1424
|
+
setupPath.traverse({ ReturnStatement(path2) {
|
1425
|
+
parseReturnJsxPattern({
|
1426
|
+
path: path2,
|
1427
|
+
parentPath: setupPath,
|
1428
|
+
cb: addUsed
|
1429
|
+
});
|
1430
|
+
} });
|
1431
|
+
traverse(setupNode, {
|
1432
|
+
VariableDeclarator(path1) {
|
1433
|
+
parseEdgeLeftIdentifierPattern({
|
1434
|
+
path: path1,
|
1435
|
+
rootScope: setupScope,
|
1436
|
+
collectionNodes: graph.nodes,
|
1437
|
+
cb: addEdge,
|
1438
|
+
spread
|
1439
|
+
});
|
1440
|
+
parseEdgeLeftObjectPattern({
|
1441
|
+
path: path1,
|
1442
|
+
rootScope: setupScope,
|
1443
|
+
collectionNodes: graph.nodes,
|
1444
|
+
cb: addEdge
|
1445
|
+
});
|
1446
|
+
parseEdgeLeftArrayPattern({
|
1447
|
+
path: path1,
|
1448
|
+
rootScope: setupScope,
|
1449
|
+
collectionNodes: graph.nodes,
|
1450
|
+
cb: addEdge
|
1451
|
+
});
|
1452
|
+
},
|
1453
|
+
FunctionDeclaration(path1) {
|
1454
|
+
parseEdgeFunctionPattern({
|
1455
|
+
path: path1,
|
1456
|
+
rootScope: setupScope,
|
1457
|
+
collectionNodes: graph.nodes,
|
1458
|
+
cb: addEdge
|
1459
|
+
});
|
1460
|
+
}
|
1461
|
+
}, setupScope, setupPath);
|
1462
|
+
return {
|
1463
|
+
graph,
|
1464
|
+
nodeCollection,
|
1465
|
+
nodesUsedInTemplate
|
1466
|
+
};
|
1932
1467
|
}
|
1933
1468
|
function processByReact(params) {
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
collectionNodes: graph.nodes,
|
2032
|
-
cb: addEdge
|
2033
|
-
});
|
2034
|
-
}
|
2035
|
-
}, parentScope, parentPath);
|
2036
|
-
return {
|
2037
|
-
graph,
|
2038
|
-
nodeCollection,
|
2039
|
-
nodesUsedInTemplate
|
2040
|
-
};
|
1469
|
+
const { node, parentScope, parentPath, lineOffset, addInfo } = params;
|
1470
|
+
const nodeCollection = new NodeCollection(lineOffset, addInfo);
|
1471
|
+
const nodesUsedInTemplate = /* @__PURE__ */ new Set();
|
1472
|
+
const graph = {
|
1473
|
+
nodes: /* @__PURE__ */ new Set(),
|
1474
|
+
edges: /* @__PURE__ */ new Map(),
|
1475
|
+
spread: /* @__PURE__ */ new Map()
|
1476
|
+
};
|
1477
|
+
function addNode({ name, node: node$1, path, scope }, commentParentNode) {
|
1478
|
+
const binding = path.scope.getBinding(name);
|
1479
|
+
if (scope === binding?.scope) {
|
1480
|
+
graph.nodes.add(name);
|
1481
|
+
nodeCollection.addNode(name, node$1, { comment: commentParentNode ? getComment(commentParentNode) : "" });
|
1482
|
+
if (!graph.edges.get(name)) graph.edges.set(name, /* @__PURE__ */ new Set());
|
1483
|
+
}
|
1484
|
+
}
|
1485
|
+
function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
|
1486
|
+
const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
|
1487
|
+
if (scope === bindingScope && collectionNodes.has(toName)) graph.edges.get(fromName)?.add({
|
1488
|
+
label: toName,
|
1489
|
+
type: getRelationType(path)
|
1490
|
+
});
|
1491
|
+
}
|
1492
|
+
function addUsed({ name, path, parentPath: parentPath$1 }) {
|
1493
|
+
const binding = path.scope.getBinding(name);
|
1494
|
+
if (binding?.scope === parentPath$1.scope) nodesUsedInTemplate.add(name);
|
1495
|
+
}
|
1496
|
+
traverse(node, {
|
1497
|
+
VariableDeclarator(path1) {
|
1498
|
+
parseNodeIdentifierPattern({
|
1499
|
+
path: path1,
|
1500
|
+
rootScope: parentScope,
|
1501
|
+
cb: (params$1) => {
|
1502
|
+
addNode(params$1, path1.node);
|
1503
|
+
}
|
1504
|
+
});
|
1505
|
+
parseNodeObjectPattern({
|
1506
|
+
path: path1,
|
1507
|
+
rootScope: parentScope,
|
1508
|
+
cb: addNode
|
1509
|
+
});
|
1510
|
+
parseNodeArrayPattern({
|
1511
|
+
path: path1,
|
1512
|
+
rootScope: parentScope,
|
1513
|
+
cb: addNode
|
1514
|
+
});
|
1515
|
+
},
|
1516
|
+
FunctionDeclaration(path1) {
|
1517
|
+
parseNodeFunctionPattern({
|
1518
|
+
path: path1,
|
1519
|
+
rootScope: parentScope,
|
1520
|
+
cb: addNode
|
1521
|
+
});
|
1522
|
+
}
|
1523
|
+
}, parentScope, parentPath);
|
1524
|
+
traverse(node, { ReturnStatement(path2) {
|
1525
|
+
parseReturnJsxPattern({
|
1526
|
+
path: path2,
|
1527
|
+
parentPath,
|
1528
|
+
cb: addUsed
|
1529
|
+
});
|
1530
|
+
} }, parentScope, parentPath);
|
1531
|
+
traverse(node, {
|
1532
|
+
VariableDeclarator(path1) {
|
1533
|
+
parseEdgeLeftIdentifierPattern({
|
1534
|
+
path: path1,
|
1535
|
+
rootScope: parentScope,
|
1536
|
+
collectionNodes: graph.nodes,
|
1537
|
+
cb: addEdge
|
1538
|
+
});
|
1539
|
+
parseEdgeLeftObjectPattern({
|
1540
|
+
path: path1,
|
1541
|
+
rootScope: parentScope,
|
1542
|
+
collectionNodes: graph.nodes,
|
1543
|
+
cb: addEdge
|
1544
|
+
});
|
1545
|
+
parseEdgeLeftArrayPattern({
|
1546
|
+
path: path1,
|
1547
|
+
rootScope: parentScope,
|
1548
|
+
collectionNodes: graph.nodes,
|
1549
|
+
cb: addEdge
|
1550
|
+
});
|
1551
|
+
},
|
1552
|
+
FunctionDeclaration(path1) {
|
1553
|
+
parseEdgeFunctionPattern({
|
1554
|
+
path: path1,
|
1555
|
+
rootScope: parentScope,
|
1556
|
+
collectionNodes: graph.nodes,
|
1557
|
+
cb: addEdge
|
1558
|
+
});
|
1559
|
+
}
|
1560
|
+
}, parentScope, parentPath);
|
1561
|
+
return {
|
1562
|
+
graph,
|
1563
|
+
nodeCollection,
|
1564
|
+
nodesUsedInTemplate
|
1565
|
+
};
|
2041
1566
|
}
|
2042
1567
|
function processTsx(params) {
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
node: renderFunction.body,
|
2101
|
-
parentNode: renderFunction,
|
2102
|
-
parentPath: renderPath,
|
2103
|
-
parentScope: renderPath.scope
|
2104
|
-
});
|
2105
|
-
}
|
2106
|
-
}
|
2107
|
-
}
|
2108
|
-
});
|
2109
|
-
return result;
|
1568
|
+
let result;
|
1569
|
+
function process(params$1) {
|
1570
|
+
const { node, parentPath } = params$1;
|
1571
|
+
const setupPath = traverseSetup({
|
1572
|
+
node,
|
1573
|
+
parentScope: parentPath.scope,
|
1574
|
+
parentPath
|
1575
|
+
});
|
1576
|
+
setupPath.traverse({ ReturnStatement(path) {
|
1577
|
+
if (path.node.argument && (path.node.argument.type === "ArrowFunctionExpression" || path.node.argument.type === "FunctionExpression") && (path.node.argument.body.type === "JSXElement" || path.node.argument.body.type === "JSXFragment")) result = processByReturnJSX(params$1);
|
1578
|
+
else result = processByReturnNotJSX(params$1);
|
1579
|
+
} });
|
1580
|
+
}
|
1581
|
+
traverse(params.node, { ExportDefaultDeclaration(path) {
|
1582
|
+
if (params.type === "vue") {
|
1583
|
+
if (path.node.declaration.type === "ObjectExpression") process({
|
1584
|
+
...params,
|
1585
|
+
node: path.node.declaration,
|
1586
|
+
parentNode: path.node,
|
1587
|
+
parentPath: path
|
1588
|
+
});
|
1589
|
+
else if (path.node.declaration.type === "CallExpression" && path.node.declaration.callee.type === "Identifier" && path.node.declaration.callee.name === "defineComponent" && path.node.declaration.arguments[0].type === "ObjectExpression") process({
|
1590
|
+
...params,
|
1591
|
+
node: path.node.declaration.arguments[0],
|
1592
|
+
parentNode: path.node,
|
1593
|
+
parentPath: path
|
1594
|
+
});
|
1595
|
+
}
|
1596
|
+
if (params.type === "react") {
|
1597
|
+
if ((path.node.declaration.type === "FunctionDeclaration" || path.node.declaration.type === "ArrowFunctionExpression") && path.node.declaration.body.type === "BlockStatement") {
|
1598
|
+
const functionPath = path.get("declaration");
|
1599
|
+
result = processByReact({
|
1600
|
+
...params,
|
1601
|
+
node: path.node.declaration.body,
|
1602
|
+
parentNode: functionPath.node,
|
1603
|
+
parentPath: functionPath,
|
1604
|
+
parentScope: functionPath.scope
|
1605
|
+
});
|
1606
|
+
}
|
1607
|
+
if (path.node.declaration.type === "ClassDeclaration") {
|
1608
|
+
const renderFunction = path.node.declaration.body.body.find((node) => {
|
1609
|
+
if (node.type === "ClassMethod" && node.key.type === "Identifier" && node.key.name === "render") return node;
|
1610
|
+
return void 0;
|
1611
|
+
});
|
1612
|
+
if (!renderFunction) return;
|
1613
|
+
const renderPath = path.get(`declaration.body.body.${path.node.declaration.body.body.indexOf(renderFunction)}`);
|
1614
|
+
result = processByReact({
|
1615
|
+
...params,
|
1616
|
+
node: renderFunction.body,
|
1617
|
+
parentNode: renderFunction,
|
1618
|
+
parentPath: renderPath,
|
1619
|
+
parentScope: renderPath.scope
|
1620
|
+
});
|
1621
|
+
}
|
1622
|
+
}
|
1623
|
+
} });
|
1624
|
+
return result;
|
2110
1625
|
}
|
2111
|
-
function
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
1626
|
+
function analyze$4(content, type = "vue", lineOffset = 0, addInfo = true) {
|
1627
|
+
const ast = babelParse(content, {
|
1628
|
+
sourceType: "module",
|
1629
|
+
plugins: ["typescript", "jsx"]
|
1630
|
+
});
|
1631
|
+
const { graph, nodeCollection, nodesUsedInTemplate } = processTsx({
|
1632
|
+
node: ast,
|
1633
|
+
type,
|
1634
|
+
lineOffset,
|
1635
|
+
addInfo
|
1636
|
+
});
|
1637
|
+
return {
|
1638
|
+
graph: nodeCollection.map(graph),
|
1639
|
+
nodesUsedInTemplate
|
1640
|
+
};
|
2126
1641
|
}
|
2127
1642
|
|
2128
|
-
|
1643
|
+
//#endregion
|
1644
|
+
//#region src/mermaid.ts
|
2129
1645
|
function getMermaidText(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set(), options = {}) {
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
1646
|
+
const direction = options.direction || "TB";
|
1647
|
+
const usedNodes = new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
1648
|
+
let mermaidText = `flowchart ${direction}
|
2133
1649
|
%% Legend:
|
2134
1650
|
%% () = variable node
|
2135
1651
|
%% [] = function node
|
2136
1652
|
%% * suffix = unused in template/style
|
2137
|
-
%% A --> B means A depends on B
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
mermaidText += ` ${key.label} --> ${to.node.label}
|
2152
|
-
`;
|
2153
|
-
});
|
2154
|
-
});
|
2155
|
-
return mermaidText;
|
1653
|
+
%% A --> B means A depends on B\n`;
|
1654
|
+
graph.nodes.forEach((node) => {
|
1655
|
+
const shape = node.type === "var" ? "(" : "[";
|
1656
|
+
const closeShape = node.type === "var" ? ")" : "]";
|
1657
|
+
const unusedSuffix = !(usedNodes.has(node.label) || node.info?.used?.size) ? "*" : "";
|
1658
|
+
mermaidText += ` ${node.label}${shape}${node.label}${unusedSuffix}${closeShape}\n`;
|
1659
|
+
});
|
1660
|
+
graph.edges.forEach((edge, key) => {
|
1661
|
+
edge.forEach((to) => {
|
1662
|
+
if (!to || !to.node.label) return;
|
1663
|
+
mermaidText += ` ${key.label} --> ${to.node.label}\n`;
|
1664
|
+
});
|
1665
|
+
});
|
1666
|
+
return mermaidText;
|
2156
1667
|
}
|
2157
1668
|
|
2158
|
-
|
1669
|
+
//#endregion
|
1670
|
+
//#region src/suggest/filter.ts
|
1671
|
+
/**
|
1672
|
+
* Filter out nodes that have no indegree.
|
1673
|
+
*/
|
2159
1674
|
function noIndegreeFilter(graph) {
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
1675
|
+
const nodes = Array.from(graph.keys());
|
1676
|
+
const indegree = /* @__PURE__ */ new Map();
|
1677
|
+
nodes.forEach((node) => {
|
1678
|
+
indegree.set(node, 0);
|
1679
|
+
});
|
1680
|
+
graph.forEach((targets, node) => {
|
1681
|
+
targets.forEach((target) => {
|
1682
|
+
indegree.set(target.node, (indegree.get(target.node) || 0) + 1);
|
1683
|
+
});
|
1684
|
+
});
|
1685
|
+
return nodes.filter((node) => indegree.get(node) === 0);
|
2171
1686
|
}
|
2172
1687
|
function findLinearPaths(graph) {
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
}
|
2225
|
-
for (let i = 0; i <= longPath.length - shortPath.length; i++) {
|
2226
|
-
let isSub = true;
|
2227
|
-
for (let j = 0; j < shortPath.length; j++) {
|
2228
|
-
if (shortPath[j] !== longPath[i + j]) {
|
2229
|
-
isSub = false;
|
2230
|
-
break;
|
2231
|
-
}
|
2232
|
-
}
|
2233
|
-
if (isSub) {
|
2234
|
-
return true;
|
2235
|
-
}
|
2236
|
-
}
|
2237
|
-
return false;
|
2238
|
-
}
|
2239
|
-
for (const node of graph.keys()) {
|
2240
|
-
dfs2(node, []);
|
2241
|
-
}
|
2242
|
-
return linearPaths;
|
1688
|
+
const linearPaths = [];
|
1689
|
+
const visitedNodes = /* @__PURE__ */ new Set();
|
1690
|
+
const nodeInDegrees = /* @__PURE__ */ new Map();
|
1691
|
+
for (const [node, edges] of graph.entries()) {
|
1692
|
+
if (!nodeInDegrees.has(node)) nodeInDegrees.set(node, 0);
|
1693
|
+
for (const edge of edges) {
|
1694
|
+
const inDegree = nodeInDegrees.get(edge.node) || 0;
|
1695
|
+
nodeInDegrees.set(edge.node, inDegree + 1);
|
1696
|
+
}
|
1697
|
+
}
|
1698
|
+
function dfs$1(node, path) {
|
1699
|
+
if (visitedNodes.has(node)) return;
|
1700
|
+
path.push(node);
|
1701
|
+
visitedNodes.add(node);
|
1702
|
+
const edges = graph.get(node) || /* @__PURE__ */ new Set();
|
1703
|
+
if (edges.size === 0 || edges.size > 1) {
|
1704
|
+
if (path.length > 1) addOrUpdatePath([...path]);
|
1705
|
+
} else {
|
1706
|
+
const nextNode = Array.from(edges)[0].node;
|
1707
|
+
const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
|
1708
|
+
if (nextNodeInDegree === 1) dfs$1(nextNode, path);
|
1709
|
+
}
|
1710
|
+
path.pop();
|
1711
|
+
visitedNodes.delete(node);
|
1712
|
+
}
|
1713
|
+
function addOrUpdatePath(newPath) {
|
1714
|
+
let shouldAddNewPath = true;
|
1715
|
+
for (let i = linearPaths.length - 1; i >= 0; i--) {
|
1716
|
+
const existingPath = linearPaths[i];
|
1717
|
+
if (isSubpath(existingPath, newPath)) linearPaths.splice(i, 1);
|
1718
|
+
else if (isSubpath(newPath, existingPath)) {
|
1719
|
+
shouldAddNewPath = false;
|
1720
|
+
break;
|
1721
|
+
}
|
1722
|
+
}
|
1723
|
+
if (shouldAddNewPath && newPath.length > 2) linearPaths.push(newPath);
|
1724
|
+
}
|
1725
|
+
function isSubpath(shortPath, longPath) {
|
1726
|
+
if (shortPath.length >= longPath.length) return false;
|
1727
|
+
for (let i = 0; i <= longPath.length - shortPath.length; i++) {
|
1728
|
+
let isSub = true;
|
1729
|
+
for (let j = 0; j < shortPath.length; j++) if (shortPath[j] !== longPath[i + j]) {
|
1730
|
+
isSub = false;
|
1731
|
+
break;
|
1732
|
+
}
|
1733
|
+
if (isSub) return true;
|
1734
|
+
}
|
1735
|
+
return false;
|
1736
|
+
}
|
1737
|
+
for (const node of graph.keys()) dfs$1(node, []);
|
1738
|
+
return linearPaths;
|
2243
1739
|
}
|
2244
1740
|
function findArticulationPoints(graph) {
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
}
|
2270
|
-
} else if (neighbor.node !== parent.get(node)) {
|
2271
|
-
low.set(node, Math.min(low.get(node), disc.get(neighbor.node)));
|
2272
|
-
}
|
2273
|
-
}
|
2274
|
-
}
|
2275
|
-
for (const node of graph.keys()) {
|
2276
|
-
if (!visited.has(node) && !noIndegreeNodes.includes(node)) {
|
2277
|
-
APUtil(graph, node);
|
2278
|
-
}
|
2279
|
-
}
|
2280
|
-
return ap;
|
1741
|
+
const noIndegreeNodes = noIndegreeFilter(graph);
|
1742
|
+
let time = 0;
|
1743
|
+
const low = /* @__PURE__ */ new Map();
|
1744
|
+
const disc = /* @__PURE__ */ new Map();
|
1745
|
+
const parent = /* @__PURE__ */ new Map();
|
1746
|
+
const ap = /* @__PURE__ */ new Set();
|
1747
|
+
const visited = /* @__PURE__ */ new Set();
|
1748
|
+
function APUtil(graph$1, node) {
|
1749
|
+
let children = 0;
|
1750
|
+
disc.set(node, time);
|
1751
|
+
low.set(node, time);
|
1752
|
+
time++;
|
1753
|
+
visited.add(node);
|
1754
|
+
for (const neighbor of graph$1.get(node) || []) if (!visited.has(neighbor.node)) {
|
1755
|
+
children++;
|
1756
|
+
parent.set(neighbor.node, node);
|
1757
|
+
APUtil(graph$1, neighbor.node);
|
1758
|
+
low.set(node, Math.min(low.get(node), low.get(neighbor.node)));
|
1759
|
+
if (parent.get(node) === null && children > 1) ap.add(node);
|
1760
|
+
if (parent.get(node) !== null && low.get(neighbor.node) >= disc.get(node)) ap.add(node);
|
1761
|
+
} else if (neighbor.node !== parent.get(node)) low.set(node, Math.min(low.get(node), disc.get(neighbor.node)));
|
1762
|
+
}
|
1763
|
+
for (const node of graph.keys()) if (!visited.has(node) && !noIndegreeNodes.includes(node)) APUtil(graph, node);
|
1764
|
+
return ap;
|
2281
1765
|
}
|
2282
1766
|
|
2283
|
-
|
1767
|
+
//#endregion
|
1768
|
+
//#region src/suggest/split.ts
|
2284
1769
|
function dfs(graph, node, targets, visited, component) {
|
2285
|
-
|
2286
|
-
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2290
|
-
}
|
2291
|
-
});
|
1770
|
+
component.add(node);
|
1771
|
+
visited.add(node);
|
1772
|
+
targets.forEach((target) => {
|
1773
|
+
if (!visited.has(target.node)) dfs(graph, target.node, graph.get(target.node) || /* @__PURE__ */ new Set(), visited, component);
|
1774
|
+
});
|
2292
1775
|
}
|
2293
1776
|
function haveIntersection(setA, setB) {
|
2294
|
-
|
2295
|
-
|
2296
|
-
return true;
|
2297
|
-
}
|
2298
|
-
}
|
2299
|
-
return false;
|
1777
|
+
for (const item of setA) if (setB.has(item)) return true;
|
1778
|
+
return false;
|
2300
1779
|
}
|
2301
1780
|
function mergeSets(arr) {
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
}
|
2312
|
-
}
|
2313
|
-
}
|
2314
|
-
return result;
|
1781
|
+
let result = [...arr];
|
1782
|
+
for (let i = 0; i < result.length; i++) for (let j = i + 1; j < result.length; j++) if (haveIntersection(result[i], result[j])) {
|
1783
|
+
const newSet = new Set([...result[i], ...result[j]]);
|
1784
|
+
result.splice(j, 1);
|
1785
|
+
result.splice(i, 1);
|
1786
|
+
result = [...result, newSet];
|
1787
|
+
return mergeSets(result);
|
1788
|
+
}
|
1789
|
+
return result;
|
2315
1790
|
}
|
2316
1791
|
function splitGraph(graph) {
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
return subGraph;
|
2336
|
-
});
|
1792
|
+
const components = [];
|
1793
|
+
const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
|
1794
|
+
new Map(sorted).forEach((targets, node) => {
|
1795
|
+
const visited = /* @__PURE__ */ new Set();
|
1796
|
+
if (!visited.has(node)) {
|
1797
|
+
const component = /* @__PURE__ */ new Set();
|
1798
|
+
dfs(graph, node, targets, visited, component);
|
1799
|
+
components.push(component);
|
1800
|
+
}
|
1801
|
+
});
|
1802
|
+
return mergeSets(components).map((component) => {
|
1803
|
+
const subGraph = /* @__PURE__ */ new Map();
|
1804
|
+
component.forEach((node) => {
|
1805
|
+
const targets = graph.get(node);
|
1806
|
+
if (targets) subGraph.set(node, targets);
|
1807
|
+
});
|
1808
|
+
return subGraph;
|
1809
|
+
});
|
2337
1810
|
}
|
2338
1811
|
|
2339
|
-
|
1812
|
+
//#endregion
|
1813
|
+
//#region src/suggest/utils.ts
|
2340
1814
|
function hasCycle(graph) {
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2347
|
-
|
2348
|
-
|
2349
|
-
|
2350
|
-
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
}
|
2385
|
-
return { hasCycle: false, cycleNodes: [] };
|
1815
|
+
const visited = /* @__PURE__ */ new Set();
|
1816
|
+
const onStack = /* @__PURE__ */ new Set();
|
1817
|
+
const stack = [];
|
1818
|
+
let cycleNodes = [];
|
1819
|
+
function dfs$1(node) {
|
1820
|
+
if (visited.has(node)) {
|
1821
|
+
if (onStack.has(node)) {
|
1822
|
+
const idx = stack.indexOf(node);
|
1823
|
+
const cycle = stack.slice(idx);
|
1824
|
+
const allNotGet = cycle.every((curr, i) => {
|
1825
|
+
const next = cycle[(i + 1) % cycle.length];
|
1826
|
+
return Array.from(graph.get(curr) || []).some((edge) => edge.node === next && edge.type !== "get");
|
1827
|
+
});
|
1828
|
+
if (allNotGet) {
|
1829
|
+
cycleNodes = cycle;
|
1830
|
+
return true;
|
1831
|
+
}
|
1832
|
+
return false;
|
1833
|
+
}
|
1834
|
+
return false;
|
1835
|
+
}
|
1836
|
+
visited.add(node);
|
1837
|
+
onStack.add(node);
|
1838
|
+
stack.push(node);
|
1839
|
+
for (const neighbor of graph.get(node) || /* @__PURE__ */ new Set()) {
|
1840
|
+
if (neighbor.node === node && neighbor.type !== "get") {
|
1841
|
+
cycleNodes = [node];
|
1842
|
+
return true;
|
1843
|
+
}
|
1844
|
+
if (dfs$1(neighbor.node)) return true;
|
1845
|
+
}
|
1846
|
+
onStack.delete(node);
|
1847
|
+
stack.pop();
|
1848
|
+
return false;
|
1849
|
+
}
|
1850
|
+
for (const [node, targets] of graph) if (dfs$1(node)) return {
|
1851
|
+
hasCycle: true,
|
1852
|
+
cycleNodes
|
1853
|
+
};
|
1854
|
+
return {
|
1855
|
+
hasCycle: false,
|
1856
|
+
cycleNodes: []
|
1857
|
+
};
|
2386
1858
|
}
|
2387
1859
|
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
1860
|
+
//#endregion
|
1861
|
+
//#region src/suggest/index.ts
|
1862
|
+
let SuggestionType = /* @__PURE__ */ function(SuggestionType$1) {
|
1863
|
+
SuggestionType$1["info"] = "info";
|
1864
|
+
SuggestionType$1["warning"] = "warning";
|
1865
|
+
SuggestionType$1["error"] = "error";
|
1866
|
+
return SuggestionType$1;
|
1867
|
+
}({});
|
2395
1868
|
function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2396
|
-
|
2397
|
-
|
2398
|
-
|
2399
|
-
|
2400
|
-
|
2401
|
-
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
|
2425
|
-
|
2426
|
-
|
2427
|
-
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2438
|
-
|
2439
|
-
|
2440
|
-
|
2441
|
-
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
|
2450
|
-
});
|
2451
|
-
const noIndegreeNodes = noIndegreeFilter(graph.edges);
|
2452
|
-
noIndegreeNodes.forEach((node) => {
|
2453
|
-
if (!usedNodes.has(node.label) && !node.info?.used?.size) {
|
2454
|
-
suggestions.push({
|
2455
|
-
type: "info" /* info */,
|
2456
|
-
message: `Node [${node.label}] is not used, perhaps you can remove it.`,
|
2457
|
-
nodeInfo: node
|
2458
|
-
});
|
2459
|
-
}
|
2460
|
-
});
|
2461
|
-
return suggestions;
|
1869
|
+
const usedNodes = new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
1870
|
+
const suggestions = [];
|
1871
|
+
const splitedGraph = splitGraph(graph.edges);
|
1872
|
+
splitedGraph.forEach((g) => {
|
1873
|
+
const nodes = Array.from(g.keys());
|
1874
|
+
if (splitedGraph.length > 1) {
|
1875
|
+
if (nodes.length > 2 && nodes.some((node) => !usedNodes.has(node.label))) suggestions.push({
|
1876
|
+
type: SuggestionType.info,
|
1877
|
+
message: `Nodes [${nodes.length > 10 ? `${nodes.slice(0, 10).map((node) => node.label).join(",")}...(${nodes.length})` : nodes.map((node) => node.label).join(",")}] are isolated, perhaps you can refactor them to an isolated file.`,
|
1878
|
+
nodeInfo: nodes
|
1879
|
+
});
|
1880
|
+
}
|
1881
|
+
if (nodes.length > 1 && nodes.every((node) => !usedNodes.has(node.label) && !node.info?.used?.size)) suggestions.push({
|
1882
|
+
type: SuggestionType.info,
|
1883
|
+
message: `Nodes [${nodes.length > 10 ? `${nodes.slice(0, 10).map((node) => node.label).join(",")}...` : nodes.map((node) => node.label).join(",")}] are not used, perhaps you can remove them.`,
|
1884
|
+
nodeInfo: nodes
|
1885
|
+
});
|
1886
|
+
const hasCycleResult = hasCycle(g);
|
1887
|
+
if (hasCycleResult.hasCycle) suggestions.push({
|
1888
|
+
type: SuggestionType.error,
|
1889
|
+
message: `There is a loop call in nodes [${hasCycleResult.cycleNodes.map((node) => node.label).join(",")}], perhaps you can refactor it.`,
|
1890
|
+
nodeInfo: hasCycleResult.cycleNodes
|
1891
|
+
});
|
1892
|
+
const paths = findLinearPaths(g);
|
1893
|
+
paths.forEach((path) => {
|
1894
|
+
const firstUsedNodeIndex = path.findIndex((node) => usedNodes.has(node.label));
|
1895
|
+
const reverseLastNotUsedNodeIndex = path.slice().reverse().findIndex((node) => !usedNodes.has(node.label));
|
1896
|
+
const lastNotUsedNodeIndex = reverseLastNotUsedNodeIndex !== -1 ? path.length - 1 - reverseLastNotUsedNodeIndex : -1;
|
1897
|
+
if (firstUsedNodeIndex > -1 && firstUsedNodeIndex < lastNotUsedNodeIndex) suggestions.push({
|
1898
|
+
type: SuggestionType.warning,
|
1899
|
+
message: `Nodes [${path.length > 10 ? `${path.slice(0, 10).map((node) => node.label).join(",")}...(${path.length})` : path.map((node) => node.label).join(",")}] are have function chain calls, perhaps you can refactor it.`,
|
1900
|
+
nodeInfo: path
|
1901
|
+
});
|
1902
|
+
});
|
1903
|
+
if (g.size > 5) {
|
1904
|
+
const ap = findArticulationPoints(g);
|
1905
|
+
ap.forEach((node) => {
|
1906
|
+
if (node.type === NodeType.fun) suggestions.push({
|
1907
|
+
type: SuggestionType.info,
|
1908
|
+
message: `Node [${node.label}] is an articulation point, perhaps you need to pay special attention to this node.`,
|
1909
|
+
nodeInfo: node
|
1910
|
+
});
|
1911
|
+
});
|
1912
|
+
}
|
1913
|
+
});
|
1914
|
+
const noIndegreeNodes = noIndegreeFilter(graph.edges);
|
1915
|
+
noIndegreeNodes.forEach((node) => {
|
1916
|
+
if (!usedNodes.has(node.label) && !node.info?.used?.size) suggestions.push({
|
1917
|
+
type: SuggestionType.info,
|
1918
|
+
message: `Node [${node.label}] is not used, perhaps you can remove it.`,
|
1919
|
+
nodeInfo: node
|
1920
|
+
});
|
1921
|
+
});
|
1922
|
+
return suggestions;
|
2462
1923
|
}
|
2463
1924
|
|
2464
|
-
|
1925
|
+
//#endregion
|
1926
|
+
//#region src/vis.ts
|
2465
1927
|
function filterNodeUserd(used) {
|
2466
|
-
|
2467
|
-
|
2468
|
-
"Assignment Expression",
|
2469
|
-
"Call Expression"
|
2470
|
-
].includes(u)));
|
1928
|
+
const usedArray = Array.from(used || []);
|
1929
|
+
return new Set(usedArray.filter((u) => !["Assignment Expression", "Call Expression"].includes(u)));
|
2471
1930
|
}
|
2472
1931
|
function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set()) {
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
arrows: {
|
2517
|
-
to: {
|
2518
|
-
enabled: true,
|
2519
|
-
scaleFactor: 0.8
|
2520
|
-
}
|
2521
|
-
}
|
2522
|
-
});
|
2523
|
-
});
|
2524
|
-
});
|
2525
|
-
return {
|
2526
|
-
nodes,
|
2527
|
-
edges
|
2528
|
-
};
|
1932
|
+
const usedNodes = new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
1933
|
+
const nodes = [];
|
1934
|
+
const edges = [];
|
1935
|
+
const inDegreeMap = {};
|
1936
|
+
const outDegreeMap = {};
|
1937
|
+
graph.edges.forEach((edge) => {
|
1938
|
+
edge.forEach((to) => {
|
1939
|
+
if (to) inDegreeMap[to.node.label] = (inDegreeMap[to.node.label] || 0) + 1;
|
1940
|
+
});
|
1941
|
+
});
|
1942
|
+
graph.edges.forEach((edge, key) => {
|
1943
|
+
outDegreeMap[key.label] = edge.size;
|
1944
|
+
});
|
1945
|
+
graph.nodes.forEach((node) => {
|
1946
|
+
const inDegree = inDegreeMap[node.label] || 0;
|
1947
|
+
const outDegree = outDegreeMap[node.label] || 0;
|
1948
|
+
nodes.push({
|
1949
|
+
id: node.label,
|
1950
|
+
label: node.label,
|
1951
|
+
shape: node.type === "var" ? "dot" : "diamond",
|
1952
|
+
group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
|
1953
|
+
size: 20 + 1.6 ** (inDegree * .75 + outDegree * .25),
|
1954
|
+
title: `${filterNodeUserd(node.info?.used).size ? `used by ${Array.from(filterNodeUserd(node.info?.used))?.map((i) => `\`${i}\``).join(",")}\n\n` : ""}${usedNodes.has(node.label) ? `used in ${[nodesUsedInStyle.has(node.label) ? "style" : "", nodesUsedInTemplate.has(node.label) ? "template" : ""].filter(Boolean).join(" and ")}\n\n` : ""}${node.info?.comment || ""}`.trim() || void 0,
|
1955
|
+
info: node.info
|
1956
|
+
});
|
1957
|
+
});
|
1958
|
+
graph.edges.forEach((edge, key) => {
|
1959
|
+
edge.forEach((to) => {
|
1960
|
+
if (!to) return;
|
1961
|
+
edges.push({
|
1962
|
+
from: key.label,
|
1963
|
+
to: to.node.label,
|
1964
|
+
arrows: { to: {
|
1965
|
+
enabled: true,
|
1966
|
+
scaleFactor: .8
|
1967
|
+
} }
|
1968
|
+
});
|
1969
|
+
});
|
1970
|
+
});
|
1971
|
+
return {
|
1972
|
+
nodes,
|
1973
|
+
edges
|
1974
|
+
};
|
2529
1975
|
}
|
2530
1976
|
|
2531
|
-
|
2532
|
-
|
2533
|
-
// Annotate the CommonJS export names for ESM import in node:
|
2534
|
-
0 && (module.exports = {
|
2535
|
-
NodeType,
|
2536
|
-
SuggestionType,
|
2537
|
-
analyzeOptions,
|
2538
|
-
analyzeSetupScript,
|
2539
|
-
analyzeStyle,
|
2540
|
-
analyzeTemplate,
|
2541
|
-
analyzeTsx,
|
2542
|
-
gen,
|
2543
|
-
getMermaidText,
|
2544
|
-
getVisData,
|
2545
|
-
parse
|
2546
|
-
});
|
1977
|
+
//#endregion
|
1978
|
+
export { SuggestionType, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeStyle, analyze$3 as analyzeTemplate, analyze$4 as analyzeTsx, gen, getMermaidText, getVisData, parse };
|
2547
1979
|
//# sourceMappingURL=index.js.map
|