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.js
CHANGED
@@ -48,8 +48,8 @@ var require_virtual_types = __commonJS({
|
|
48
48
|
exports.Statement = Statement;
|
49
49
|
var Expression = ["Expression"];
|
50
50
|
exports.Expression = Expression;
|
51
|
-
var
|
52
|
-
exports.Scope =
|
51
|
+
var Scope3 = ["Scopable", "Pattern"];
|
52
|
+
exports.Scope = Scope3;
|
53
53
|
var Referenced = null;
|
54
54
|
exports.Referenced = Referenced;
|
55
55
|
var BlockScoped = null;
|
@@ -18062,7 +18062,7 @@ var require_scope = __commonJS({
|
|
18062
18062
|
}
|
18063
18063
|
};
|
18064
18064
|
var uid = 0;
|
18065
|
-
var
|
18065
|
+
var Scope3 = class _Scope {
|
18066
18066
|
constructor(path2) {
|
18067
18067
|
this.uid = void 0;
|
18068
18068
|
this.path = void 0;
|
@@ -18697,9 +18697,9 @@ var require_scope = __commonJS({
|
|
18697
18697
|
} while (scope = scope.parent);
|
18698
18698
|
}
|
18699
18699
|
};
|
18700
|
-
exports.default =
|
18701
|
-
|
18702
|
-
|
18700
|
+
exports.default = Scope3;
|
18701
|
+
Scope3.globals = Object.keys(_globals.builtin);
|
18702
|
+
Scope3.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
18703
18703
|
}
|
18704
18704
|
});
|
18705
18705
|
|
@@ -29011,7 +29011,7 @@ var require_lib9 = __commonJS({
|
|
29011
29011
|
var CLASS_ELEMENT_INSTANCE_GETTER2 = CLASS_ELEMENT_KIND_GETTER2;
|
29012
29012
|
var CLASS_ELEMENT_INSTANCE_SETTER2 = CLASS_ELEMENT_KIND_SETTER2;
|
29013
29013
|
var CLASS_ELEMENT_OTHER2 = 0;
|
29014
|
-
var
|
29014
|
+
var Scope3 = class {
|
29015
29015
|
constructor(flags) {
|
29016
29016
|
this.var = /* @__PURE__ */ new Set();
|
29017
29017
|
this.lexical = /* @__PURE__ */ new Set();
|
@@ -29067,7 +29067,7 @@ var require_lib9 = __commonJS({
|
|
29067
29067
|
return this.treatFunctionsAsVarInScope(this.currentScope());
|
29068
29068
|
}
|
29069
29069
|
createScope(flags) {
|
29070
|
-
return new
|
29070
|
+
return new Scope3(flags);
|
29071
29071
|
}
|
29072
29072
|
enter(flags) {
|
29073
29073
|
this.scopeStack.push(this.createScope(flags));
|
@@ -29162,7 +29162,7 @@ var require_lib9 = __commonJS({
|
|
29162
29162
|
}
|
29163
29163
|
}
|
29164
29164
|
};
|
29165
|
-
var FlowScope2 = class extends
|
29165
|
+
var FlowScope2 = class extends Scope3 {
|
29166
29166
|
constructor(...args) {
|
29167
29167
|
super(...args);
|
29168
29168
|
this.declareFunctions = /* @__PURE__ */ new Set();
|
@@ -34668,7 +34668,7 @@ var require_lib9 = __commonJS({
|
|
34668
34668
|
}
|
34669
34669
|
}
|
34670
34670
|
};
|
34671
|
-
var TypeScriptScope2 = class extends
|
34671
|
+
var TypeScriptScope2 = class extends Scope3 {
|
34672
34672
|
constructor(...args) {
|
34673
34673
|
super(...args);
|
34674
34674
|
this.types = /* @__PURE__ */ new Set();
|
@@ -86277,13 +86277,7 @@ var traverse2 = (
|
|
86277
86277
|
//@ts-ignore
|
86278
86278
|
import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default
|
86279
86279
|
);
|
86280
|
-
function
|
86281
|
-
const ast = parse_1$1(content, {
|
86282
|
-
sourceType: "module",
|
86283
|
-
plugins: [
|
86284
|
-
"typescript"
|
86285
|
-
]
|
86286
|
-
});
|
86280
|
+
function processSetup(ast, parentScope, parentPath) {
|
86287
86281
|
const graph = {
|
86288
86282
|
nodes: /* @__PURE__ */ new Set(),
|
86289
86283
|
edges: /* @__PURE__ */ new Map()
|
@@ -86291,10 +86285,38 @@ function analyze2(content) {
|
|
86291
86285
|
traverse2(ast, {
|
86292
86286
|
VariableDeclaration(path2) {
|
86293
86287
|
path2.node.declarations.forEach((declaration2) => {
|
86288
|
+
if (declaration2.id.type === "ArrayPattern") {
|
86289
|
+
declaration2.id.elements.forEach((element) => {
|
86290
|
+
if (element?.type === "Identifier") {
|
86291
|
+
const name = element.name;
|
86292
|
+
const binding2 = path2.scope.getBinding(name);
|
86293
|
+
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))) {
|
86294
|
+
graph.nodes.add(name);
|
86295
|
+
if (!graph.edges.get(name)) {
|
86296
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86297
|
+
}
|
86298
|
+
}
|
86299
|
+
}
|
86300
|
+
});
|
86301
|
+
}
|
86302
|
+
if (declaration2.id.type === "ObjectPattern") {
|
86303
|
+
declaration2.id.properties.forEach((property) => {
|
86304
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
86305
|
+
const name = property.value.name;
|
86306
|
+
const binding2 = path2.scope.getBinding(name);
|
86307
|
+
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))) {
|
86308
|
+
graph.nodes.add(name);
|
86309
|
+
if (!graph.edges.get(name)) {
|
86310
|
+
graph.edges.set(name, /* @__PURE__ */ new Set());
|
86311
|
+
}
|
86312
|
+
}
|
86313
|
+
}
|
86314
|
+
});
|
86315
|
+
}
|
86294
86316
|
if (declaration2.id?.type === "Identifier") {
|
86295
86317
|
const name = declaration2.id.name;
|
86296
86318
|
const binding2 = path2.scope.getBinding(name);
|
86297
|
-
if (binding2 && path2.parent.type === "Program" && !(declaration2.init?.type === "CallExpression" && declaration2.init?.callee.type === "Identifier" && ["defineProps", "defineEmits"].includes(declaration2.init?.callee.name))) {
|
86319
|
+
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
86320
|
graph.nodes.add(name);
|
86299
86321
|
if (!graph.edges.get(name)) {
|
86300
86322
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
@@ -86307,7 +86329,7 @@ function analyze2(content) {
|
|
86307
86329
|
const name = path2.node.id?.name;
|
86308
86330
|
if (name) {
|
86309
86331
|
const binding2 = path2.scope.getBinding(name);
|
86310
|
-
if (binding2 && path2.parent.type === "Program") {
|
86332
|
+
if (binding2 && (path2.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path2.parent)) {
|
86311
86333
|
graph.nodes.add(name);
|
86312
86334
|
if (!graph.edges.get(name)) {
|
86313
86335
|
graph.edges.set(name, /* @__PURE__ */ new Set());
|
@@ -86315,7 +86337,7 @@ function analyze2(content) {
|
|
86315
86337
|
}
|
86316
86338
|
}
|
86317
86339
|
}
|
86318
|
-
});
|
86340
|
+
}, parentScope, parentPath);
|
86319
86341
|
traverse2(ast, {
|
86320
86342
|
FunctionDeclaration(path2) {
|
86321
86343
|
const name = path2.node.id?.name;
|
@@ -86323,7 +86345,7 @@ function analyze2(content) {
|
|
86323
86345
|
path2.traverse({
|
86324
86346
|
Identifier(path1) {
|
86325
86347
|
const binding2 = path1.scope.getBinding(path1.node.name);
|
86326
|
-
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
|
86348
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86327
86349
|
graph.edges.get(name)?.add(path1.node.name);
|
86328
86350
|
}
|
86329
86351
|
}
|
@@ -86332,6 +86354,40 @@ function analyze2(content) {
|
|
86332
86354
|
},
|
86333
86355
|
VariableDeclarator(path2) {
|
86334
86356
|
if (path2.node.init) {
|
86357
|
+
if (path2.node.id.type === "ArrayPattern") {
|
86358
|
+
path2.node.id.elements.forEach((element) => {
|
86359
|
+
if (element?.type === "Identifier") {
|
86360
|
+
const name = element.name;
|
86361
|
+
if (name && graph.nodes.has(name) && path2.node.init?.type === "CallExpression") {
|
86362
|
+
traverse2(path2.node.init, {
|
86363
|
+
Identifier(path1) {
|
86364
|
+
const binding2 = path1.scope.getBinding(path1.node.name);
|
86365
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86366
|
+
graph.edges.get(name)?.add(path1.node.name);
|
86367
|
+
}
|
86368
|
+
}
|
86369
|
+
}, path2.scope, path2);
|
86370
|
+
}
|
86371
|
+
}
|
86372
|
+
});
|
86373
|
+
}
|
86374
|
+
if (path2.node.id.type === "ObjectPattern") {
|
86375
|
+
path2.node.id.properties.forEach((property) => {
|
86376
|
+
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
86377
|
+
const name = property.value.name;
|
86378
|
+
if (name && graph.nodes.has(name) && path2.node.init) {
|
86379
|
+
traverse2(path2.node.init, {
|
86380
|
+
Identifier(path1) {
|
86381
|
+
const binding2 = path1.scope.getBinding(path1.node.name);
|
86382
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86383
|
+
graph.edges.get(name)?.add(path1.node.name);
|
86384
|
+
}
|
86385
|
+
}
|
86386
|
+
}, path2.scope, path2);
|
86387
|
+
}
|
86388
|
+
}
|
86389
|
+
});
|
86390
|
+
}
|
86335
86391
|
if ([
|
86336
86392
|
"CallExpression",
|
86337
86393
|
"ArrowFunctionExpression",
|
@@ -86339,21 +86395,30 @@ function analyze2(content) {
|
|
86339
86395
|
].includes(path2.node.init.type) && path2.node.id.type === "Identifier") {
|
86340
86396
|
const name = path2.node.id?.name;
|
86341
86397
|
if (name && graph.nodes.has(name)) {
|
86342
|
-
path2.
|
86398
|
+
traverse2(path2.node.init, {
|
86343
86399
|
Identifier(path1) {
|
86344
86400
|
const binding2 = path1.scope.getBinding(path1.node.name);
|
86345
|
-
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && binding2?.scope.block.type === "Program") {
|
86401
|
+
if (graph.nodes.has(path1.node.name) && path1.node.name !== name && (binding2?.scope.block.type === "Program" || parentScope === binding2?.scope)) {
|
86346
86402
|
graph.edges.get(name)?.add(path1.node.name);
|
86347
86403
|
}
|
86348
86404
|
}
|
86349
|
-
});
|
86405
|
+
}, path2.scope, path2);
|
86350
86406
|
}
|
86351
86407
|
}
|
86352
86408
|
}
|
86353
86409
|
}
|
86354
|
-
});
|
86410
|
+
}, parentScope, parentPath);
|
86355
86411
|
return graph;
|
86356
86412
|
}
|
86413
|
+
function analyze2(content) {
|
86414
|
+
const ast = parse_1$1(content, {
|
86415
|
+
sourceType: "module",
|
86416
|
+
plugins: [
|
86417
|
+
"typescript"
|
86418
|
+
]
|
86419
|
+
});
|
86420
|
+
return processSetup(ast);
|
86421
|
+
}
|
86357
86422
|
|
86358
86423
|
// src/analyze/options.ts
|
86359
86424
|
var import_traverse3 = __toESM(require_lib13());
|
@@ -86414,68 +86479,10 @@ function analyze3(content) {
|
|
86414
86479
|
if (path2.node.declaration.type === "ObjectExpression" && path1.parent === path2.node.declaration || path2.node.declaration.type === "CallExpression" && path1.parent === path2.node.declaration.arguments[0]) {
|
86415
86480
|
if (path1.node.key.type === "Identifier" && path1.node.key.name === "setup") {
|
86416
86481
|
const setupNode = path1.node;
|
86417
|
-
const
|
86418
|
-
|
86419
|
-
|
86420
|
-
|
86421
|
-
path22.node.declarations.forEach((declaration2) => {
|
86422
|
-
if (declaration2.id?.type === "Identifier") {
|
86423
|
-
const name = declaration2.id.name;
|
86424
|
-
if (path22.parent == setupNode.body) {
|
86425
|
-
tempNodes.add(name);
|
86426
|
-
if (!tempEdges.get(name)) {
|
86427
|
-
tempEdges.set(name, /* @__PURE__ */ new Set());
|
86428
|
-
}
|
86429
|
-
}
|
86430
|
-
}
|
86431
|
-
});
|
86432
|
-
},
|
86433
|
-
FunctionDeclaration(path22) {
|
86434
|
-
const name = path22.node.id?.name;
|
86435
|
-
if (name) {
|
86436
|
-
if (path22.parent == setupNode.body) {
|
86437
|
-
tempNodes.add(name);
|
86438
|
-
if (!tempEdges.get(name)) {
|
86439
|
-
tempEdges.set(name, /* @__PURE__ */ new Set());
|
86440
|
-
}
|
86441
|
-
}
|
86442
|
-
}
|
86443
|
-
}
|
86444
|
-
}, path1.scope, path1);
|
86445
|
-
traverse3(setupNode, {
|
86446
|
-
FunctionDeclaration(path3) {
|
86447
|
-
const name = path3.node.id?.name;
|
86448
|
-
if (name && tempNodes.has(name)) {
|
86449
|
-
path3.traverse({
|
86450
|
-
Identifier(path4) {
|
86451
|
-
if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
|
86452
|
-
tempEdges.get(name)?.add(path4.node.name);
|
86453
|
-
}
|
86454
|
-
}
|
86455
|
-
});
|
86456
|
-
}
|
86457
|
-
},
|
86458
|
-
VariableDeclarator(path3) {
|
86459
|
-
if (path3.node.init) {
|
86460
|
-
if ([
|
86461
|
-
"CallExpression",
|
86462
|
-
"ArrowFunctionExpression",
|
86463
|
-
"FunctionDeclaration"
|
86464
|
-
].includes(path3.node.init.type) && path3.node.id.type === "Identifier") {
|
86465
|
-
const name = path3.node.id?.name;
|
86466
|
-
if (name && tempNodes.has(name)) {
|
86467
|
-
path3.traverse({
|
86468
|
-
Identifier(path4) {
|
86469
|
-
if (tempNodes.has(path4.node.name) && path4.node.name !== name) {
|
86470
|
-
tempEdges.get(name)?.add(path4.node.name);
|
86471
|
-
}
|
86472
|
-
}
|
86473
|
-
});
|
86474
|
-
}
|
86475
|
-
}
|
86476
|
-
}
|
86477
|
-
}
|
86478
|
-
}, path1.scope, path1);
|
86482
|
+
const {
|
86483
|
+
nodes: tempNodes,
|
86484
|
+
edges: tempEdges
|
86485
|
+
} = processSetup(setupNode, path1.scope, setupNode);
|
86479
86486
|
traverse3(setupNode, {
|
86480
86487
|
ReturnStatement(path22) {
|
86481
86488
|
if (path22.node.argument?.type === "ObjectExpression") {
|