vue-hook-optimizer 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -39,8 +39,8 @@ So I want to build a tool to help us analyze the code, and find the relations be
39
39
 
40
40
  - [ ] add node type and more info
41
41
  - [ ] provide some suggestions for optimization
42
- - [ ] maybe support `options api`
43
- - [x] vscode extension
42
+ - [x] support `options api`
43
+ - [x] [vscode extension](./packages/vscode)
44
44
 
45
45
  ## Contribution
46
46
 
package/dist/index.js CHANGED
@@ -86291,6 +86291,34 @@ function analyze2(content) {
86291
86291
  traverse2(ast, {
86292
86292
  VariableDeclaration(path2) {
86293
86293
  path2.node.declarations.forEach((declaration2) => {
86294
+ if (declaration2.id.type === "ArrayPattern") {
86295
+ declaration2.id.elements.forEach((element) => {
86296
+ if (element?.type === "Identifier") {
86297
+ const name = element.name;
86298
+ const binding2 = path2.scope.getBinding(name);
86299
+ if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86300
+ graph.nodes.add(name);
86301
+ if (!graph.edges.get(name)) {
86302
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86303
+ }
86304
+ }
86305
+ }
86306
+ });
86307
+ }
86308
+ if (declaration2.id.type === "ObjectPattern") {
86309
+ declaration2.id.properties.forEach((property) => {
86310
+ if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
86311
+ const name = property.value.name;
86312
+ const binding2 = path2.scope.getBinding(name);
86313
+ if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86314
+ graph.nodes.add(name);
86315
+ if (!graph.edges.get(name)) {
86316
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86317
+ }
86318
+ }
86319
+ }
86320
+ });
86321
+ }
86294
86322
  if (declaration2.id?.type === "Identifier") {
86295
86323
  const name = declaration2.id.name;
86296
86324
  const binding2 = path2.scope.getBinding(name);
@@ -86321,9 +86349,10 @@ function analyze2(content) {
86321
86349
  const name = path2.node.id?.name;
86322
86350
  if (name && graph.nodes.has(name)) {
86323
86351
  path2.traverse({
86324
- Identifier(path3) {
86325
- if (graph.nodes.has(path3.node.name) && path3.node.name !== name) {
86326
- graph.edges.get(name)?.add(path3.node.name);
86352
+ Identifier(path1) {
86353
+ const binding2 = path1.scope.getBinding(path1.node.name);
86354
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86355
+ graph.edges.get(name)?.add(path1.node.name);
86327
86356
  }
86328
86357
  }
86329
86358
  });
@@ -86331,6 +86360,40 @@ function analyze2(content) {
86331
86360
  },
86332
86361
  VariableDeclarator(path2) {
86333
86362
  if (path2.node.init) {
86363
+ if (path2.node.id.type === "ArrayPattern") {
86364
+ path2.node.id.elements.forEach((element) => {
86365
+ if (element?.type === "Identifier") {
86366
+ const name = element.name;
86367
+ if (name && graph.nodes.has(name) && path2.node.init?.type === "CallExpression") {
86368
+ traverse2(path2.node.init, {
86369
+ Identifier(path1) {
86370
+ const binding2 = path1.scope.getBinding(path1.node.name);
86371
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86372
+ graph.edges.get(name)?.add(path1.node.name);
86373
+ }
86374
+ }
86375
+ }, path2.scope, path2);
86376
+ }
86377
+ }
86378
+ });
86379
+ }
86380
+ if (path2.node.id.type === "ObjectPattern") {
86381
+ path2.node.id.properties.forEach((property) => {
86382
+ if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
86383
+ const name = property.value.name;
86384
+ if (name && graph.nodes.has(name) && path2.node.init) {
86385
+ traverse2(path2.node.init, {
86386
+ Identifier(path1) {
86387
+ const binding2 = path1.scope.getBinding(path1.node.name);
86388
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86389
+ graph.edges.get(name)?.add(path1.node.name);
86390
+ }
86391
+ }
86392
+ }, path2.scope, path2);
86393
+ }
86394
+ }
86395
+ });
86396
+ }
86334
86397
  if ([
86335
86398
  "CallExpression",
86336
86399
  "ArrowFunctionExpression",
@@ -86338,13 +86401,14 @@ function analyze2(content) {
86338
86401
  ].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
86339
86402
  const name = path2.node.id?.name;
86340
86403
  if (name && graph.nodes.has(name)) {
86341
- path2.traverse({
86342
- Identifier(path3) {
86343
- if (graph.nodes.has(path3.node.name) && path3.node.name !== name) {
86344
- graph.edges.get(name)?.add(path3.node.name);
86404
+ traverse2(path2.node.init, {
86405
+ Identifier(path1) {
86406
+ const binding2 = path1.scope.getBinding(path1.node.name);
86407
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86408
+ graph.edges.get(name)?.add(path1.node.name);
86345
86409
  }
86346
86410
  }
86347
- });
86411
+ }, path2.scope, path2);
86348
86412
  }
86349
86413
  }
86350
86414
  }
@@ -86589,7 +86653,6 @@ function analyze3(content) {
86589
86653
  process2(path2.node.declaration, path2);
86590
86654
  } 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
86655
  process2(path2.node.declaration.arguments[0], path2);
86592
- console.log(graph);
86593
86656
  }
86594
86657
  }
86595
86658
  });