vue-hook-optimizer 0.0.8 → 0.0.10
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.js +94 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
53
|
-
exports.Scope =
|
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
|
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 =
|
18702
|
-
|
18703
|
-
|
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
|
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
|
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
|
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
|
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
|
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()
|
@@ -86281,10 +86275,38 @@ function analyze2(content) {
|
|
86281
86275
|
traverse2(ast, {
|
86282
86276
|
VariableDeclaration(path2) {
|
86283
86277
|
path2.node.declarations.forEach((declaration2) => {
|
86278
|
+
if (declaration2.id.type === "ArrayPattern") {
|
86279
|
+
declaration2.id.elements.forEach((element) => {
|
86280
|
+
if (element?.type === "Identifier") {
|
86281
|
+
const name = element.name;
|
86282
|
+
const binding2 = path2.scope.getBinding(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))) {
|
86284
|
+
graph.nodes.add(name);
|
86285
|
+
if (!graph.edges.get(name)) {
|
86286
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86287
|
+
}
|
86288
|
+
}
|
86289
|
+
}
|
86290
|
+
});
|
86291
|
+
}
|
86292
|
+
if (declaration2.id.type === "ObjectPattern") {
|
86293
|
+
declaration2.id.properties.forEach((property) => {
|
86294
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
86295
|
+
const name = property.value.name;
|
86296
|
+
const binding2 = path2.scope.getBinding(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))) {
|
86298
|
+
graph.nodes.add(name);
|
86299
|
+
if (!graph.edges.get(name)) {
|
86300
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86301
|
+
}
|
86302
|
+
}
|
86303
|
+
}
|
86304
|
+
});
|
86305
|
+
}
|
86284
86306
|
if (declaration2.id?.type === "Identifier") {
|
86285
86307
|
const name = declaration2.id.name;
|
86286
86308
|
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))) {
|
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))) {
|
86288
86310
|
graph.nodes.add(name);
|
86289
86311
|
if (!graph.edges.get(name)) {
|
86290
86312
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
@@ -86297,7 +86319,7 @@ function analyze2(content) {
|
|
86297
86319
|
const name = path2.node.id?.name;
|
86298
86320
|
if (name) {
|
86299
86321
|
const binding2 = path2.scope.getBinding(name);
|
86300
|
-
if (binding2 && path2.parent.type === "Program") {
|
86322
|
+
if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
|
86301
86323
|
graph.nodes.add(name);
|
86302
86324
|
if (!graph.edges.get(name)) {
|
86303
86325
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
@@ -86305,7 +86327,7 @@ function analyze2(content) {
|
|
86305
86327
|
}
|
86306
86328
|
}
|
86307
86329
|
}
|
86308
|
-
});
|
86330
|
+
}, parentScope, parentPath);
|
86309
86331
|
traverse2(ast, {
|
86310
86332
|
FunctionDeclaration(path2) {
|
86311
86333
|
const name = path2.node.id?.name;
|
@@ -86313,7 +86335,7 @@ function analyze2(content) {
|
|
86313
86335
|
path2.traverse({
|
86314
86336
|
Identifier(path1) {
|
86315
86337
|
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") {
|
86338
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86317
86339
|
graph.edges.get(name)?.add(path1.node.name);
|
86318
86340
|
}
|
86319
86341
|
}
|
@@ -86322,6 +86344,40 @@ function analyze2(content) {
|
|
86322
86344
|
},
|
86323
86345
|
VariableDeclarator(path2) {
|
86324
86346
|
if (path2.node.init) {
|
86347
|
+
if (path2.node.id.type === "ArrayPattern") {
|
86348
|
+
path2.node.id.elements.forEach((element) => {
|
86349
|
+
if (element?.type === "Identifier") {
|
86350
|
+
const name = element.name;
|
86351
|
+
if (name && graph.nodes.has(name) && path2.node.init?.type === "CallExpression") {
|
86352
|
+
traverse2(path2.node.init, {
|
86353
|
+
Identifier(path1) {
|
86354
|
+
const binding2 = path1.scope.getBinding(path1.node.name);
|
86355
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86356
|
+
graph.edges.get(name)?.add(path1.node.name);
|
86357
|
+
}
|
86358
|
+
}
|
86359
|
+
}, path2.scope, path2);
|
86360
|
+
}
|
86361
|
+
}
|
86362
|
+
});
|
86363
|
+
}
|
86364
|
+
if (path2.node.id.type === "ObjectPattern") {
|
86365
|
+
path2.node.id.properties.forEach((property) => {
|
86366
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
86367
|
+
const name = property.value.name;
|
86368
|
+
if (name && graph.nodes.has(name) && path2.node.init) {
|
86369
|
+
traverse2(path2.node.init, {
|
86370
|
+
Identifier(path1) {
|
86371
|
+
const binding2 = path1.scope.getBinding(path1.node.name);
|
86372
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86373
|
+
graph.edges.get(name)?.add(path1.node.name);
|
86374
|
+
}
|
86375
|
+
}
|
86376
|
+
}, path2.scope, path2);
|
86377
|
+
}
|
86378
|
+
}
|
86379
|
+
});
|
86380
|
+
}
|
86325
86381
|
if ([
|
86326
86382
|
"CallExpression",
|
86327
86383
|
"ArrowFunctionExpression",
|
@@ -86329,21 +86385,30 @@ function analyze2(content) {
|
|
86329
86385
|
].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
|
86330
86386
|
const name = path2.node.id?.name;
|
86331
86387
|
if (name && graph.nodes.has(name)) {
|
86332
|
-
path2.
|
86388
|
+
traverse2(path2.node.init, {
|
86333
86389
|
Identifier(path1) {
|
86334
86390
|
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") {
|
86391
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86336
86392
|
graph.edges.get(name)?.add(path1.node.name);
|
86337
86393
|
}
|
86338
86394
|
}
|
86339
|
-
});
|
86395
|
+
}, path2.scope, path2);
|
86340
86396
|
}
|
86341
86397
|
}
|
86342
86398
|
}
|
86343
86399
|
}
|
86344
|
-
});
|
86400
|
+
}, parentScope, parentPath);
|
86345
86401
|
return graph;
|
86346
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
|
+
}
|
86347
86412
|
|
86348
86413
|
// src/analyze/options.ts
|
86349
86414
|
var import_traverse3 = __toESM(require_lib13());
|
@@ -86404,68 +86469,10 @@ function analyze3(content) {
|
|
86404
86469
|
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86405
86470
|
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
|
86406
86471
|
const setupNode = path1.node;
|
86407
|
-
const
|
86408
|
-
|
86409
|
-
|
86410
|
-
|
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);
|
86472
|
+
const {
|
86473
|
+
nodes: tempNodes,
|
86474
|
+
edges: tempEdges
|
86475
|
+
} = processSetup(setupNode, path1.scope, setupNode);
|
86469
86476
|
traverse3(setupNode, {
|
86470
86477
|
ReturnStatement(path22) {
|
86471
86478
|
if (path22.node.argument?.type === "ObjectExpression") {
|