@base44-preview/vite-plugin 0.2.26-pr.43.e9195be → 0.2.27-pr.41.77be9cb
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/capabilities/inline-edit/controller.d.ts +3 -0
- package/dist/capabilities/inline-edit/controller.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/controller.js +194 -0
- package/dist/capabilities/inline-edit/controller.js.map +1 -0
- package/dist/capabilities/inline-edit/dom-utils.d.ts +6 -0
- package/dist/capabilities/inline-edit/dom-utils.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/dom-utils.js +49 -0
- package/dist/capabilities/inline-edit/dom-utils.js.map +1 -0
- package/dist/capabilities/inline-edit/index.d.ts +3 -0
- package/dist/capabilities/inline-edit/index.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/index.js +2 -0
- package/dist/capabilities/inline-edit/index.js.map +1 -0
- package/dist/capabilities/inline-edit/types.d.ts +25 -0
- package/dist/capabilities/inline-edit/types.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/types.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +25 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +95 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +9 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +26 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +17 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +76 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +1 -0
- package/dist/injections/visual-edit-agent/constants.d.ts +10 -0
- package/dist/injections/visual-edit-agent/constants.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/constants.js +10 -0
- package/dist/injections/visual-edit-agent/constants.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +10 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js +117 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +64 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +114 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +26 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js +148 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +7 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +54 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +11 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +32 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +105 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js +28 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +1 -0
- package/dist/injections/visual-edit-agent/index.d.ts +6 -0
- package/dist/injections/visual-edit-agent/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/index.js +109 -0
- package/dist/injections/visual-edit-agent/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts +17 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js +18 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts +26 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js +104 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +14 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js +34 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +1 -0
- package/dist/injections/visual-edit-agent.d.ts +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +1 -506
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/jsx-processor.d.ts +1 -4
- package/dist/jsx-processor.d.ts.map +1 -1
- package/dist/jsx-processor.js +6 -33
- package/dist/jsx-processor.js.map +1 -1
- package/dist/jsx-utils.d.ts +0 -9
- package/dist/jsx-utils.d.ts.map +1 -1
- package/dist/jsx-utils.js +0 -86
- package/dist/jsx-utils.js.map +1 -1
- package/dist/processors/shared-utils.d.ts +0 -64
- package/dist/processors/shared-utils.d.ts.map +1 -1
- package/dist/processors/shared-utils.js +0 -468
- package/dist/processors/shared-utils.js.map +1 -1
- package/dist/processors/static-array-processor.d.ts +3 -2
- package/dist/processors/static-array-processor.d.ts.map +1 -1
- package/dist/processors/static-array-processor.js +3 -2
- package/dist/processors/static-array-processor.js.map +1 -1
- package/dist/statics/index.mjs +5 -1
- package/dist/statics/index.mjs.map +1 -1
- package/dist/visual-edit-plugin.d.ts +1 -0
- package/dist/visual-edit-plugin.d.ts.map +1 -1
- package/dist/visual-edit-plugin.js +178 -29
- package/dist/visual-edit-plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/inline-edit/controller.ts +245 -0
- package/src/capabilities/inline-edit/dom-utils.ts +48 -0
- package/src/capabilities/inline-edit/index.ts +2 -0
- package/src/capabilities/inline-edit/types.ts +30 -0
- package/src/injections/visual-edit-agent/README.md +222 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +120 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +10 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +26 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +87 -0
- package/src/injections/visual-edit-agent/constants.ts +9 -0
- package/src/injections/visual-edit-agent/handlers/click-handlers.ts +146 -0
- package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
- package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +146 -0
- package/src/injections/visual-edit-agent/handlers/message-handlers.ts +201 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +65 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +40 -0
- package/src/injections/visual-edit-agent/handlers/messages/types.ts +134 -0
- package/src/injections/visual-edit-agent/index.ts +121 -0
- package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
- package/src/injections/visual-edit-agent/ui/overlay.ts +126 -0
- package/src/injections/visual-edit-agent/utils/dom-utils.ts +39 -0
- package/src/injections/visual-edit-agent.ts +1 -625
- package/src/jsx-processor.ts +14 -41
- package/src/jsx-utils.ts +0 -116
- package/src/processors/shared-utils.ts +0 -596
- package/src/processors/static-array-processor.ts +3 -6
- package/src/visual-edit-plugin.ts +215 -34
- package/dist/consts.d.ts +0 -12
- package/dist/consts.d.ts.map +0 -1
- package/dist/consts.js +0 -12
- package/dist/consts.js.map +0 -1
- package/dist/processors/collection-id-processor.d.ts +0 -20
- package/dist/processors/collection-id-processor.d.ts.map +0 -1
- package/dist/processors/collection-id-processor.js +0 -182
- package/dist/processors/collection-id-processor.js.map +0 -1
- package/dist/processors/collection-item-field-processor.d.ts +0 -33
- package/dist/processors/collection-item-field-processor.d.ts.map +0 -1
- package/dist/processors/collection-item-field-processor.js +0 -275
- package/dist/processors/collection-item-field-processor.js.map +0 -1
- package/dist/processors/collection-item-id-processor.d.ts +0 -12
- package/dist/processors/collection-item-id-processor.d.ts.map +0 -1
- package/dist/processors/collection-item-id-processor.js +0 -50
- package/dist/processors/collection-item-id-processor.js.map +0 -1
- package/dist/processors/collection-reference-field-processor.d.ts +0 -31
- package/dist/processors/collection-reference-field-processor.d.ts.map +0 -1
- package/dist/processors/collection-reference-field-processor.js +0 -174
- package/dist/processors/collection-reference-field-processor.js.map +0 -1
- package/dist/processors/collection-tracing-utils.d.ts +0 -31
- package/dist/processors/collection-tracing-utils.d.ts.map +0 -1
- package/dist/processors/collection-tracing-utils.js +0 -326
- package/dist/processors/collection-tracing-utils.js.map +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/src/consts.ts +0 -12
- package/src/processors/collection-id-processor.ts +0 -261
- package/src/processors/collection-item-field-processor.ts +0 -410
- package/src/processors/collection-item-id-processor.ts +0 -69
- package/src/processors/collection-reference-field-processor.ts +0 -225
- package/src/processors/collection-tracing-utils.ts +0 -436
- package/src/types.ts +0 -4
- /package/dist/{types.js → capabilities/inline-edit/types.js} +0 -0
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import { ExpressionAnalysisUtils, BindingUtils, CallExpressionUtils, } from "./shared-utils.js";
|
|
2
|
-
export class CollectionTracingUtils {
|
|
3
|
-
types;
|
|
4
|
-
expressionUtils;
|
|
5
|
-
bindingUtils;
|
|
6
|
-
callUtils;
|
|
7
|
-
visitedSetters = new Set();
|
|
8
|
-
visitedGetByIdSetters = new Set();
|
|
9
|
-
constructor(types) {
|
|
10
|
-
this.types = types;
|
|
11
|
-
this.expressionUtils = new ExpressionAnalysisUtils(types);
|
|
12
|
-
this.bindingUtils = new BindingUtils(types);
|
|
13
|
-
this.callUtils = new CallExpressionUtils(types);
|
|
14
|
-
}
|
|
15
|
-
resetVisited() {
|
|
16
|
-
this.visitedSetters.clear();
|
|
17
|
-
this.visitedGetByIdSetters.clear();
|
|
18
|
-
}
|
|
19
|
-
traceCollectionSource(path) {
|
|
20
|
-
this.resetVisited();
|
|
21
|
-
return this.traceExpression(path);
|
|
22
|
-
}
|
|
23
|
-
traceExpression(path) {
|
|
24
|
-
if (path.isIdentifier()) {
|
|
25
|
-
return this.traceIdentifierToCollection(path);
|
|
26
|
-
}
|
|
27
|
-
if (path.isMemberExpression()) {
|
|
28
|
-
return this.traceMemberExpression(path);
|
|
29
|
-
}
|
|
30
|
-
if (path.isCallExpression()) {
|
|
31
|
-
return this.traceCallExpression(path);
|
|
32
|
-
}
|
|
33
|
-
if (path.isAwaitExpression()) {
|
|
34
|
-
const argument = path.get("argument");
|
|
35
|
-
if (argument.isExpression()) {
|
|
36
|
-
return this.traceExpression(argument);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (path.isArrayExpression()) {
|
|
40
|
-
return this.traceArrayExpression(path);
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
traceIdentifierToCollection(path) {
|
|
45
|
-
const name = path.node.name;
|
|
46
|
-
const binding = path.scope.getBinding(name);
|
|
47
|
-
if (!binding)
|
|
48
|
-
return null;
|
|
49
|
-
if (binding.path.isVariableDeclarator()) {
|
|
50
|
-
return this.traceVariableDeclarator(binding.path, name);
|
|
51
|
-
}
|
|
52
|
-
if (this.bindingUtils.isFunctionParameter(name, path)) {
|
|
53
|
-
return this.traceParameterToCollection(name, path);
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
traceVariableDeclarator(declaratorPath, variableName) {
|
|
58
|
-
const init = declaratorPath.get("init");
|
|
59
|
-
if (init.isCallExpression()) {
|
|
60
|
-
const directResult = this.checkDirectServiceCall(init);
|
|
61
|
-
if (directResult)
|
|
62
|
-
return directResult;
|
|
63
|
-
const useStateInfo = this.bindingUtils.isUseStateCall(init);
|
|
64
|
-
if (useStateInfo?.setterName) {
|
|
65
|
-
return this.traceUseStateSetter(useStateInfo.setterName, declaratorPath);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (init.isAwaitExpression()) {
|
|
69
|
-
const awaitArg = init.get("argument");
|
|
70
|
-
if (awaitArg.isCallExpression()) {
|
|
71
|
-
const directResult = this.checkDirectServiceCall(awaitArg);
|
|
72
|
-
if (directResult)
|
|
73
|
-
return directResult;
|
|
74
|
-
}
|
|
75
|
-
return this.traceExpression(init);
|
|
76
|
-
}
|
|
77
|
-
if (init.isMemberExpression()) {
|
|
78
|
-
return this.traceExpression(init);
|
|
79
|
-
}
|
|
80
|
-
if (init.isIdentifier()) {
|
|
81
|
-
return this.traceExpression(init);
|
|
82
|
-
}
|
|
83
|
-
if (init.isCallExpression()) {
|
|
84
|
-
return this.traceExpression(init);
|
|
85
|
-
}
|
|
86
|
-
const id = declaratorPath.get("id");
|
|
87
|
-
if (id.isArrayPattern()) {
|
|
88
|
-
return this.traceArrayDestructuring(declaratorPath, id, variableName);
|
|
89
|
-
}
|
|
90
|
-
if (id.isObjectPattern()) {
|
|
91
|
-
return this.traceObjectDestructuring(declaratorPath, id, variableName);
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
traceUseStateSetter(setterName, declaratorPath) {
|
|
96
|
-
if (this.visitedSetters.has(setterName))
|
|
97
|
-
return null;
|
|
98
|
-
this.visitedSetters.add(setterName);
|
|
99
|
-
const functionScope = declaratorPath.getFunctionParent() ?? declaratorPath.scope.path;
|
|
100
|
-
const setterCall = this.bindingUtils.findSetterCallInScope(setterName, functionScope);
|
|
101
|
-
if (!setterCall)
|
|
102
|
-
return null;
|
|
103
|
-
const args = setterCall.get("arguments");
|
|
104
|
-
const firstArg = args[0];
|
|
105
|
-
if (!firstArg || !firstArg.isExpression())
|
|
106
|
-
return null;
|
|
107
|
-
return this.traceExpression(firstArg);
|
|
108
|
-
}
|
|
109
|
-
traceMemberExpression(path) {
|
|
110
|
-
const property = path.get("property");
|
|
111
|
-
const object = path.get("object");
|
|
112
|
-
if (property.isIdentifier() &&
|
|
113
|
-
property.node.name === "items") {
|
|
114
|
-
if (object.isExpression()) {
|
|
115
|
-
return this.traceExpression(object);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (object.isIdentifier()) {
|
|
119
|
-
const objResult = this.traceIdentifierToCollection(object);
|
|
120
|
-
if (objResult && property.isIdentifier()) {
|
|
121
|
-
if (objResult.references.includes(property.node.name)) {
|
|
122
|
-
return { id: property.node.name, references: [] };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return objResult;
|
|
126
|
-
}
|
|
127
|
-
if (object.isExpression()) {
|
|
128
|
-
return this.traceExpression(object);
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
traceCallExpression(path) {
|
|
133
|
-
const directResult = this.checkDirectServiceCall(path);
|
|
134
|
-
if (directResult)
|
|
135
|
-
return directResult;
|
|
136
|
-
if (this.callUtils.isChainedArrayMethod(path.node)) {
|
|
137
|
-
const callee = path.get("callee");
|
|
138
|
-
if (callee.isMemberExpression()) {
|
|
139
|
-
const obj = callee.get("object");
|
|
140
|
-
return this.traceExpression(obj);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
checkDirectServiceCall(path) {
|
|
146
|
-
const getAllInfo = this.callUtils.isGetAllCall(path.node);
|
|
147
|
-
if (getAllInfo) {
|
|
148
|
-
return {
|
|
149
|
-
id: getAllInfo.collectionName,
|
|
150
|
-
references: getAllInfo.references,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
const getByIdInfo = this.callUtils.isGetByIdCall(path.node);
|
|
154
|
-
if (getByIdInfo) {
|
|
155
|
-
return {
|
|
156
|
-
id: getByIdInfo.collectionName,
|
|
157
|
-
references: getByIdInfo.multiRefFields,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
traceArrayDestructuring(declaratorPath, pattern, variableName) {
|
|
163
|
-
const elements = pattern.get("elements");
|
|
164
|
-
const index = elements.findIndex((el) => el.isIdentifier() && el.node.name === variableName);
|
|
165
|
-
if (index === -1)
|
|
166
|
-
return null;
|
|
167
|
-
const init = declaratorPath.get("init");
|
|
168
|
-
if (init.hasNode() && this.bindingUtils.isPromiseAllCall(init)) {
|
|
169
|
-
return this.tracePromiseAllElement(init, index);
|
|
170
|
-
}
|
|
171
|
-
if (init.isCallExpression()) {
|
|
172
|
-
const useStateInfo = this.bindingUtils.isUseStateCall(init);
|
|
173
|
-
if (useStateInfo && index === 0 && useStateInfo.setterName) {
|
|
174
|
-
return this.traceUseStateSetter(useStateInfo.setterName, declaratorPath);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
traceObjectDestructuring(declaratorPath, pattern, variableName) {
|
|
180
|
-
const init = declaratorPath.get("init");
|
|
181
|
-
if (!init.isExpression())
|
|
182
|
-
return null;
|
|
183
|
-
const prop = pattern.node.properties.find((p) => this.types.isObjectProperty(p) &&
|
|
184
|
-
this.types.isIdentifier(p.value) &&
|
|
185
|
-
p.value.name === variableName);
|
|
186
|
-
if (!prop || !this.types.isObjectProperty(prop))
|
|
187
|
-
return null;
|
|
188
|
-
const key = prop.key;
|
|
189
|
-
const propertyName = this.types.isIdentifier(key)
|
|
190
|
-
? key.name
|
|
191
|
-
: this.types.isStringLiteral(key)
|
|
192
|
-
? key.value
|
|
193
|
-
: null;
|
|
194
|
-
if (propertyName === "items") {
|
|
195
|
-
return this.traceExpression(init);
|
|
196
|
-
}
|
|
197
|
-
return this.traceExpression(init);
|
|
198
|
-
}
|
|
199
|
-
tracePromiseAllElement(init, index) {
|
|
200
|
-
let callExpr;
|
|
201
|
-
if (init.isAwaitExpression()) {
|
|
202
|
-
const arg = init.get("argument");
|
|
203
|
-
if (!arg.isCallExpression())
|
|
204
|
-
return null;
|
|
205
|
-
callExpr = arg;
|
|
206
|
-
}
|
|
207
|
-
else if (init.isCallExpression()) {
|
|
208
|
-
callExpr = init;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
const args = callExpr.get("arguments");
|
|
214
|
-
const firstArg = args[0];
|
|
215
|
-
if (!firstArg?.isArrayExpression())
|
|
216
|
-
return null;
|
|
217
|
-
const elements = firstArg.get("elements");
|
|
218
|
-
const targetElement = elements[index];
|
|
219
|
-
if (!targetElement || !targetElement.isExpression())
|
|
220
|
-
return null;
|
|
221
|
-
return this.traceExpression(targetElement);
|
|
222
|
-
}
|
|
223
|
-
traceParameterToCollection(paramName, path) {
|
|
224
|
-
const fn = path.getFunctionParent();
|
|
225
|
-
if (!fn)
|
|
226
|
-
return null;
|
|
227
|
-
const fnName = this.getFunctionName(fn);
|
|
228
|
-
if (!fnName)
|
|
229
|
-
return null;
|
|
230
|
-
const programPath = fn.findParent((p) => p.isProgram());
|
|
231
|
-
if (!programPath)
|
|
232
|
-
return null;
|
|
233
|
-
let result = null;
|
|
234
|
-
programPath.traverse({
|
|
235
|
-
JSXOpeningElement: (jsxPath) => {
|
|
236
|
-
if (result)
|
|
237
|
-
return;
|
|
238
|
-
const elementName = this.getJSXElementName(jsxPath.node);
|
|
239
|
-
if (elementName !== fnName)
|
|
240
|
-
return;
|
|
241
|
-
for (const attr of jsxPath.node.attributes) {
|
|
242
|
-
if (!this.types.isJSXAttribute(attr))
|
|
243
|
-
continue;
|
|
244
|
-
if (!this.types.isJSXIdentifier(attr.name))
|
|
245
|
-
continue;
|
|
246
|
-
if (attr.name.name !== paramName)
|
|
247
|
-
continue;
|
|
248
|
-
if (attr.value &&
|
|
249
|
-
this.types.isJSXExpressionContainer(attr.value) &&
|
|
250
|
-
this.types.isExpression(attr.value.expression)) {
|
|
251
|
-
const exprPath = jsxPath
|
|
252
|
-
.get("attributes")
|
|
253
|
-
.find((a) => a.isJSXAttribute() &&
|
|
254
|
-
this.types.isJSXIdentifier(a.node.name) &&
|
|
255
|
-
a.node.name.name === paramName);
|
|
256
|
-
if (exprPath && exprPath.isJSXAttribute()) {
|
|
257
|
-
const valPath = exprPath.get("value");
|
|
258
|
-
if (valPath.isJSXExpressionContainer()) {
|
|
259
|
-
const expr = valPath.get("expression");
|
|
260
|
-
if (expr.isExpression()) {
|
|
261
|
-
result = this.traceExpression(expr);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
});
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
traceArrayExpression(path) {
|
|
272
|
-
const elements = path.get("elements");
|
|
273
|
-
for (const el of elements) {
|
|
274
|
-
if (el.isSpreadElement()) {
|
|
275
|
-
const arg = el.get("argument");
|
|
276
|
-
if (arg.isExpression()) {
|
|
277
|
-
const result = this.traceExpression(arg);
|
|
278
|
-
if (result)
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
getFunctionName(fn) {
|
|
286
|
-
if (fn.isFunctionDeclaration() && fn.node.id) {
|
|
287
|
-
return fn.node.id.name;
|
|
288
|
-
}
|
|
289
|
-
const parent = fn.parentPath;
|
|
290
|
-
if (parent?.isVariableDeclarator()) {
|
|
291
|
-
const id = parent.get("id");
|
|
292
|
-
if (id.isIdentifier())
|
|
293
|
-
return id.node.name;
|
|
294
|
-
}
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
getJSXElementName(node) {
|
|
298
|
-
if (this.types.isJSXIdentifier(node.name)) {
|
|
299
|
-
return node.name.name;
|
|
300
|
-
}
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
traceGetByIdSource(path) {
|
|
304
|
-
this.visitedGetByIdSetters.clear();
|
|
305
|
-
return this.findGetByIdInScope(path);
|
|
306
|
-
}
|
|
307
|
-
findGetByIdInScope(path) {
|
|
308
|
-
const fn = path.getFunctionParent() ?? path.scope.path;
|
|
309
|
-
let result = null;
|
|
310
|
-
fn.traverse({
|
|
311
|
-
CallExpression: (callPath) => {
|
|
312
|
-
if (result)
|
|
313
|
-
return;
|
|
314
|
-
const info = this.callUtils.isGetByIdCall(callPath.node);
|
|
315
|
-
if (info) {
|
|
316
|
-
result = {
|
|
317
|
-
id: info.collectionName,
|
|
318
|
-
references: info.multiRefFields,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
return result;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
//# sourceMappingURL=collection-tracing-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection-tracing-utils.js","sourceRoot":"","sources":["../../src/processors/collection-tracing-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,OAAO,sBAAsB;IAOb;IANZ,eAAe,CAA0B;IACzC,YAAY,CAAe;IAC3B,SAAS,CAAsB;IAC/B,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAElD,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QACjC,IAAI,CAAC,eAAe,GAAG,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,YAAY;QACV,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;IAED,qBAAqB,CACnB,IAA4B;QAE5B,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEO,eAAe,CACrB,IAA4B;QAE5B,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,E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AC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,EAAE,CAAC,YAAY,EAAE;gBAAE,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,iBAAiB,CAAC,IAAyB;QACjD,IAAI,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACxB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB,CAChB,IAAc;QAEd,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAEO,kBAAkB,CACxB,IAAc;QAEd,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QACvD,IAAI,MAAM,GAA0B,IAAI,CAAC;QAEzC,EAAE,CAAC,QAAQ,CAAC;YACV,cAAc,EAAE,CAAC,QAAoC,EAAE,EAAE;gBACvD,IAAI,MAAM;oBAAE,OAAO;gBACnB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBACzD,IAAI,IAAI,EAAE,CAAC;oBACT,MAAM,GAAG;wBACP,EAAE,EAAE,IAAI,CAAC,cAAc;wBACvB,UAAU,EAAE,IAAI,CAAC,cAAc;qBAChC,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/dist/types.d.ts
DELETED
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/src/consts.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const DATA_COLLECTION_ID = "data-collection-id";
|
|
2
|
-
export const DATA_COLLECTION_ITEM_ID = "data-collection-item-id";
|
|
3
|
-
export const DATA_COLLECTION_ITEM_FIELD = "data-collection-item-field";
|
|
4
|
-
export const DATA_COLLECTION_REFERENCE = "data-collection-reference";
|
|
5
|
-
export const DATA_COLLECTION_FIELD_REFERENCE = "data-collection-field-reference";
|
|
6
|
-
export const DATA_ARR_INDEX = "data-arr-index";
|
|
7
|
-
export const DATA_ARR_VARIABLE_NAME = "data-arr-variable-name";
|
|
8
|
-
export const DATA_ARR_FIELD = "data-arr-field";
|
|
9
|
-
|
|
10
|
-
export const ALLOWED_CUSTOM_COMPONENTS = ["Image", "Link"];
|
|
11
|
-
export const MAX_JSX_DEPTH = 10;
|
|
12
|
-
export const EXCLUDED_FIELDS = ["children", "length"];
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from "@babel/traverse";
|
|
2
|
-
import type * as t from "@babel/types";
|
|
3
|
-
import type { CollectionInfo } from "../types.js";
|
|
4
|
-
import {
|
|
5
|
-
DATA_COLLECTION_ID,
|
|
6
|
-
DATA_COLLECTION_REFERENCE,
|
|
7
|
-
MAX_JSX_DEPTH,
|
|
8
|
-
} from "../consts.js";
|
|
9
|
-
import { JSXUtils } from "../jsx-utils.js";
|
|
10
|
-
import {
|
|
11
|
-
JSXAttributeUtils,
|
|
12
|
-
PathNavigationUtils,
|
|
13
|
-
ExpressionAnalysisUtils,
|
|
14
|
-
} from "./shared-utils.js";
|
|
15
|
-
import { CollectionTracingUtils } from "./collection-tracing-utils.js";
|
|
16
|
-
|
|
17
|
-
export class CollectionIdProcessor {
|
|
18
|
-
private attributeUtils: JSXAttributeUtils;
|
|
19
|
-
private pathUtils: PathNavigationUtils;
|
|
20
|
-
private expressionUtils: ExpressionAnalysisUtils;
|
|
21
|
-
private tracingUtils: CollectionTracingUtils;
|
|
22
|
-
|
|
23
|
-
constructor(private types: typeof t) {
|
|
24
|
-
this.attributeUtils = new JSXAttributeUtils(types);
|
|
25
|
-
this.pathUtils = new PathNavigationUtils(types);
|
|
26
|
-
this.expressionUtils = new ExpressionAnalysisUtils(types);
|
|
27
|
-
this.tracingUtils = new CollectionTracingUtils(types);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
process(path: NodePath<t.JSXOpeningElement>): void {
|
|
31
|
-
if (this.attributeUtils.hasAttribute(path, DATA_COLLECTION_ID)) return;
|
|
32
|
-
|
|
33
|
-
const info =
|
|
34
|
-
this.tryDirectMapInChildren(path) ??
|
|
35
|
-
this.tryGetByIdInChildren(path) ??
|
|
36
|
-
this.tryComponentRootWithCollectionProp(path);
|
|
37
|
-
|
|
38
|
-
if (!info) return;
|
|
39
|
-
|
|
40
|
-
const target = this.pathUtils.findDOMElementTarget(path) ?? path;
|
|
41
|
-
|
|
42
|
-
this.attributeUtils.addStringAttribute(target, DATA_COLLECTION_ID, info.id);
|
|
43
|
-
|
|
44
|
-
if (info.references.length > 0) {
|
|
45
|
-
this.attributeUtils.addStringAttribute(
|
|
46
|
-
target,
|
|
47
|
-
DATA_COLLECTION_REFERENCE,
|
|
48
|
-
info.references.join(",")
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private tryDirectMapInChildren(
|
|
54
|
-
path: NodePath<t.JSXOpeningElement>
|
|
55
|
-
): CollectionInfo | null {
|
|
56
|
-
const jsxElement = path.parentPath;
|
|
57
|
-
if (!jsxElement?.isJSXElement()) return null;
|
|
58
|
-
|
|
59
|
-
const children = jsxElement.get("children");
|
|
60
|
-
for (const child of children) {
|
|
61
|
-
if (!child.isJSXExpressionContainer()) continue;
|
|
62
|
-
|
|
63
|
-
const expression = child.get("expression");
|
|
64
|
-
if (expression.isJSXEmptyExpression()) continue;
|
|
65
|
-
|
|
66
|
-
const mapSource = this.extractMapSource(
|
|
67
|
-
expression as NodePath<t.Expression>
|
|
68
|
-
);
|
|
69
|
-
if (mapSource) return mapSource;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private extractMapSource(
|
|
76
|
-
expr: NodePath<t.Expression>
|
|
77
|
-
): CollectionInfo | null {
|
|
78
|
-
if (expr.isCallExpression()) {
|
|
79
|
-
return this.traceMapCall(expr);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (expr.isLogicalExpression()) {
|
|
83
|
-
if (expr.node.operator === "&&") {
|
|
84
|
-
const right = expr.get("right") as NodePath<t.Expression>;
|
|
85
|
-
return this.extractMapSource(right);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (expr.isConditionalExpression()) {
|
|
90
|
-
const consequent = expr.get("consequent") as NodePath<t.Expression>;
|
|
91
|
-
const alternate = expr.get("alternate") as NodePath<t.Expression>;
|
|
92
|
-
return (
|
|
93
|
-
this.extractMapSource(consequent) ?? this.extractMapSource(alternate)
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (expr.isOptionalCallExpression()) {
|
|
98
|
-
return this.traceOptionalMapCall(expr);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private traceMapCall(
|
|
105
|
-
callPath: NodePath<t.CallExpression>
|
|
106
|
-
): CollectionInfo | null {
|
|
107
|
-
const callee = callPath.get("callee");
|
|
108
|
-
if (!callee.isMemberExpression()) return null;
|
|
109
|
-
|
|
110
|
-
const property = callee.get("property") as NodePath;
|
|
111
|
-
if (
|
|
112
|
-
!property.isIdentifier() ||
|
|
113
|
-
(property.node.name !== "map" && property.node.name !== "flatMap")
|
|
114
|
-
) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!this.callbackProducesJSX(callPath)) return null;
|
|
119
|
-
|
|
120
|
-
const arrayObj = callee.get("object") as NodePath<t.Expression>;
|
|
121
|
-
return this.tracingUtils.traceCollectionSource(arrayObj);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private traceOptionalMapCall(
|
|
125
|
-
callPath: NodePath<t.OptionalCallExpression>
|
|
126
|
-
): CollectionInfo | null {
|
|
127
|
-
const callee = callPath.get("callee");
|
|
128
|
-
if (
|
|
129
|
-
!callee.isMemberExpression() &&
|
|
130
|
-
!callee.isOptionalMemberExpression()
|
|
131
|
-
) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const property = (callee as NodePath<t.MemberExpression>).get(
|
|
136
|
-
"property"
|
|
137
|
-
) as NodePath;
|
|
138
|
-
if (
|
|
139
|
-
!property.isIdentifier() ||
|
|
140
|
-
(property.node.name !== "map" && property.node.name !== "flatMap")
|
|
141
|
-
) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const arrayObj = (callee as NodePath<t.MemberExpression>).get(
|
|
146
|
-
"object"
|
|
147
|
-
) as NodePath<t.Expression>;
|
|
148
|
-
return this.tracingUtils.traceCollectionSource(arrayObj);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private callbackProducesJSX(
|
|
152
|
-
callPath: NodePath<t.CallExpression>
|
|
153
|
-
): boolean {
|
|
154
|
-
const args = callPath.get("arguments");
|
|
155
|
-
const callback = args[0];
|
|
156
|
-
if (!callback) return false;
|
|
157
|
-
|
|
158
|
-
if (callback.isArrowFunctionExpression()) {
|
|
159
|
-
const body = callback.get("body");
|
|
160
|
-
if (body.isBlockStatement()) {
|
|
161
|
-
return JSXUtils.doesBlockReturnJSX(body.node);
|
|
162
|
-
}
|
|
163
|
-
return JSXUtils.producesJSX(body.node);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (callback.isFunctionExpression()) {
|
|
167
|
-
return JSXUtils.doesBlockReturnJSX(callback.node.body);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private tryGetByIdInChildren(
|
|
174
|
-
path: NodePath<t.JSXOpeningElement>,
|
|
175
|
-
depth: number = 0
|
|
176
|
-
): CollectionInfo | null {
|
|
177
|
-
if (depth > MAX_JSX_DEPTH) return null;
|
|
178
|
-
|
|
179
|
-
const jsxElement = path.parentPath;
|
|
180
|
-
if (!jsxElement?.isJSXElement()) return null;
|
|
181
|
-
|
|
182
|
-
const children = jsxElement.get("children");
|
|
183
|
-
for (const child of children) {
|
|
184
|
-
const info = this.checkChildForGetById(child, depth);
|
|
185
|
-
if (info) return info;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for (const attr of path.node.attributes) {
|
|
189
|
-
if (
|
|
190
|
-
this.types.isJSXAttribute(attr) &&
|
|
191
|
-
attr.value &&
|
|
192
|
-
this.types.isJSXExpressionContainer(attr.value)
|
|
193
|
-
) {
|
|
194
|
-
const expr = attr.value.expression;
|
|
195
|
-
if (this.types.isMemberExpression(expr)) {
|
|
196
|
-
const info = this.tracingUtils.traceGetByIdSource(path);
|
|
197
|
-
if (info) return info;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private checkChildForGetById(
|
|
206
|
-
child: NodePath,
|
|
207
|
-
depth: number
|
|
208
|
-
): CollectionInfo | null {
|
|
209
|
-
if (child.isJSXExpressionContainer()) {
|
|
210
|
-
const expr = child.get("expression");
|
|
211
|
-
if (
|
|
212
|
-
expr.isMemberExpression() ||
|
|
213
|
-
expr.isOptionalMemberExpression()
|
|
214
|
-
) {
|
|
215
|
-
return this.tracingUtils.traceGetByIdSource(child);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (child.isJSXElement()) {
|
|
220
|
-
const childOpening = child.get("openingElement");
|
|
221
|
-
return this.tryGetByIdInChildren(childOpening, depth + 1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private tryComponentRootWithCollectionProp(
|
|
228
|
-
path: NodePath<t.JSXOpeningElement>
|
|
229
|
-
): CollectionInfo | null {
|
|
230
|
-
if (!this.pathUtils.isRootReturnElement(path)) return null;
|
|
231
|
-
|
|
232
|
-
const fn = this.pathUtils.findEnclosingFunction(path);
|
|
233
|
-
if (!fn) return null;
|
|
234
|
-
|
|
235
|
-
let info: CollectionInfo | null = null;
|
|
236
|
-
|
|
237
|
-
fn.traverse({
|
|
238
|
-
CallExpression: (callPath: NodePath<t.CallExpression>) => {
|
|
239
|
-
if (info) return;
|
|
240
|
-
|
|
241
|
-
const callee = callPath.get("callee");
|
|
242
|
-
if (!callee.isMemberExpression()) return;
|
|
243
|
-
|
|
244
|
-
const prop = callee.get("property") as NodePath;
|
|
245
|
-
if (
|
|
246
|
-
!prop.isIdentifier() ||
|
|
247
|
-
(prop.node.name !== "map" && prop.node.name !== "flatMap")
|
|
248
|
-
) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (!this.callbackProducesJSX(callPath)) return;
|
|
253
|
-
|
|
254
|
-
const arrayObj = callee.get("object") as NodePath<t.Expression>;
|
|
255
|
-
info = this.tracingUtils.traceCollectionSource(arrayObj);
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
return info;
|
|
260
|
-
}
|
|
261
|
-
}
|