vue-hook-optimizer 0.0.12 → 0.0.14

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
@@ -19803,12 +19803,12 @@ var require_gen_mapping_umd = __commonJS({
19803
19803
  };
19804
19804
  exports2.fromMap = (input2) => {
19805
19805
  const map2 = new traceMapping.TraceMap(input2);
19806
- const gen = new GenMapping({ file: map2.file, sourceRoot: map2.sourceRoot });
19807
- putAll(gen._names, map2.names);
19808
- putAll(gen._sources, map2.sources);
19809
- gen._sourcesContent = map2.sourcesContent || map2.sources.map(() => null);
19810
- gen._mappings = traceMapping.decodedMappings(map2);
19811
- return gen;
19806
+ const gen2 = new GenMapping({ file: map2.file, sourceRoot: map2.sourceRoot });
19807
+ putAll(gen2._names, map2.names);
19808
+ putAll(gen2._sources, map2.sources);
19809
+ gen2._sourcesContent = map2.sourcesContent || map2.sources.map(() => null);
19810
+ gen2._mappings = traceMapping.decodedMappings(map2);
19811
+ return gen2;
19812
19812
  };
19813
19813
  addSegmentInternal = (skipable, map2, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
19814
19814
  const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names } = map2;
@@ -25139,8 +25139,8 @@ var require_lib6 = __commonJS({
25139
25139
  };
25140
25140
  exports.CodeGenerator = CodeGenerator;
25141
25141
  function generate2(ast, opts, code) {
25142
- const gen = new Generator(ast, opts, code);
25143
- return gen.generate();
25142
+ const gen2 = new Generator(ast, opts, code);
25143
+ return gen2.generate();
25144
25144
  }
25145
25145
  }
25146
25146
  });
@@ -46320,6 +46320,55 @@ var require_lib13 = __commonJS({
46320
46320
  }
46321
46321
  });
46322
46322
 
46323
+ // src/analyze/utils.ts
46324
+ var NodeType = /* @__PURE__ */ ((NodeType3) => {
46325
+ NodeType3["var"] = "var";
46326
+ NodeType3["fun"] = "fun";
46327
+ return NodeType3;
46328
+ })(NodeType || {});
46329
+ var NodeCollection = class {
46330
+ nodes = /* @__PURE__ */ new Map();
46331
+ addNode(label, node2, options = { isComputed: false }) {
46332
+ if (this.nodes.has(label)) {
46333
+ return;
46334
+ }
46335
+ if (!options.isComputed && (node2.type === "VariableDeclarator" && [
46336
+ "ArrowFunctionExpression",
46337
+ "FunctionDeclaration"
46338
+ ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
46339
+ this.nodes.set(label, {
46340
+ label,
46341
+ type: "fun" /* fun */
46342
+ });
46343
+ } else {
46344
+ this.nodes.set(label, {
46345
+ label,
46346
+ type: "var" /* var */
46347
+ });
46348
+ }
46349
+ }
46350
+ addTypedNode(label, node2) {
46351
+ this.nodes.set(label, {
46352
+ label,
46353
+ type: node2.type
46354
+ });
46355
+ }
46356
+ map(graph) {
46357
+ const nodes = new Set(Array.from(graph.nodes).map((node2) => {
46358
+ return this.nodes.get(node2);
46359
+ }).filter((node2) => !!node2));
46360
+ const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
46361
+ return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
46362
+ return this.nodes.get(node2);
46363
+ }).filter((node2) => !!node2))];
46364
+ }));
46365
+ return {
46366
+ nodes,
46367
+ edges
46368
+ };
46369
+ }
46370
+ };
46371
+
46323
46372
  // node_modules/.pnpm/@vue+compiler-sfc@3.3.4/node_modules/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js
