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.js +26 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -202,6 +202,7 @@ function getComment(node) {
|
|
202
202
|
|
203
203
|
// src/analyze/setupScript.ts
|
204
204
|
var traverse2 = import_traverse2.default.default?.default || import_traverse2.default.default || import_traverse2.default;
|
205
|
+
var ignoreFunctionsName = ["defineProps", "defineEmits", "withDefaults"];
|
205
206
|
function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
206
207
|
const spread = _spread || [];
|
207
208
|
const nodeCollection = new NodeCollection(_lineOffset);
|
@@ -218,7 +219,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
218
219
|
if (element?.type === "Identifier") {
|
219
220
|
const name = element.name;
|
220
221
|
const binding = path.scope.getBinding(name);
|
221
|
-
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" &&
|
222
|
+
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))) {
|
222
223
|
graph.nodes.add(name);
|
223
224
|
nodeCollection.addNode(name, element, {
|
224
225
|
comment: getComment(path.node)
|
@@ -231,7 +232,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
231
232
|
if (element?.type === "RestElement" && element.argument.type === "Identifier") {
|
232
233
|
const name = element.argument.name;
|
233
234
|
const binding = path.scope.getBinding(name);
|
234
|
-
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" &&
|
235
|
+
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))) {
|
235
236
|
graph.nodes.add(name);
|
236
237
|
nodeCollection.addNode(name, element.argument, {
|
237
238
|
comment: getComment(path.node)
|
@@ -248,7 +249,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
248
249
|
if (property.type === "ObjectProperty" && property.value.type === "Identifier") {
|
249
250
|
const name = property.value.name;
|
250
251
|
const binding = path.scope.getBinding(name);
|
251
|
-
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" &&
|
252
|
+
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))) {
|
252
253
|
graph.nodes.add(name);
|
253
254
|
nodeCollection.addNode(name, property.value, {
|
254
255
|
comment: getComment(property)
|
@@ -261,7 +262,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
261
262
|
if (property.type === "RestElement" && property.argument.type === "Identifier") {
|
262
263
|
const name = property.argument.name;
|
263
264
|
const binding = path.scope.getBinding(name);
|
264
|
-
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" &&
|
265
|
+
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))) {
|
265
266
|
graph.nodes.add(name);
|
266
267
|
nodeCollection.addNode(name, property.argument, {
|
267
268
|
comment: getComment(property)
|
@@ -276,7 +277,7 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
276
277
|
if (declaration.id?.type === "Identifier") {
|
277
278
|
const name = declaration.id.name;
|
278
279
|
const binding = path.scope.getBinding(name);
|
279
|
-
if (binding && (path.parent.type === "Program" || parentPath?.type === "ObjectMethod" && parentPath.body === path.parent) && !(declaration.init?.type === "CallExpression" && declaration.init?.callee.type === "Identifier" &&
|
280
|
+
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))) {
|
280
281
|
graph.nodes.add(name);
|
281
282
|
nodeCollection.addNode(name, declaration, {
|
282
283
|
comment: getComment(path.node)
|
@@ -512,7 +513,24 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
|
|
512
513
|
return;
|
513
514
|
}
|
514
515
|
const watchArgs = /* @__PURE__ */ new Set();
|
515
|
-
if (hookName === "
|
516
|
+
if (hookName === "provide") {
|
517
|
+
traverse2(path.node.expression, {
|
518
|
+
Identifier(path1) {
|
519
|
+
const binding = path1.scope.getBinding(path1.node.name);
|
520
|
+
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)) {
|
521
|
+
const _node = nodeCollection.getNode(path1.node.name);
|
522
|
+
if (_node?.info?.used) {
|
523
|
+
_node?.info?.used?.add(hookName);
|
524
|
+
} else if (_node) {
|
525
|
+
_node.info = {
|
526
|
+
..._node?.info,
|
527
|
+
used: /* @__PURE__ */ new Set([hookName])
|
528
|
+
};
|
529
|
+
}
|
530
|
+
}
|
531
|
+
}
|
532
|
+
}, path.scope, path);
|
533
|
+
} else if (hookName === "watch") {
|
516
534
|
if (path.node.expression.arguments[0].type === "Identifier") {
|
517
535
|
const binding = path.scope.getBinding(path.node.expression.arguments[0].name);
|
518
536
|
if (graph.nodes.has(path.node.expression.arguments[0].name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
|
@@ -610,7 +628,8 @@ var vueLifeCycleHooks = [
|
|
610
628
|
"deactivated",
|
611
629
|
"errorCaptured",
|
612
630
|
"renderTracked",
|
613
|
-
"renderTriggered"
|
631
|
+
"renderTriggered",
|
632
|
+
"provide"
|
614
633
|
];
|
615
634
|
function analyze3(content, lineOffset = 0, jsx = false) {
|
616
635
|
const ast = (0, import_compiler_sfc3.babelParse)(content, { sourceType: "module", plugins: [
|