vue-hook-optimizer 0.0.6 → 0.0.8

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;
@@ -86310,24 +86311,29 @@ function analyze2(content) {
86310
86311
  const name = path2.node.id?.name;
86311
86312
  if (name && graph.nodes.has(name)) {
86312
86313
  path2.traverse({
86313
- Identifier(path3) {
86314
- if (graph.nodes.has(path3.node.name) && path3.node.name !== name) {
86315
- graph.edges.get(name)?.add(path3.node.name);
86314
+ Identifier(path1) {
86315
+ const binding2 = path1.scope.getBinding(path1.node.name);
86316
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86317
+ graph.edges.get(name)?.add(path1.node.name);
86316
86318
  }
86317
86319
  }
86318
86320
  });
86319
86321
  }
86320
86322
  },
86321
- // get the relation between the variable and the function
86322
86323
  VariableDeclarator(path2) {
86323
86324
  if (path2.node.init) {
86324
- if (["CallExpression", "ArrowFunctionExpression", "FunctionDeclaration"].includes(path2.node.init.type)) {
86325
+ if ([
86326
+ "CallExpression",
86327
+ "ArrowFunctionExpression",
86328
+ "FunctionDeclaration"
86329
+ ].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
86325
86330
  const name = path2.node.id?.name;
86326
86331
  if (name && graph.nodes.has(name)) {
86327
86332
  path2.traverse({
86328
- Identifier(path3) {
86329
- if (graph.nodes.has(path3.node.name) && path3.node.name !== name) {
86330
- graph.edges.get(name)?.add(path3.node.name);
86333
+ Identifier(path1) {
86334
+ const binding2 = path1.scope.getBinding(path1.node.name);
86335
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86336
+ graph.edges.get(name)?.add(path1.node.name);
86331
86337
  }
86332
86338
  }
86333
86339
  });
@@ -86339,6 +86345,248 @@ function analyze2(content) {
86339
86345
  return graph;
86340
86346
  }
86341
86347
 
86348
+ // src/analyze/options.ts
86349
+ var import_traverse3 = __toESM(require_lib13());
86350
+ var traverse3 = (
86351
+ //@ts-ignore
86352
+ import_traverse3.default.default?.default || import_traverse3.default.default || import_traverse3.default
86353
+ );
86354
+ function analyze3(content) {
86355
+ const ast = parse_1$1(content, {
86356
+ sourceType: "module",
86357
+ plugins: [
86358
+ "typescript"
86359
+ ]
86360
+ });
86361
+ const graph = {
86362
+ nodes: /* @__PURE__ */ new Set(),
86363
+ edges: /* @__PURE__ */ new Map()
86364
+ };
86365
+ function process2(node2, path2) {
86366
+ traverse3(node2, {
86367
+ ObjectProperty(path1) {
86368
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86369
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86370
+ const computedNode = path1.node;
86371
+ if (computedNode.value.type === "ObjectExpression") {
86372
+ computedNode.value.properties.forEach((prop) => {
86373
+ if (prop.type === "ObjectProperty" || prop.type === "ObjectMethod") {
86374
+ if (prop.key.type === "Identifier") {
86375
+ const name = prop.key.name;
86376
+ graph.nodes.add(name);
86377
+ if (!graph.edges.get(name)) {
86378
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86379
+ }
86380
+ }
86381
+ }
86382
+ });
86383
+ }
86384
+ }
86385
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
86386
+ const methodsNode = path1.node;
86387
+ if (methodsNode.value.type === "ObjectExpression") {
86388
+ methodsNode.value.properties.forEach((prop) => {
86389
+ if (prop.type === "ObjectMethod") {
86390
+ if (prop.key.type === "Identifier") {
86391
+ const name = prop.key.name;
86392
+ graph.nodes.add(name);
86393
+ if (!graph.edges.get(name)) {
86394
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86395
+ }
86396
+ }
86397
+ }
86398
+ });
86399
+ }
86400
+ }
86401
+ }
86402
+ },
86403
+ ObjectMethod(path1) {
86404
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86405
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
86406
+ const setupNode = path1.node;
86407
+ const tempNodes = /* @__PURE__ */ new Set();
86408
+ const tempEdges = /* @__PURE__ */ new Map();
86409
+ traverse3(setupNode, {
86410
+ VariableDeclaration(path22) {
86411
+ path22.node.declarations.forEach((declaration2) => {
86412
+ if (declaration2.id?.type === "Identifier") {
86413
+ const name = declaration2.id.name;
86414
+ if (path22.parent == setupNode.body) {
86415
+ tempNodes.add(name);
86416
+ if (!tempEdges.get(name)) {
86417
+ tempEdges.set(name, /* @__PURE__ */ new Set());
86418
+ }
86419
+ }
86420
+ }
86421
+ });
86422
+ },
86423
+ FunctionDeclaration(path22) {
86424
+ const name = path22.node.id?.name;
86425
+ if (name) {
86426
+ if (path22.parent == setupNode.body) {
86427
+ tempNodes.add(name);
86428
+ if (!tempEdges.get(name)) {
86429
+ tempEdges.set(name, /* @__PURE__ */ new Set());
86430
+ }
86431
+ }
86432
+ }
86433
+ }
86434
+ }, path1.scope, path1);
86435
+ traverse3(setupNode, {
86436
+ FunctionDeclaration(path3) {
86437
+ const name = path3.node.id?.name;
86438
+ if (name && tempNodes.has(name)) {
86439
+ path3.traverse({
86440
+ Identifier(path4) {
86441
+ if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86442
+ tempEdges.get(name)?.add(path4.node.name);
86443
+ }
86444
+ }
86445
+ });
86446
+ }
86447
+ },
86448
+ VariableDeclarator(path3) {
86449
+ if (path3.node.init) {
86450
+ if ([
86451
+ "CallExpression",
86452
+ "ArrowFunctionExpression",
86453
+ "FunctionDeclaration"
86454
+ ].includes(path3.node.init.type) && path3.node.id.type === "Identifier") {
86455
+ const name = path3.node.id?.name;
86456
+ if (name && tempNodes.has(name)) {
86457
+ path3.traverse({
86458
+ Identifier(path4) {
86459
+ if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86460
+ tempEdges.get(name)?.add(path4.node.name);
86461
+ }
86462
+ }
86463
+ });
86464
+ }
86465
+ }
86466
+ }
86467
+ }
86468
+ }, path1.scope, path1);
86469
+ traverse3(setupNode, {
86470
+ ReturnStatement(path22) {
86471
+ if (path22.node.argument?.type === "ObjectExpression") {
86472
+ const returnNode = path22.node.argument;
86473
+ traverse3(returnNode, {
86474
+ ObjectProperty(path3) {
86475
+ if (path3.parent === returnNode) {
86476
+ if (path3.node.key.type === "Identifier") {
86477
+ const name = path3.node.key.name;
86478
+ const valName = path3.node.value.type === "Identifier" ? path3.node.value.name : "";
86479
+ if (valName && tempNodes.has(valName)) {
86480
+ graph.nodes.add(name);
86481
+ if (!graph.edges.get(name)) {
86482
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86483
+ tempEdges.get(valName)?.forEach((edge) => {
86484
+ graph.edges.get(name)?.add(edge);
86485
+ });
86486
+ }
86487
+ }
86488
+ }
86489
+ }
86490
+ }
86491
+ }, path22.scope, path22);
86492
+ } else {
86493
+ console.warn("setup return type is not ObjectExpression");
86494
+ }
86495
+ }
86496
+ }, path1.scope, path1);
86497
+ }
86498
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "data") {
86499
+ const dataNode = path1.node;
86500
+ traverse3(dataNode, {
86501
+ ReturnStatement(path22) {
86502
+ if (path22.parent == dataNode.body) {
86503
+ if (path22.node.argument?.type === "ObjectExpression") {
86504
+ path22.node.argument.properties.forEach((prop) => {
86505
+ if (prop.type === "ObjectProperty") {
86506
+ if (prop.key.type === "Identifier") {
86507
+ const name = prop.key.name;
86508
+ graph.nodes.add(name);
86509
+ if (!graph.edges.get(name)) {
86510
+ graph.edges.set(name, /* @__PURE__ */ new Set());
86511
+ }
86512
+ }
86513
+ }
86514
+ });
86515
+ }
86516
+ }
86517
+ }
86518
+ }, path1.scope, path1);
86519
+ }
86520
+ }
86521
+ }
86522
+ }, path2.scope, path2);
86523
+ traverse3(node2, {
86524
+ ObjectProperty(path1) {
86525
+ if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86526
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "computed") {
86527
+ const computedNode = path1.node;
86528
+ if (computedNode.value.type === "ObjectExpression") {
86529
+ computedNode.value.properties.forEach((prop) => {
86530
+ if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
86531
+ const name = prop.key.name;
86532
+ traverse3(prop, {
86533
+ MemberExpression(path22) {
86534
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86535
+ graph.edges.get(name)?.add(path22.node.property.name);
86536
+ }
86537
+ }
86538
+ }, path1.scope, path1);
86539
+ }
86540
+ if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.value.type === "ObjectExpression") {
86541
+ const name = prop.key.name;
86542
+ prop.value.properties.forEach((prop1) => {
86543
+ if (prop1.type === "ObjectProperty" && prop1.key.type === "Identifier" && prop1.key.name === "get") {
86544
+ traverse3(prop1, {
86545
+ MemberExpression(path22) {
86546
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86547
+ graph.edges.get(name)?.add(path22.node.property.name);
86548
+ }
86549
+ }
86550
+ }, path1.scope, path1);
86551
+ }
86552
+ });
86553
+ }
86554
+ });
86555
+ }
86556
+ }
86557
+ if (path1.node.key.type === "Identifier" && path1.node.key.name === "methods") {
86558
+ const methodsNode = path1.node;
86559
+ if (methodsNode.value.type === "ObjectExpression") {
86560
+ methodsNode.value.properties.forEach((prop) => {
86561
+ if (prop.type === "ObjectMethod" && prop.key.type === "Identifier") {
86562
+ const name = prop.key.name;
86563
+ traverse3(prop, {
86564
+ MemberExpression(path22) {
86565
+ if (path22.node.object.type === "ThisExpression" && path22.node.property.type === "Identifier") {
86566
+ graph.edges.get(name)?.add(path22.node.property.name);
86567
+ }
86568
+ }
86569
+ }, path1.scope, path1);
86570
+ }
86571
+ });
86572
+ }
86573
+ }
86574
+ }
86575
+ }
86576
+ }, path2.scope, path2);
86577
+ }
86578
+ traverse3(ast, {
86579
+ ExportDefaultDeclaration(path2) {
86580
+ if (path2.node.declaration.type === "ObjectExpression") {
86581
+ process2(path2.node.declaration, path2);
86582
+ } 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") {
86583
+ process2(path2.node.declaration.arguments[0], path2);
86584
+ }
86585
+ }
86586
+ });
86587
+ return graph;
86588
+ }
86589
+
86342
86590
  // src/vis.ts
86343
86591
  function getVisData(graph, usedNodes) {
86344
86592
  const nodes = [];
@@ -86370,6 +86618,7 @@ function getVisData(graph, usedNodes) {
86370
86618
  };
86371
86619
  }
86372
86620
  export {
86621
+ analyze3 as analyzeOptions,
86373
86622
  analyze2 as analyzeSetupScript,
86374
86623
  analyze as analyzeTemplate,
86375
86624
  getVisData,