46324
46373
  function makeMap(str2, expectsLowerCase) {
46325
46374
  const map2 = /* @__PURE__ */ Object.create(null);
@@ -86263,52 +86312,6 @@ function analyze(content) {
86263
86312
 
86264
86313
  // src/analyze/setupScript.ts
86265
86314
  var import_traverse2 = __toESM(require_lib13());
86266
-
86267
- // src/analyze/utils.ts
86268
- var NodeCollection = class {
86269
- nodes = /* @__PURE__ */ new Map();
86270
- addNode(label, node2, options = { isComputed: false }) {
86271
- if (this.nodes.has(label)) {
86272
- return;
86273
- }
86274
- if (!options.isComputed && (node2.type === "VariableDeclarator" && [
86275
- "ArrowFunctionExpression",
86276
- "FunctionDeclaration"
86277
- ].includes(node2.init?.type || "") || node2.type === "FunctionDeclaration" || node2.type === "ObjectMethod")) {
86278
- this.nodes.set(label, {
86279
- label,
86280
- type: "fun" /* fun */
86281
- });
86282
- } else {
86283
- this.nodes.set(label, {
86284
- label,
86285
- type: "var" /* var */
86286
- });
86287
- }
86288
- }
86289
- addTypedNode(label, node2) {
86290
- this.nodes.set(label, {
86291
- label,
86292
- type: node2.type
86293
- });
86294
- }
86295
- map(graph) {
86296
- const nodes = new Set(Array.from(graph.nodes).map((node2) => {
86297
- return this.nodes.get(node2);
86298
- }).filter((node2) => !!node2));
86299
- const edges = new Map(Array.from(graph.edges).map(([from2, to]) => {
86300
- return [this.nodes.get(from2), new Set(Array.from(to).map((node2) => {
86301
- return this.nodes.get(node2);
86302
- }).filter((node2) => !!node2))];
86303
- }));
86304
- return {
86305
- nodes,
86306
- edges
86307
- };
86308
- }
86309
- };
86310
-
86311
- // src/analyze/setupScript.ts
86312
86315
  var traverse2 = (
86313
86316
  //@ts-ignore
86314
86317
  import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
@@ -86798,6 +86801,99 @@ function analyze3(content) {
86798
86801
  return nodeCollection.map(graph);
86799
86802
  }
86800
86803
 
86804
+ // src/suggest/split.ts
86805
+ function dfs(graph, node2, targets, visited, component) {
86806
+ component.add(node2);
86807
+ visited.add(node2);
86808
+ targets.forEach((target) => {
86809
+ if (!visited.has(target)) {
86810
+ dfs(graph, target, graph.get(target) || /* @__PURE__ */ new Set(), visited, component);
86811
+ }
86812
+ });
86813
+ }
86814
+ function haveIntersection(setA, setB) {
86815
+ for (let item of setA) {
86816
+ if (setB.has(item)) {
86817
+ return true;
86818
+ }
86819
+ }
86820
+ return false;
86821
+ }
86822
+ function mergeSets(arr) {
86823
+ let result2 = [...arr];
86824
+ for (let i = 0; i < result2.length; i++) {
86825
+ for (let j = i + 1; j < result2.length; j++) {
86826
+ if (haveIntersection(result2[i], result2[j])) {
86827
+ const newSet = /* @__PURE__ */ new Set([...result2[i], ...result2[j]]);
86828
+ result2.splice(j, 1);
86829
+ result2.splice(i, 1);
86830
+ result2 = [...result2, newSet];
86831
+ return mergeSets(result2);
86832
+ }
86833
+ }
86834
+ }
86835
+ return result2;
86836
+ }
86837
+ function splitGraph(graph) {
86838
+ const components = [];
86839
+ const sorted = Array.from(graph).sort((a, b) => b[1].size - a[1].size);
86840
+ new Map(sorted).forEach((targets, node2) => {
86841
+ const visited = /* @__PURE__ */ new Set();
86842
+ if (!visited.has(node2)) {
86843
+ let component = /* @__PURE__ */ new Set();
86844
+ dfs(graph, node2, targets, visited, component);
86845
+ components.push(component);
86846
+ }
86847
+ });
86848
+ return mergeSets(components).map((component) => {
86849
+ const subGraph = /* @__PURE__ */ new Map();
86850
+ component.forEach((node2) => {
86851
+ const targets = graph.get(node2);
86852
+ if (targets) {
86853
+ subGraph.set(node2, targets);
86854
+ }
86855
+ });
86856
+ return subGraph;
86857
+ });
86858
+ }
86859
+
86860
+ // src/suggest/filter.ts
86861
+ function noIndegreeFilter(graph) {
86862
+ const nodes = Array.from(graph.keys());
86863
+ const indegree = /* @__PURE__ */ new Map();
86864
+ nodes.forEach((node2) => {
86865
+ indegree.set(node2, 0);
86866
+ });
86867
+ graph.forEach((targets, node2) => {
86868
+ targets.forEach((target) => {
86869
+ indegree.set(target, (indegree.get(target) || 0) + 1);
86870
+ });
86871
+ });
86872
+ return nodes.filter((node2) => indegree.get(node2) === 0);
86873
+ }
86874
+
86875
+ // src/suggest/index.ts
86876
+ function gen(graph, usedNodes) {
86877
+ const suggests = [];
86878
+ const splitedGraph = splitGraph(graph.edges);
86879
+ splitedGraph.forEach((g) => {
86880
+ const nodes = Array.from(g.keys());
86881
+ if (splitedGraph.length > 1) {
86882
+ suggests.push(`Node${nodes.length > 1 ? "s" : ""} [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "...(" + nodes.length + ")" : nodes.map((node2) => node2.label).join(",")}] ${nodes.length > 1 ? "are" : "is"} isolated${nodes.length > 2 ? ", perhaps you can refactor them to an isolated file." : "."}`);
86883
+ }
86884
+ if (nodes.every((node2) => !usedNodes.has(node2.label))) {
86885
+ suggests.push(`Node${nodes.length > 1 ? "s" : ""} [${nodes.length > 10 ? nodes.slice(0, 10).map((node2) => node2.label).join(",") + "..." : nodes.map((node2) => node2.label).join(",")}] ${nodes.length > 1 ? "are" : "is"} not used, perhaps you can remove ${nodes.length > 1 ? "them" : "it"}.`);
86886
+ }
86887
+ });
86888
+ const noIndegreeNodes = noIndegreeFilter(graph.edges);
86889
+ noIndegreeNodes.forEach((node2) => {
86890
+ if (!usedNodes.has(node2.label)) {
86891
+ suggests.push(`Node [${node2.label}] is not used, perhaps you can remove it.`);
86892
+ }
86893
+ });
86894
+ return suggests;
86895
+ }
86896
+
86801
86897
  // src/vis.ts
86802
86898
  function getVisData(graph, usedNodes) {
86803
86899
  const nodes = [];
@@ -86832,9 +86928,11 @@ function getVisData(graph, usedNodes) {
86832
86928
  };
86833
86929
  }
86834
86930
  export {
86931
+ NodeType,
86835
86932
  analyze3 as analyzeOptions,
86836
86933
  analyze2 as analyzeSetupScript,
86837
86934
  analyze as analyzeTemplate,
86935
+ gen,
86838
86936
  getVisData,
86839
86937
  parse$7 as parse
86840
86938
  };