vue-hook-optimizer 0.0.53 → 0.0.55

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.mjs CHANGED
@@ -160,6 +160,7 @@ function getComment(node) {
160
160
 
161
161
  // src/analyze/setupScript.ts
162
162
  var traverse2 = _traverse2.default?.default || _traverse2.default || _traverse2;
163
+ var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
163
164
  function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
164
165
  const spread = _spread || [];
165
166
  const nodeCollection = new NodeCollection(_lineOffset);
@@ -176,7 +177,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
176
177
  if (element?.type === "Identifier") {
177
178
  const name = element.name;
178
179
  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" && ["defineProps", "defineEmits"].includes(declaration.init?.callee.name))) {
180
+ 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
181
  graph.nodes.add(name);
181
182
  nodeCollection.addNode(name, element, {
182
183
  comment: getComment(path.node)
@@ -189,7 +190,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
189
190
  if (element?.type === "RestElement" && element.argument.type === "Identifier") {
190
191
  const name = element.argument.name;
191
192
  const binding = path.scope.getBinding(name);
192
- if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration.init?.callee.name))) {
193
+ 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))) {
193
194
  graph.nodes.add(name);
194
195
  nodeCollection.addNode(name, element.argument, {
195
196
  comment: getComment(path.node)
@@ -206,7 +207,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
206
207
  if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
207
208
  const name = property.value.name;
208
209
  const binding = path.scope.getBinding(name);
209
- if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration.init?.callee.name))) {
210
+ 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))) {
210
211
  graph.nodes.add(name);
211
212
  nodeCollection.addNode(name, property.value, {
212
213
  comment: getComment(property)
@@ -219,7 +220,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
219
220
  if (property.type === "RestElement" && property.argument.type === "Identifier") {
220
221
  const name = property.argument.name;
221
222
  const binding = path.scope.getBinding(name);
222
- if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration.init?.callee.name))) {
223
+ 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))) {
223
224
  graph.nodes.add(name);
224
225
  nodeCollection.addNode(name, property.argument, {
225
226
  comment: getComment(property)
@@ -234,7 +235,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
234
235
  if (declaration.id?.type === "Identifier") {
235
236
  const name = declaration.id.name;
236
237
  const binding = path.scope.getBinding(name);
237
- if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration.init?.callee.name))) {
238
+ 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))) {
238
239
  graph.nodes.add(name);
239
240
  nodeCollection.addNode(name, declaration, {
240
241
  comment: getComment(path.node)
@@ -470,7 +471,24 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
470
471
  return;
471
472
  }
472
473
  const watchArgs = /* @__PURE__ */ new Set();
473
- if (hookName === "watch") {
474
+ if (hookName === "provide") {
475
+ traverse2(path.node.expression, {
476
+ Identifier(path1) {
477
+ const binding = path1.scope.getBinding(path1.node.name);
478
+ 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)) {
479
+ const _node = nodeCollection.getNode(path1.node.name);
480
+ if (_node?.info?.used) {
481
+ _node?.info?.used?.add(hookName);
482
+ } else if (_node) {
483
+ _node.info = {
484
+ ..._node?.info,
485
+ used: /* @__PURE__ */ new Set([hookName])
486
+ };
487
+ }
488
+ }
489
+ }
490
+ }, path.scope, path);
491
+ } else if (hookName === "watch") {
474
492
  if (path.node.expression.arguments[0].type === "Identifier") {
475
493
  const binding = path.scope.getBinding(path.node.expression.arguments[0].name);
476
494
  if (graph.nodes.has(path.node.expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
@@ -568,7 +586,8 @@ var vueLifeCycleHooks = [
568
586
  "deactivated",
569
587
  "errorCaptured",
570
588
  "renderTracked",
571
- "renderTriggered"
589
+ "renderTriggered",
590
+ "provide"
572
591
  ];
573
592
  function analyze3(content, lineOffset = 0, jsx = false) {
574
593
  const ast = babelParse3(content, { sourceType: "module", plugins: [