vue-hook-optimizer 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +57 -54
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +290 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +289 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -10
package/README.md
CHANGED
@@ -1,54 +1,57 @@
|
|
1
|
-
[
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
pnpm
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
- [ ]
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
[![NPM version](https://img.shields.io/npm/v/vue-hook-optimizer?color=a1b858&label=)](https://www.npmjs.com/package/vue-hook-optimizer)
|
2
|
+
|
3
|
+
[中文文档](./README_cn.md)
|
4
|
+
|
5
|
+
This is a tool to analyze your `vue` code.
|
6
|
+
|
7
|
+
## Install And Run Playground
|
8
|
+
|
9
|
+
```bash
|
10
|
+
# clone the repo then install the dependencies
|
11
|
+
pnpm install
|
12
|
+
# run the playground
|
13
|
+
pnpm run play
|
14
|
+
```
|
15
|
+
|
16
|
+
Open the browser and visit `http://localhost:3000/`.
|
17
|
+
|
18
|
+
![playground](./images/playground1.png)
|
19
|
+
|
20
|
+
## How To Use
|
21
|
+
|
22
|
+
1. paste your `vue` code into the editor
|
23
|
+
|
24
|
+
Up to now, it only supports the code with `<script setup>` syntax block.If your code use `options api`, it's not working at the moment.
|
25
|
+
|
26
|
+
2. click `Analyze` button
|
27
|
+
|
28
|
+
The tool will analyze the `setup block` and `template block`, and show the relations between the variables and the methods. This is a simple demo.
|
29
|
+
|
30
|
+
![demo](./images/demo1.png)
|
31
|
+
|
32
|
+
## Motive
|
33
|
+
|
34
|
+
Sometime we have to refactor the code, maybe there are thousands of lines of code in one file. And it is too complex and hard to understand.
|
35
|
+
|
36
|
+
So I want to build a tool to help us analyze the code, and find the relations between the variables and the methods. We can find out some variables are isolated, and some methods are over-association, and then we can refactor them.
|
37
|
+
|
38
|
+
## Development Plan
|
39
|
+
|
40
|
+
- [ ] add node type and more info
|
41
|
+
- [ ] provide some suggestions for optimization
|
42
|
+
- [ ] maybe support `options api`
|
43
|
+
- [x] vscode extension
|
44
|
+
|
45
|
+
## Contribution
|
46
|
+
|
47
|
+
Any contributions are welcome.
|
48
|
+
|
49
|
+
## Sponsor Me
|
50
|
+
|
51
|
+
If you like this tool, please consider to sponsor me. I will keep working on this tool and add more features.
|
52
|
+
|
53
|
+
![sponsor](./images/sponsor.png)
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
MIT
|
package/dist/index.d.mts
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
export { parse } from '@vue/compiler-sfc';
|
2
2
|
import * as vis_network from 'vis-network';
|
3
3
|
|
4
|
-
declare function analyze$
|
4
|
+
declare function analyze$2(content: string): Set<string>;
|
5
|
+
|
6
|
+
declare function analyze$1(content: string): {
|
7
|
+
nodes: Set<string>;
|
8
|
+
edges: Map<string, Set<string>>;
|
9
|
+
};
|
5
10
|
|
6
11
|
declare function analyze(content: string): {
|
7
12
|
nodes: Set<string>;
|
@@ -16,4 +21,4 @@ declare function getVisData(graph: {
|
|
16
21
|
edges: vis_network.Edge[];
|
17
22
|
};
|
18
23
|
|
19
|
-
export { analyze as
|
24
|
+
export { analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, getVisData };
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
export { parse } from '@vue/compiler-sfc';
|
2
2
|
import * as vis_network from 'vis-network';
|
3
3
|
|
4
|
-
declare function analyze$
|
4
|
+
declare function analyze$2(content: string): Set<string>;
|
5
|
+
|
6
|
+
declare function analyze$1(content: string): {
|
7
|
+
nodes: Set<string>;
|
8
|
+
edges: Map<string, Set<string>>;
|
9
|
+
};
|
5
10
|
|
6
11
|
declare function analyze(content: string): {
|
7
12
|
nodes: Set<string>;
|
@@ -16,4 +21,4 @@ declare function getVisData(graph: {
|
|
16
21
|
edges: vis_network.Edge[];
|
17
22
|
};
|
18
23
|
|
19
|
-
export { analyze as
|
24
|
+
export { analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeTemplate, getVisData };
|
package/dist/index.js
CHANGED
@@ -13887,9 +13887,9 @@ var require_traverse = __commonJS({
|
|
13887
13887
|
Object.defineProperty(exports, "__esModule", {
|
13888
13888
|
value: true
|
13889
13889
|
});
|
13890
|
-
exports.default =
|
13890
|
+
exports.default = traverse4;
|
13891
13891
|
var _definitions = require_definitions();
|
13892
|
-
function
|
13892
|
+
function traverse4(node2, handlers, state) {
|
13893
13893
|
if (typeof handlers === "function") {
|
13894
13894
|
handlers = {
|
13895
13895
|
enter: handlers
|
@@ -14646,7 +14646,7 @@ var require_lib3 = __commonJS({
|
|
14646
14646
|
Object.defineProperty(exports, "traverse", {
|
14647
14647
|
enumerable: true,
|
14648
14648
|
get: function() {
|
14649
|
-
return
|
14649
|
+
return _traverse4.default;
|
14650
14650
|
}
|
14651
14651
|
});
|
14652
14652
|
Object.defineProperty(exports, "traverseFast", {
|
@@ -14794,18 +14794,18 @@ var require_lib3 = __commonJS({
|
|
14794
14794
|
var _removeTypeDuplicates = require_removeTypeDuplicates();
|
14795
14795
|
var _getBindingIdentifiers = require_getBindingIdentifiers();
|
14796
14796
|
var _getOuterBindingIdentifiers = require_getOuterBindingIdentifiers();
|
14797
|
-
var
|
14798
|
-
Object.keys(
|
14797
|
+
var _traverse4 = require_traverse();
|
14798
|
+
Object.keys(_traverse4).forEach(function(key) {
|
14799
14799
|
if (key === "default" || key === "__esModule")
|
14800
14800
|
return;
|
14801
14801
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key))
|
14802
14802
|
return;
|
14803
|
-
if (key in exports && exports[key] ===
|
14803
|
+
if (key in exports && exports[key] === _traverse4[key])
|
14804
14804
|
return;
|
14805
14805
|
Object.defineProperty(exports, key, {
|
14806
14806
|
enumerable: true,
|
14807
14807
|
get: function() {
|
14808
|
-
return
|
14808
|
+
return _traverse4[key];
|
14809
14809
|
}
|
14810
14810
|
});
|
14811
14811
|
});
|
@@ -42952,7 +42952,7 @@ var require_parse = __commonJS({
|
|
42952
42952
|
isStatement,
|
42953
42953
|
isStringLiteral,
|
42954
42954
|
removePropertiesDeep,
|
42955
|
-
traverse:
|
42955
|
+
traverse: traverse4
|
42956
42956
|
} = _t;
|
42957
42957
|
var PATTERN = /^[_$A-Z0-9]+$/;
|
42958
42958
|
function parseAndBuildMetadata(formatter2, code, opts) {
|
@@ -42980,7 +42980,7 @@ var require_parse = __commonJS({
|
|
42980
42980
|
placeholderPattern,
|
42981
42981
|
syntacticPlaceholders
|
42982
42982
|
};
|
42983
|
-
|
42983
|
+
traverse4(ast, placeholderVisitorHandler, state);
|
42984
42984
|
return Object.assign({
|
42985
42985
|
ast
|
42986
42986
|
}, state.syntactic.placeholders.length ? state.syntactic : state.legacy);
|
@@ -45871,7 +45871,7 @@ var require_path = __commonJS({
|
|
45871
45871
|
exports.SHOULD_STOP = SHOULD_STOP;
|
45872
45872
|
var SHOULD_SKIP = 1 << 2;
|
45873
45873
|
exports.SHOULD_SKIP = SHOULD_SKIP;
|
45874
|
-
var
|
45874
|
+
var NodePath2 = class _NodePath {
|
45875
45875
|
constructor(hub, parent) {
|
45876
45876
|
this.contexts = [];
|
45877
45877
|
this.state = null;
|
@@ -46011,30 +46011,30 @@ var require_path = __commonJS({
|
|
46011
46011
|
}
|
46012
46012
|
}
|
46013
46013
|
};
|
46014
|
-
Object.assign(
|
46014
|
+
Object.assign(NodePath2.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
46015
46015
|
{
|
46016
|
-
|
46016
|
+
NodePath2.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
|
46017
46017
|
}
|
46018
46018
|
for (const type of t.TYPES) {
|
46019
46019
|
const typeKey = `is${type}`;
|
46020
46020
|
const fn = t[typeKey];
|
46021
|
-
|
46021
|
+
NodePath2.prototype[typeKey] = function(opts) {
|
46022
46022
|
return fn(this.node, opts);
|
46023
46023
|
};
|
46024
|
-
|
46024
|
+
NodePath2.prototype[`assert${type}`] = function(opts) {
|
46025
46025
|
if (!fn(this.node, opts)) {
|
46026
46026
|
throw new TypeError(`Expected node path of type ${type}`);
|
46027
46027
|
}
|
46028
46028
|
};
|
46029
46029
|
}
|
46030
|
-
Object.assign(
|
46030
|
+
Object.assign(NodePath2.prototype, NodePath_virtual_types_validator);
|
46031
46031
|
for (const type of Object.keys(virtualTypes)) {
|
46032
46032
|
if (type[0] === "_")
|
46033
46033
|
continue;
|
46034
46034
|
if (!t.TYPES.includes(type))
|
46035
46035
|
t.TYPES.push(type);
|
46036
46036
|
}
|
46037
|
-
var _default =
|
46037
|
+
var _default = NodePath2;
|
46038
46038
|
exports.default = _default;
|
46039
46039
|
}
|
46040
46040
|
});
|
@@ -46259,7 +46259,7 @@ var require_lib13 = __commonJS({
|
|
46259
46259
|
removeProperties,
|
46260
46260
|
traverseFast
|
46261
46261
|
} = _t;
|
46262
|
-
function
|
46262
|
+
function traverse4(parent, opts = {}, scope, state, parentPath) {
|
46263
46263
|
if (!parent)
|
46264
46264
|
return;
|
46265
46265
|
if (!opts.noScope && !scope) {
|
@@ -46273,24 +46273,24 @@ var require_lib13 = __commonJS({
|
|
46273
46273
|
visitors.explode(opts);
|
46274
46274
|
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath);
|
46275
46275
|
}
|
46276
|
-
var _default =
|
46276
|
+
var _default = traverse4;
|
46277
46277
|
exports.default = _default;
|
46278
|
-
|
46279
|
-
|
46280
|
-
|
46281
|
-
|
46278
|
+
traverse4.visitors = visitors;
|
46279
|
+
traverse4.verify = visitors.verify;
|
46280
|
+
traverse4.explode = visitors.explode;
|
46281
|
+
traverse4.cheap = function(node2, enter) {
|
46282
46282
|
traverseFast(node2, enter);
|
46283
46283
|
return;
|
46284
46284
|
};
|
46285
|
-
|
46285
|
+
traverse4.node = function(node2, opts, scope, state, path2, skipKeys) {
|
46286
46286
|
(0, _traverseNode.traverseNode)(node2, opts, scope, state, path2, skipKeys);
|
46287
46287
|
};
|
46288
|
-
|
46288
|
+
traverse4.clearNode = function(node2, opts) {
|
46289
46289
|
removeProperties(node2, opts);
|
46290
46290
|
cache.path.delete(node2);
|
46291
46291
|
};
|
46292
|
-
|
46293
|
-
traverseFast(tree,
|
46292
|
+
traverse4.removeProperties = function(tree, opts) {
|
46293
|
+
traverseFast(tree, traverse4.clearNode, opts);
|
46294
46294
|
return tree;
|
46295
46295
|
};
|
46296
46296
|
function hasDenylistedType(path2, state) {
|
@@ -46299,7 +46299,7 @@ var require_lib13 = __commonJS({
|
|
46299
46299
|
path2.stop();
|
46300
46300
|
}
|
46301
46301
|
}
|
46302
|
-
|
46302
|
+
traverse4.hasType = function(tree, type, denylistTypes) {
|
46303
46303
|
if (denylistTypes != null && denylistTypes.includes(tree.type))
|
46304
46304
|
return false;
|
46305
46305
|
if (tree.type === type)
|
@@ -46308,20 +46308,21 @@ var require_lib13 = __commonJS({
|
|
46308
46308
|
has: false,
|
46309
46309
|
type
|
46310
46310
|
};
|
46311
|
-
|
46311
|
+
traverse4(tree, {
|
46312
46312
|
noScope: true,
|
46313
46313
|
denylist: denylistTypes,
|
46314
46314
|
enter: hasDenylistedType
|
46315
46315
|
}, null, state);
|
46316
46316
|
return state.has;
|
46317
46317
|
};
|
46318
|
-
|
46318
|
+
traverse4.cache = cache;
|
46319
46319
|
}
|
46320
46320
|
});
|
46321
46321
|
|
46322
46322
|
// src/index.ts
|
46323
46323
|
var src_exports = {};
|
46324
46324
|
__export(src_exports, {
|
46325
|
+
analyzeOptions: () => analyze3,
|
46325
46326
|
analyzeSetupScript: () => analyze2,
|
46326
46327
|
analyzeTemplate: () => analyze,
|
46327
46328
|
getVisData: () => getVisData,
|
@@ -86288,18 +86289,19 @@ function analyze2(content) {
|
|
86288
86289
|
edges: /* @__PURE__ */ new Map()
|
86289
86290
|
};
|
86290
86291
|
traverse2(ast, {
|
86291
|
-
|
86292
|
-
|
86293
|
-
|
86294
|
-
|
86295
|
-
|
86296
|
-
|
86297
|
-
|
86298
|
-
|
86299
|
-
|
86292
|
+
VariableDeclaration(path2) {
|
86293
|
+
path2.node.declarations.forEach((declaration2) => {
|
86294
|
+
if (declaration2.id?.type === "Identifier") {
|
86295
|
+
const name = declaration2.id.name;
|
86296
|
+
const binding2 = path2.scope.getBinding(name);
|
86297
|
+
if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
|
86298
|
+
graph.nodes.add(name);
|
86299
|
+
if (!graph.edges.get(name)) {
|
86300
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86301
|
+
}
|
86300
86302
|
}
|
86301
86303
|
}
|
86302
|
-
}
|
86304
|
+
});
|
86303
86305
|
},
|
86304
86306
|
FunctionDeclaration(path2) {
|
86305
86307
|
const name = path2.node.id?.name;
|
@@ -86327,10 +86329,13 @@ function analyze2(content) {
|
|
86327
86329
|
});
|
86328
86330
|
}
|
86329
86331
|
},
|
86330
|
-
// get the relation between the variable and the function
|
86331
86332
|
VariableDeclarator(path2) {
|
86332
86333
|
if (path2.node.init) {
|
86333
|
-
if ([
|
86334
|
+
if ([
|
86335
|
+
"CallExpression",
|
86336
|
+
"ArrowFunctionExpression",
|
86337
|
+
"FunctionDeclaration"
|
86338
|
+
].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
|
86334
86339
|
const name = path2.node.id?.name;
|
86335
86340
|
if (name && graph.nodes.has(name)) {
|
86336
86341
|
path2.traverse({
|
@@ -86348,6 +86353,249 @@ function analyze2(content) {
|
|
86348
86353
|
return graph;
|
86349
86354
|
}
|
86350
86355
|
|
86356
|
+
// src/analyze/options.ts
|
86357
|
+
var import_traverse3 = __toESM(require_lib13());
|
86358
|
+
var traverse3 = (
|
86359
|
+
//@ts-ignore
|
86360
|
+
import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
|
86361
|
+
);
|
86362
|
+
function analyze3(content) {
|
86363
|
+
const ast = parse_1$1(content, {
|
86364
|
+
sourceType: "module",
|
86365
|
+
plugins: [
|
86366
|
+
"typescript"
|
86367
|
+
]
|
86368
|
+
});
|
86369
|
+
const graph = {
|
86370
|
+
nodes: /* @__PURE__ */ new Set(),
|
86371
|
+
edges: /* @__PURE__ */ new Map()
|
86372
|
+
};
|
86373
|
+
function process2(node2, path2) {
|
86374
|
+
traverse3(node2, {
|
86375
|
+
ObjectProperty(path1) {
|
86376
|
+
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86377
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
|
86378
|
+
const computedNode = path1.node;
|
86379
|
+
if (computedNode.value.type === "ObjectExpression") {
|
86380
|
+
computedNode.value.properties.forEach((prop) => {
|
86381
|
+
if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
|
86382
|
+
if (prop.key.type === "Identifier") {
|
86383
|
+
const name = prop.key.name;
|
86384
|
+
graph.nodes.add(name);
|
86385
|
+
if (!graph.edges.get(name)) {
|
86386
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86387
|
+
}
|
86388
|
+
}
|
86389
|
+
}
|
86390
|
+
});
|
86391
|
+
}
|
86392
|
+
}
|
86393
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
|
86394
|
+
const methodsNode = path1.node;
|
86395
|
+
if (methodsNode.value.type === "ObjectExpression") {
|
86396
|
+
methodsNode.value.properties.forEach((prop) => {
|
86397
|
+
if (prop.type === "ObjectMethod") {
|
86398
|
+
if (prop.key.type === "Identifier") {
|
86399
|
+
const name = prop.key.name;
|
86400
|
+
graph.nodes.add(name);
|
86401
|
+
if (!graph.edges.get(name)) {
|
86402
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86403
|
+
}
|
86404
|
+
}
|
86405
|
+
}
|
86406
|
+
});
|
86407
|
+
}
|
86408
|
+
}
|
86409
|
+
}
|
86410
|
+
},
|
86411
|
+
ObjectMethod(path1) {
|
86412
|
+
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86413
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
|
86414
|
+
const setupNode = path1.node;
|
86415
|
+
const tempNodes = /* @__PURE__ */ new Set();
|
86416
|
+
const tempEdges = /* @__PURE__ */ new Map();
|
86417
|
+
traverse3(setupNode, {
|
86418
|
+
VariableDeclaration(path22) {
|
86419
|
+
path22.node.declarations.forEach((declaration2) => {
|
86420
|
+
if (declaration2.id?.type === "Identifier") {
|
86421
|
+
const name = declaration2.id.name;
|
86422
|
+
if (path22.parent == setupNode.body) {
|
86423
|
+
tempNodes.add(name);
|
86424
|
+
if (!tempEdges.get(name)) {
|
86425
|
+
tempEdges.set(name, /* @__PURE__ */ new Set());
|
86426
|
+
}
|
86427
|
+
}
|
86428
|
+
}
|
86429
|
+
});
|
86430
|
+
},
|
86431
|
+
FunctionDeclaration(path22) {
|
86432
|
+
const name = path22.node.id?.name;
|
86433
|
+
if (name) {
|
86434
|
+
if (path22.parent == setupNode.body) {
|
86435
|
+
tempNodes.add(name);
|
86436
|
+
if (!tempEdges.get(name)) {
|
86437
|
+
tempEdges.set(name, /* @__PURE__ */ new Set());
|
86438
|
+
}
|
86439
|
+
}
|
86440
|
+
}
|
86441
|
+
}
|
86442
|
+
}, path1.scope, path1);
|
86443
|
+
traverse3(setupNode, {
|
86444
|
+
FunctionDeclaration(path3) {
|
86445
|
+
const name = path3.node.id?.name;
|
86446
|
+
if (name && tempNodes.has(name)) {
|
86447
|
+
path3.traverse({
|
86448
|
+
Identifier(path4) {
|
86449
|
+
if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
|
86450
|
+
tempEdges.get(name)?.add(path4.node.name);
|
86451
|
+
}
|
86452
|
+
}
|
86453
|
+
});
|
86454
|
+
}
|
86455
|
+
},
|
86456
|
+
VariableDeclarator(path3) {
|
86457
|
+
if (path3.node.init) {
|
86458
|
+
if ([
|
86459
|
+
"CallExpression",
|
86460
|
+
"ArrowFunctionExpression",
|
86461
|
+
"FunctionDeclaration"
|
86462
|
+
].includes(path3.node.init.type) && path3.node.id.type === "Identifier") {
|
86463
|
+
const name = path3.node.id?.name;
|
86464
|
+
if (name && tempNodes.has(name)) {
|
86465
|
+
path3.traverse({
|
86466
|
+
Identifier(path4) {
|
86467
|
+
if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
|
86468
|
+
tempEdges.get(name)?.add(path4.node.name);
|
86469
|
+
}
|
86470
|
+
}
|
86471
|
+
});
|
86472
|
+
}
|
86473
|
+
}
|
86474
|
+
}
|
86475
|
+
}
|
86476
|
+
}, path1.scope, path1);
|
86477
|
+
traverse3(setupNode, {
|
86478
|
+
ReturnStatement(path22) {
|
86479
|
+
if (path22.node.argument?.type === "ObjectExpression") {
|
86480
|
+
const returnNode = path22.node.argument;
|
86481
|
+
traverse3(returnNode, {
|
86482
|
+
ObjectProperty(path3) {
|
86483
|
+
if (path3.parent === returnNode) {
|
86484
|
+
if (path3.node.key.type === "Identifier") {
|
86485
|
+
const name = path3.node.key.name;
|
86486
|
+
const valName = path3.node.value.type === "Identifier" ? path3.node.value.name : "";
|
86487
|
+
if (valName && tempNodes.has(valName)) {
|
86488
|
+
graph.nodes.add(name);
|
86489
|
+
if (!graph.edges.get(name)) {
|
86490
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86491
|
+
tempEdges.get(valName)?.forEach((edge) => {
|
86492
|
+
graph.edges.get(name)?.add(edge);
|
86493
|
+
});
|
86494
|
+
}
|
86495
|
+
}
|
86496
|
+
}
|
86497
|
+
}
|
86498
|
+
}
|
86499
|
+
}, path22.scope, path22);
|
86500
|
+
} else {
|
86501
|
+
console.warn("setup return type is not ObjectExpression");
|
86502
|
+
}
|
86503
|
+
}
|
86504
|
+
}, path1.scope, path1);
|
86505
|
+
}
|
86506
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
|
86507
|
+
const dataNode = path1.node;
|
86508
|
+
traverse3(dataNode, {
|
86509
|
+
ReturnStatement(path22) {
|
86510
|
+
if (path22.parent == dataNode.body) {
|
86511
|
+
if (path22.node.argument?.type === "ObjectExpression") {
|
86512
|
+
path22.node.argument.properties.forEach((prop) => {
|
86513
|
+
if (prop.type === "ObjectProperty") {
|
86514
|
+
if (prop.key.type === "Identifier") {
|
86515
|
+
const name = prop.key.name;
|
86516
|
+
graph.nodes.add(name);
|
86517
|
+
if (!graph.edges.get(name)) {
|
86518
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86519
|
+
}
|
86520
|
+
}
|
86521
|
+
}
|
86522
|
+
});
|
86523
|
+
}
|
86524
|
+
}
|
86525
|
+
}
|
86526
|
+
}, path1.scope, path1);
|
86527
|
+
}
|
86528
|
+
}
|
86529
|
+
}
|
86530
|
+
}, path2.scope, path2);
|
86531
|
+
traverse3(node2, {
|
86532
|
+
ObjectProperty(path1) {
|
86533
|
+
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86534
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
|
86535
|
+
const computedNode = path1.node;
|
86536
|
+
if (computedNode.value.type === "ObjectExpression") {
|
86537
|
+
computedNode.value.properties.forEach((prop) => {
|
86538
|
+
if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
|
86539
|
+
const name = prop.key.name;
|
86540
|
+
traverse3(prop, {
|
86541
|
+
MemberExpression(path22) {
|
86542
|
+
if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
|
86543
|
+
graph.edges.get(name)?.add(path22.node.property.name);
|
86544
|
+
}
|
86545
|
+
}
|
86546
|
+
}, path1.scope, path1);
|
86547
|
+
}
|
86548
|
+
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.value.type === "ObjectExpression") {
|
86549
|
+
const name = prop.key.name;
|
86550
|
+
prop.value.properties.forEach((prop1) => {
|
86551
|
+
if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
|
86552
|
+
traverse3(prop1, {
|
86553
|
+
MemberExpression(path22) {
|
86554
|
+
if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
|
86555
|
+
graph.edges.get(name)?.add(path22.node.property.name);
|
86556
|
+
}
|
86557
|
+
}
|
86558
|
+
}, path1.scope, path1);
|
86559
|
+
}
|
86560
|
+
});
|
86561
|
+
}
|
86562
|
+
});
|
86563
|
+
}
|
86564
|
+
}
|
86565
|
+
if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
|
86566
|
+
const methodsNode = path1.node;
|
86567
|
+
if (methodsNode.value.type === "ObjectExpression") {
|
86568
|
+
methodsNode.value.properties.forEach((prop) => {
|
86569
|
+
if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
|
86570
|
+
const name = prop.key.name;
|
86571
|
+
traverse3(prop, {
|
86572
|
+
MemberExpression(path22) {
|
86573
|
+
if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
|
86574
|
+
graph.edges.get(name)?.add(path22.node.property.name);
|
86575
|
+
}
|
86576
|
+
}
|
86577
|
+
}, path1.scope, path1);
|
86578
|
+
}
|
86579
|
+
});
|
86580
|
+
}
|
86581
|
+
}
|
86582
|
+
}
|
86583
|
+
}
|
86584
|
+
}, path2.scope, path2);
|
86585
|
+
}
|
86586
|
+
traverse3(ast, {
|
86587
|
+
ExportDefaultDeclaration(path2) {
|
86588
|
+
if (path2.node.declaration.type === "ObjectExpression") {
|
86589
|
+
process2(path2.node.declaration, path2);
|
86590
|
+
} else if (path2.node.declaration.type === "CallExpression" && path2.node.declaration.callee.type === "Identifier" && path2.node.declaration.callee.name === "defineComponent" && path2.node.declaration.arguments[0].type === "ObjectExpression") {
|
86591
|
+
process2(path2.node.declaration.arguments[0], path2);
|
86592
|
+
console.log(graph);
|
86593
|
+
}
|
86594
|
+
}
|
86595
|
+
});
|
86596
|
+
return graph;
|
86597
|
+
}
|
86598
|
+
|
86351
86599
|
// src/vis.ts
|
86352
86600
|
function getVisData(graph, usedNodes) {
|
86353
86601
|
const nodes = [];
|
@@ -86380,6 +86628,7 @@ function getVisData(graph, usedNodes) {
|
|
86380
86628
|
}
|
86381
86629
|
// Annotate the CommonJS export names for ESM import in node:
|
86382
86630
|
0 && (module.exports = {
|
86631
|
+
analyzeOptions,
|
86383
86632
|
analyzeSetupScript,
|
86384
86633
|
analyzeTemplate,
|
86385
86634
|
getVisData,
|