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.js CHANGED
@@ -1,2547 +1,1979 @@
1
- "use strict";
2
- var __create = Object.create;
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
- // src/analyze/options.ts
48
- var import_traverse2 = __toESM(require("@babel/traverse"));
49
- var import_compiler_sfc2 = require("@vue/compiler-sfc");
50
-
51
- // src/analyze/setupScript.ts
52
- var import_traverse = __toESM(require("@babel/traverse"));
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
- lineOffset = 0;
63
- addInfo = true;
64
- constructor(_lineOffset = 0, _addInfo = true) {
65
- this.lineOffset = _lineOffset;
66
- this.addInfo = _addInfo;
67
- }
68
- nodes = /* @__PURE__ */ new Map();
69
- addNode(label, node, options = { isComputed: false, isMethod: false, comment: "" }) {
70
- if (this.nodes.has(label)) {
71
- return;
72
- }
73
- if (!options.isComputed && (node.type === "VariableDeclarator" && [
74
- "ArrowFunctionExpression",
75
- "FunctionDeclaration",
76
- "FunctionExpression"
77
- ].includes(node.init?.type || "") || node.type === "ObjectProperty" && [
78
- "ArrowFunctionExpression",
79
- "FunctionDeclaration",
80
- "FunctionExpression"
81
- ].includes(node.value?.type || "") || node.type === "FunctionDeclaration" || node.type === "ObjectMethod" || node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") || options.isMethod) {
82
- this.nodes.set(label, {
83
- label,
84
- type: "fun" /* fun */,
85
- ...this.addInfo ? {
86
- info: {
87
- line: (node.loc?.start.line || 1) - 1 + this.lineOffset,
88
- column: node.loc?.start.column || 0,
89
- ...options.comment ? { comment: options.comment } : {}
90
- }
91
- } : {}
92
- });
93
- } else {
94
- this.nodes.set(label, {
95
- label,
96
- type: "var" /* var */,
97
- ...this.addInfo ? {
98
- info: {
99
- line: (node.loc?.start.line || 1) - 1 + this.lineOffset,
100
- column: node.loc?.start.column || 0,
101
- ...options.comment ? { comment: options.comment } : {}
102
- }
103
- } : {}
104
- });
105
- }
106
- }
107
- addTypedNode(label, node) {
108
- this.nodes.set(label, {
109
- label,
110
- type: node.type,
111
- ...this.addInfo ? {
112
- info: {
113
- ...node.info || {}
114
- }
115
- } : {}
116
- });
117
- }
118
- getNode(label) {
119
- return this.nodes.get(label);
120
- }
121
- map(graph) {
122
- const nodes = new Set(Array.from(graph.nodes).map((node) => {
123
- return this.nodes.get(node);
124
- }).filter((node) => !!node));
125
- const edges = new Map(Array.from(graph.edges).map(([from, to]) => {
126
- const labelMap = /* @__PURE__ */ new Map();
127
- for (const item of to) {
128
- const node = this.nodes.get(item.label);
129
- if (!node) {
130
- continue;
131
- }
132
- const existing = labelMap.get(item.label);
133
- if (!existing || existing.type === "get" && item.type === "set") {
134
- labelMap.set(item.label, { node, type: item.type });
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
- let comment = "";
148
- node.leadingComments?.forEach((_comment) => {
149
- if (_comment.loc.end.line > node.loc.start.line) {
150
- return;
151
- }
152
- if (_comment.value.trim().startsWith("*")) {
153
- comment += `${_comment.value.trim().replace(/^\s*\*+\s*\**/gm, "").trim()}
154
- `;
155
- }
156
- });
157
- node.trailingComments?.forEach((_comment) => {
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
- const assignParent = path.findParent((p) => p.isAssignmentExpression());
173
- if (assignParent) {
174
- const leftNode = assignParent.node.left;
175
- if (leftNode.start != null && path.node.start >= leftNode.start && path.node.end <= leftNode.end) {
176
- return true;
177
- }
178
- }
179
- const updateParent = path.findParent((p) => p.isUpdateExpression());
180
- if (updateParent) {
181
- const argNode = updateParent.node.argument;
182
- if (argNode.start != null && path.node.start >= argNode.start && path.node.end <= argNode.end) {
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
- const parent = path.parentPath;
190
- if (parent && parent.isCallExpression()) {
191
- return parent.node.callee === path.node;
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
- if (path.node.type === "Identifier" && isCallingNode(path)) {
197
- return "call";
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
- // src/analyze/setupScript.ts
206
- var traverse = import_traverse.default.default?.default || import_traverse.default.default || import_traverse.default;
207
- var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
208
- var watchHooks = [
209
- "watch",
210
- // from `@vueuse/core`
211
- "watchArray",
212
- "watchAtMost",
213
- "watchDebounced",
214
- "watchDeep",
215
- "watchIgnorable",
216
- "watchImmediate",
217
- "watchOnce",
218
- "watchPausable",
219
- "watchThrottled",
220
- "watchTriggerable",
221
- "watchWithFilter"
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
- const spread = _spread || [];
225
- const nodeCollection = new NodeCollection(_lineOffset);
226
- const graph = {
227
- nodes: /* @__PURE__ */ new Set(),
228
- edges: /* @__PURE__ */ new Map(),
229
- spread: /* @__PURE__ */ new Map()
230
- };
231
- traverse(ast, {
232
- VariableDeclaration(path) {
233
- path.node.declarations.forEach((declaration) => {
234
- if (declaration.id.type === "ArrayPattern") {
235
- declaration.id.elements.forEach((element) => {
236
- if (element?.type === "Identifier") {
237
- const name = element.name;
238
- const binding = path.scope.getBinding(name);
239
- 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))) {
240
- graph.nodes.add(name);
241
- nodeCollection.addNode(name, element, {
242
- comment: getComment(path.node)
243
- });
244
- if (!graph.edges.get(name)) {
245
- graph.edges.set(name, /* @__PURE__ */ new Set());
246
- }
247
- }
248
- }
249
- if (element?.type === "RestElement" && element.argument.type === "Identifier") {
250
- const name = element.argument.name;
251
- const binding = path.scope.getBinding(name);
252
- 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))) {
253
- graph.nodes.add(name);
254
- nodeCollection.addNode(name, element.argument, {
255
- comment: getComment(path.node)
256
- });
257
- if (!graph.edges.get(name)) {
258
- graph.edges.set(name, /* @__PURE__ */ new Set());
259
- }
260
- }
261
- }
262
- });
263
- }
264
- if (declaration.id.type === "ObjectPattern") {
265
- declaration.id.properties.forEach((property) => {
266
- if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
267
- const name = property.value.name;
268
- const binding = path.scope.getBinding(name);
269
- 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))) {
270
- graph.nodes.add(name);
271
- nodeCollection.addNode(name, property.value, {
272
- comment: getComment(property)
273
- });
274
- if (!graph.edges.get(name)) {
275
- graph.edges.set(name, /* @__PURE__ */ new Set());
276
- }
277
- }
278
- }
279
- if (property.type === "RestElement" && property.argument.type === "Identifier") {
280
- const name = property.argument.name;
281
- const binding = path.scope.getBinding(name);
282
- 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))) {
283
- graph.nodes.add(name);
284
- nodeCollection.addNode(name, property.argument, {
285
- comment: getComment(property)
286
- });
287
- if (!graph.edges.get(name)) {
288
- graph.edges.set(name, /* @__PURE__ */ new Set());
289
- }
290
- }
291
- }
292
- });
293
- }
294
- if (declaration.id?.type === "Identifier") {
295
- const name = declaration.id.name;
296
- const binding = path.scope.getBinding(name);
297
- 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))) {
298
- graph.nodes.add(name);
299
- nodeCollection.addNode(name, declaration, {
300
- comment: getComment(path.node)
301
- });
302
- if (!graph.edges.get(name)) {
303
- graph.edges.set(name, /* @__PURE__ */ new Set());
304
- }
305
- if (spread.includes(name)) {
306
- if (declaration.init?.type === "ObjectExpression") {
307
- declaration.init?.properties.forEach((prop) => {
308
- if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
309
- const keyName = prop.key.name;
310
- graph.nodes.add(keyName);
311
- nodeCollection.addNode(keyName, prop, {
312
- comment: getComment(prop)
313
- });
314
- if (!graph.edges.get(keyName)) {
315
- graph.edges.set(keyName, /* @__PURE__ */ new Set());
316
- }
317
- if (graph.spread.has(name)) {
318
- graph.spread.get(name)?.add(keyName);
319
- } else {
320
- graph.spread.set(name, /* @__PURE__ */ new Set([keyName]));
321
- }
322
- } else if (prop.type === "SpreadElement") {
323
- console.warn("not support spread in spread");
324
- }
325
- });
326
- }
327
- if (declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && declaration.init?.callee.name === "reactive") {
328
- const arg = declaration.init?.arguments[0];
329
- if (arg.type === "ObjectExpression") {
330
- arg.properties.forEach((prop) => {
331
- if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
332
- const keyName = prop.key.name;
333
- graph.nodes.add(keyName);
334
- nodeCollection.addNode(keyName, prop, {
335
- comment: getComment(prop)
336
- });
337
- if (!graph.edges.get(keyName)) {
338
- graph.edges.set(keyName, /* @__PURE__ */ new Set());
339
- }
340
- if (graph.spread.has(name)) {
341
- graph.spread.get(name)?.add(keyName);
342
- } else {
343
- graph.spread.set(name, /* @__PURE__ */ new Set([keyName]));
344
- }
345
- } else if (prop.type === "SpreadElement") {
346
- console.warn("not support spread in spread");
347
- }
348
- });
349
- }
350
- }
351
- }
352
- }
353
- }
354
- });
355
- },
356
- FunctionDeclaration(path) {
357
- const name = path.node.id?.name;
358
- if (name) {
359
- const binding = path.scope.getBinding(name);
360
- if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent)) {
361
- graph.nodes.add(name);
362
- nodeCollection.addNode(name, path.node.id, {
363
- isMethod: true,
364
- comment: getComment(path.node)
365
- });
366
- if (!graph.edges.get(name)) {
367
- graph.edges.set(name, /* @__PURE__ */ new Set());
368
- }
369
- }
370
- }
371
- }
372
- }, parentScope, parentPath);
373
- function traverseHooks(node, patentScope) {
374
- if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier" || node.type === "CallExpression" && node.callee.type === "Identifier") {
375
- const hookName = (() => {
376
- if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && node.expression.callee.type === "Identifier") {
377
- return node.expression.callee.name;
378
- }
379
- if (node.type === "CallExpression" && node.callee.type === "Identifier") {
380
- return node.callee.name;
381
- }
382
- })() || "";
383
- if (!hookName) {
384
- return;
385
- }
386
- const hookBinding = patentScope.getBinding(hookName);
387
- if (!(hookBinding === void 0 || hookBinding?.scope.block.type === "Program" || parentScope === hookBinding?.scope)) {
388
- return;
389
- }
390
- const expression = node.type === "ExpressionStatement" ? node.expression : node;
391
- const watchArgs = /* @__PURE__ */ new Set();
392
- if (hookName === "provide") {
393
- traverse(expression, {
394
- Identifier(path1) {
395
- const binding = path1.scope.getBinding(path1.node.name);
396
- 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)) {
397
- const _node = nodeCollection.getNode(path1.node.name);
398
- if (_node?.info?.used) {
399
- _node?.info?.used?.add(hookName);
400
- } else if (_node) {
401
- _node.info = {
402
- ..._node?.info,
403
- used: /* @__PURE__ */ new Set([hookName])
404
- };
405
- }
406
- }
407
- }
408
- }, patentScope, node);
409
- } else if (watchHooks.includes(hookName)) {
410
- if (expression.arguments[0].type === "Identifier") {
411
- const binding = patentScope.getBinding(expression.arguments[0].name);
412
- if (graph.nodes.has(expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
413
- watchArgs.add(expression.arguments[0]);
414
- }
415
- } else {
416
- traverse(expression.arguments[0], {
417
- Identifier(path1) {
418
- const binding = path1.scope.getBinding(path1.node.name);
419
- 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)) {
420
- watchArgs.add(path1.node);
421
- }
422
- }
423
- }, patentScope, node);
424
- }
425
- } else if (hookName === "useEffect" && expression.arguments[1].type === "ArrayExpression") {
426
- traverse(expression.arguments[1], {
427
- Identifier(path1) {
428
- const binding = path1.scope.getBinding(path1.node.name);
429
- 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)) {
430
- watchArgs.add(path1.node);
431
- }
432
- }
433
- }, patentScope, node);
434
- }
435
- expression.arguments.forEach((argNode, index) => {
436
- if (watchHooks.includes(hookName) && index === 0 && argNode.type === "Identifier") {
437
- const _node = nodeCollection.getNode(argNode.name);
438
- if (_node?.info?.used) {
439
- _node?.info?.used?.add(hookName);
440
- } else if (_node) {
441
- _node.info = {
442
- ..._node?.info,
443
- used: /* @__PURE__ */ new Set([hookName])
444
- };
445
- }
446
- return;
447
- }
448
- if (argNode.type === "Identifier") {
449
- const binding = patentScope.getBinding(argNode.name);
450
- if (graph.nodes.has(argNode.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
451
- const _node = nodeCollection.getNode(argNode.name);
452
- if (_node?.info?.used) {
453
- _node?.info?.used?.add(hookName);
454
- } else if (_node) {
455
- _node.info = {
456
- ..._node?.info,
457
- used: /* @__PURE__ */ new Set([hookName])
458
- };
459
- }
460
- }
461
- } else {
462
- traverse(argNode, {
463
- Identifier(path1) {
464
- const binding = path1.scope.getBinding(path1.node.name);
465
- 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)) {
466
- if ([...watchHooks, "useEffect"].includes(hookName) && watchArgs.size > 0) {
467
- const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
468
- watchArgs.forEach((watchArg) => {
469
- if (!watchArgsNames.includes(path1.node.name)) {
470
- graph.edges.get(watchArg.name)?.add({
471
- label: path1.node.name,
472
- type: getRelationType(path1)
473
- });
474
- }
475
- });
476
- }
477
- const _node = nodeCollection.getNode(path1.node.name);
478
- if (_node?.info?.used) {
479
- _node?.info?.used?.add(hookName);
480
- } else if (_node) {
481
- _node.info = {
482
- ..._node?.info,
483
- used: /* @__PURE__ */ new Set([hookName])
484
- };
485
- }
486
- }
487
- }
488
- }, patentScope, node);
489
- }
490
- });
491
- }
492
- }
493
- traverse(ast, {
494
- FunctionDeclaration(path) {
495
- const name = path.node.id?.name;
496
- if (name && graph.nodes.has(name)) {
497
- traverse(path.node.body, {
498
- Identifier(path1) {
499
- const binding = path1.scope.getBinding(path1.node.name);
500
- 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)) {
501
- graph.edges.get(name)?.add({
502
- label: path1.node.name,
503
- type: getRelationType(path1)
504
- });
505
- }
506
- },
507
- MemberExpression(path1) {
508
- if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
509
- const binding = path1.scope.getBinding(path1.node.object.name);
510
- if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
511
- graph.edges.get(name)?.add({
512
- label: path1.node.property.name,
513
- type: getRelationType(path1)
514
- });
515
- }
516
- }
517
- }
518
- }, path.scope, path);
519
- }
520
- },
521
- VariableDeclarator(path) {
522
- if (path.node.init) {
523
- if (path.node.id.type === "ArrayPattern") {
524
- path.node.id.elements.forEach((element) => {
525
- if (element?.type === "Identifier") {
526
- const name = element.name;
527
- if (name && graph.nodes.has(name) && path.node.init?.type === "CallExpression") {
528
- traverse(path.node.init, {
529
- Identifier(path1) {
530
- const binding = path1.scope.getBinding(path1.node.name);
531
- 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)) {
532
- graph.edges.get(name)?.add({
533
- label: path1.node.name,
534
- type: getRelationType(path1)
535
- });
536
- }
537
- },
538
- MemberExpression(path1) {
539
- if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
540
- const binding = path1.scope.getBinding(path1.node.object.name);
541
- if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
542
- graph.edges.get(name)?.add({
543
- label: path1.node.property.name,
544
- type: getRelationType(path1)
545
- });
546
- }
547
- }
548
- }
549
- }, path.scope, path);
550
- }
551
- }
552
- });
553
- } else if (path.node.id.type === "ObjectPattern") {
554
- path.node.id.properties.forEach((property) => {
555
- if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
556
- const name = property.value.name;
557
- if (name && graph.nodes.has(name) && path.node.init) {
558
- traverse(path.node.init, {
559
- Identifier(path1) {
560
- const binding = path1.scope.getBinding(path1.node.name);
561
- 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)) {
562
- graph.edges.get(name)?.add({
563
- label: path1.node.name,
564
- type: getRelationType(path1)
565
- });
566
- }
567
- },
568
- MemberExpression(path1) {
569
- if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
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
- const ast = (0, import_compiler_sfc.babelParse)(content, { sourceType: "module", plugins: [
716
- "typescript",
717
- ...jsx ? ["jsx"] : []
718
- ] });
719
- const { graph, nodeCollection } = processSetup(ast, void 0, void 0, void 0, lineOffset);
720
- return nodeCollection.map(graph);
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
- // src/analyze/options.ts
724
- var traverse2 = import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default;
725
- var vueLifeCycleHooks = [
726
- "beforeCreate",
727
- "created",
728
- "beforeMount",
729
- "mounted",
730
- "beforeUpdate",
731
- "updated",
732
- "beforeDestroy",
733
- "destroyed",
734
- "activated",
735
- "deactivated",
736
- "errorCaptured",
737
- "renderTracked",
738
- "renderTriggered",
739
- "provide"
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 analyze2(content, lineOffset = 0, jsx = false) {
742
- const ast = (0, import_compiler_sfc2.babelParse)(content, { sourceType: "module", plugins: [
743
- "typescript",
744
- ...jsx ? ["jsx"] : []
745
- ] });
746
- let nodeCollection = new NodeCollection(lineOffset);
747
- const tNodes = /* @__PURE__ */ new Map();
748
- const graph = {
749
- nodes: /* @__PURE__ */ new Set(),
750
- edges: /* @__PURE__ */ new Map()
751
- };
752
- const nodesUsedInTemplate = /* @__PURE__ */ new Set();
753
- function process(node, path) {
754
- traverse2(node, {
755
- ObjectProperty(path1) {
756
- if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
757
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "data" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
758
- const dataNode = path1.node.value;
759
- traverse2(dataNode, {
760
- ReturnStatement(path2) {
761
- if (path2.parent === dataNode.body) {
762
- if (path2.node.argument?.type === "ObjectExpression") {
763
- path2.node.argument.properties.forEach((prop) => {
764
- if (prop.type === "ObjectProperty") {
765
- if (prop.key.type === "Identifier") {
766
- const name = prop.key.name;
767
- graph.nodes.add(name);
768
- tNodes.set(name, prop.key);
769
- nodeCollection.addNode(name, prop, {
770
- comment: getComment(prop)
771
- });
772
- if (!graph.edges.get(name)) {
773
- graph.edges.set(name, /* @__PURE__ */ new Set());
774
- }
775
- }
776
- }
777
- });
778
- }
779
- }
780
- }
781
- }, path1.scope, path1);
782
- }
783
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
784
- const computedNode = path1.node;
785
- if (computedNode.value.type === "ObjectExpression") {
786
- computedNode.value.properties.forEach((prop) => {
787
- if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
788
- if (prop.key.type === "Identifier") {
789
- const name = prop.key.name;
790
- graph.nodes.add(name);
791
- tNodes.set(name, prop.key);
792
- nodeCollection.addNode(name, prop, {
793
- isComputed: true,
794
- comment: getComment(prop)
795
- });
796
- if (!graph.edges.get(name)) {
797
- graph.edges.set(name, /* @__PURE__ */ new Set());
798
- }
799
- }
800
- }
801
- });
802
- }
803
- }
804
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
805
- const methodsNode = path1.node;
806
- if (methodsNode.value.type === "ObjectExpression") {
807
- methodsNode.value.properties.forEach((prop) => {
808
- if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
809
- if (prop.key.type === "Identifier") {
810
- const name = prop.key.name;
811
- graph.nodes.add(name);
812
- tNodes.set(name, prop.key);
813
- nodeCollection.addNode(name, prop, {
814
- isMethod: true,
815
- comment: getComment(prop)
816
- });
817
- if (!graph.edges.get(name)) {
818
- graph.edges.set(name, /* @__PURE__ */ new Set());
819
- }
820
- }
821
- }
822
- });
823
- }
824
- }
825
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "render" && (path1.node.value.type === "ArrowFunctionExpression" || path1.node.value.type === "FunctionExpression")) {
826
- traverse2(path1.node.value, {
827
- ReturnStatement(path2) {
828
- const templateNode = path2.node;
829
- traverse2(templateNode, {
830
- MemberExpression(path3) {
831
- if (path3.node.object && path3.node.object.type === "ThisExpression") {
832
- if (path3.node.property && path3.node.property.type === "Identifier") {
833
- nodesUsedInTemplate.add(path3.node.property.name);
834
- }
835
- }
836
- }
837
- }, path2.scope, path2);
838
- }
839
- }, path1.scope, path1);
840
- }
841
- }
842
- },
843
- ObjectMethod(path1) {
844
- if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
845
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
846
- const setupNode = path1.node;
847
- const spread = [];
848
- traverse2(setupNode, {
849
- ReturnStatement(path2) {
850
- if (path2.node.argument?.type === "ObjectExpression") {
851
- const returnNode = path2.node.argument;
852
- traverse2(returnNode, {
853
- SpreadElement(path3) {
854
- 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") {
855
- spread.push(path3.node.argument.arguments[0].name);
856
- } else if (path3.node.argument.type === "Identifier") {
857
- spread.push(path3.node.argument.name);
858
- }
859
- }
860
- }, path2.scope, path2);
861
- }
862
- if (path2.node.argument?.type === "FunctionExpression" || path2.node.argument?.type === "ArrowFunctionExpression") {
863
- const templateNode = path2.node.argument.body;
864
- traverse2(templateNode, {
865
- Identifier(path3) {
866
- const binding = path3.scope.getBinding(path3.node.name);
867
- if (binding?.scope === path1.scope) {
868
- nodesUsedInTemplate.add(path3.node.name);
869
- }
870
- },
871
- JSXIdentifier(path3) {
872
- const binding = path3.scope.getBinding(path3.node.name);
873
- if (binding?.scope === path1.scope) {
874
- nodesUsedInTemplate.add(path3.node.name);
875
- }
876
- }
877
- }, path2.scope, path2);
878
- }
879
- }
880
- }, path1.scope, path1);
881
- const {
882
- graph: {
883
- nodes: tempNodes,
884
- edges: tempEdges,
885
- spread: tempSpread
886
- },
887
- nodeCollection: tempNodeCollection
888
- } = processSetup(setupNode, path1.scope, setupNode, spread, lineOffset);
889
- traverse2(setupNode, {
890
- ReturnStatement(path2) {
891
- if (path2.scope !== path1.scope) {
892
- return;
893
- }
894
- if (path2.node.argument?.type === "ObjectExpression") {
895
- const returnNode = path2.node.argument;
896
- traverse2(returnNode, {
897
- ObjectProperty(path3) {
898
- if (path3.parent === returnNode) {
899
- if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier" && tempNodes.has(path3.node.value.name)) {
900
- const valName = path3.node.value.name;
901
- if (!graph.nodes.has(valName)) {
902
- graph.nodes.add(valName);
903
- tNodes.set(valName, path3.node.value);
904
- nodeCollection.addTypedNode(
905
- valName,
906
- tempNodeCollection.nodes.get(valName)
907
- );
908
- }
909
- if (!graph.edges.has(valName)) {
910
- graph.edges.set(valName, /* @__PURE__ */ new Set([...Array.from(
911
- tempEdges.get(valName) || /* @__PURE__ */ new Set()
912
- )]));
913
- }
914
- const name = path3.node.key.name;
915
- if (name !== valName) {
916
- graph.nodes.add(name);
917
- tNodes.set(name, path3.node.key);
918
- nodeCollection.addNode(name, path3.node.key, {
919
- comment: getComment(path3.node)
920
- });
921
- graph.edges.set(name, /* @__PURE__ */ new Set([{
922
- label: valName,
923
- type: getRelationType(path3)
924
- }]));
925
- }
926
- }
927
- }
928
- },
929
- SpreadElement(path3) {
930
- 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)) {
931
- tempSpread.get(path3.node.argument.arguments[0].name)?.forEach((name) => {
932
- graph.nodes.add(name);
933
- tNodes.set(name, path3.node.argument.arguments[0]);
934
- nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
935
- if (!graph.edges.get(name)) {
936
- graph.edges.set(name, /* @__PURE__ */ new Set());
937
- tempEdges.get(name)?.forEach((edge) => {
938
- graph.edges.get(name)?.add(edge);
939
- });
940
- }
941
- });
942
- } else if (path3.node.argument.type === "Identifier" && tempSpread.get(path3.node.argument.name)) {
943
- tempSpread.get(path3.node.argument.name)?.forEach((name) => {
944
- graph.nodes.add(name);
945
- tNodes.set(name, path3.node.argument);
946
- nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
947
- if (!graph.edges.get(name)) {
948
- graph.edges.set(name, /* @__PURE__ */ new Set());
949
- tempEdges.get(name)?.forEach((edge) => {
950
- graph.edges.get(name)?.add(edge);
951
- });
952
- }
953
- });
954
- }
955
- }
956
- }, path2.scope, path2);
957
- } else {
958
- graph.edges = tempEdges;
959
- graph.nodes = tempNodes;
960
- nodeCollection = tempNodeCollection;
961
- }
962
- }
963
- }, path1.scope, path1);
964
- }
965
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
966
- const dataNode = path1.node;
967
- traverse2(dataNode, {
968
- ReturnStatement(path2) {
969
- if (path2.parent === dataNode.body) {
970
- if (path2.node.argument?.type === "ObjectExpression") {
971
- path2.node.argument.properties.forEach((prop) => {
972
- if (prop.type === "ObjectProperty") {
973
- if (prop.key.type === "Identifier") {
974
- const name = prop.key.name;
975
- graph.nodes.add(name);
976
- tNodes.set(name, prop.key);
977
- nodeCollection.addNode(name, prop, {
978
- comment: getComment(prop)
979
- });
980
- if (!graph.edges.get(name)) {
981
- graph.edges.set(name, /* @__PURE__ */ new Set());
982
- }
983
- }
984
- }
985
- });
986
- }
987
- }
988
- }
989
- }, path1.scope, path1);
990
- }
991
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "render") {
992
- traverse2(path1.node, {
993
- ReturnStatement(path2) {
994
- const templateNode = path2.node;
995
- traverse2(templateNode, {
996
- MemberExpression(path3) {
997
- if (path3.node.object && path3.node.object.type === "ThisExpression") {
998
- if (path3.node.property && path3.node.property.type === "Identifier") {
999
- nodesUsedInTemplate.add(path3.node.property.name);
1000
- }
1001
- }
1002
- }
1003
- }, path2.scope, path2);
1004
- }
1005
- }, path1.scope, path1);
1006
- }
1007
- }
1008
- }
1009
- }, path.scope, path);
1010
- traverse2(node, {
1011
- ObjectMethod(path1) {
1012
- if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
1013
- if (path1.node.key.type === "Identifier" && vueLifeCycleHooks.includes(path1.node.key.name)) {
1014
- const hookName = path1.node.key.name;
1015
- traverse2(path1.node.body, {
1016
- MemberExpression(path2) {
1017
- if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
1018
- const _node = nodeCollection.getNode(path2.node.property.name);
1019
- if (_node?.info?.used) {
1020
- _node?.info?.used?.add(hookName);
1021
- } else if (_node) {
1022
- _node.info = {
1023
- ..._node?.info,
1024
- used: /* @__PURE__ */ new Set([hookName])
1025
- };
1026
- }
1027
- }
1028
- }
1029
- }, path1.scope, path1);
1030
- }
1031
- }
1032
- },
1033
- ObjectProperty(path1) {
1034
- if (path.node.declaration.type === "ObjectExpression" && path1.parent === path.node.declaration || path.node.declaration.type === "CallExpression" && path1.parent === path.node.declaration.arguments[0]) {
1035
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
1036
- const computedNode = path1.node;
1037
- if (computedNode.value.type === "ObjectExpression") {
1038
- computedNode.value.properties.forEach((prop) => {
1039
- if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
1040
- const name = prop.key.name;
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
- // src/analyze/style.ts
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
- let state = 0 /* inParens */;
1162
- let parenDepth = 0;
1163
- for (let i = start; i < content.length; i++) {
1164
- const char = content.charAt(i);
1165
- switch (state) {
1166
- case 0 /* inParens */:
1167
- if (char === "'") {
1168
- state = 1 /* inSingleQuoteString */;
1169
- } else if (char === '"') {
1170
- state = 2 /* inDoubleQuoteString */;
1171
- } else if (char === "(") {
1172
- parenDepth++;
1173
- } else if (char === ")") {
1174
- if (parenDepth > 0) {
1175
- parenDepth--;
1176
- } else {
1177
- return i;
1178
- }
1179
- }
1180
- break;
1181
- case 1 /* inSingleQuoteString */:
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
- exp = exp.trim();
1197
- if (exp[0] === "'" && exp[exp.length - 1] === "'" || exp[0] === '"' && exp[exp.length - 1] === '"') {
1198
- return exp.slice(1, -1);
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
- var vBindRE = /v-bind\s*\(/g;
1203
- function analyze3(styles) {
1204
- const nodes = /* @__PURE__ */ new Set();
1205
- styles.forEach((style) => {
1206
- let match;
1207
- const content = style.content.replace(/\/\*([\s\S]*?)\*\/|\/\/.*/g, "");
1208
- while (match = vBindRE.exec(content)) {
1209
- const start = match.index + match[0].length;
1210
- const end = lexBinding(content, start);
1211
- if (end !== null) {
1212
- const variable = normalizeExpression(content.slice(start, end));
1213
- nodes.add(variable);
1214
- }
1215
- }
1216
- });
1217
- return nodes;
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
- // src/analyze/template.ts
1221
- var import_traverse3 = __toESM(require("@babel/traverse"));
1222
- var import_compiler_sfc3 = require("@vue/compiler-sfc");
1223
- var traverse3 = import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default;
1224
- function analyze4(content) {
1225
- const id = "template";
1226
- const { code } = (0, import_compiler_sfc3.compileTemplate)({
1227
- id,
1228
- source: content,
1229
- filename: `${id}.js`
1230
- });
1231
- const ast = (0, import_compiler_sfc3.babelParse)(code, { sourceType: "module", plugins: [
1232
- "typescript"
1233
- ] });
1234
- const nodes = /* @__PURE__ */ new Set();
1235
- traverse3(ast, {
1236
- MemberExpression(path) {
1237
- if (path.type === "MemberExpression") {
1238
- if (path.node.object && path.node.object.type === "Identifier" && path.node.object.name === "_ctx") {
1239
- if (path.node.property && path.node.property.type === "Identifier") {
1240
- nodes.add(path.node.property.name);
1241
- }
1242
- }
1243
- }
1244
- },
1245
- ObjectProperty(path) {
1246
- if (path.node.key.type === "Identifier" && path.node.key.name === "ref") {
1247
- if (path.node.value.type === "StringLiteral") {
1248
- const name = path.node.value.value;
1249
- if (name) {
1250
- nodes.add(name);
1251
- }
1252
- }
1253
- }
1254
- },
1255
- // component
1256
- CallExpression(path) {
1257
- if (path.node.callee.type === "Identifier" && path.node.callee.name === "_resolveComponent") {
1258
- if (path.node.arguments[0].type === "StringLiteral") {
1259
- const name = path.node.arguments[0].value;
1260
- if (name) {
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
- // src/analyze/tsx.ts
1271
- var import_compiler_sfc4 = require("@vue/compiler-sfc");
1272
-
1273
- // src/utils/traverse.ts
1274
- var import_traverse4 = __toESM(require("@babel/traverse"));
1275
- var traverse4 = import_traverse4.default.default?.default || import_traverse4.default.default || import_traverse4.default;
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
- traverse4(node, {
1278
- ObjectProperty(path1) {
1279
- if (path1.node.type === "ObjectProperty" && path1.node.key.type === "Identifier" && path1.node.value.type === "Identifier") {
1280
- const name = path1.node.value.name;
1281
- const _scope = path1.scope.getBinding(name)?.scope;
1282
- if (_scope && _scope === rootScope) {
1283
- res.push(path1.node.value);
1284
- }
1285
- } else if (path1.node.type === "ObjectProperty" && path1.node.key.type === "Identifier" && path1.node.value.type === "ObjectPattern") {
1286
- rescureObjectPattern({
1287
- node: path1.node.value,
1288
- rootScope,
1289
- res,
1290
- parentScope: path1.scope,
1291
- parentPath: path1
1292
- });
1293
- }
1294
- },
1295
- RestElement(path1) {
1296
- if (path1.node.argument.type === "Identifier") {
1297
- const name = path1.node.argument.name;
1298
- const _scope = path1.scope.getBinding(name)?.scope;
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
- traverse4(node, {
1308
- Identifier(path1) {
1309
- if (path1.node.type === "Identifier") {
1310
- const name = path1.node.name;
1311
- const _scope = path1.scope.getBinding(name)?.scope;
1312
- if (_scope && _scope === rootScope) {
1313
- res.push(path1.node);
1314
- }
1315
- }
1316
- },
1317
- ArrayPattern(path1) {
1318
- if (path1.node.type === "ArrayPattern") {
1319
- rescureArrayPattern({
1320
- node: path1.node,
1321
- rootScope,
1322
- res,
1323
- parentScope: path1.scope,
1324
- parentPath: path1
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
- path,
1332
- rootScope,
1333
- cb
1334
- }) {
1335
- if (path.node.id.type !== "Identifier") {
1336
- return;
1337
- }
1338
- if (path.node.init?.type === "ArrowFunctionExpression" || path.node.init?.type === "FunctionExpression") {
1339
- cb?.({
1340
- name: path.node.id.name,
1341
- node: path.node,
1342
- path,
1343
- scope: rootScope
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
- if (path.node.id.type !== "ObjectPattern") {
1356
- return;
1357
- }
1358
- path.node.id.properties.forEach((property) => {
1359
- if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "Identifier") {
1360
- cb?.({
1361
- name: property.value.name,
1362
- node: property,
1363
- path,
1364
- scope: rootScope
1365
- });
1366
- } else if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "AssignmentPattern") {
1367
- cb?.({
1368
- name: property.key.name,
1369
- node: property,
1370
- path,
1371
- scope: rootScope
1372
- });
1373
- } else if (property.type === "RestElement" && property.argument.type === "Identifier") {
1374
- cb?.({
1375
- name: property.argument.name,
1376
- node: property,
1377
- path,
1378
- scope: rootScope
1379
- });
1380
- } else if (property.type === "ObjectProperty" && property.key.type === "Identifier" && property.value.type === "ObjectPattern") {
1381
- const res = [];
1382
- rescureObjectPattern({
1383
- node: property.value,
1384
- rootScope,
1385
- res,
1386
- parentScope: path.scope,
1387
- parentPath: path
1388
- });
1389
- res.forEach((r) => cb?.({
1390
- name: r.name,
1391
- node: r,
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
- if (path.node.id.type !== "ArrayPattern") {
1400
- return;
1401
- }
1402
- path.node.id.elements.forEach((ele) => {
1403
- if (ele?.type === "Identifier") {
1404
- cb?.({
1405
- name: ele.name,
1406
- node: ele,
1407
- path,
1408
- scope: rootScope
1409
- });
1410
- } else if (ele?.type === "ArrayPattern") {
1411
- const res = [];
1412
- rescureArrayPattern({
1413
- node: ele,
1414
- rootScope,
1415
- res,
1416
- parentScope: path.scope,
1417
- parentPath: path
1418
- });
1419
- res.forEach((r) => cb?.({
1420
- name: r.name,
1421
- node: r,
1422
- path,
1423
- scope: rootScope
1424
- }));
1425
- } else if (ele?.type === "AssignmentPattern") {
1426
- if (ele.left.type === "Identifier") {
1427
- cb?.({
1428
- name: ele.left.name,
1429
- node: ele,
1430
- path,
1431
- scope: rootScope
1432
- });
1433
- }
1434
- } else if (ele?.type === "RestElement") {
1435
- if (ele.argument.type === "Identifier") {
1436
- cb?.({
1437
- name: ele.argument.name,
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
- if (path.node.type !== "FunctionDeclaration") {
1448
- return;
1449
- }
1450
- if (path.node.id?.type === "Identifier") {
1451
- cb?.({
1452
- name: path.node.id.name,
1453
- node: path.node,
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
- if (!path.node.id || path.node.id.type !== "Identifier") {
1461
- return;
1462
- }
1463
- if (path.node.init?.type && [
1464
- "ArrowFunctionExpression",
1465
- "FunctionExpression",
1466
- "CallExpression",
1467
- "ObjectExpression",
1468
- "ArrayExpression"
1469
- ].includes(path.node.init.type)) {
1470
- if (collectionNodes.has(path.node.id.name) && path.scope.getBinding(path.node.id.name)?.scope === rootScope) {
1471
- const name = path.node.id.name;
1472
- traverse4(path.node.init, {
1473
- Identifier(path1) {
1474
- const binding = path1.scope.getBinding(path1.node.name);
1475
- if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) {
1476
- cb?.({
1477
- fromName: name,
1478
- toName: path1.node.name,
1479
- path: path1,
1480
- scope: rootScope,
1481
- collectionNodes
1482
- });
1483
- }
1484
- },
1485
- MemberExpression(path1) {
1486
- if (spread?.length && path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier") {
1487
- cb?.({
1488
- fromName: name,
1489
- toName: path1.node.property.name,
1490
- toScope: path1.scope.getBinding(path1.node.object.name)?.scope,
1491
- path: path1,
1492
- scope: rootScope,
1493
- collectionNodes
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
- if (!path.node.id || path.node.id.type !== "ObjectPattern") {
1503
- return;
1504
- }
1505
- if (path.node.init?.type && [
1506
- "ArrowFunctionExpression",
1507
- "FunctionExpression",
1508
- "CallExpression",
1509
- "ObjectExpression",
1510
- "ArrayExpression"
1511
- ].includes(path.node.init.type)) {
1512
- const res = [];
1513
- rescureObjectPattern({
1514
- node: path.node.id,
1515
- rootScope,
1516
- res,
1517
- parentScope: path.scope,
1518
- parentPath: path
1519
- });
1520
- res.filter((r) => collectionNodes.has(r.name) && path.scope.getBinding(r.name)?.scope === rootScope);
1521
- traverse4(path.node.init, {
1522
- Identifier(path1) {
1523
- const binding = path1.scope.getBinding(path1.node.name);
1524
- if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) {
1525
- res.forEach((r) => {
1526
- cb?.({
1527
- fromName: r.name,
1528
- toName: path1.node.name,
1529
- path: path1,
1530
- scope: rootScope,
1531
- collectionNodes
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
- if (!path.node.id || path.node.id.type !== "ArrayPattern") {
1541
- return;
1542
- }
1543
- if (path.node.init?.type && [
1544
- "ArrowFunctionExpression",
1545
- "FunctionExpression",
1546
- "CallExpression",
1547
- "ObjectExpression",
1548
- "ArrayExpression"
1549
- ].includes(path.node.init.type)) {
1550
- const res = [];
1551
- rescureArrayPattern({
1552
- node: path.node.id,
1553
- rootScope,
1554
- res,
1555
- parentScope: path.scope,
1556
- parentPath: path
1557
- });
1558
- res.filter((r) => collectionNodes.has(r.name) && path.scope.getBinding(r.name)?.scope === rootScope);
1559
- traverse4(path.node.init, {
1560
- Identifier(path1) {
1561
- const binding = path1.scope.getBinding(path1.node.name);
1562
- if (binding?.scope === rootScope && collectionNodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node)) {
1563
- res.forEach((r) => {
1564
- cb?.({
1565
- fromName: r.name,
1566
- toName: path1.node.name,
1567
- path: path1,
1568
- scope: rootScope,
1569
- collectionNodes
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
- if (!path.node.id) {
1579
- return;
1580
- }
1581
- if (collectionNodes.has(path.node.id.name) && path.scope.getBinding(path.node.id.name)?.scope === rootScope) {
1582
- const name = path.node.id.name;
1583
- traverse4(path.node.body, {
1584
- Identifier(path1) {
1585
- const binding = path1.scope.getBinding(path1.node.name);
1586
- if (binding?.scope === rootScope && collectionNodes.has(path1.node.name)) {
1587
- cb?.({
1588
- fromName: name,
1589
- toName: path1.node.name,
1590
- path: path1,
1591
- scope: rootScope,
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
- if (path.node.argument && // return () => (<div></div>)
1601
- // return function() (<div></div>)
1602
- ((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"))) {
1603
- path.traverse({
1604
- Identifier(path1) {
1605
- cb?.({
1606
- name: path1.node.name,
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
- let path;
1616
- traverse4(node, {
1617
- ObjectMethod(path1) {
1618
- if (parentPath.node.declaration.type === "ObjectExpression" && path1.parent === parentPath.node.declaration || parentPath.node.declaration.type === "CallExpression" && path1.parent === parentPath.node.declaration.arguments[0]) {
1619
- if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
1620
- path = path1;
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
- path1.traverse({
1629
- ReturnStatement(path2) {
1630
- if (path2.node.argument?.type === "ObjectExpression") {
1631
- const returnNode = path2.node.argument;
1632
- traverse4(returnNode, {
1633
- SpreadElement(path3) {
1634
- 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") {
1635
- spread.push(path3.node.argument.arguments[0].name);
1636
- } else if (path3.node.argument.type === "Identifier") {
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
- path1.traverse({
1647
- ReturnStatement(path2) {
1648
- if (path2.node.argument?.type === "ObjectExpression") {
1649
- const returnNode = path2.node.argument;
1650
- traverse4(returnNode, {
1651
- ObjectProperty(path3) {
1652
- if (path3.parent === returnNode) {
1653
- if (path3.node.key.type === "Identifier" && path3.node.value.type === "Identifier") {
1654
- const valName = path3.node.value.name;
1655
- if (!graph.nodes.has(valName)) {
1656
- graph.nodes.add(valName);
1657
- nodeCollection.addTypedNode(
1658
- valName,
1659
- tempNodeCollection.nodes.get(valName)
1660
- );
1661
- }
1662
- if (!graph.edges.has(valName)) {
1663
- graph.edges.set(valName, /* @__PURE__ */ new Set([...Array.from(
1664
- tempEdges.get(valName) || /* @__PURE__ */ new Set()
1665
- )]));
1666
- }
1667
- const name = path3.node.key.name;
1668
- if (name !== valName) {
1669
- graph.nodes.add(name);
1670
- nodeCollection.addNode(name, path3.node.key, {
1671
- comment: getComment(path3.node)
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
- path1.traverse({
1688
- ReturnStatement(path2) {
1689
- if (path2.node.argument?.type === "ObjectExpression") {
1690
- const returnNode = path2.node.argument;
1691
- traverse4(returnNode, {
1692
- SpreadElement(path3) {
1693
- 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)) {
1694
- tempSpread.get(path3.node.argument.arguments[0].name)?.forEach((name) => {
1695
- graph.nodes.add(name);
1696
- nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
1697
- if (!graph.edges.get(name)) {
1698
- graph.edges.set(name, /* @__PURE__ */ new Set());
1699
- tempEdges.get(name)?.forEach((edge) => {
1700
- graph.edges.get(name)?.add(edge);
1701
- });
1702
- }
1703
- });
1704
- } else if (path3.node.argument.type === "Identifier" && tempSpread.get(path3.node.argument.name)) {
1705
- tempSpread.get(path3.node.argument.name)?.forEach((name) => {
1706
- graph.nodes.add(name);
1707
- nodeCollection.addTypedNode(name, tempNodeCollection.nodes.get(name));
1708
- if (!graph.edges.get(name)) {
1709
- graph.edges.set(name, /* @__PURE__ */ new Set());
1710
- tempEdges.get(name)?.forEach((edge) => {
1711
- graph.edges.get(name)?.add(edge);
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
- if (path1.node.init?.type === "ObjectExpression") {
1724
- path1.node.init?.properties.forEach((prop) => {
1725
- if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
1726
- const keyName = prop.key.name;
1727
- graph.nodes.add(keyName);
1728
- nodeCollection.addNode(keyName, prop, {
1729
- comment: getComment(prop)
1730
- });
1731
- if (!graph.edges.get(keyName)) {
1732
- graph.edges.set(keyName, /* @__PURE__ */ new Set());
1733
- }
1734
- if (graph.spread.has(iname)) {
1735
- graph.spread.get(iname)?.add(keyName);
1736
- } else {
1737
- graph.spread.set(iname, /* @__PURE__ */ new Set([keyName]));
1738
- }
1739
- } else if (prop.type === "SpreadElement") {
1740
- console.warn("not support spread in spread");
1741
- }
1742
- });
1743
- }
1744
- if (path1.node.init?.type === "CallExpression" && path1.node.init?.callee.type === "Identifier" && path1.node.init?.callee.name === "reactive") {
1745
- const arg = path1.node.init?.arguments[0];
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
- // src/analyze/tsx.ts
1308
+ //#endregion
1309
+ //#region src/analyze/tsx.ts
1771
1310
  function processByReturnNotJSX(params) {
1772
- const { node, parentPath, lineOffset, addInfo } = params;
1773
- const spread = [];
1774
- const nodeCollection = new NodeCollection(lineOffset, addInfo);
1775
- const graph = {
1776
- nodes: /* @__PURE__ */ new Set(),
1777
- edges: /* @__PURE__ */ new Map()
1778
- };
1779
- const setupPath = traverseSetup({ node, parentScope: parentPath.scope, parentPath });
1780
- collectionSpread({ path: setupPath, spread });
1781
- const {
1782
- graph: {
1783
- nodes: tempNodes,
1784
- edges: tempEdges,
1785
- spread: tempSpread
1786
- },
1787
- nodeCollection: tempNodeCollection,
1788
- nodesUsedInTemplate
1789
- } = processByReturnJSX({ node, parentPath, spread, lineOffset, addInfo });
1790
- addIdentifiesToGraphByScanReturn({
1791
- path: setupPath,
1792
- graph,
1793
- nodeCollection,
1794
- tempNodeCollection,
1795
- tempEdges
1796
- });
1797
- addSpreadToGraphByScanReturn({
1798
- path: setupPath,
1799
- graph,
1800
- nodeCollection,
1801
- tempNodeCollection,
1802
- tempEdges,
1803
- tempSpread
1804
- });
1805
- return {
1806
- graph,
1807
- nodeCollection,
1808
- nodesUsedInTemplate
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
- const { node, parentPath, spread = [], lineOffset, addInfo } = params;
1813
- const nodeCollection = new NodeCollection(lineOffset, addInfo);
1814
- const nodesUsedInTemplate = /* @__PURE__ */ new Set();
1815
- const graph = {
1816
- nodes: /* @__PURE__ */ new Set(),
1817
- edges: /* @__PURE__ */ new Map(),
1818
- spread: /* @__PURE__ */ new Map()
1819
- };
1820
- function addNode({ name, node: node2, path, scope }, commentParentNode) {
1821
- const binding = path.scope.getBinding(name);
1822
- if (scope === binding?.scope) {
1823
- graph.nodes.add(name);
1824
- nodeCollection.addNode(name, node2, {
1825
- comment: commentParentNode ? getComment(commentParentNode) : ""
1826
- });
1827
- if (!graph.edges.get(name)) {
1828
- graph.edges.set(name, /* @__PURE__ */ new Set());
1829
- }
1830
- }
1831
- }
1832
- function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
1833
- const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
1834
- if (scope === bindingScope && collectionNodes.has(toName)) {
1835
- graph.edges.get(fromName)?.add({
1836
- label: toName,
1837
- type: getRelationType(path)
1838
- });
1839
- }
1840
- }
1841
- function addUsed({ name, path, parentPath: parentPath2 }) {
1842
- const binding = path.scope.getBinding(name);
1843
- if (binding?.scope === parentPath2.scope) {
1844
- nodesUsedInTemplate.add(name);
1845
- }
1846
- }
1847
- const setupPath = traverseSetup({ node, parentScope: parentPath.scope, parentPath });
1848
- const setupScope = setupPath.scope;
1849
- const setupNode = setupPath.node;
1850
- traverse4(setupNode, {
1851
- VariableDeclarator(path1) {
1852
- parseNodeIdentifierPattern({
1853
- path: path1,
1854
- rootScope: setupScope,
1855
- cb: (params2) => {
1856
- if (!spread.includes(params2.name)) {
1857
- addNode(params2, path1.node);
1858
- } else {
1859
- addGraphBySpreadIdentifier({
1860
- path: path1,
1861
- graph,
1862
- nodeCollection,
1863
- iname: params2.name
1864
- });
1865
- }
1866
- }
1867
- });
1868
- parseNodeObjectPattern({
1869
- path: path1,
1870
- rootScope: setupScope,
1871
- cb: addNode
1872
- });
1873
- parseNodeArrayPattern({
1874
- path: path1,
1875
- rootScope: setupScope,
1876
- cb: addNode
1877
- });
1878
- },
1879
- FunctionDeclaration(path1) {
1880
- parseNodeFunctionPattern({
1881
- path: path1,
1882
- rootScope: setupScope,
1883
- cb: addNode
1884
- });
1885
- }
1886
- }, setupScope, setupPath);
1887
- setupPath.traverse({
1888
- ReturnStatement(path2) {
1889
- parseReturnJsxPattern({
1890
- path: path2,
1891
- parentPath: setupPath,
1892
- cb: addUsed
1893
- });
1894
- }
1895
- });
1896
- traverse4(setupNode, {
1897
- VariableDeclarator(path1) {
1898
- parseEdgeLeftIdentifierPattern({
1899
- path: path1,
1900
- rootScope: setupScope,
1901
- collectionNodes: graph.nodes,
1902
- cb: addEdge,
1903
- spread
1904
- });
1905
- parseEdgeLeftObjectPattern({
1906
- path: path1,
1907
- rootScope: setupScope,
1908
- collectionNodes: graph.nodes,
1909
- cb: addEdge
1910
- });
1911
- parseEdgeLeftArrayPattern({
1912
- path: path1,
1913
- rootScope: setupScope,
1914
- collectionNodes: graph.nodes,
1915
- cb: addEdge
1916
- });
1917
- },
1918
- FunctionDeclaration(path1) {
1919
- parseEdgeFunctionPattern({
1920
- path: path1,
1921
- rootScope: setupScope,
1922
- collectionNodes: graph.nodes,
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
- const { node, parentScope, parentPath, lineOffset, addInfo } = params;
1935
- const nodeCollection = new NodeCollection(lineOffset, addInfo);
1936
- const nodesUsedInTemplate = /* @__PURE__ */ new Set();
1937
- const graph = {
1938
- nodes: /* @__PURE__ */ new Set(),
1939
- edges: /* @__PURE__ */ new Map(),
1940
- spread: /* @__PURE__ */ new Map()
1941
- };
1942
- function addNode({ name, node: node2, path, scope }, commentParentNode) {
1943
- const binding = path.scope.getBinding(name);
1944
- if (scope === binding?.scope) {
1945
- graph.nodes.add(name);
1946
- nodeCollection.addNode(name, node2, {
1947
- comment: commentParentNode ? getComment(commentParentNode) : ""
1948
- });
1949
- if (!graph.edges.get(name)) {
1950
- graph.edges.set(name, /* @__PURE__ */ new Set());
1951
- }
1952
- }
1953
- }
1954
- function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
1955
- const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
1956
- if (scope === bindingScope && collectionNodes.has(toName)) {
1957
- graph.edges.get(fromName)?.add({
1958
- label: toName,
1959
- type: getRelationType(path)
1960
- });
1961
- }
1962
- }
1963
- function addUsed({ name, path, parentPath: parentPath2 }) {
1964
- const binding = path.scope.getBinding(name);
1965
- if (binding?.scope === parentPath2.scope) {
1966
- nodesUsedInTemplate.add(name);
1967
- }
1968
- }
1969
- traverse4(node, {
1970
- VariableDeclarator(path1) {
1971
- parseNodeIdentifierPattern({
1972
- path: path1,
1973
- rootScope: parentScope,
1974
- cb: (params2) => {
1975
- addNode(params2, path1.node);
1976
- }
1977
- });
1978
- parseNodeObjectPattern({
1979
- path: path1,
1980
- rootScope: parentScope,
1981
- cb: addNode
1982
- });
1983
- parseNodeArrayPattern({
1984
- path: path1,
1985
- rootScope: parentScope,
1986
- cb: addNode
1987
- });
1988
- },
1989
- FunctionDeclaration(path1) {
1990
- parseNodeFunctionPattern({
1991
- path: path1,
1992
- rootScope: parentScope,
1993
- cb: addNode
1994
- });
1995
- }
1996
- }, parentScope, parentPath);
1997
- traverse4(node, {
1998
- ReturnStatement(path2) {
1999
- parseReturnJsxPattern({
2000
- path: path2,
2001
- parentPath,
2002
- cb: addUsed
2003
- });
2004
- }
2005
- }, parentScope, parentPath);
2006
- traverse4(node, {
2007
- VariableDeclarator(path1) {
2008
- parseEdgeLeftIdentifierPattern({
2009
- path: path1,
2010
- rootScope: parentScope,
2011
- collectionNodes: graph.nodes,
2012
- cb: addEdge
2013
- });
2014
- parseEdgeLeftObjectPattern({
2015
- path: path1,
2016
- rootScope: parentScope,
2017
- collectionNodes: graph.nodes,
2018
- cb: addEdge
2019
- });
2020
- parseEdgeLeftArrayPattern({
2021
- path: path1,
2022
- rootScope: parentScope,
2023
- collectionNodes: graph.nodes,
2024
- cb: addEdge
2025
- });
2026
- },
2027
- FunctionDeclaration(path1) {
2028
- parseEdgeFunctionPattern({
2029
- path: path1,
2030
- rootScope: parentScope,
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
- let result;
2044
- function process(params2) {
2045
- const { node, parentPath } = params2;
2046
- const setupPath = traverseSetup({ node, parentScope: parentPath.scope, parentPath });
2047
- setupPath.traverse({
2048
- ReturnStatement(path) {
2049
- 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")) {
2050
- result = processByReturnJSX(params2);
2051
- } else {
2052
- result = processByReturnNotJSX(params2);
2053
- }
2054
- }
2055
- });
2056
- }
2057
- traverse4(params.node, {
2058
- ExportDefaultDeclaration(path) {
2059
- if (params.type === "vue") {
2060
- if (path.node.declaration.type === "ObjectExpression") {
2061
- process({
2062
- ...params,
2063
- node: path.node.declaration,
2064
- parentNode: path.node,
2065
- parentPath: path
2066
- });
2067
- } 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") {
2068
- process({
2069
- ...params,
2070
- node: path.node.declaration.arguments[0],
2071
- parentNode: path.node,
2072
- parentPath: path
2073
- });
2074
- }
2075
- }
2076
- if (params.type === "react") {
2077
- if ((path.node.declaration.type === "FunctionDeclaration" || path.node.declaration.type === "ArrowFunctionExpression") && path.node.declaration.body.type === "BlockStatement") {
2078
- const functionPath = path.get("declaration");
2079
- result = processByReact({
2080
- ...params,
2081
- node: path.node.declaration.body,
2082
- parentNode: functionPath.node,
2083
- parentPath: functionPath,
2084
- parentScope: functionPath.scope
2085
- });
2086
- }
2087
- if (path.node.declaration.type === "ClassDeclaration") {
2088
- const renderFunction = path.node.declaration.body.body.find((node) => {
2089
- if (node.type === "ClassMethod" && node.key.type === "Identifier" && node.key.name === "render") {
2090
- return node;
2091
- }
2092
- return void 0;
2093
- });
2094
- if (!renderFunction) {
2095
- return;
2096
- }
2097
- const renderPath = path.get(`declaration.body.body.${path.node.declaration.body.body.indexOf(renderFunction)}`);
2098
- result = processByReact({
2099
- ...params,
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 analyze5(content, type = "vue", lineOffset = 0, addInfo = true) {
2112
- const ast = (0, import_compiler_sfc4.babelParse)(content, { sourceType: "module", plugins: [
2113
- "typescript",
2114
- "jsx"
2115
- ] });
2116
- const { graph, nodeCollection, nodesUsedInTemplate } = processTsx({
2117
- node: ast,
2118
- type,
2119
- lineOffset,
2120
- addInfo
2121
- });
2122
- return {
2123
- graph: nodeCollection.map(graph),
2124
- nodesUsedInTemplate
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
- // src/mermaid.ts
1643
+ //#endregion
1644
+ //#region src/mermaid.ts
2129
1645
  function getMermaidText(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set(), options = {}) {
2130
- const direction = options.direction || "TB";
2131
- const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
2132
- let mermaidText = `flowchart ${direction}
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
- graph.nodes.forEach((node) => {
2140
- const shape = node.type === "var" ? "(" : "[";
2141
- const closeShape = node.type === "var" ? ")" : "]";
2142
- const unusedSuffix = !(usedNodes.has(node.label) || node.info?.used?.size) ? "*" : "";
2143
- mermaidText += ` ${node.label}${shape}${node.label}${unusedSuffix}${closeShape}
2144
- `;
2145
- });
2146
- graph.edges.forEach((edge, key) => {
2147
- edge.forEach((to) => {
2148
- if (!to || !to.node.label) {
2149
- return;
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
- // src/suggest/filter.ts
1669
+ //#endregion
1670
+ //#region src/suggest/filter.ts
1671
+ /**
1672
+ * Filter out nodes that have no indegree.
1673
+ */
2159
1674
  function noIndegreeFilter(graph) {
2160
- const nodes = Array.from(graph.keys());
2161
- const indegree = /* @__PURE__ */ new Map();
2162
- nodes.forEach((node) => {
2163
- indegree.set(node, 0);
2164
- });
2165
- graph.forEach((targets, node) => {
2166
- targets.forEach((target) => {
2167
- indegree.set(target.node, (indegree.get(target.node) || 0) + 1);
2168
- });
2169
- });
2170
- return nodes.filter((node) => indegree.get(node) === 0);
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
- const linearPaths = [];
2174
- const visitedNodes = /* @__PURE__ */ new Set();
2175
- const nodeInDegrees = /* @__PURE__ */ new Map();
2176
- for (const [node, edges] of graph.entries()) {
2177
- if (!nodeInDegrees.has(node)) {
2178
- nodeInDegrees.set(node, 0);
2179
- }
2180
- for (const edge of edges) {
2181
- const inDegree = nodeInDegrees.get(edge.node) || 0;
2182
- nodeInDegrees.set(edge.node, inDegree + 1);
2183
- }
2184
- }
2185
- function dfs2(node, path) {
2186
- if (visitedNodes.has(node)) {
2187
- return;
2188
- }
2189
- path.push(node);
2190
- visitedNodes.add(node);
2191
- const edges = graph.get(node) || /* @__PURE__ */ new Set();
2192
- if (edges.size === 0 || edges.size > 1) {
2193
- if (path.length > 1) {
2194
- addOrUpdatePath([...path]);
2195
- }
2196
- } else {
2197
- const nextNode = Array.from(edges)[0].node;
2198
- const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
2199
- if (nextNodeInDegree === 1) {
2200
- dfs2(nextNode, path);
2201
- }
2202
- }
2203
- path.pop();
2204
- visitedNodes.delete(node);
2205
- }
2206
- function addOrUpdatePath(newPath) {
2207
- let shouldAddNewPath = true;
2208
- for (let i = linearPaths.length - 1; i >= 0; i--) {
2209
- const existingPath = linearPaths[i];
2210
- if (isSubpath(existingPath, newPath)) {
2211
- linearPaths.splice(i, 1);
2212
- } else if (isSubpath(newPath, existingPath)) {
2213
- shouldAddNewPath = false;
2214
- break;
2215
- }
2216
- }
2217
- if (shouldAddNewPath && newPath.length > 2) {
2218
- linearPaths.push(newPath);
2219
- }
2220
- }
2221
- function isSubpath(shortPath, longPath) {
2222
- if (shortPath.length >= longPath.length) {
2223
- return false;
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
- const noIndegreeNodes = noIndegreeFilter(graph);
2246
- let time = 0;
2247
- const low = /* @__PURE__ */ new Map();
2248
- const disc = /* @__PURE__ */ new Map();
2249
- const parent = /* @__PURE__ */ new Map();
2250
- const ap = /* @__PURE__ */ new Set();
2251
- const visited = /* @__PURE__ */ new Set();
2252
- function APUtil(graph2, node) {
2253
- let children = 0;
2254
- disc.set(node, time);
2255
- low.set(node, time);
2256
- time++;
2257
- visited.add(node);
2258
- for (const neighbor of graph2.get(node) || []) {
2259
- if (!visited.has(neighbor.node)) {
2260
- children++;
2261
- parent.set(neighbor.node, node);
2262
- APUtil(graph2, neighbor.node);
2263
- low.set(node, Math.min(low.get(node), low.get(neighbor.node)));
2264
- if (parent.get(node) === null && children > 1) {
2265
- ap.add(node);
2266
- }
2267
- if (parent.get(node) !== null && low.get(neighbor.node) >= disc.get(node)) {
2268
- ap.add(node);
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
- // src/suggest/split.ts
1767
+ //#endregion
1768
+ //#region src/suggest/split.ts
2284
1769
  function dfs(graph, node, targets, visited, component) {
2285
- component.add(node);
2286
- visited.add(node);
2287
- targets.forEach((target) => {
2288
- if (!visited.has(target.node)) {
2289
- dfs(graph, target.node, graph.get(target.node) || /* @__PURE__ */ new Set(), visited, component);
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
- for (const item of setA) {
2295
- if (setB.has(item)) {
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
- let result = [...arr];
2303
- for (let i = 0; i < result.length; i++) {
2304
- for (let j = i + 1; j < result.length; j++) {
2305
- if (haveIntersection(result[i], result[j])) {
2306
- const newSet = /* @__PURE__ */ new Set([...result[i], ...result[j]]);
2307
- result.splice(j, 1);
2308
- result.splice(i, 1);
2309
- result = [...result, newSet];
2310
- return mergeSets(result);
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
- const components = [];
2318
- const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
2319
- new Map(sorted).forEach((targets, node) => {
2320
- const visited = /* @__PURE__ */ new Set();
2321
- if (!visited.has(node)) {
2322
- const component = /* @__PURE__ */ new Set();
2323
- dfs(graph, node, targets, visited, component);
2324
- components.push(component);
2325
- }
2326
- });
2327
- return mergeSets(components).map((component) => {
2328
- const subGraph = /* @__PURE__ */ new Map();
2329
- component.forEach((node) => {
2330
- const targets = graph.get(node);
2331
- if (targets) {
2332
- subGraph.set(node, targets);
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
- // src/suggest/utils.ts
1812
+ //#endregion
1813
+ //#region src/suggest/utils.ts
2340
1814
  function hasCycle(graph) {
2341
- const visited = /* @__PURE__ */ new Set();
2342
- const onStack = /* @__PURE__ */ new Set();
2343
- const stack = [];
2344
- let cycleNodes = [];
2345
- function dfs2(node) {
2346
- if (visited.has(node)) {
2347
- if (onStack.has(node)) {
2348
- const idx = stack.indexOf(node);
2349
- const cycle = stack.slice(idx);
2350
- const allNotGet = cycle.every((curr, i) => {
2351
- const next = cycle[(i + 1) % cycle.length];
2352
- return Array.from(graph.get(curr) || []).some(
2353
- (edge) => edge.node === next && edge.type !== "get"
2354
- );
2355
- });
2356
- if (allNotGet) {
2357
- cycleNodes = cycle;
2358
- return true;
2359
- }
2360
- return false;
2361
- }
2362
- return false;
2363
- }
2364
- visited.add(node);
2365
- onStack.add(node);
2366
- stack.push(node);
2367
- for (const neighbor of graph.get(node) || /* @__PURE__ */ new Set()) {
2368
- if (neighbor.node === node && neighbor.type !== "get") {
2369
- cycleNodes = [node];
2370
- return true;
2371
- }
2372
- if (dfs2(neighbor.node)) {
2373
- return true;
2374
- }
2375
- }
2376
- onStack.delete(node);
2377
- stack.pop();
2378
- return false;
2379
- }
2380
- for (const [node, targets] of graph) {
2381
- if (dfs2(node)) {
2382
- return { hasCycle: true, cycleNodes };
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
- // src/suggest/index.ts
2389
- var SuggestionType = /* @__PURE__ */ ((SuggestionType2) => {
2390
- SuggestionType2["info"] = "info";
2391
- SuggestionType2["warning"] = "warning";
2392
- SuggestionType2["error"] = "error";
2393
- return SuggestionType2;
2394
- })(SuggestionType || {});
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
- const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
2397
- const suggestions = [];
2398
- const splitedGraph = splitGraph(graph.edges);
2399
- splitedGraph.forEach((g) => {
2400
- const nodes = Array.from(g.keys());
2401
- if (splitedGraph.length > 1) {
2402
- if (nodes.length > 2 && nodes.some((node) => !usedNodes.has(node.label))) {
2403
- suggestions.push({
2404
- type: "info" /* info */,
2405
- 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.`,
2406
- nodeInfo: nodes
2407
- });
2408
- }
2409
- }
2410
- if (nodes.length > 1 && nodes.every((node) => !usedNodes.has(node.label) && !node.info?.used?.size)) {
2411
- suggestions.push({
2412
- type: "info" /* info */,
2413
- 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.`,
2414
- nodeInfo: nodes
2415
- });
2416
- }
2417
- const hasCycleResult = hasCycle(g);
2418
- if (hasCycleResult.hasCycle) {
2419
- suggestions.push({
2420
- type: "error" /* error */,
2421
- message: `There is a loop call in nodes [${hasCycleResult.cycleNodes.map((node) => node.label).join(",")}], perhaps you can refactor it.`,
2422
- nodeInfo: hasCycleResult.cycleNodes
2423
- });
2424
- }
2425
- const paths = findLinearPaths(g);
2426
- paths.forEach((path) => {
2427
- const firstUsedNodeIndex = path.findIndex((node) => usedNodes.has(node.label));
2428
- const reverseLastNotUsedNodeIndex = path.slice().reverse().findIndex((node) => !usedNodes.has(node.label));
2429
- const lastNotUsedNodeIndex = reverseLastNotUsedNodeIndex !== -1 ? path.length - 1 - reverseLastNotUsedNodeIndex : -1;
2430
- if (firstUsedNodeIndex > -1 && firstUsedNodeIndex < lastNotUsedNodeIndex) {
2431
- suggestions.push({
2432
- type: "warning" /* warning */,
2433
- 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.`,
2434
- nodeInfo: path
2435
- });
2436
- }
2437
- });
2438
- if (g.size > 5) {
2439
- const ap = findArticulationPoints(g);
2440
- ap.forEach((node) => {
2441
- if (node.type === "fun" /* fun */) {
2442
- suggestions.push({
2443
- type: "info" /* info */,
2444
- message: `Node [${node.label}] is an articulation point, perhaps you need to pay special attention to this node.`,
2445
- nodeInfo: node
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
- // src/vis.ts
1925
+ //#endregion
1926
+ //#region src/vis.ts
2465
1927
  function filterNodeUserd(used) {
2466
- const usedArray = Array.from(used || []);
2467
- return new Set(usedArray.filter((u) => ![
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
- const usedNodes = /* @__PURE__ */ new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
2474
- const nodes = [];
2475
- const edges = [];
2476
- const inDegreeMap = {};
2477
- const outDegreeMap = {};
2478
- graph.edges.forEach((edge) => {
2479
- edge.forEach((to) => {
2480
- if (to) {
2481
- inDegreeMap[to.node.label] = (inDegreeMap[to.node.label] || 0) + 1;
2482
- }
2483
- });
2484
- });
2485
- graph.edges.forEach((edge, key) => {
2486
- outDegreeMap[key.label] = edge.size;
2487
- });
2488
- graph.nodes.forEach((node) => {
2489
- const inDegree = inDegreeMap[node.label] || 0;
2490
- const outDegree = outDegreeMap[node.label] || 0;
2491
- nodes.push({
2492
- id: node.label,
2493
- label: node.label,
2494
- shape: node.type === "var" ? "dot" : "diamond",
2495
- group: usedNodes.has(node.label) || node.info?.used?.size ? "used" : "normal",
2496
- size: 20 + 1.6 ** (inDegree * 0.75 + outDegree * 0.25),
2497
- title: `${filterNodeUserd(node.info?.used).size ? `used by ${Array.from(filterNodeUserd(node.info?.used))?.map((i) => `\`${i}\``).join(",")}
2498
-
2499
- ` : ""}${usedNodes.has(node.label) ? `used in ${[
2500
- nodesUsedInStyle.has(node.label) ? "style" : "",
2501
- nodesUsedInTemplate.has(node.label) ? "template" : ""
2502
- ].filter(Boolean).join(" and ")}
2503
-
2504
- ` : ""}${node.info?.comment || ""}`.trim() || void 0,
2505
- info: node.info
2506
- });
2507
- });
2508
- graph.edges.forEach((edge, key) => {
2509
- edge.forEach((to) => {
2510
- if (!to) {
2511
- return;
2512
- }
2513
- edges.push({
2514
- from: key.label,
2515
- to: to.node.label,
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
- // src/index.ts
2532
- var import_compiler_sfc5 = require("@vue/compiler-sfc");
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