vue-hook-optimizer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -13888,9 +13888,9 @@ var require_traverse = __commonJS({
13888
13888
  Object.defineProperty(exports, "__esModule", {
13889
13889
  value: true
13890
13890
  });
13891
- exports.default = traverse3;
13891
+ exports.default = traverse4;
13892
13892
  var _definitions = require_definitions();
13893
- function traverse3(node2, handlers, state) {
13893
+ function traverse4(node2, handlers, state) {
13894
13894
  if (typeof handlers === "function") {
13895
13895
  handlers = {
13896
13896
  enter: handlers
@@ -14647,7 +14647,7 @@ var require_lib3 = __commonJS({
14647
14647
  Object.defineProperty(exports, "traverse", {
14648
14648
  enumerable: true,
14649
14649
  get: function() {
14650
- return _traverse3.default;
14650
+ return _traverse4.default;
14651
14651
  }
14652
14652
  });
14653
14653
  Object.defineProperty(exports, "traverseFast", {
@@ -14795,18 +14795,18 @@ var require_lib3 = __commonJS({
14795
14795
  var _removeTypeDuplicates = require_removeTypeDuplicates();
14796
14796
  var _getBindingIdentifiers = require_getBindingIdentifiers();
14797
14797
  var _getOuterBindingIdentifiers = require_getOuterBindingIdentifiers();
14798
- var _traverse3 = require_traverse();
14799
- Object.keys(_traverse3).forEach(function(key) {
14798
+ var _traverse4 = require_traverse();
14799
+ Object.keys(_traverse4).forEach(function(key) {
14800
14800
  if (key === "default" || key === "__esModule")
14801
14801
  return;
14802
14802
  if (Object.prototype.hasOwnProperty.call(_exportNames, key))
14803
14803
  return;
14804
- if (key in exports && exports[key] === _traverse3[key])
14804
+ if (key in exports && exports[key] === _traverse4[key])
14805
14805
  return;
14806
14806
  Object.defineProperty(exports, key, {
14807
14807
  enumerable: true,
14808
14808
  get: function() {
14809
- return _traverse3[key];
14809
+ return _traverse4[key];
14810
14810
  }
14811
14811
  });
14812
14812
  });
@@ -42953,7 +42953,7 @@ var require_parse = __commonJS({
42953
42953
  isStatement,
42954
42954
  isStringLiteral,
42955
42955
  removePropertiesDeep,
42956
- traverse: traverse3
42956
+ traverse: traverse4
42957
42957
  } = _t;
42958
42958
  var PATTERN = /^[_$A-Z0-9]+$/;
42959
42959
  function parseAndBuildMetadata(formatter2, code, opts) {
@@ -42981,7 +42981,7 @@ var require_parse = __commonJS({
42981
42981
  placeholderPattern,
42982
42982
  syntacticPlaceholders
42983
42983
  };
42984
- traverse3(ast, placeholderVisitorHandler, state);
42984
+ traverse4(ast, placeholderVisitorHandler, state);
42985
42985
  return Object.assign({
42986
42986
  ast
42987
42987
  }, state.syntactic.placeholders.length ? state.syntactic : state.legacy);
@@ -45872,7 +45872,7 @@ var require_path = __commonJS({
45872
45872
  exports.SHOULD_STOP = SHOULD_STOP;
45873
45873
  var SHOULD_SKIP = 1 << 2;
45874
45874
  exports.SHOULD_SKIP = SHOULD_SKIP;
45875
- var NodePath = class _NodePath {
45875
+ var NodePath2 = class _NodePath {
45876
45876
  constructor(hub, parent) {
45877
45877
  this.contexts = [];
45878
45878
  this.state = null;
@@ -46012,30 +46012,30 @@ var require_path = __commonJS({
46012
46012
  }
46013
46013
  }
46014
46014
  };
46015
- Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
46015
+ 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);
46016
46016
  {
46017
- NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
46017
+ NodePath2.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
46018
46018
  }
46019
46019
  for (const type of t.TYPES) {
46020
46020
  const typeKey = `is${type}`;
46021
46021
  const fn = t[typeKey];
46022
- NodePath.prototype[typeKey] = function(opts) {
46022
+ NodePath2.prototype[typeKey] = function(opts) {
46023
46023
  return fn(this.node, opts);
46024
46024
  };
46025
- NodePath.prototype[`assert${type}`] = function(opts) {
46025
+ NodePath2.prototype[`assert${type}`] = function(opts) {
46026
46026
  if (!fn(this.node, opts)) {
46027
46027
  throw new TypeError(`Expected node path of type ${type}`);
46028
46028
  }
46029
46029
  };
46030
46030
  }
46031
- Object.assign(NodePath.prototype, NodePath_virtual_types_validator);
46031
+ Object.assign(NodePath2.prototype, NodePath_virtual_types_validator);
46032
46032
  for (const type of Object.keys(virtualTypes)) {
46033
46033
  if (type[0] === "_")
46034
46034
  continue;
46035
46035
  if (!t.TYPES.includes(type))
46036
46036
  t.TYPES.push(type);
46037
46037
  }
46038
- var _default = NodePath;
46038
+ var _default = NodePath2;
46039
46039
  exports.default = _default;
46040
46040
  }
46041
46041
  });
@@ -46260,7 +46260,7 @@ var require_lib13 = __commonJS({
46260
46260
  removeProperties,
46261
46261
  traverseFast
46262
46262
  } = _t;
46263
- function traverse3(parent, opts = {}, scope, state, parentPath) {
46263
+ function traverse4(parent, opts = {}, scope, state, parentPath) {
46264
46264
  if (!parent)
46265
46265
  return;
46266
46266
  if (!opts.noScope && !scope) {
@@ -46274,24 +46274,24 @@ var require_lib13 = __commonJS({
46274
46274
  visitors.explode(opts);
46275
46275
  (0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath);
46276
46276
  }
46277
- var _default = traverse3;
46277
+ var _default = traverse4;
46278
46278
  exports.default = _default;
46279
- traverse3.visitors = visitors;
46280
- traverse3.verify = visitors.verify;
46281
- traverse3.explode = visitors.explode;
46282
- traverse3.cheap = function(node2, enter) {
46279
+ traverse4.visitors = visitors;
46280
+ traverse4.verify = visitors.verify;
46281
+ traverse4.explode = visitors.explode;
46282
+ traverse4.cheap = function(node2, enter) {
46283
46283
  traverseFast(node2, enter);
46284
46284
  return;
46285
46285
  };
46286
- traverse3.node = function(node2, opts, scope, state, path2, skipKeys) {
46286
+ traverse4.node = function(node2, opts, scope, state, path2, skipKeys) {
46287
46287
  (0, _traverseNode.traverseNode)(node2, opts, scope, state, path2, skipKeys);
46288
46288
  };
46289
- traverse3.clearNode = function(node2, opts) {
46289
+ traverse4.clearNode = function(node2, opts) {
46290
46290
  removeProperties(node2, opts);
46291
46291
  cache.path.delete(node2);
46292
46292
  };
46293
- traverse3.removeProperties = function(tree, opts) {
46294
- traverseFast(tree, traverse3.clearNode, opts);
46293
+ traverse4.removeProperties = function(tree, opts) {
46294
+ traverseFast(tree, traverse4.clearNode, opts);
46295
46295
  return tree;
46296
46296
  };
46297
46297
  function hasDenylistedType(path2, state) {
@@ -46300,7 +46300,7 @@ var require_lib13 = __commonJS({
46300
46300
  path2.stop();
46301
46301
  }
46302
46302
  }
46303
- traverse3.hasType = function(tree, type, denylistTypes) {
46303
+ traverse4.hasType = function(tree, type, denylistTypes) {
46304
46304
  if (denylistTypes != null && denylistTypes.includes(tree.type))
46305
46305
  return false;
46306
46306
  if (tree.type === type)
@@ -46309,14 +46309,14 @@ var require_lib13 = __commonJS({
46309
46309
  has: false,
46310
46310
  type
46311
46311
  };
46312
- traverse3(tree, {
46312
+ traverse4(tree, {
46313
46313
  noScope: true,
46314
46314
  denylist: denylistTypes,
46315
46315
  enter: hasDenylistedType
46316
46316
  }, null, state);
46317
46317
  return state.has;
46318
46318
  };
46319
- traverse3.cache = cache;
46319
+ traverse4.cache = cache;
46320
46320
  }
46321
46321
  });
46322
46322
 
@@ -86279,18 +86279,19 @@ function analyze2(content) {
86279
86279
  edges: /* @__PURE__ */ new Map()
86280
86280
  };
86281
86281
  traverse2(ast, {
86282
- Identifier(path2) {
86283
- const name = path2.node.name;
86284
- const scopeParent = path2.scope.parent;
86285
- const binding2 = path2.scope.getBinding(name);
86286
- if (binding2) {
86287
- if (!scopeParent && ["const", "let", "var"].includes(binding2.kind)) {
86288
- graph.nodes.add(name);
86289
- if (!graph.edges.get(name)) {
86290
- graph.edges.set(name, /* @__PURE__ */ new Set());
86282
+ VariableDeclaration(path2) {
86283
+ path2.node.declarations.forEach((declaration2) => {
86284
+ if (declaration2.id?.type === "Identifier") {
86285
+ const name = declaration2.id.name;
86286
+ const binding2 = path2.scope.getBinding(name);
86287
+ if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86288
+ graph.nodes.add(name);
86289
+ if (!graph.edges.get(name)) {
86290
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86291
+ }
86291
86292
  }
86292
86293
  }
86293
- }
86294
+ });
86294
86295
  },
86295
86296
  FunctionDeclaration(path2) {
86296
86297
  const name = path2.node.id?.name;
@@ -86318,10 +86319,13 @@ function analyze2(content) {
86318
86319
  });
86319
86320
  }
86320
86321
  },
86321
- // get the relation between the variable and the function
86322
86322
  VariableDeclarator(path2) {
86323
86323
  if (path2.node.init) {
86324
- if (["CallExpression", "ArrowFunctionExpression", "FunctionDeclaration"].includes(path2.node.init.type)) {
86324
+ if ([
86325
+ "CallExpression",
86326
+ "ArrowFunctionExpression",
86327
+ "FunctionDeclaration"
86328
+ ].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
86325
86329
  const name = path2.node.id?.name;
86326
86330
  if (name && graph.nodes.has(name)) {
86327
86331
  path2.traverse({
@@ -86339,6 +86343,249 @@ function analyze2(content) {
86339
86343
  return graph;
86340
86344
  }
86341
86345
 
86346
+ // src/analyze/options.ts
86347
+ var import_traverse3 = __toESM(require_lib13());
86348
+ var traverse3 = (
86349
+ //@ts-ignore
86350
+ import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
86351
+ );
86352
+ function analyze3(content) {
86353
+ const ast = parse_1$1(content, {
86354
+ sourceType: "module",
86355
+ plugins: [
86356
+ "typescript"
86357
+ ]
86358
+ });
86359
+ const graph = {
86360
+ nodes: /* @__PURE__ */ new Set(),
86361
+ edges: /* @__PURE__ */ new Map()
86362
+ };
86363
+ function process2(node2, path2) {
86364
+ traverse3(node2, {
86365
+ ObjectProperty(path1) {
86366
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86367
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86368
+ const computedNode = path1.node;
86369
+ if (computedNode.value.type === "ObjectExpression") {
86370
+ computedNode.value.properties.forEach((prop) => {
86371
+ if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
86372
+ if (prop.key.type === "Identifier") {
86373
+ const name = prop.key.name;
86374
+ graph.nodes.add(name);
86375
+ if (!graph.edges.get(name)) {
86376
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86377
+ }
86378
+ }
86379
+ }
86380
+ });
86381
+ }
86382
+ }
86383
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
86384
+ const methodsNode = path1.node;
86385
+ if (methodsNode.value.type === "ObjectExpression") {
86386
+ methodsNode.value.properties.forEach((prop) => {
86387
+ if (prop.type === "ObjectMethod") {
86388
+ if (prop.key.type === "Identifier") {
86389
+ const name = prop.key.name;
86390
+ graph.nodes.add(name);
86391
+ if (!graph.edges.get(name)) {
86392
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86393
+ }
86394
+ }
86395
+ }
86396
+ });
86397
+ }
86398
+ }
86399
+ }
86400
+ },
86401
+ ObjectMethod(path1) {
86402
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86403
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
86404
+ const setupNode = path1.node;
86405
+ const tempNodes = /* @__PURE__ */ new Set();
86406
+ const tempEdges = /* @__PURE__ */ new Map();
86407
+ traverse3(setupNode, {
86408
+ VariableDeclaration(path22) {
86409
+ path22.node.declarations.forEach((declaration2) => {
86410
+ if (declaration2.id?.type === "Identifier") {
86411
+ const name = declaration2.id.name;
86412
+ if (path22.parent == setupNode.body) {
86413
+ tempNodes.add(name);
86414
+ if (!tempEdges.get(name)) {
86415
+ tempEdges.set(name, /* @__PURE__ */ new Set());
86416
+ }
86417
+ }
86418
+ }
86419
+ });
86420
+ },
86421
+ FunctionDeclaration(path22) {
86422
+ const name = path22.node.id?.name;
86423
+ if (name) {
86424
+ if (path22.parent == setupNode.body) {
86425
+ tempNodes.add(name);
86426
+ if (!tempEdges.get(name)) {
86427
+ tempEdges.set(name, /* @__PURE__ */ new Set());
86428
+ }
86429
+ }
86430
+ }
86431
+ }
86432
+ }, path1.scope, path1);
86433
+ traverse3(setupNode, {
86434
+ FunctionDeclaration(path3) {
86435
+ const name = path3.node.id?.name;
86436
+ if (name && tempNodes.has(name)) {
86437
+ path3.traverse({
86438
+ Identifier(path4) {
86439
+ if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86440
+ tempEdges.get(name)?.add(path4.node.name);
86441
+ }
86442
+ }
86443
+ });
86444
+ }
86445
+ },
86446
+ VariableDeclarator(path3) {
86447
+ if (path3.node.init) {
86448
+ if ([
86449
+ "CallExpression",
86450
+ "ArrowFunctionExpression",
86451
+ "FunctionDeclaration"
86452
+ ].includes(path3.node.init.type) && path3.node.id.type === "Identifier") {
86453
+ const name = path3.node.id?.name;
86454
+ if (name && tempNodes.has(name)) {
86455
+ path3.traverse({
86456
+ Identifier(path4) {
86457
+ if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86458
+ tempEdges.get(name)?.add(path4.node.name);
86459
+ }
86460
+ }
86461
+ });
86462
+ }
86463
+ }
86464
+ }
86465
+ }
86466
+ }, path1.scope, path1);
86467
+ traverse3(setupNode, {
86468
+ ReturnStatement(path22) {
86469
+ if (path22.node.argument?.type === "ObjectExpression") {
86470
+ const returnNode = path22.node.argument;
86471
+ traverse3(returnNode, {
86472
+ ObjectProperty(path3) {
86473
+ if (path3.parent === returnNode) {
86474
+ if (path3.node.key.type === "Identifier") {
86475
+ const name = path3.node.key.name;
86476
+ const valName = path3.node.value.type === "Identifier" ? path3.node.value.name : "";
86477
+ if (valName && tempNodes.has(valName)) {
86478
+ graph.nodes.add(name);
86479
+ if (!graph.edges.get(name)) {
86480
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86481
+ tempEdges.get(valName)?.forEach((edge) => {
86482
+ graph.edges.get(name)?.add(edge);
86483
+ });
86484
+ }
86485
+ }
86486
+ }
86487
+ }
86488
+ }
86489
+ }, path22.scope, path22);
86490
+ } else {
86491
+ console.warn("setup return type is not ObjectExpression");
86492
+ }
86493
+ }
86494
+ }, path1.scope, path1);
86495
+ }
86496
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
86497
+ const dataNode = path1.node;
86498
+ traverse3(dataNode, {
86499
+ ReturnStatement(path22) {
86500
+ if (path22.parent == dataNode.body) {
86501
+ if (path22.node.argument?.type === "ObjectExpression") {
86502
+ path22.node.argument.properties.forEach((prop) => {
86503
+ if (prop.type === "ObjectProperty") {
86504
+ if (prop.key.type === "Identifier") {
86505
+ const name = prop.key.name;
86506
+ graph.nodes.add(name);
86507
+ if (!graph.edges.get(name)) {
86508
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86509
+ }
86510
+ }
86511
+ }
86512
+ });
86513
+ }
86514
+ }
86515
+ }
86516
+ }, path1.scope, path1);
86517
+ }
86518
+ }
86519
+ }
86520
+ }, path2.scope, path2);
86521
+ traverse3(node2, {
86522
+ ObjectProperty(path1) {
86523
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86524
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86525
+ const computedNode = path1.node;
86526
+ if (computedNode.value.type === "ObjectExpression") {
86527
+ computedNode.value.properties.forEach((prop) => {
86528
+ if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
86529
+ const name = prop.key.name;
86530
+ traverse3(prop, {
86531
+ MemberExpression(path22) {
86532
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86533
+ graph.edges.get(name)?.add(path22.node.property.name);
86534
+ }
86535
+ }
86536
+ }, path1.scope, path1);
86537
+ }
86538
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.value.type === "ObjectExpression") {
86539
+ const name = prop.key.name;
86540
+ prop.value.properties.forEach((prop1) => {
86541
+ if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
86542
+ traverse3(prop1, {
86543
+ MemberExpression(path22) {
86544
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86545
+ graph.edges.get(name)?.add(path22.node.property.name);
86546
+ }
86547
+ }
86548
+ }, path1.scope, path1);
86549
+ }
86550
+ });
86551
+ }
86552
+ });
86553
+ }
86554
+ }
86555
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
86556
+ const methodsNode = path1.node;
86557
+ if (methodsNode.value.type === "ObjectExpression") {
86558
+ methodsNode.value.properties.forEach((prop) => {
86559
+ if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
86560
+ const name = prop.key.name;
86561
+ traverse3(prop, {
86562
+ MemberExpression(path22) {
86563
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86564
+ graph.edges.get(name)?.add(path22.node.property.name);
86565
+ }
86566
+ }
86567
+ }, path1.scope, path1);
86568
+ }
86569
+ });
86570
+ }
86571
+ }
86572
+ }
86573
+ }
86574
+ }, path2.scope, path2);
86575
+ }
86576
+ traverse3(ast, {
86577
+ ExportDefaultDeclaration(path2) {
86578
+ if (path2.node.declaration.type === "ObjectExpression") {
86579
+ process2(path2.node.declaration, path2);
86580
+ } 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") {
86581
+ process2(path2.node.declaration.arguments[0], path2);
86582
+ console.log(graph);
86583
+ }
86584
+ }
86585
+ });
86586
+ return graph;
86587
+ }
86588
+
86342
86589
  // src/vis.ts
86343
86590
  function getVisData(graph, usedNodes) {
86344
86591
  const nodes = [];
@@ -86370,6 +86617,7 @@ function getVisData(graph, usedNodes) {
86370
86617
  };
86371
86618
  }
86372
86619
  export {
86620
+ analyze3 as analyzeOptions,
86373
86621
  analyze2 as analyzeSetupScript,
86374
86622
  analyze as analyzeTemplate,
86375
86623
  getVisData,