pasika 0.10.22 → 0.10.23

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.
@@ -59,6 +59,7 @@ import path from "path";
59
59
  import ts from "typescript";
60
60
  var isPascalCase = (name) => /^[A-Z][A-Za-z0-9]*$/.test(name);
61
61
  var isHookCallName = (name) => /^use[A-Z]/.test(name);
62
+ var isHandlerName = (name) => /^handle[A-Z]/.test(name);
62
63
  function isExported(node) {
63
64
  if (!ts.canHaveModifiers(node)) return false;
64
65
  return (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
@@ -87,35 +88,77 @@ function containsJsx(node) {
87
88
  ts.forEachChild(node, visit);
88
89
  return found;
89
90
  }
90
- function containsSmartCall(node) {
91
+ function containsDataFetch(node) {
91
92
  let found = false;
92
93
  const visit = (child) => {
93
94
  if (found) return;
94
- if (ts.isCallExpression(child)) {
95
- const expression = child.expression;
96
- let name = "";
97
- if (ts.isIdentifier(expression)) {
98
- name = expression.text;
99
- } else if (ts.isPropertyAccessExpression(expression)) {
100
- name = expression.name.text;
101
- }
102
- if (isHookCallName(name)) {
103
- found = true;
104
- return;
105
- }
95
+ if (ts.isCallExpression(child) && ts.isIdentifier(child.expression) && child.expression.text === "zodFetch") {
96
+ found = true;
97
+ return;
106
98
  }
107
99
  ts.forEachChild(child, visit);
108
100
  };
109
101
  ts.forEachChild(node, visit);
110
102
  return found;
111
103
  }
112
- function isAsyncFunction(node) {
113
- return (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
104
+ function isComponentTagName(tagName2) {
105
+ if (ts.isIdentifier(tagName2)) return isPascalCase(tagName2.text);
106
+ if (ts.isPropertyAccessExpression(tagName2)) {
107
+ let root = tagName2.expression;
108
+ while (ts.isPropertyAccessExpression(root)) root = root.expression;
109
+ return ts.isIdentifier(root) && isPascalCase(root.text);
110
+ }
111
+ return false;
112
+ }
113
+ function containsOwnedHandlerProp(node) {
114
+ const handlerNames = /* @__PURE__ */ new Set();
115
+ const collectHandlers = (child) => {
116
+ if (ts.isVariableDeclaration(child) && ts.isIdentifier(child.name) && isHandlerName(child.name.text) && child.initializer && (ts.isArrowFunction(child.initializer) || ts.isFunctionExpression(child.initializer) || ts.isCallExpression(child.initializer) && ts.isPropertyAccessExpression(child.initializer.expression) && child.initializer.expression.name.text === "useCallback" || ts.isCallExpression(child.initializer) && ts.isIdentifier(child.initializer.expression) && child.initializer.expression.text === "useCallback")) {
117
+ handlerNames.add(child.name.text);
118
+ } else if (ts.isFunctionDeclaration(child) && child.name && isHandlerName(child.name.text)) {
119
+ handlerNames.add(child.name.text);
120
+ }
121
+ ts.forEachChild(child, collectHandlers);
122
+ };
123
+ ts.forEachChild(node, collectHandlers);
124
+ if (handlerNames.size === 0) return false;
125
+ let found = false;
126
+ const findPassedHandler = (child) => {
127
+ if (found) return;
128
+ let attributes;
129
+ let tagName2;
130
+ if (ts.isJsxElement(child)) {
131
+ attributes = child.openingElement.attributes;
132
+ tagName2 = child.openingElement.tagName;
133
+ } else if (ts.isJsxSelfClosingElement(child)) {
134
+ attributes = child.attributes;
135
+ tagName2 = child.tagName;
136
+ }
137
+ if (attributes && tagName2 && isComponentTagName(tagName2)) {
138
+ for (const property of attributes.properties) {
139
+ if (!ts.isJsxAttribute(property) || !ts.isIdentifier(property.name) || !/^on[A-Z]/.test(property.name.text)) {
140
+ continue;
141
+ }
142
+ const initializer = property.initializer;
143
+ if (!initializer || !ts.isJsxExpression(initializer) || !initializer.expression) continue;
144
+ if (ts.isIdentifier(initializer.expression) && handlerNames.has(initializer.expression.text)) {
145
+ found = true;
146
+ return;
147
+ }
148
+ }
149
+ }
150
+ ts.forEachChild(child, findPassedHandler);
151
+ };
152
+ ts.forEachChild(node, findPassedHandler);
153
+ return found;
154
+ }
155
+ function isSmartComponent(node) {
156
+ return containsDataFetch(node) || containsOwnedHandlerProp(node);
114
157
  }
115
158
  function componentFromFunction(node) {
116
159
  const name = node.name?.text;
117
160
  if (!name || !isPascalCase(name) || !containsJsx(node)) return void 0;
118
- return { name, declaration: node, smart: containsSmartCall(node) || isAsyncFunction(node) };
161
+ return { name, declaration: node, smart: isSmartComponent(node) };
119
162
  }
120
163
  function componentFromVariable(node) {
121
164
  if (!ts.isIdentifier(node.name) || !isPascalCase(node.name.text)) return void 0;
@@ -125,7 +168,7 @@ function componentFromVariable(node) {
125
168
  return {
126
169
  name: node.name.text,
127
170
  declaration: node,
128
- smart: containsSmartCall(initializer)
171
+ smart: isSmartComponent(initializer)
129
172
  };
130
173
  }
131
174
  function parseComponentInfo(text, filename, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.22",
3
+ "version": "0.10.23",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",