@eventra_dev/eventra-cli 0.1.8 → 0.1.9
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/engine/scanner.js +18 -12
- package/package.json +1 -1
- package/src/engine/scanner.ts +30 -11
package/dist/engine/scanner.js
CHANGED
|
@@ -41,7 +41,8 @@ function isPropUsedInTracking(fn, prop) {
|
|
|
41
41
|
return;
|
|
42
42
|
for (const arg of node.arguments) {
|
|
43
43
|
if ((typescript_1.default.isIdentifier(arg) && arg.text === prop) ||
|
|
44
|
-
(typescript_1.default.isPropertyAccessExpression(arg) &&
|
|
44
|
+
(typescript_1.default.isPropertyAccessExpression(arg) &&
|
|
45
|
+
arg.name.text === prop)) {
|
|
45
46
|
found = true;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -51,7 +52,7 @@ function isPropUsedInTracking(fn, prop) {
|
|
|
51
52
|
visit(fn);
|
|
52
53
|
return found;
|
|
53
54
|
}
|
|
54
|
-
function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
55
|
+
function scanSource(source, checker, config, visited = new Set(), depth = 0, inheritedParamMap) {
|
|
55
56
|
const events = new Set();
|
|
56
57
|
const detectedFunctionWrappers = new Set();
|
|
57
58
|
const detectedComponentWrappers = new Map();
|
|
@@ -68,13 +69,16 @@ function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
|
68
69
|
const isAutoWrapper = fn && (0, functionAnalyzer_1.findTrackParamIndex)(fn) !== null;
|
|
69
70
|
const isTracking = isKnownWrapper ||
|
|
70
71
|
TRACKING_NAMES.has(name) ||
|
|
71
|
-
(isAutoWrapper &&
|
|
72
|
+
(isAutoWrapper &&
|
|
73
|
+
fn &&
|
|
74
|
+
!(0, boundary_1.isExternalFile)(fn.getSourceFile().fileName));
|
|
72
75
|
if (!isTracking)
|
|
73
76
|
return;
|
|
74
77
|
if (!isKnownWrapper && isAutoWrapper && !TRACKING_NAMES.has(name)) {
|
|
75
78
|
detectedFunctionWrappers.add(name);
|
|
76
79
|
}
|
|
77
|
-
|
|
80
|
+
// paramMap
|
|
81
|
+
const paramMap = new Map(inheritedParamMap ?? []);
|
|
78
82
|
if (fn && typescript_1.default.isFunctionLike(fn)) {
|
|
79
83
|
fn.parameters.forEach((param, i) => {
|
|
80
84
|
const arg = node.arguments[i];
|
|
@@ -97,6 +101,7 @@ function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
|
97
101
|
handled = true;
|
|
98
102
|
}
|
|
99
103
|
}
|
|
104
|
+
// fallback
|
|
100
105
|
if (!handled) {
|
|
101
106
|
for (const arg of node.arguments) {
|
|
102
107
|
const res = (0, resolver_1.resolveNodeValue)(arg, checker, paramMap);
|
|
@@ -106,15 +111,16 @@ function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
113
|
}
|
|
114
|
+
// cross-file WITH paramMap
|
|
109
115
|
if (fn) {
|
|
110
116
|
const sf = fn.getSourceFile();
|
|
111
117
|
if (!visited.has(sf.fileName)) {
|
|
112
|
-
const res = scanSource(sf, checker, config, visited, depth + 1);
|
|
118
|
+
const res = scanSource(sf, checker, config, visited, depth + 1, paramMap);
|
|
113
119
|
res.events.forEach(e => events.add(e));
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
|
-
// JSX
|
|
123
|
+
// JSX COMPONENTS
|
|
118
124
|
if (typescript_1.default.isJsxSelfClosingElement(node) ||
|
|
119
125
|
typescript_1.default.isJsxOpeningElement(node)) {
|
|
120
126
|
const tagNode = typescript_1.default.isPropertyAccessExpression(node.tagName)
|
|
@@ -138,7 +144,8 @@ function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
|
138
144
|
fn = decl;
|
|
139
145
|
if (typescript_1.default.isVariableDeclaration(decl) && decl.initializer) {
|
|
140
146
|
const init = decl.initializer;
|
|
141
|
-
if (typescript_1.default.isArrowFunction(init) ||
|
|
147
|
+
if (typescript_1.default.isArrowFunction(init) ||
|
|
148
|
+
typescript_1.default.isFunctionExpression(init)) {
|
|
142
149
|
fn = init;
|
|
143
150
|
}
|
|
144
151
|
}
|
|
@@ -165,11 +172,10 @@ function scanSource(source, checker, config, visited = new Set(), depth = 0) {
|
|
|
165
172
|
: attr.initializer;
|
|
166
173
|
if (!expr)
|
|
167
174
|
continue;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
175
|
+
const paramMap = new Map();
|
|
176
|
+
paramMap.set(prop, expr);
|
|
177
|
+
const res = scanSource(fn.getSourceFile(), checker, config, visited, depth + 1, paramMap);
|
|
178
|
+
res.events.forEach(e => events.add(e));
|
|
173
179
|
detectedComponentWrappers.set(tagName, prop);
|
|
174
180
|
}
|
|
175
181
|
}
|
package/package.json
CHANGED
package/src/engine/scanner.ts
CHANGED
|
@@ -45,7 +45,8 @@ function isPropUsedInTracking(
|
|
|
45
45
|
for (const arg of node.arguments) {
|
|
46
46
|
if (
|
|
47
47
|
(ts.isIdentifier(arg) && arg.text === prop) ||
|
|
48
|
-
(ts.isPropertyAccessExpression(arg) &&
|
|
48
|
+
(ts.isPropertyAccessExpression(arg) &&
|
|
49
|
+
arg.name.text === prop)
|
|
49
50
|
) {
|
|
50
51
|
found = true;
|
|
51
52
|
}
|
|
@@ -70,7 +71,8 @@ export function scanSource(
|
|
|
70
71
|
checker: ts.TypeChecker,
|
|
71
72
|
config: EventraConfig,
|
|
72
73
|
visited = new Set<string>(),
|
|
73
|
-
depth = 0
|
|
74
|
+
depth = 0,
|
|
75
|
+
inheritedParamMap?: Map<string, ts.Expression>
|
|
74
76
|
): ScanResult {
|
|
75
77
|
const events = new Set<string>();
|
|
76
78
|
const detectedFunctionWrappers = new Set<string>();
|
|
@@ -99,7 +101,9 @@ export function scanSource(
|
|
|
99
101
|
const isTracking =
|
|
100
102
|
isKnownWrapper ||
|
|
101
103
|
TRACKING_NAMES.has(name) ||
|
|
102
|
-
(isAutoWrapper &&
|
|
104
|
+
(isAutoWrapper &&
|
|
105
|
+
fn &&
|
|
106
|
+
!isExternalFile(fn.getSourceFile().fileName));
|
|
103
107
|
|
|
104
108
|
if (!isTracking) return;
|
|
105
109
|
|
|
@@ -107,7 +111,8 @@ export function scanSource(
|
|
|
107
111
|
detectedFunctionWrappers.add(name);
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
// paramMap
|
|
115
|
+
const paramMap = new Map(inheritedParamMap ?? []);
|
|
111
116
|
|
|
112
117
|
if (fn && ts.isFunctionLike(fn)) {
|
|
113
118
|
fn.parameters.forEach((param, i) => {
|
|
@@ -140,6 +145,7 @@ export function scanSource(
|
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
|
|
148
|
+
// fallback
|
|
143
149
|
if (!handled) {
|
|
144
150
|
for (const arg of node.arguments) {
|
|
145
151
|
const res = resolveNodeValue(arg, checker, paramMap);
|
|
@@ -150,6 +156,7 @@ export function scanSource(
|
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
|
|
159
|
+
// cross-file WITH paramMap
|
|
153
160
|
if (fn) {
|
|
154
161
|
const sf = fn.getSourceFile();
|
|
155
162
|
|
|
@@ -159,7 +166,8 @@ export function scanSource(
|
|
|
159
166
|
checker,
|
|
160
167
|
config,
|
|
161
168
|
visited,
|
|
162
|
-
depth + 1
|
|
169
|
+
depth + 1,
|
|
170
|
+
paramMap
|
|
163
171
|
);
|
|
164
172
|
|
|
165
173
|
res.events.forEach(e => events.add(e));
|
|
@@ -167,7 +175,7 @@ export function scanSource(
|
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
|
|
170
|
-
// JSX
|
|
178
|
+
// JSX COMPONENTS
|
|
171
179
|
if (
|
|
172
180
|
ts.isJsxSelfClosingElement(node) ||
|
|
173
181
|
ts.isJsxOpeningElement(node)
|
|
@@ -201,7 +209,10 @@ export function scanSource(
|
|
|
201
209
|
|
|
202
210
|
if (ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
203
211
|
const init = decl.initializer;
|
|
204
|
-
if (
|
|
212
|
+
if (
|
|
213
|
+
ts.isArrowFunction(init) ||
|
|
214
|
+
ts.isFunctionExpression(init)
|
|
215
|
+
) {
|
|
205
216
|
fn = init;
|
|
206
217
|
}
|
|
207
218
|
}
|
|
@@ -235,11 +246,19 @@ export function scanSource(
|
|
|
235
246
|
|
|
236
247
|
if (!expr) continue;
|
|
237
248
|
|
|
238
|
-
const
|
|
249
|
+
const paramMap = new Map<string, ts.Expression>();
|
|
250
|
+
paramMap.set(prop, expr);
|
|
239
251
|
|
|
240
|
-
res
|
|
241
|
-
|
|
242
|
-
|
|
252
|
+
const res = scanSource(
|
|
253
|
+
fn.getSourceFile(),
|
|
254
|
+
checker,
|
|
255
|
+
config,
|
|
256
|
+
visited,
|
|
257
|
+
depth + 1,
|
|
258
|
+
paramMap
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
res.events.forEach(e => events.add(e));
|
|
243
262
|
|
|
244
263
|
detectedComponentWrappers.set(tagName, prop);
|
|
245
264
|
}
|