vue-hook-optimizer 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -49,8 +49,8 @@ var require_virtual_types = __commonJS({
49
49
  exports.Statement = Statement;
50
50
  var Expression = ["Expression"];
51
51
  exports.Expression = Expression;
52
- var Scope2 = ["Scopable", "Pattern"];
53
- exports.Scope = Scope2;
52
+ var Scope3 = ["Scopable", "Pattern"];
53
+ exports.Scope = Scope3;
54
54
  var Referenced = null;
55
55
  exports.Referenced = Referenced;
56
56
  var BlockScoped = null;
@@ -18063,7 +18063,7 @@ var require_scope = __commonJS({
18063
18063
  }
18064
18064
  };
18065
18065
  var uid = 0;
18066
- var Scope2 = class _Scope {
18066
+ var Scope3 = class _Scope {
18067
18067
  constructor(path2) {
18068
18068
  this.uid = void 0;
18069
18069
  this.path = void 0;
@@ -18698,9 +18698,9 @@ var require_scope = __commonJS({
18698
18698
  } while (scope = scope.parent);
18699
18699
  }
18700
18700
  };
18701
- exports.default = Scope2;
18702
- Scope2.globals = Object.keys(_globals.builtin);
18703
- Scope2.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
18701
+ exports.default = Scope3;
18702
+ Scope3.globals = Object.keys(_globals.builtin);
18703
+ Scope3.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
18704
18704
  }
18705
18705
  });
18706
18706
 
@@ -29012,7 +29012,7 @@ var require_lib9 = __commonJS({
29012
29012
  var CLASS_ELEMENT_INSTANCE_GETTER2 = CLASS_ELEMENT_KIND_GETTER2;
29013
29013
  var CLASS_ELEMENT_INSTANCE_SETTER2 = CLASS_ELEMENT_KIND_SETTER2;
29014
29014
  var CLASS_ELEMENT_OTHER2 = 0;
29015
- var Scope2 = class {
29015
+ var Scope3 = class {
29016
29016
  constructor(flags) {
29017
29017
  this.var = /* @__PURE__ */ new Set();
29018
29018
  this.lexical = /* @__PURE__ */ new Set();
@@ -29068,7 +29068,7 @@ var require_lib9 = __commonJS({
29068
29068
  return this.treatFunctionsAsVarInScope(this.currentScope());
29069
29069
  }
29070
29070
  createScope(flags) {
29071
- return new Scope2(flags);
29071
+ return new Scope3(flags);
29072
29072
  }
29073
29073
  enter(flags) {
29074
29074
  this.scopeStack.push(this.createScope(flags));
@@ -29163,7 +29163,7 @@ var require_lib9 = __commonJS({
29163
29163
  }
29164
29164
  }
29165
29165
  };
29166
- var FlowScope2 = class extends Scope2 {
29166
+ var FlowScope2 = class extends Scope3 {
29167
29167
  constructor(...args) {
29168
29168
  super(...args);
29169
29169
  this.declareFunctions = /* @__PURE__ */ new Set();
@@ -34669,7 +34669,7 @@ var require_lib9 = __commonJS({
34669
34669
  }
34670
34670
  }
34671
34671
  };
34672
- var TypeScriptScope2 = class extends Scope2 {
34672
+ var TypeScriptScope2 = class extends Scope3 {
34673
34673
  constructor(...args) {
34674
34674
  super(...args);
34675
34675
  this.types = /* @__PURE__ */ new Set();
@@ -86267,13 +86267,7 @@ var traverse2 = (
86267
86267
  //@ts-ignore
86268
86268
  import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
86269
86269
  );
86270
- function analyze2(content) {
86271
- const ast = parse_1$1(content, {
86272
- sourceType: "module",
86273
- plugins: [
86274
- "typescript"
86275
- ]
86276
- });
86270
+ function processSetup(ast, parentScope, parentPath) {
86277
86271
  const graph = {
86278
86272
  nodes: /* @__PURE__ */ new Set(),
86279
86273
  edges: /* @__PURE__ */ new Map()
@@ -86286,7 +86280,7 @@ function analyze2(content) {
86286
86280
  if (element?.type === "Identifier") {
86287
86281
  const name = element.name;
86288
86282
  const binding2 = path2.scope.getBinding(name);
86289
- if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86283
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent) && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86290
86284
  graph.nodes.add(name);
86291
86285
  if (!graph.edges.get(name)) {
86292
86286
  graph.edges.set(name, /* @__PURE__ */ new Set());
@@ -86300,7 +86294,7 @@ function analyze2(content) {
86300
86294
  if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
86301
86295
  const name = property.value.name;
86302
86296
  const binding2 = path2.scope.getBinding(name);
86303
- if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86297
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent) && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86304
86298
  graph.nodes.add(name);
86305
86299
  if (!graph.edges.get(name)) {
86306
86300
  graph.edges.set(name, /* @__PURE__ */ new Set());
@@ -86312,7 +86306,7 @@ function analyze2(content) {
86312
86306
  if (declaration2.id?.type === "Identifier") {
86313
86307
  const name = declaration2.id.name;
86314
86308
  const binding2 = path2.scope.getBinding(name);
86315
- if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86309
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent) && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
86316
86310
  graph.nodes.add(name);
86317
86311
  if (!graph.edges.get(name)) {
86318
86312
  graph.edges.set(name, /* @__PURE__ */ new Set());
@@ -86325,7 +86319,7 @@ function analyze2(content) {
86325
86319
  const name = path2.node.id?.name;
86326
86320
  if (name) {
86327
86321
  const binding2 = path2.scope.getBinding(name);
86328
- if (binding2 && path2.parent.type === "Program") {
86322
+ if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
86329
86323
  graph.nodes.add(name);
86330
86324
  if (!graph.edges.get(name)) {
86331
86325
  graph.edges.set(name, /* @__PURE__ */ new Set());
@@ -86333,7 +86327,7 @@ function analyze2(content) {
86333
86327
  }
86334
86328
  }
86335
86329
  }
86336
- });
86330
+ }, parentScope, parentPath);
86337
86331
  traverse2(ast, {
86338
86332
  FunctionDeclaration(path2) {
86339
86333
  const name = path2.node.id?.name;
@@ -86341,7 +86335,7 @@ function analyze2(content) {
86341
86335
  path2.traverse({
86342
86336
  Identifier(path1) {
86343
86337
  const binding2 = path1.scope.getBinding(path1.node.name);
86344
- if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86338
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
86345
86339
  graph.edges.get(name)?.add(path1.node.name);
86346
86340
  }
86347
86341
  }
@@ -86358,7 +86352,7 @@ function analyze2(content) {
86358
86352
  traverse2(path2.node.init, {
86359
86353
  Identifier(path1) {
86360
86354
  const binding2 = path1.scope.getBinding(path1.node.name);
86361
- if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86355
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
86362
86356
  graph.edges.get(name)?.add(path1.node.name);
86363
86357
  }
86364
86358
  }
@@ -86375,7 +86369,7 @@ function analyze2(content) {
86375
86369
  traverse2(path2.node.init, {
86376
86370
  Identifier(path1) {
86377
86371
  const binding2 = path1.scope.getBinding(path1.node.name);
86378
- if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86372
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
86379
86373
  graph.edges.get(name)?.add(path1.node.name);
86380
86374
  }
86381
86375
  }
@@ -86394,7 +86388,7 @@ function analyze2(content) {
86394
86388
  traverse2(path2.node.init, {
86395
86389
  Identifier(path1) {
86396
86390
  const binding2 = path1.scope.getBinding(path1.node.name);
86397
- if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
86391
+ if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
86398
86392
  graph.edges.get(name)?.add(path1.node.name);
86399
86393
  }
86400
86394
  }
@@ -86403,9 +86397,18 @@ function analyze2(content) {
86403
86397
  }
86404
86398
  }
86405
86399
  }
86406
- });
86400
+ }, parentScope, parentPath);
86407
86401
  return graph;
86408
86402
  }
86403
+ function analyze2(content) {
86404
+ const ast = parse_1$1(content, {
86405
+ sourceType: "module",
86406
+ plugins: [
86407
+ "typescript"
86408
+ ]
86409
+ });
86410
+ return processSetup(ast);
86411
+ }
86409
86412
 
86410
86413
  // src/analyze/options.ts
86411
86414
  var import_traverse3 = __toESM(require_lib13());
@@ -86466,68 +86469,10 @@ function analyze3(content) {
86466
86469
  if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
86467
86470
  if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
86468
86471
  const setupNode = path1.node;
86469
- const tempNodes = /* @__PURE__ */ new Set();
86470
- const tempEdges = /* @__PURE__ */ new Map();
86471
- traverse3(setupNode, {
86472
- VariableDeclaration(path22) {
86473
- path22.node.declarations.forEach((declaration2) => {
86474
- if (declaration2.id?.type === "Identifier") {
86475
- const name = declaration2.id.name;
86476
- if (path22.parent == setupNode.body) {
86477
- tempNodes.add(name);
86478
- if (!tempEdges.get(name)) {
86479
- tempEdges.set(name, /* @__PURE__ */ new Set());
86480
- }
86481
- }
86482
- }
86483
- });
86484
- },
86485
- FunctionDeclaration(path22) {
86486
- const name = path22.node.id?.name;
86487
- if (name) {
86488
- if (path22.parent == setupNode.body) {
86489
- tempNodes.add(name);
86490
- if (!tempEdges.get(name)) {
86491
- tempEdges.set(name, /* @__PURE__ */ new Set());
86492
- }
86493
- }
86494
- }
86495
- }
86496
- }, path1.scope, path1);
86497
- traverse3(setupNode, {
86498
- FunctionDeclaration(path3) {
86499
- const name = path3.node.id?.name;
86500
- if (name && tempNodes.has(name)) {
86501
- path3.traverse({
86502
- Identifier(path4) {
86503
- if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86504
- tempEdges.get(name)?.add(path4.node.name);
86505
- }
86506
- }
86507
- });
86508
- }
86509
- },
86510
- VariableDeclarator(path3) {
86511
- if (path3.node.init) {
86512
- if ([
86513
- "CallExpression",
86514
- "ArrowFunctionExpression",
86515
- "FunctionDeclaration"
86516
- ].includes(path3.node.init.type) && path3.node.id.type === "Identifier") {
86517
- const name = path3.node.id?.name;
86518
- if (name && tempNodes.has(name)) {
86519
- path3.traverse({
86520
- Identifier(path4) {
86521
- if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
86522
- tempEdges.get(name)?.add(path4.node.name);
86523
- }
86524
- }
86525
- });
86526
- }
86527
- }
86528
- }
86529
- }
86530
- }, path1.scope, path1);
86472
+ const {
86473
+ nodes: tempNodes,
86474
+ edges: tempEdges
86475
+ } = processSetup(setupNode, path1.scope, setupNode);
86531
86476
  traverse3(setupNode, {
86532
86477
  ReturnStatement(path22) {
86533
86478
  if (path22.node.argument?.type === "ObjectExpression") {