@bamboocss/extractor 1.11.1 → 1.11.2
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.cjs +1832 -0
- package/dist/index.d.cts +303 -0
- package/dist/index.d.mts +303 -0
- package/dist/index.mjs +1735 -1868
- package/package.json +9 -9
- package/dist/index.js +0 -1989
package/dist/index.mjs
CHANGED
|
@@ -1,1947 +1,1814 @@
|
|
|
1
|
-
// src/get-typeof-literal.ts
|
|
2
1
|
import { BambooError } from "@bamboocss/shared";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { Node, SyntaxKind, ts } from "ts-morph";
|
|
3
|
+
import { evaluate } from "ts-evaluator";
|
|
4
|
+
//#region src/get-typeof-literal.ts
|
|
5
|
+
const getTypeOfLiteral = (value) => {
|
|
6
|
+
if (Array.isArray(value)) return "array";
|
|
7
|
+
if (typeof value === "string") return "string";
|
|
8
|
+
if (typeof value === "number") return "number";
|
|
9
|
+
if (typeof value === "boolean") return "boolean";
|
|
10
|
+
if (value === null) return "null";
|
|
11
|
+
if (value === void 0) return "undefined";
|
|
12
|
+
throw new BambooError("UNKNOWN_LITERAL_TYPE", `Unexpected literal type: ${value}. Expected: string, number, boolean, null, undefined, or array`);
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/utils.ts
|
|
16
|
+
const isNotNullish = (element) => element != null;
|
|
17
|
+
const isNullish = (element) => element == null;
|
|
18
|
+
const isTruthyOrZero = (element) => !!element || element === 0;
|
|
19
|
+
/** Returns true if typeof value is object && not null */
|
|
20
|
+
const isObject = (value) => value != null && typeof value === "object";
|
|
21
|
+
const isArray = (value) => Array.isArray(value);
|
|
22
|
+
const isPrimitiveType = (value) => {
|
|
23
|
+
const type = typeof value;
|
|
24
|
+
return type === "string" || type === "number" || type === "boolean" || value === null || value === void 0;
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (Node.isNonNullExpression(node)) {
|
|
35
|
-
return unwrapExpression(node.getExpression());
|
|
36
|
-
}
|
|
37
|
-
if (Node.isTypeAssertion(node)) {
|
|
38
|
-
return unwrapExpression(node.getExpression());
|
|
39
|
-
}
|
|
40
|
-
if (Node.isSatisfiesExpression(node)) {
|
|
41
|
-
return unwrapExpression(node.getExpression());
|
|
42
|
-
}
|
|
43
|
-
return node;
|
|
26
|
+
const unwrapExpression = (node) => {
|
|
27
|
+
if (Node.isAsExpression(node)) return unwrapExpression(node.getExpression());
|
|
28
|
+
if (Node.isParenthesizedExpression(node)) return unwrapExpression(node.getExpression());
|
|
29
|
+
if (Node.isNonNullExpression(node)) return unwrapExpression(node.getExpression());
|
|
30
|
+
if (Node.isTypeAssertion(node)) return unwrapExpression(node.getExpression());
|
|
31
|
+
if (Node.isSatisfiesExpression(node)) return unwrapExpression(node.getExpression());
|
|
32
|
+
return node;
|
|
44
33
|
};
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
const getComponentName = (node) => {
|
|
35
|
+
return node.getTagNameNode().getText();
|
|
47
36
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
const whitespaceRegex = /\s+/g;
|
|
38
|
+
const trimWhitespace = (str) => {
|
|
39
|
+
return str.replaceAll(whitespaceRegex, " ");
|
|
51
40
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/get-node-range.ts
|
|
43
|
+
const getNodeRange = (node) => {
|
|
44
|
+
const src = node.getSourceFile();
|
|
45
|
+
const [startPosition, endPosition] = [node.getStart(), node.getEnd()];
|
|
46
|
+
const startInfo = src.getLineAndColumnAtPos(startPosition);
|
|
47
|
+
const endInfo = src.getLineAndColumnAtPos(endPosition);
|
|
48
|
+
return {
|
|
49
|
+
startPosition,
|
|
50
|
+
startLineNumber: startInfo.line,
|
|
51
|
+
startColumn: startInfo.column,
|
|
52
|
+
endPosition,
|
|
53
|
+
endLineNumber: endInfo.line,
|
|
54
|
+
endColumn: endInfo.column
|
|
55
|
+
};
|
|
67
56
|
};
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/box-factory.ts
|
|
70
59
|
var BoxNodeType = class {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
60
|
+
type;
|
|
61
|
+
stack = [];
|
|
62
|
+
node;
|
|
63
|
+
constructor(definition) {
|
|
64
|
+
this.type = definition.type;
|
|
65
|
+
this.node = definition.node;
|
|
66
|
+
this.stack = [...definition.stack ?? []];
|
|
67
|
+
}
|
|
68
|
+
getNode() {
|
|
69
|
+
return this.node;
|
|
70
|
+
}
|
|
71
|
+
getStack() {
|
|
72
|
+
return this.stack;
|
|
73
|
+
}
|
|
74
|
+
getRange = () => getNodeRange(this.node);
|
|
75
|
+
toJSON() {
|
|
76
|
+
const range = this.getRange();
|
|
77
|
+
return {
|
|
78
|
+
type: this.type,
|
|
79
|
+
value: this.value,
|
|
80
|
+
node: this.node.getKindName(),
|
|
81
|
+
line: range.startLineNumber,
|
|
82
|
+
column: range.startColumn,
|
|
83
|
+
endLineNumber: range.endLineNumber,
|
|
84
|
+
endColumn: range.endColumn
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
toString() {
|
|
88
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
89
|
+
}
|
|
102
90
|
};
|
|
103
91
|
var BoxNodeObject = class extends BoxNodeType {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
92
|
+
value;
|
|
93
|
+
isEmpty;
|
|
94
|
+
constructor(definition) {
|
|
95
|
+
super(definition);
|
|
96
|
+
this.value = definition.value;
|
|
97
|
+
this.isEmpty = definition.isEmpty;
|
|
98
|
+
}
|
|
111
99
|
};
|
|
112
100
|
var BoxNodeLiteral = class extends BoxNodeType {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
101
|
+
value;
|
|
102
|
+
kind;
|
|
103
|
+
constructor(definition) {
|
|
104
|
+
super(definition);
|
|
105
|
+
this.value = definition.value;
|
|
106
|
+
this.kind = definition.kind;
|
|
107
|
+
}
|
|
120
108
|
};
|
|
121
|
-
|
|
109
|
+
const recipeProps = [
|
|
110
|
+
"compoundVariants",
|
|
111
|
+
"defaultVariants",
|
|
112
|
+
"variants",
|
|
113
|
+
"base"
|
|
114
|
+
];
|
|
122
115
|
var BoxNodeMap = class extends BoxNodeType {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
value;
|
|
117
|
+
spreadConditions;
|
|
118
|
+
constructor(definition) {
|
|
119
|
+
super(definition);
|
|
120
|
+
this.value = definition.value;
|
|
121
|
+
}
|
|
122
|
+
isRecipe = () => {
|
|
123
|
+
return recipeProps.some((prop) => this.value.has(prop));
|
|
124
|
+
};
|
|
132
125
|
};
|
|
133
126
|
var BoxNodeArray = class extends BoxNodeType {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
var BoxNodeUnresolvable = class extends BoxNodeType {
|
|
127
|
+
value;
|
|
128
|
+
constructor(definition) {
|
|
129
|
+
super(definition);
|
|
130
|
+
this.value = definition.value;
|
|
131
|
+
}
|
|
141
132
|
};
|
|
133
|
+
var BoxNodeUnresolvable = class extends BoxNodeType {};
|
|
142
134
|
var BoxNodeConditional = class extends BoxNodeType {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
whenTrue;
|
|
136
|
+
whenFalse;
|
|
137
|
+
constructor(definition) {
|
|
138
|
+
super(definition);
|
|
139
|
+
this.whenTrue = definition.whenTrue;
|
|
140
|
+
this.whenFalse = definition.whenFalse;
|
|
141
|
+
}
|
|
150
142
|
};
|
|
151
|
-
var BoxNodeEmptyInitializer = class extends BoxNodeType {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// src/to-box-node.ts
|
|
143
|
+
var BoxNodeEmptyInitializer = class extends BoxNodeType {};
|
|
144
|
+
const isBoxNode = (value) => value instanceof BoxNodeType;
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/to-box-node.ts
|
|
156
147
|
function toBoxNode(value, node, stack) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
if (isNullish(value)) return;
|
|
149
|
+
if (isBoxNode(value)) return value;
|
|
150
|
+
if (isObject(value)) return box.object(value, node, stack);
|
|
151
|
+
if (isArray(value)) {
|
|
152
|
+
if (value.length === 1) return toBoxNode(value[0], node, stack);
|
|
153
|
+
return value.map((item) => toBoxNode(item, node, stack));
|
|
154
|
+
}
|
|
155
|
+
if (isPrimitiveType(value)) return box.literal(value, node, stack);
|
|
165
156
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/box.ts
|
|
159
|
+
const box = {
|
|
160
|
+
object(value, node, stack) {
|
|
161
|
+
return new BoxNodeObject({
|
|
162
|
+
type: "object",
|
|
163
|
+
value,
|
|
164
|
+
node,
|
|
165
|
+
stack
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
literal(value, node, stack) {
|
|
169
|
+
return new BoxNodeLiteral({
|
|
170
|
+
type: "literal",
|
|
171
|
+
value,
|
|
172
|
+
kind: getTypeOfLiteral(value),
|
|
173
|
+
node,
|
|
174
|
+
stack
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
map(value, node, stack) {
|
|
178
|
+
return new BoxNodeMap({
|
|
179
|
+
type: "map",
|
|
180
|
+
value,
|
|
181
|
+
node,
|
|
182
|
+
stack
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
array(value, node, stack) {
|
|
186
|
+
return new BoxNodeArray({
|
|
187
|
+
type: "array",
|
|
188
|
+
value,
|
|
189
|
+
node,
|
|
190
|
+
stack
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
conditional(whenTrue, whenFalse, node, stack) {
|
|
194
|
+
return new BoxNodeConditional({
|
|
195
|
+
type: "conditional",
|
|
196
|
+
whenTrue,
|
|
197
|
+
whenFalse,
|
|
198
|
+
node,
|
|
199
|
+
stack
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
from: toBoxNode,
|
|
203
|
+
objectToMap: (value, node, stack) => {
|
|
204
|
+
return new BoxNodeMap({
|
|
205
|
+
type: "map",
|
|
206
|
+
value: new Map(Object.entries(value).map(([k, v]) => {
|
|
207
|
+
return [k, box.from(v, node, stack) || null];
|
|
208
|
+
})),
|
|
209
|
+
node,
|
|
210
|
+
stack
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
emptyObject: (node, stack) => {
|
|
214
|
+
return new BoxNodeObject({
|
|
215
|
+
type: "object",
|
|
216
|
+
value: {},
|
|
217
|
+
isEmpty: true,
|
|
218
|
+
node,
|
|
219
|
+
stack
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
emptyInitializer: (node, stack) => {
|
|
223
|
+
return new BoxNodeEmptyInitializer({
|
|
224
|
+
type: "empty-initializer",
|
|
225
|
+
node,
|
|
226
|
+
stack
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
unresolvable: (node, stack) => {
|
|
230
|
+
return new BoxNodeUnresolvable({
|
|
231
|
+
type: "unresolvable",
|
|
232
|
+
node,
|
|
233
|
+
stack
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
fallback(node) {
|
|
237
|
+
return {
|
|
238
|
+
value: void 0,
|
|
239
|
+
getNode: () => node.getNode(),
|
|
240
|
+
getStack: () => node.getStack(),
|
|
241
|
+
getRange: () => node.getRange()
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* box.type === “object” -> object that was resolved using ts-evaluator, most likely from a
|
|
246
|
+
* complex condition OR a simple CallExpression eval result, we don’t have access to individual
|
|
247
|
+
* AST nodes here so we need the distinction
|
|
248
|
+
*/
|
|
249
|
+
isObject(value) {
|
|
250
|
+
return value?.type === "object";
|
|
251
|
+
},
|
|
252
|
+
isLiteral(value) {
|
|
253
|
+
return value?.type === "literal";
|
|
254
|
+
},
|
|
255
|
+
/**
|
|
256
|
+
* box.type === “map” -> basically any object that was statically analyzable, we store each
|
|
257
|
+
* prop + value in a Map
|
|
258
|
+
*/
|
|
259
|
+
isMap(value) {
|
|
260
|
+
return value?.type === "map";
|
|
261
|
+
},
|
|
262
|
+
isRecipe(value) {
|
|
263
|
+
return box.isMap(value) && value.isRecipe();
|
|
264
|
+
},
|
|
265
|
+
isArray(value) {
|
|
266
|
+
return value?.type === "array";
|
|
267
|
+
},
|
|
268
|
+
isUnresolvable(value) {
|
|
269
|
+
return value?.type === "unresolvable";
|
|
270
|
+
},
|
|
271
|
+
isConditional(value) {
|
|
272
|
+
return value?.type === "conditional";
|
|
273
|
+
},
|
|
274
|
+
isEmptyInitializer(value) {
|
|
275
|
+
return value?.type === "empty-initializer";
|
|
276
|
+
},
|
|
277
|
+
isNumberLiteral(node) {
|
|
278
|
+
return box.isLiteral(node) && node.kind === "number";
|
|
279
|
+
},
|
|
280
|
+
hasValue: (node) => {
|
|
281
|
+
return box.isObject(node) || box.isLiteral(node) || box.isMap(node) || box.isArray(node);
|
|
282
|
+
}
|
|
251
283
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/evaluate-node.ts
|
|
286
|
+
const TsEvalError = Symbol("EvalError");
|
|
287
|
+
const cacheMap$2 = /* @__PURE__ */ new WeakMap();
|
|
288
|
+
/**
|
|
289
|
+
* Evaluates a node with strict policies restrictions
|
|
290
|
+
* @see https://github.com/wessberg/ts-evaluator#setting-up-policies
|
|
291
|
+
*/
|
|
292
|
+
const evaluateNode = (node, stack, ctx) => {
|
|
293
|
+
if (ctx.flags?.skipEvaluate) return;
|
|
294
|
+
if (ctx.canEval && !ctx.canEval?.(node, stack)) return;
|
|
295
|
+
if (cacheMap$2.has(node)) return cacheMap$2.get(node);
|
|
296
|
+
const result = evaluate({
|
|
297
|
+
policy: {
|
|
298
|
+
deterministic: true,
|
|
299
|
+
network: false,
|
|
300
|
+
console: false,
|
|
301
|
+
maxOps: Number.POSITIVE_INFINITY,
|
|
302
|
+
maxOpDuration: 1e3,
|
|
303
|
+
io: {
|
|
304
|
+
read: true,
|
|
305
|
+
write: false
|
|
306
|
+
},
|
|
307
|
+
process: {
|
|
308
|
+
exit: false,
|
|
309
|
+
spawnChild: false
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
...ctx.getEvaluateOptions?.(node, stack),
|
|
313
|
+
node: node.compilerNode,
|
|
314
|
+
typescript: ts
|
|
315
|
+
});
|
|
316
|
+
const expr = result.success ? result.value : TsEvalError;
|
|
317
|
+
cacheMap$2.set(node, expr);
|
|
318
|
+
return expr;
|
|
284
319
|
};
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
320
|
+
const safeEvaluateNode = (node, stack, ctx) => {
|
|
321
|
+
const result = evaluateNode(node, stack, ctx);
|
|
322
|
+
if (result === TsEvalError) return;
|
|
323
|
+
return result;
|
|
289
324
|
};
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
import {
|
|
293
|
-
Node as Node2
|
|
294
|
-
} from "ts-morph";
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/find-identifier-value-declaration.ts
|
|
295
327
|
function isScope(node) {
|
|
296
|
-
|
|
328
|
+
return Node.isFunctionDeclaration(node) || Node.isFunctionExpression(node) || Node.isArrowFunction(node) || Node.isSourceFile(node);
|
|
297
329
|
}
|
|
298
330
|
function getDeclarationFor(node, stack, ctx) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
return declaration;
|
|
331
|
+
const parent = node.getParent();
|
|
332
|
+
if (!parent) return;
|
|
333
|
+
const declarationStack = [];
|
|
334
|
+
let declaration;
|
|
335
|
+
if ((Node.isVariableDeclaration(parent) || Node.isParameterDeclaration(parent) || Node.isFunctionDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isBindingElement(parent)) && parent.getNameNode() == node) {
|
|
336
|
+
declarationStack.push(parent);
|
|
337
|
+
declaration = parent;
|
|
338
|
+
} else if (Node.isImportSpecifier(parent) && parent.getNameNode() == node) {
|
|
339
|
+
if (ctx.flags?.skipTraverseFiles) return;
|
|
340
|
+
const sourceFile = getModuleSpecifierSourceFile(parent.getImportDeclaration());
|
|
341
|
+
if (sourceFile) {
|
|
342
|
+
const exportStack = [parent, sourceFile];
|
|
343
|
+
const maybeVar = getExportedVarDeclarationWithName(node.getText(), sourceFile, exportStack, ctx);
|
|
344
|
+
if (maybeVar) {
|
|
345
|
+
declarationStack.push(...exportStack.concat(maybeVar));
|
|
346
|
+
declaration = maybeVar;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (declaration) stack.push(...declarationStack);
|
|
351
|
+
return declaration;
|
|
322
352
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
return scope;
|
|
353
|
+
const getInnermostScope = (from) => {
|
|
354
|
+
let scope = from.getParent();
|
|
355
|
+
while (scope && !isScope(scope)) scope = scope.getParent();
|
|
356
|
+
return scope;
|
|
329
357
|
};
|
|
330
358
|
function findIdentifierValueDeclaration(identifier, stack, ctx, visitedsWithStack = /* @__PURE__ */ new Map()) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
return foundNode;
|
|
379
|
-
}
|
|
380
|
-
} while (scope && !Node2.isSourceFile(scope) && !foundNode && !isUnresolvable && count < 100);
|
|
359
|
+
let scope = identifier;
|
|
360
|
+
let foundNode;
|
|
361
|
+
let isUnresolvable = false;
|
|
362
|
+
let count = 0;
|
|
363
|
+
const innerStack = [];
|
|
364
|
+
do {
|
|
365
|
+
scope = getInnermostScope(scope);
|
|
366
|
+
count++;
|
|
367
|
+
if (!scope) return;
|
|
368
|
+
const refName = identifier.getText();
|
|
369
|
+
scope.forEachDescendant((node, traversal) => {
|
|
370
|
+
if (visitedsWithStack.has(node)) {
|
|
371
|
+
traversal.skip();
|
|
372
|
+
innerStack.push(...visitedsWithStack.get(node));
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (node == identifier) return;
|
|
376
|
+
visitedsWithStack.set(node, innerStack);
|
|
377
|
+
if (Node.isIdentifier(node) && node.getText() == refName) {
|
|
378
|
+
const declarationStack = [node];
|
|
379
|
+
const maybeDeclaration = getDeclarationFor(node, declarationStack, ctx);
|
|
380
|
+
if (maybeDeclaration) {
|
|
381
|
+
if (Node.isParameterDeclaration(maybeDeclaration)) {
|
|
382
|
+
const initializer = maybeDeclaration.getInitializer();
|
|
383
|
+
const typeNode = maybeDeclaration.getTypeNode();
|
|
384
|
+
if (initializer) {
|
|
385
|
+
innerStack.push(...declarationStack.concat(initializer));
|
|
386
|
+
foundNode = maybeDeclaration;
|
|
387
|
+
} else if (typeNode && Node.isTypeLiteral(typeNode)) {
|
|
388
|
+
innerStack.push(...declarationStack.concat(typeNode));
|
|
389
|
+
foundNode = maybeDeclaration;
|
|
390
|
+
} else isUnresolvable = true;
|
|
391
|
+
traversal.stop();
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
innerStack.push(...declarationStack);
|
|
395
|
+
foundNode = maybeDeclaration;
|
|
396
|
+
traversal.stop();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
if (foundNode || isUnresolvable) {
|
|
401
|
+
if (foundNode) stack.push(...innerStack);
|
|
402
|
+
return foundNode;
|
|
403
|
+
}
|
|
404
|
+
} while (scope && !Node.isSourceFile(scope) && !foundNode && !isUnresolvable && count < 100);
|
|
381
405
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return maybePropName(expression, stack, ctx);
|
|
411
|
-
}
|
|
412
|
-
if (Node3.isStringLiteral(node) || Node3.isNumericLiteral(node)) return box.from(node.getLiteralText(), node, stack);
|
|
413
|
-
}
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/get-property-name.ts
|
|
408
|
+
const getPropertyName = (property, stack, ctx) => {
|
|
409
|
+
if (!property) return;
|
|
410
|
+
if (Node.isPropertyAssignment(property)) {
|
|
411
|
+
const node = unwrapExpression(property.getNameNode());
|
|
412
|
+
if (Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
413
|
+
if (Node.isComputedPropertyName(node)) {
|
|
414
|
+
const expression = node.getExpression();
|
|
415
|
+
stack.push(expression);
|
|
416
|
+
return maybePropName(expression, stack, ctx);
|
|
417
|
+
}
|
|
418
|
+
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(node.getLiteralText(), node, stack);
|
|
419
|
+
}
|
|
420
|
+
if (Node.isShorthandPropertyAssignment(property)) {
|
|
421
|
+
const name = property.getName();
|
|
422
|
+
if (name != null) return box.from(name, property, stack);
|
|
423
|
+
}
|
|
424
|
+
if (Node.isGetAccessorDeclaration(property)) {
|
|
425
|
+
const node = unwrapExpression(property.getNameNode());
|
|
426
|
+
if (Node.isIdentifier(node)) return box.from(node.getText(), node, stack);
|
|
427
|
+
if (Node.isComputedPropertyName(node)) {
|
|
428
|
+
const expression = node.getExpression();
|
|
429
|
+
stack.push(expression);
|
|
430
|
+
return maybePropName(expression, stack, ctx);
|
|
431
|
+
}
|
|
432
|
+
if (Node.isStringLiteral(node) || Node.isNumericLiteral(node)) return box.from(node.getLiteralText(), node, stack);
|
|
433
|
+
}
|
|
414
434
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (orderedMapValue.has(propName)) {
|
|
488
|
-
orderedMapValue.delete(propName);
|
|
489
|
-
}
|
|
490
|
-
orderedMapValue.set(propName, value);
|
|
491
|
-
});
|
|
492
|
-
const map = box.map(orderedMapValue, expression, expressionStack);
|
|
493
|
-
if (spreadConditions.length > 0) {
|
|
494
|
-
map.spreadConditions = spreadConditions;
|
|
495
|
-
}
|
|
496
|
-
return map;
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/get-object-literal-expression-prop-pairs.ts
|
|
437
|
+
const getObjectLiteralExpressionPropPairs = (expression, expressionStack, ctx, matchProp) => {
|
|
438
|
+
const properties = expression.getProperties();
|
|
439
|
+
if (properties.length === 0) return box.emptyObject(expression, expressionStack);
|
|
440
|
+
const extractedPropValues = [];
|
|
441
|
+
const spreadConditions = [];
|
|
442
|
+
properties.forEach((property) => {
|
|
443
|
+
const stack = [...expressionStack];
|
|
444
|
+
stack.push(property);
|
|
445
|
+
if (Node.isPropertyAssignment(property) || Node.isShorthandPropertyAssignment(property) || Node.isGetAccessorDeclaration(property)) {
|
|
446
|
+
const propNameBox = getPropertyName(property, stack, ctx);
|
|
447
|
+
if (!propNameBox) return;
|
|
448
|
+
const propName = propNameBox.value;
|
|
449
|
+
if (isNullish(propName)) return;
|
|
450
|
+
if (matchProp && !matchProp?.({
|
|
451
|
+
propName,
|
|
452
|
+
propNode: property
|
|
453
|
+
})) return;
|
|
454
|
+
if (Node.isShorthandPropertyAssignment(property)) {
|
|
455
|
+
const initializer = property.getNameNode();
|
|
456
|
+
stack.push(initializer);
|
|
457
|
+
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
458
|
+
if (maybeValue) {
|
|
459
|
+
extractedPropValues.push([propName.toString(), maybeValue]);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
let init;
|
|
464
|
+
if (Node.isGetAccessorDeclaration(property)) {
|
|
465
|
+
const body = property.getBody();
|
|
466
|
+
init = Node.isBlock(body) ? body.getStatements().at(-1) : void 0;
|
|
467
|
+
} else init = property.getInitializer();
|
|
468
|
+
if (!init) return;
|
|
469
|
+
const initializer = unwrapExpression((Node.isReturnStatement(init) ? init.getExpression() : void 0) ?? init);
|
|
470
|
+
stack.push(initializer);
|
|
471
|
+
const maybeValue = maybeBoxNode(initializer, stack, ctx);
|
|
472
|
+
if (maybeValue) {
|
|
473
|
+
extractedPropValues.push([propName.toString(), maybeValue]);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (Node.isSpreadAssignment(property)) {
|
|
478
|
+
const initializer = unwrapExpression(property.getExpression());
|
|
479
|
+
stack.push(initializer);
|
|
480
|
+
const maybeObject = maybeBoxNode(initializer, stack, ctx, matchProp);
|
|
481
|
+
if (!maybeObject) return;
|
|
482
|
+
if (box.isObject(maybeObject)) {
|
|
483
|
+
Object.entries(maybeObject.value).forEach(([propName, value]) => {
|
|
484
|
+
const boxNode = box.from(value, initializer, stack);
|
|
485
|
+
if (!boxNode) return;
|
|
486
|
+
extractedPropValues.push([propName, boxNode]);
|
|
487
|
+
});
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (box.isMap(maybeObject)) {
|
|
491
|
+
maybeObject.value.forEach((nested, propName) => {
|
|
492
|
+
extractedPropValues.push([propName, nested]);
|
|
493
|
+
});
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (box.isConditional(maybeObject)) spreadConditions.push(maybeObject);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
const orderedMapValue = /* @__PURE__ */ new Map();
|
|
500
|
+
extractedPropValues.forEach(([propName, value]) => {
|
|
501
|
+
if (orderedMapValue.has(propName)) orderedMapValue.delete(propName);
|
|
502
|
+
orderedMapValue.set(propName, value);
|
|
503
|
+
});
|
|
504
|
+
const map = box.map(orderedMapValue, expression, expressionStack);
|
|
505
|
+
if (spreadConditions.length > 0) map.spreadConditions = spreadConditions;
|
|
506
|
+
return map;
|
|
497
507
|
};
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/maybe-box-node.ts
|
|
510
|
+
const cacheMap$1 = /* @__PURE__ */ new WeakMap();
|
|
511
|
+
const isCached = (node) => cacheMap$1.has(node);
|
|
512
|
+
const getCached = (node) => cacheMap$1.get(node);
|
|
513
|
+
const isPlusSyntax = (op) => op === ts.SyntaxKind.PlusToken;
|
|
514
|
+
const isLogicalSyntax = (op) => op === ts.SyntaxKind.BarBarToken || op === ts.SyntaxKind.QuestionQuestionToken || op === ts.SyntaxKind.AmpersandAmpersandToken || op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken || op === ts.SyntaxKind.GreaterThanEqualsToken || op === ts.SyntaxKind.GreaterThanToken || op === ts.SyntaxKind.LessThanEqualsToken || op === ts.SyntaxKind.LessThanToken || op === ts.SyntaxKind.InstanceOfKeyword || op === ts.SyntaxKind.InKeyword;
|
|
515
|
+
const isOperationSyntax = (op) => op === ts.SyntaxKind.AsteriskToken || op === ts.SyntaxKind.SlashToken || op === ts.SyntaxKind.PercentToken || op === ts.SyntaxKind.AsteriskAsteriskToken || op === ts.SyntaxKind.MinusToken;
|
|
516
|
+
const canReturnWhenTrueInLogicalExpression = (op) => {
|
|
517
|
+
return op === ts.SyntaxKind.BarBarToken || op === ts.SyntaxKind.QuestionQuestionToken;
|
|
508
518
|
};
|
|
509
519
|
function maybeBoxNode(node, stack, ctx, matchProp) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
return cache(box.literal(resolvedValue, node, stack));
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
const value = safeEvaluateNode(node, stack, ctx);
|
|
625
|
-
if (!value) return;
|
|
626
|
-
return cache(box.from(value, node, stack));
|
|
627
|
-
}
|
|
628
|
-
if (Node5.isBinaryExpression(node)) {
|
|
629
|
-
const operatorKind = node.getOperatorToken().getKind();
|
|
630
|
-
if (isPlusSyntax(operatorKind)) {
|
|
631
|
-
const value = tryComputingPlusTokenBinaryExpressionToString(node, stack, ctx) ?? safeEvaluateNode(node, stack, ctx);
|
|
632
|
-
if (!value) return;
|
|
633
|
-
return cache(box.from(value, node, stack));
|
|
634
|
-
}
|
|
635
|
-
if (isLogicalSyntax(operatorKind)) {
|
|
636
|
-
const whenTrueExpr = unwrapExpression(node.getLeft());
|
|
637
|
-
const whenFalseExpr = unwrapExpression(node.getRight());
|
|
638
|
-
const exprObject = {
|
|
639
|
-
whenTrueExpr,
|
|
640
|
-
whenFalseExpr,
|
|
641
|
-
node,
|
|
642
|
-
stack,
|
|
643
|
-
canReturnWhenTrue: canReturnWhenTrueInLogicalExpression(operatorKind)
|
|
644
|
-
};
|
|
645
|
-
return cache(maybeResolveConditionalExpression(exprObject, ctx));
|
|
646
|
-
}
|
|
647
|
-
if (isOperationSyntax(operatorKind)) {
|
|
648
|
-
return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
649
|
-
}
|
|
650
|
-
}
|
|
520
|
+
const cache = (value) => {
|
|
521
|
+
cacheMap$1.set(node, value);
|
|
522
|
+
return value;
|
|
523
|
+
};
|
|
524
|
+
if (isCached(node)) return getCached(node);
|
|
525
|
+
if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) {
|
|
526
|
+
const value = trimWhitespace(node.getLiteralValue());
|
|
527
|
+
return cache(box.literal(value, node, stack));
|
|
528
|
+
}
|
|
529
|
+
if (Node.isObjectLiteralExpression(node)) return cache(getObjectLiteralExpressionPropPairs(node, stack, ctx, matchProp));
|
|
530
|
+
if (Node.isTrueLiteral(node) || Node.isFalseLiteral(node)) {
|
|
531
|
+
const value = node.getLiteralValue();
|
|
532
|
+
return cache(box.literal(value, node, stack));
|
|
533
|
+
}
|
|
534
|
+
if (Node.isNumericLiteral(node)) {
|
|
535
|
+
const value = node.getLiteralValue();
|
|
536
|
+
return cache(box.literal(value, node, stack));
|
|
537
|
+
}
|
|
538
|
+
if (Node.isNullLiteral(node)) return cache(box.literal(null, node, stack));
|
|
539
|
+
if (Node.isPrefixUnaryExpression(node)) {
|
|
540
|
+
const operand = node.getOperand();
|
|
541
|
+
const operator = node.getOperatorToken();
|
|
542
|
+
const boxNode = maybeBoxNode(operand, stack, ctx);
|
|
543
|
+
if (!box.isNumberLiteral(boxNode)) return;
|
|
544
|
+
return cache(operator === ts.SyntaxKind.MinusToken ? box.literal(-Number(boxNode.value), node, stack) : boxNode);
|
|
545
|
+
}
|
|
546
|
+
if (Node.isArrayLiteralExpression(node)) {
|
|
547
|
+
const boxNodes = node.getElements().map((element) => {
|
|
548
|
+
return maybeBoxNode(element, stack, ctx) ?? cache(box.unresolvable(element, stack));
|
|
549
|
+
});
|
|
550
|
+
return cache(box.array(boxNodes, node, stack));
|
|
551
|
+
}
|
|
552
|
+
if (Node.isIdentifier(node)) {
|
|
553
|
+
if (node.getText() === "undefined") return cache(box.literal(void 0, node, stack));
|
|
554
|
+
return cache(maybeIdentifierValue(node, stack, ctx));
|
|
555
|
+
}
|
|
556
|
+
if (Node.isTemplateHead(node)) return cache(box.literal(node.getLiteralText(), node, stack));
|
|
557
|
+
if (Node.isTemplateExpression(node)) {
|
|
558
|
+
const value = maybeTemplateStringValue(node, stack, ctx);
|
|
559
|
+
return cache(box.literal(value, node, stack));
|
|
560
|
+
}
|
|
561
|
+
if (Node.isTaggedTemplateExpression(node)) return cache(maybeBoxNode(node.getTemplate(), stack, ctx));
|
|
562
|
+
if (Node.isElementAccessExpression(node)) return cache(getElementAccessedExpressionValue(node, stack, ctx));
|
|
563
|
+
if (Node.isPropertyAccessExpression(node)) return cache(getPropertyAccessedExpressionValue(node, [], stack, ctx));
|
|
564
|
+
if (Node.isConditionalExpression(node)) {
|
|
565
|
+
if (ctx.flags?.skipConditions) return cache(box.unresolvable(node, stack));
|
|
566
|
+
const condExpr = unwrapExpression(node.getCondition());
|
|
567
|
+
const condBoxNode = (Node.isIdentifier(condExpr) ? maybeBoxNode(condExpr, [], ctx) : safeEvaluateNode(condExpr, stack, ctx)) ?? box.unresolvable(condExpr, stack);
|
|
568
|
+
const condValue = isBoxNode(condBoxNode) ? condBoxNode : box.from(condBoxNode, node, stack);
|
|
569
|
+
if (box.isEmptyInitializer(condValue)) return;
|
|
570
|
+
const isFromDefaultBinding = condValue.getStack().some((node) => Node.isBindingElement(node));
|
|
571
|
+
if (box.isUnresolvable(condValue) || box.isConditional(condValue) || isFromDefaultBinding) return cache(maybeResolveConditionalExpression({
|
|
572
|
+
whenTrueExpr: unwrapExpression(node.getWhenTrue()),
|
|
573
|
+
whenFalseExpr: unwrapExpression(node.getWhenFalse()),
|
|
574
|
+
node,
|
|
575
|
+
stack
|
|
576
|
+
}, ctx));
|
|
577
|
+
if (condValue.value) {
|
|
578
|
+
const whenTrueExpr = unwrapExpression(node.getWhenTrue());
|
|
579
|
+
return cache(maybeBoxNode(whenTrueExpr, [...stack], ctx) ?? box.unresolvable(whenTrueExpr, stack));
|
|
580
|
+
}
|
|
581
|
+
return cache(maybeBoxNode(unwrapExpression(node.getWhenFalse()), [...stack], ctx) ?? box.unresolvable(node, stack));
|
|
582
|
+
}
|
|
583
|
+
if (Node.isCallExpression(node)) {
|
|
584
|
+
if (ctx.tokens) {
|
|
585
|
+
const expr = node.getExpression();
|
|
586
|
+
let fnName = "";
|
|
587
|
+
let isVarMethod = false;
|
|
588
|
+
if (Node.isIdentifier(expr)) fnName = expr.getText();
|
|
589
|
+
else if (Node.isPropertyAccessExpression(expr)) {
|
|
590
|
+
const exprName = expr.getExpression();
|
|
591
|
+
const propertyName = expr.getName();
|
|
592
|
+
if (Node.isIdentifier(exprName)) {
|
|
593
|
+
fnName = exprName.getText();
|
|
594
|
+
isVarMethod = propertyName === "var";
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (ctx.tokens.isTokenFn ? ctx.tokens.isTokenFn(fnName) : fnName === "token") {
|
|
598
|
+
const args = node.getArguments();
|
|
599
|
+
const tokenPathArg = args[0];
|
|
600
|
+
if (tokenPathArg && Node.isStringLiteral(tokenPathArg)) {
|
|
601
|
+
const tokenPath = tokenPathArg.getLiteralValue();
|
|
602
|
+
const fallbackArg = args[1];
|
|
603
|
+
const fallbackValue = fallbackArg && Node.isStringLiteral(fallbackArg) ? fallbackArg.getLiteralValue() : void 0;
|
|
604
|
+
const resolvedValue = isVarMethod ? ctx.tokens.view.getVar(tokenPath, fallbackValue) : ctx.tokens.view.get(tokenPath, fallbackValue);
|
|
605
|
+
if (resolvedValue) return cache(box.literal(resolvedValue, node, stack));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const value = safeEvaluateNode(node, stack, ctx);
|
|
610
|
+
if (!value) return;
|
|
611
|
+
return cache(box.from(value, node, stack));
|
|
612
|
+
}
|
|
613
|
+
if (Node.isBinaryExpression(node)) {
|
|
614
|
+
const operatorKind = node.getOperatorToken().getKind();
|
|
615
|
+
if (isPlusSyntax(operatorKind)) {
|
|
616
|
+
const value = tryComputingPlusTokenBinaryExpressionToString(node, stack, ctx) ?? safeEvaluateNode(node, stack, ctx);
|
|
617
|
+
if (!value) return;
|
|
618
|
+
return cache(box.from(value, node, stack));
|
|
619
|
+
}
|
|
620
|
+
if (isLogicalSyntax(operatorKind)) return cache(maybeResolveConditionalExpression({
|
|
621
|
+
whenTrueExpr: unwrapExpression(node.getLeft()),
|
|
622
|
+
whenFalseExpr: unwrapExpression(node.getRight()),
|
|
623
|
+
node,
|
|
624
|
+
stack,
|
|
625
|
+
canReturnWhenTrue: canReturnWhenTrueInLogicalExpression(operatorKind)
|
|
626
|
+
}, ctx));
|
|
627
|
+
if (isOperationSyntax(operatorKind)) return cache(box.literal(safeEvaluateNode(node, stack, ctx), node, stack));
|
|
628
|
+
}
|
|
651
629
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
return boxNode;
|
|
656
|
-
}
|
|
630
|
+
const onlyStringLiteral = (boxNode) => {
|
|
631
|
+
if (!boxNode) return;
|
|
632
|
+
if (isBoxNode(boxNode) && box.isLiteral(boxNode) && typeof boxNode.value === "string") return boxNode;
|
|
657
633
|
};
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
return boxNode;
|
|
662
|
-
}
|
|
634
|
+
const onlyNumberLiteral = (boxNode) => {
|
|
635
|
+
if (!boxNode) return;
|
|
636
|
+
if (isBoxNode(boxNode) && box.isLiteral(boxNode) && typeof boxNode.value === "number") return boxNode;
|
|
663
637
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
638
|
+
const maybeStringLiteral = (node, stack, ctx) => onlyStringLiteral(maybeBoxNode(node, stack, ctx));
|
|
639
|
+
const maybePropName = (node, stack, ctx) => {
|
|
640
|
+
const boxed = maybeBoxNode(node, stack, ctx);
|
|
641
|
+
const strBox = onlyStringLiteral(boxed);
|
|
642
|
+
if (strBox) return strBox;
|
|
643
|
+
const numberBox = onlyNumberLiteral(boxed);
|
|
644
|
+
if (numberBox) return numberBox;
|
|
671
645
|
};
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (Node5.isBinaryExpression(node) && node.getOperatorToken().getKind() === ts2.SyntaxKind.AmpersandAmpersandToken && whenTrueValue && whenFalseValue && box.isLiteral(whenTrueValue) && whenTrueValue.value === true) {
|
|
685
|
-
return whenFalseValue;
|
|
686
|
-
}
|
|
687
|
-
if (!whenTrueValue && !whenFalseValue) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
if (whenTrueValue && !whenFalseValue) {
|
|
691
|
-
return whenTrueValue;
|
|
692
|
-
}
|
|
693
|
-
if (!whenTrueValue && whenFalseValue) {
|
|
694
|
-
return whenFalseValue;
|
|
695
|
-
}
|
|
696
|
-
const whenTrue = whenTrueValue;
|
|
697
|
-
const whenFalse = whenFalseValue;
|
|
698
|
-
if (box.isLiteral(whenTrue) && box.isLiteral(whenFalse) && whenTrue.value === whenFalse.value) {
|
|
699
|
-
return whenTrue;
|
|
700
|
-
}
|
|
701
|
-
return box.conditional(whenTrue, whenFalse, node, stack);
|
|
646
|
+
const maybeResolveConditionalExpression = ({ whenTrueExpr, whenFalseExpr, node, stack, canReturnWhenTrue }, ctx) => {
|
|
647
|
+
const whenTrueValue = maybeBoxNode(whenTrueExpr, stack, ctx);
|
|
648
|
+
const whenFalseValue = maybeBoxNode(whenFalseExpr, stack, ctx);
|
|
649
|
+
if (canReturnWhenTrue && whenTrueValue && !box.isUnresolvable(whenTrueValue)) return whenTrueValue;
|
|
650
|
+
if (Node.isBinaryExpression(node) && node.getOperatorToken().getKind() === ts.SyntaxKind.AmpersandAmpersandToken && whenTrueValue && whenFalseValue && box.isLiteral(whenTrueValue) && whenTrueValue.value === true) return whenFalseValue;
|
|
651
|
+
if (!whenTrueValue && !whenFalseValue) return;
|
|
652
|
+
if (whenTrueValue && !whenFalseValue) return whenTrueValue;
|
|
653
|
+
if (!whenTrueValue && whenFalseValue) return whenFalseValue;
|
|
654
|
+
const whenTrue = whenTrueValue;
|
|
655
|
+
const whenFalse = whenFalseValue;
|
|
656
|
+
if (box.isLiteral(whenTrue) && box.isLiteral(whenFalse) && whenTrue.value === whenFalse.value) return whenTrue;
|
|
657
|
+
return box.conditional(whenTrue, whenFalse, node, stack);
|
|
702
658
|
};
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
659
|
+
const findProperty = (node, propName, _stack, ctx) => {
|
|
660
|
+
const stack = [..._stack];
|
|
661
|
+
if (Node.isPropertyAssignment(node)) {
|
|
662
|
+
const name = node.getNameNode();
|
|
663
|
+
if (Node.isIdentifier(name) && name.getText() === propName) {
|
|
664
|
+
stack.push(name);
|
|
665
|
+
return node;
|
|
666
|
+
}
|
|
667
|
+
if (Node.isStringLiteral(name) && name.getLiteralText() === propName) {
|
|
668
|
+
stack.push(name);
|
|
669
|
+
return name.getLiteralText();
|
|
670
|
+
}
|
|
671
|
+
if (Node.isComputedPropertyName(name)) {
|
|
672
|
+
const expression = unwrapExpression(name.getExpression());
|
|
673
|
+
const computedPropNameBox = maybePropName(expression, stack, ctx);
|
|
674
|
+
if (!computedPropNameBox) return;
|
|
675
|
+
if (String(computedPropNameBox.value) === propName) {
|
|
676
|
+
stack.push(name, expression);
|
|
677
|
+
return node;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (Node.isShorthandPropertyAssignment(node)) {
|
|
682
|
+
const name = node.getNameNode();
|
|
683
|
+
if (Node.isIdentifier(name) && name.getText() === propName) {
|
|
684
|
+
stack.push(name);
|
|
685
|
+
return node;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
732
688
|
};
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
if (accessList.length > 0) {
|
|
756
|
-
return maybePropIdentifierValue(identifier, accessList, stack, ctx);
|
|
757
|
-
}
|
|
758
|
-
const maybePropValue = maybeBoxNode(identifier, stack, ctx);
|
|
759
|
-
if (maybePropValue) {
|
|
760
|
-
return maybePropValue;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
689
|
+
const getObjectLiteralPropValue = (initializer, accessList, _stack, ctx) => {
|
|
690
|
+
const stack = [..._stack];
|
|
691
|
+
const propName = accessList.pop();
|
|
692
|
+
const property = initializer.getProperty(propName) ?? initializer.getProperties().find((p) => findProperty(p, propName, stack, ctx));
|
|
693
|
+
if (!property) return;
|
|
694
|
+
stack.push(property);
|
|
695
|
+
if (Node.isPropertyAssignment(property)) {
|
|
696
|
+
const propInit = property.getInitializer();
|
|
697
|
+
if (!propInit) return;
|
|
698
|
+
if (Node.isObjectLiteralExpression(propInit)) {
|
|
699
|
+
if (accessList.length > 0) return getObjectLiteralPropValue(propInit, accessList, stack, ctx);
|
|
700
|
+
return maybeBoxNode(propInit, stack, ctx);
|
|
701
|
+
}
|
|
702
|
+
const maybePropValue = maybeBoxNode(propInit, stack, ctx);
|
|
703
|
+
if (maybePropValue) return maybePropValue;
|
|
704
|
+
}
|
|
705
|
+
if (Node.isShorthandPropertyAssignment(property)) {
|
|
706
|
+
const identifier = property.getNameNode();
|
|
707
|
+
if (accessList.length > 0) return maybePropIdentifierValue(identifier, accessList, stack, ctx);
|
|
708
|
+
const maybePropValue = maybeBoxNode(identifier, stack, ctx);
|
|
709
|
+
if (maybePropValue) return maybePropValue;
|
|
710
|
+
}
|
|
763
711
|
};
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (tailValues.every(isNotNullish)) {
|
|
777
|
-
return headValue.value + tailValues.join("");
|
|
778
|
-
}
|
|
712
|
+
const maybeTemplateStringValue = (template, stack, ctx) => {
|
|
713
|
+
const head = template.getHead();
|
|
714
|
+
const tail = template.getTemplateSpans();
|
|
715
|
+
const headValue = maybeStringLiteral(head, stack, ctx);
|
|
716
|
+
if (!headValue) return;
|
|
717
|
+
const tailValues = tail.map((t) => {
|
|
718
|
+
const propBox = maybePropName(t.getExpression(), stack, ctx);
|
|
719
|
+
if (!propBox) return;
|
|
720
|
+
const literal = t.getLiteral();
|
|
721
|
+
return propBox.value + literal.getLiteralText();
|
|
722
|
+
});
|
|
723
|
+
if (tailValues.every(isNotNullish)) return headValue.value + tailValues.join("");
|
|
779
724
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
725
|
+
const maybeBindingElementValue = (def, stack, propName, ctx) => {
|
|
726
|
+
const parent = def.getParent();
|
|
727
|
+
if (!parent) return;
|
|
728
|
+
const grandParent = parent.getParent();
|
|
729
|
+
if (!grandParent) return;
|
|
730
|
+
if (Node.isArrayBindingPattern(parent)) {
|
|
731
|
+
const index = parent.getChildIndex();
|
|
732
|
+
if (Number.isNaN(index)) return;
|
|
733
|
+
if (Node.isVariableDeclaration(grandParent)) {
|
|
734
|
+
const init = grandParent.getInitializer();
|
|
735
|
+
if (!init) return;
|
|
736
|
+
const initializer = unwrapExpression(init);
|
|
737
|
+
if (!Node.isArrayLiteralExpression(initializer)) return;
|
|
738
|
+
const element = initializer.getElements()[index + 1];
|
|
739
|
+
if (!element) return;
|
|
740
|
+
const innerStack = [
|
|
741
|
+
...stack,
|
|
742
|
+
initializer,
|
|
743
|
+
element
|
|
744
|
+
];
|
|
745
|
+
const maybeObject = maybeBoxNode(element, innerStack, ctx);
|
|
746
|
+
if (!maybeObject) return;
|
|
747
|
+
if (box.isObject(maybeObject)) {
|
|
748
|
+
const propValue = maybeObject.value[propName];
|
|
749
|
+
return box.from(propValue, element, innerStack);
|
|
750
|
+
}
|
|
751
|
+
if (!box.isMap(maybeObject)) return maybeObject;
|
|
752
|
+
const propValue = maybeObject.value.get(propName);
|
|
753
|
+
if (!propValue) return;
|
|
754
|
+
return propValue;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (Node.isObjectBindingPattern(parent)) {}
|
|
812
758
|
};
|
|
813
759
|
function maybePropDefinitionValue(def, accessList, _stack, ctx) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
const innerStack = [..._stack, initializer];
|
|
875
|
-
const maybeValue = maybeBoxNode(initializer, innerStack, ctx);
|
|
876
|
-
if (maybeValue) return maybeValue;
|
|
877
|
-
}
|
|
760
|
+
const propName = accessList.at(-1);
|
|
761
|
+
if (Node.isVariableDeclaration(def)) {
|
|
762
|
+
const init = def.getInitializer();
|
|
763
|
+
if (!init) {
|
|
764
|
+
const type = def.getTypeNode();
|
|
765
|
+
if (!type) return;
|
|
766
|
+
if (Node.isTypeLiteral(type)) {
|
|
767
|
+
if (accessList.length > 0) {
|
|
768
|
+
const stack = [..._stack];
|
|
769
|
+
stack.push(type);
|
|
770
|
+
let propName = accessList.pop();
|
|
771
|
+
let typeProp = type.getProperty(propName);
|
|
772
|
+
let typeLiteral = typeProp?.getTypeNode();
|
|
773
|
+
while (typeProp && accessList.length > 0 && typeLiteral && Node.isTypeLiteral(typeLiteral)) {
|
|
774
|
+
stack.push(typeProp, typeLiteral);
|
|
775
|
+
propName = accessList.pop();
|
|
776
|
+
typeProp = typeLiteral.getProperty(propName);
|
|
777
|
+
typeLiteral = typeProp?.getTypeNode();
|
|
778
|
+
}
|
|
779
|
+
if (!typeLiteral) return;
|
|
780
|
+
const typeValue = getTypeNodeValue(typeLiteral, stack, ctx);
|
|
781
|
+
return box.from(typeValue, typeLiteral, stack);
|
|
782
|
+
}
|
|
783
|
+
const propValue = getTypeLiteralNodePropValue(type, propName, _stack, ctx);
|
|
784
|
+
_stack.push(type);
|
|
785
|
+
return box.from(propValue, type, _stack);
|
|
786
|
+
}
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const initializer = unwrapExpression(init);
|
|
790
|
+
if (Node.isObjectLiteralExpression(initializer)) {
|
|
791
|
+
const propValue = getObjectLiteralPropValue(initializer, accessList, _stack, ctx);
|
|
792
|
+
if (!propValue) return;
|
|
793
|
+
_stack.push(initializer);
|
|
794
|
+
return propValue;
|
|
795
|
+
}
|
|
796
|
+
if (Node.isArrayLiteralExpression(initializer)) {
|
|
797
|
+
const index = Number(propName);
|
|
798
|
+
if (Number.isNaN(index)) return;
|
|
799
|
+
const element = initializer.getElements()[index];
|
|
800
|
+
if (!element) return;
|
|
801
|
+
_stack.push(initializer);
|
|
802
|
+
const boxed = maybeBoxNode(element, _stack, ctx);
|
|
803
|
+
if (boxed && isBoxNode(boxed) && box.isLiteral(boxed)) return boxed;
|
|
804
|
+
}
|
|
805
|
+
const maybeValue = maybeBoxNode(initializer, [..._stack, initializer], ctx);
|
|
806
|
+
if (maybeValue) return maybeValue;
|
|
807
|
+
}
|
|
808
|
+
if (Node.isBindingElement(def)) {
|
|
809
|
+
const value = maybeBindingElementValue(def, _stack, propName, ctx);
|
|
810
|
+
if (value) return value;
|
|
811
|
+
}
|
|
812
|
+
if (Node.isEnumDeclaration(def)) {
|
|
813
|
+
const member = def.getMember(propName);
|
|
814
|
+
if (!member) return;
|
|
815
|
+
const initializer = member.getInitializer();
|
|
816
|
+
if (!initializer) return;
|
|
817
|
+
const maybeValue = maybeBoxNode(initializer, [..._stack, initializer], ctx);
|
|
818
|
+
if (maybeValue) return maybeValue;
|
|
819
|
+
}
|
|
878
820
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (maybeValue) return maybeValue;
|
|
886
|
-
return box.unresolvable(identifier, _stack);
|
|
821
|
+
const maybePropIdentifierValue = (identifier, accessList, _stack, ctx) => {
|
|
822
|
+
const maybeValueDeclaration = findIdentifierValueDeclaration(identifier, _stack, ctx);
|
|
823
|
+
if (!maybeValueDeclaration) return box.unresolvable(identifier, _stack);
|
|
824
|
+
const maybeValue = maybePropDefinitionValue(maybeValueDeclaration, accessList, _stack, ctx);
|
|
825
|
+
if (maybeValue) return maybeValue;
|
|
826
|
+
return box.unresolvable(identifier, _stack);
|
|
887
827
|
};
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const map = typeLiteralCache.get(type);
|
|
911
|
-
map.set(propName, propValue);
|
|
912
|
-
return propValue;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
typeLiteralCache.set(type, null);
|
|
828
|
+
const typeLiteralCache = /* @__PURE__ */ new WeakMap();
|
|
829
|
+
const getTypeLiteralNodePropValue = (type, propName, stack, ctx) => {
|
|
830
|
+
if (typeLiteralCache.has(type)) {
|
|
831
|
+
const map = typeLiteralCache.get(type);
|
|
832
|
+
if (map === null) return;
|
|
833
|
+
if (map?.has(propName)) return map.get(propName);
|
|
834
|
+
}
|
|
835
|
+
const prop = type.getMembers().find((member) => Node.isPropertySignature(member) && member.getName() === propName);
|
|
836
|
+
if (Node.isPropertySignature(prop) && prop.isReadonly()) {
|
|
837
|
+
const propType = prop.getTypeNode();
|
|
838
|
+
if (!propType) {
|
|
839
|
+
typeLiteralCache.set(type, null);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const propValue = getTypeNodeValue(propType, stack, ctx);
|
|
843
|
+
if (isNotNullish(propValue)) {
|
|
844
|
+
if (!typeLiteralCache.has(type)) typeLiteralCache.set(type, /* @__PURE__ */ new Map());
|
|
845
|
+
typeLiteralCache.get(type).set(propName, propValue);
|
|
846
|
+
return propValue;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
typeLiteralCache.set(type, null);
|
|
916
850
|
};
|
|
917
851
|
function getNameLiteral(wrapper) {
|
|
918
|
-
|
|
919
|
-
|
|
852
|
+
if (Node.isStringLiteral(wrapper)) return wrapper.getLiteralText();
|
|
853
|
+
return wrapper.getText();
|
|
920
854
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
return result;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
typeNodeCache.set(type, void 0);
|
|
855
|
+
const typeNodeCache = /* @__PURE__ */ new WeakMap();
|
|
856
|
+
const getTypeNodeValue = (type, stack, ctx) => {
|
|
857
|
+
if (typeNodeCache.has(type)) return typeNodeCache.get(type);
|
|
858
|
+
if (Node.isLiteralTypeNode(type)) {
|
|
859
|
+
const literal = type.getLiteral();
|
|
860
|
+
if (Node.isStringLiteral(literal)) {
|
|
861
|
+
const result = literal.getLiteralText();
|
|
862
|
+
typeNodeCache.set(type, result);
|
|
863
|
+
return result;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
if (Node.isTypeLiteral(type)) {
|
|
867
|
+
const members = type.getMembers();
|
|
868
|
+
if (!members.some((member) => !Node.isPropertySignature(member) || !member.isReadonly())) {
|
|
869
|
+
const entries = members.map((member) => {
|
|
870
|
+
const nameNode = member.getNameNode();
|
|
871
|
+
const nameText = nameNode.getText();
|
|
872
|
+
const name = getNameLiteral(nameNode);
|
|
873
|
+
if (!name) return;
|
|
874
|
+
return [name, getTypeLiteralNodePropValue(type, nameText, stack, ctx)];
|
|
875
|
+
}).filter(isNotNullish);
|
|
876
|
+
const result = Object.fromEntries(entries);
|
|
877
|
+
typeNodeCache.set(type, result);
|
|
878
|
+
return result;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
typeNodeCache.set(type, void 0);
|
|
952
882
|
};
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
const maybeValue = maybeBoxNode(initializer, innerStack, ctx);
|
|
988
|
-
if (maybeValue) return maybeValue;
|
|
989
|
-
}
|
|
883
|
+
const maybeDefinitionValue = (def, stack, ctx) => {
|
|
884
|
+
if (Node.isShorthandPropertyAssignment(def)) {
|
|
885
|
+
const propNameNode = def.getNameNode();
|
|
886
|
+
return maybePropIdentifierValue(propNameNode, [propNameNode.getText()], stack, ctx);
|
|
887
|
+
}
|
|
888
|
+
if (Node.isVariableDeclaration(def)) {
|
|
889
|
+
const init = def.getInitializer();
|
|
890
|
+
if (!init) {
|
|
891
|
+
const type = def.getTypeNode();
|
|
892
|
+
if (!type) return;
|
|
893
|
+
if (Node.isTypeLiteral(type)) {
|
|
894
|
+
stack.push(type);
|
|
895
|
+
const maybeTypeValue = getTypeNodeValue(type, stack, ctx);
|
|
896
|
+
if (isNotNullish(maybeTypeValue)) return box.from(maybeTypeValue, def, stack);
|
|
897
|
+
}
|
|
898
|
+
return box.unresolvable(def, stack);
|
|
899
|
+
}
|
|
900
|
+
const initializer = unwrapExpression(init);
|
|
901
|
+
const maybeValue = maybeBoxNode(initializer, [...stack, initializer], ctx);
|
|
902
|
+
if (maybeValue) return maybeValue;
|
|
903
|
+
}
|
|
904
|
+
if (Node.isBindingElement(def)) {
|
|
905
|
+
const init = def.getInitializer();
|
|
906
|
+
if (!init) {
|
|
907
|
+
const nameNode = def.getPropertyNameNode() ?? def.getNameNode();
|
|
908
|
+
const propName = nameNode.getText();
|
|
909
|
+
const value = maybeBindingElementValue(def, [...stack, nameNode], propName, ctx);
|
|
910
|
+
if (value) return value;
|
|
911
|
+
return box.unresolvable(def, stack);
|
|
912
|
+
}
|
|
913
|
+
const initializer = unwrapExpression(init);
|
|
914
|
+
const maybeValue = maybeBoxNode(initializer, [...stack, initializer], ctx);
|
|
915
|
+
if (maybeValue) return maybeValue;
|
|
916
|
+
}
|
|
990
917
|
};
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
918
|
+
const getExportedVarDeclarationWithName = (varName, sourceFile, stack, ctx) => {
|
|
919
|
+
const maybeVar = sourceFile.getVariableDeclaration(varName);
|
|
920
|
+
if (maybeVar) return maybeVar;
|
|
921
|
+
const exportDeclaration = resolveVarDeclarationFromExportWithName(varName, sourceFile, stack, ctx);
|
|
922
|
+
if (!exportDeclaration) return;
|
|
923
|
+
return exportDeclaration;
|
|
997
924
|
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
const exportedName = namedExport.getNameNode().getText();
|
|
1003
|
-
if (exportedName === name) {
|
|
1004
|
-
return true;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
925
|
+
const hasNamedExportWithName = (name, exportDeclaration) => {
|
|
926
|
+
const namedExports = exportDeclaration.getNamedExports();
|
|
927
|
+
if (namedExports.length === 0) return true;
|
|
928
|
+
for (const namedExport of namedExports) if (namedExport.getNameNode().getText() === name) return true;
|
|
1007
929
|
};
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
930
|
+
/**
|
|
931
|
+
* Faster than declaration.getModuleSpecifierSourceFile()
|
|
932
|
+
*
|
|
933
|
+
* since it does NOT require a call to `initializeTypeChecker`
|
|
934
|
+
* > getModuleSpecifierSourceFile > getSymbol > getTypechecker > createTypeChecker > initializeTypeChecker
|
|
935
|
+
*
|
|
936
|
+
* which costs a minimum of around 90ms (and scales up with the file/project, could be hundreds of ms)
|
|
937
|
+
* @see https://github.com/dsherret/ts-morph/blob/42d811ed9a5177fc678a5bfec4923a2048124fe0/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts#L160
|
|
938
|
+
*/
|
|
939
|
+
const getModuleSpecifierSourceFile = (declaration) => {
|
|
940
|
+
const project = declaration.getProject();
|
|
941
|
+
const moduleName = declaration.getModuleSpecifierValue();
|
|
942
|
+
if (!moduleName) return;
|
|
943
|
+
const containingFile = declaration.getSourceFile().getFilePath();
|
|
944
|
+
const resolved = ts.resolveModuleName(moduleName, containingFile, project.getCompilerOptions(), project.getModuleResolutionHost());
|
|
945
|
+
if (!resolved.resolvedModule) return;
|
|
946
|
+
return project.addSourceFileAtPath(resolved.resolvedModule.resolvedFileName);
|
|
1022
947
|
};
|
|
1023
948
|
function resolveVarDeclarationFromExportWithName(symbolName, sourceFile, stack, ctx) {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
949
|
+
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
950
|
+
const exportStack = [exportDeclaration];
|
|
951
|
+
if (!hasNamedExportWithName(symbolName, exportDeclaration)) continue;
|
|
952
|
+
const maybeFile = getModuleSpecifierSourceFile(exportDeclaration);
|
|
953
|
+
if (!maybeFile) continue;
|
|
954
|
+
exportStack.push(maybeFile);
|
|
955
|
+
const maybeVar = getExportedVarDeclarationWithName(symbolName, maybeFile, stack, ctx);
|
|
956
|
+
if (maybeVar) {
|
|
957
|
+
stack.push(...exportStack.concat(maybeVar));
|
|
958
|
+
return maybeVar;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
1036
961
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (maybeValue) return maybeValue;
|
|
1046
|
-
return box.unresolvable(identifier, stack);
|
|
962
|
+
const maybeIdentifierValue = (identifier, _stack, ctx) => {
|
|
963
|
+
const valueDeclaration = findIdentifierValueDeclaration(identifier, _stack, ctx);
|
|
964
|
+
if (!valueDeclaration) return box.unresolvable(identifier, _stack);
|
|
965
|
+
const declaration = unwrapExpression(valueDeclaration);
|
|
966
|
+
const stack = [..._stack];
|
|
967
|
+
const maybeValue = maybeDefinitionValue(declaration, stack, ctx);
|
|
968
|
+
if (maybeValue) return maybeValue;
|
|
969
|
+
return box.unresolvable(identifier, stack);
|
|
1047
970
|
};
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
return box.literal(String(leftValue.value) + String(rightValue.value), node, stack);
|
|
1056
|
-
}
|
|
971
|
+
const tryComputingPlusTokenBinaryExpressionToString = (node, stack, ctx) => {
|
|
972
|
+
const left = unwrapExpression(node.getLeft());
|
|
973
|
+
const right = unwrapExpression(node.getRight());
|
|
974
|
+
const leftValue = maybePropName(left, stack, ctx);
|
|
975
|
+
const rightValue = maybePropName(right, stack, ctx);
|
|
976
|
+
if (!leftValue || !rightValue) return;
|
|
977
|
+
if (isNotNullish(leftValue.value) && isNotNullish(rightValue.value)) return box.literal(String(leftValue.value) + String(rightValue.value), node, stack);
|
|
1057
978
|
};
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
if (Node5.isIdentifier(elementAccessed)) {
|
|
1145
|
-
const whenTrueResolved = whenTrueValue && isNotNullish(whenTrueValue.value) ? maybePropIdentifierValue(elementAccessed, [whenTrueValue.value.toString()], stack, ctx) : void 0;
|
|
1146
|
-
const whenFalseResolved = whenFalseValue && isNotNullish(whenFalseValue.value) ? maybePropIdentifierValue(elementAccessed, [whenFalseValue.value.toString()], stack, ctx) : void 0;
|
|
1147
|
-
if (!whenTrueResolved && !whenFalseResolved) {
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
if (whenTrueResolved && !whenFalseResolved) {
|
|
1151
|
-
return whenTrueResolved;
|
|
1152
|
-
}
|
|
1153
|
-
if (!whenTrueResolved && whenFalseResolved) {
|
|
1154
|
-
return whenFalseResolved;
|
|
1155
|
-
}
|
|
1156
|
-
return box.conditional(whenTrueResolved, whenFalseResolved, arg, stack);
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
979
|
+
const getElementAccessedExpressionValue = (expression, _stack, ctx) => {
|
|
980
|
+
const elementAccessed = unwrapExpression(expression.getExpression());
|
|
981
|
+
const argExpr = expression.getArgumentExpression();
|
|
982
|
+
if (!argExpr) return;
|
|
983
|
+
const arg = unwrapExpression(argExpr);
|
|
984
|
+
const stack = [
|
|
985
|
+
..._stack,
|
|
986
|
+
elementAccessed,
|
|
987
|
+
arg
|
|
988
|
+
];
|
|
989
|
+
const argLiteral = maybePropName(arg, stack, ctx);
|
|
990
|
+
if (Node.isIdentifier(elementAccessed) && argLiteral) {
|
|
991
|
+
if (!isNotNullish(argLiteral.value)) return;
|
|
992
|
+
return maybePropIdentifierValue(elementAccessed, [argLiteral.value.toString()], stack, ctx);
|
|
993
|
+
}
|
|
994
|
+
if (Node.isBinaryExpression(arg)) {
|
|
995
|
+
if (arg.getOperatorToken().getKind() !== ts.SyntaxKind.PlusToken) return;
|
|
996
|
+
const propName = tryComputingPlusTokenBinaryExpressionToString(arg, stack, ctx) ?? maybePropName(arg, stack, ctx);
|
|
997
|
+
if (propName && Node.isIdentifier(elementAccessed)) {
|
|
998
|
+
if (!isNotNullish(propName.value)) return;
|
|
999
|
+
return maybePropIdentifierValue(elementAccessed, [propName.value.toString()], stack, ctx);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (Node.isTemplateExpression(arg)) {
|
|
1003
|
+
const propName = maybeTemplateStringValue(arg, stack, ctx);
|
|
1004
|
+
if (propName && Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, [propName], stack, ctx);
|
|
1005
|
+
}
|
|
1006
|
+
if (Node.isObjectLiteralExpression(elementAccessed) && argLiteral) {
|
|
1007
|
+
if (!isNotNullish(argLiteral.value)) return;
|
|
1008
|
+
return getObjectLiteralPropValue(elementAccessed, [argLiteral.value.toString()], stack, ctx);
|
|
1009
|
+
}
|
|
1010
|
+
if (Node.isPropertyAccessExpression(arg)) return getPropertyAccessedExpressionValue(arg, [], stack, ctx);
|
|
1011
|
+
if (Node.isPropertyAccessExpression(elementAccessed) && argLiteral && isNotNullish(argLiteral.value)) {
|
|
1012
|
+
const propRefValue = getPropertyAccessedExpressionValue(elementAccessed, [], stack, ctx);
|
|
1013
|
+
if (!propRefValue) return box.unresolvable(elementAccessed, stack);
|
|
1014
|
+
const propName = argLiteral.value.toString();
|
|
1015
|
+
if (box.isObject(propRefValue)) {
|
|
1016
|
+
const propValue = propRefValue.value[propName];
|
|
1017
|
+
return box.from(propValue, arg, stack);
|
|
1018
|
+
}
|
|
1019
|
+
if (box.isMap(propRefValue)) {
|
|
1020
|
+
const propValue = propRefValue.value.get(propName);
|
|
1021
|
+
return box.from(propValue, arg, stack);
|
|
1022
|
+
}
|
|
1023
|
+
if (box.isArray(propRefValue)) {
|
|
1024
|
+
const propValue = propRefValue.value[Number(propName)];
|
|
1025
|
+
return box.from(propValue, arg, stack);
|
|
1026
|
+
}
|
|
1027
|
+
return box.unresolvable(elementAccessed, stack);
|
|
1028
|
+
}
|
|
1029
|
+
if (Node.isIdentifier(elementAccessed) && Node.isElementAccessExpression(arg)) {
|
|
1030
|
+
const propName = getElementAccessedExpressionValue(arg, stack, ctx);
|
|
1031
|
+
if (typeof propName === "string" && isNotNullish(propName)) return maybePropIdentifierValue(elementAccessed, [propName], stack, ctx);
|
|
1032
|
+
}
|
|
1033
|
+
if (Node.isElementAccessExpression(elementAccessed) && argLiteral && isNotNullish(argLiteral.value)) {
|
|
1034
|
+
const identifier = getElementAccessedExpressionValue(elementAccessed, stack, ctx);
|
|
1035
|
+
if (isObject(identifier)) {
|
|
1036
|
+
const argValue = argLiteral.value.toString();
|
|
1037
|
+
if (box.isMap(identifier)) return identifier.value.get(argValue);
|
|
1038
|
+
if (box.isObject(identifier)) {
|
|
1039
|
+
const maybeLiteralValue = identifier.value[argValue];
|
|
1040
|
+
if (!maybeLiteralValue) return;
|
|
1041
|
+
return box.from(maybeLiteralValue, expression, stack);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (Node.isArrayLiteralExpression(elementAccessed) && argLiteral) return getArrayElementValueAtIndex(elementAccessed, Number(argLiteral.value), stack, ctx);
|
|
1046
|
+
if (Node.isConditionalExpression(arg)) {
|
|
1047
|
+
if (ctx.flags?.skipConditions) return box.unresolvable(arg, stack);
|
|
1048
|
+
const propName = maybePropName(arg, stack, ctx);
|
|
1049
|
+
if (isNotNullish(propName) && isNotNullish(propName.value)) {
|
|
1050
|
+
if (Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, [propName.value.toString()], stack, ctx);
|
|
1051
|
+
}
|
|
1052
|
+
const whenTrueExpr = unwrapExpression(arg.getWhenTrue());
|
|
1053
|
+
const whenFalseExpr = unwrapExpression(arg.getWhenFalse());
|
|
1054
|
+
const whenTrueValue = maybePropName(whenTrueExpr, stack, ctx);
|
|
1055
|
+
const whenFalseValue = maybePropName(whenFalseExpr, stack, ctx);
|
|
1056
|
+
if (Node.isIdentifier(elementAccessed)) {
|
|
1057
|
+
const whenTrueResolved = whenTrueValue && isNotNullish(whenTrueValue.value) ? maybePropIdentifierValue(elementAccessed, [whenTrueValue.value.toString()], stack, ctx) : void 0;
|
|
1058
|
+
const whenFalseResolved = whenFalseValue && isNotNullish(whenFalseValue.value) ? maybePropIdentifierValue(elementAccessed, [whenFalseValue.value.toString()], stack, ctx) : void 0;
|
|
1059
|
+
if (!whenTrueResolved && !whenFalseResolved) return;
|
|
1060
|
+
if (whenTrueResolved && !whenFalseResolved) return whenTrueResolved;
|
|
1061
|
+
if (!whenTrueResolved && whenFalseResolved) return whenFalseResolved;
|
|
1062
|
+
return box.conditional(whenTrueResolved, whenFalseResolved, arg, stack);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1159
1065
|
};
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
return value;
|
|
1166
|
-
}
|
|
1066
|
+
const getArrayElementValueAtIndex = (array, index, stack, ctx) => {
|
|
1067
|
+
const element = array.getElements()[index];
|
|
1068
|
+
if (!element) return;
|
|
1069
|
+
const value = maybeBoxNode(element, stack, ctx);
|
|
1070
|
+
if (isNotNullish(value)) return value;
|
|
1167
1071
|
};
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
if (box.isMap(leftElementAccessed)) {
|
|
1188
|
-
const propValue = leftElementAccessed.value.get(propName);
|
|
1189
|
-
return box.from(propValue, expression, stack);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1072
|
+
const getPropertyAccessedExpressionValue = (expression, _accessList, stack, ctx) => {
|
|
1073
|
+
const propName = expression.getName();
|
|
1074
|
+
const elementAccessed = unwrapExpression(expression.getExpression());
|
|
1075
|
+
const accessList = _accessList.concat(propName);
|
|
1076
|
+
stack.push(elementAccessed);
|
|
1077
|
+
if (Node.isIdentifier(elementAccessed)) return maybePropIdentifierValue(elementAccessed, accessList, stack, ctx);
|
|
1078
|
+
if (Node.isPropertyAccessExpression(elementAccessed)) return getPropertyAccessedExpressionValue(elementAccessed, accessList, stack, ctx);
|
|
1079
|
+
if (Node.isElementAccessExpression(elementAccessed)) {
|
|
1080
|
+
const leftElementAccessed = getElementAccessedExpressionValue(elementAccessed, stack, ctx);
|
|
1081
|
+
if (!leftElementAccessed) return;
|
|
1082
|
+
if (box.isObject(leftElementAccessed)) {
|
|
1083
|
+
const propValue = leftElementAccessed.value[propName];
|
|
1084
|
+
return box.from(propValue, expression, stack);
|
|
1085
|
+
}
|
|
1086
|
+
if (box.isMap(leftElementAccessed)) {
|
|
1087
|
+
const propValue = leftElementAccessed.value.get(propName);
|
|
1088
|
+
return box.from(propValue, expression, stack);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1192
1091
|
};
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
node,
|
|
1212
|
-
[]
|
|
1213
|
-
);
|
|
1092
|
+
//#endregion
|
|
1093
|
+
//#region src/call-expression.ts
|
|
1094
|
+
const trueFn = () => true;
|
|
1095
|
+
const extractCallExpressionArguments = (node, ctx, matchProp = trueFn, matchArg = trueFn) => {
|
|
1096
|
+
const fnArguments = node.getArguments();
|
|
1097
|
+
const fnName = node.getExpression().getText();
|
|
1098
|
+
if (fnArguments.length === 0) return box.array([], node, []);
|
|
1099
|
+
return box.array(fnArguments.map((argument, index) => {
|
|
1100
|
+
const argNode = unwrapExpression(argument);
|
|
1101
|
+
const stack = [node, argNode];
|
|
1102
|
+
if (matchArg({
|
|
1103
|
+
fnNode: node,
|
|
1104
|
+
fnName,
|
|
1105
|
+
argNode,
|
|
1106
|
+
index
|
|
1107
|
+
})) return maybeBoxNode(argNode, stack, ctx, matchProp) ?? box.unresolvable(argNode, stack);
|
|
1108
|
+
return box.unresolvable(argNode, stack);
|
|
1109
|
+
}), node, []);
|
|
1214
1110
|
};
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/compiled-jsx.ts
|
|
1113
|
+
const reactRuntimeMods = new Set(["react/jsx-runtime", "react/jsx-dev-runtime"]);
|
|
1114
|
+
const preactRuntimeMods = new Set(["preact/jsx-runtime", "preact/jsx-dev-runtime"]);
|
|
1115
|
+
const classicReactMods = new Set(["react"]);
|
|
1116
|
+
const classicPreactMods = new Set(["preact"]);
|
|
1117
|
+
const solidMods = new Set(["solid-js", "solid-js/web"]);
|
|
1118
|
+
const vueMods = new Set(["vue"]);
|
|
1119
|
+
const resolveBundledHelperImport = (name, node) => {
|
|
1120
|
+
if (!node) return;
|
|
1121
|
+
const text = node.getText();
|
|
1122
|
+
const isVueBundledCreateVNode = text.includes("type, props = null, children = null") && (text.includes("createBaseVNode") && text.includes("guardReactiveProps") || text.includes("patchFlag = -2") && text.includes("__vccOpts") && text.includes("shapeFlag"));
|
|
1123
|
+
const isVueBundledCreateVNodeTransform = name.includes("createVNodeWithArgsTransform") && text.includes("...args") && text.includes("_createVNode");
|
|
1124
|
+
const isVueBundledMergeProps = text.includes("const ret = {}") && text.includes("toMerge = args[i]") && text.includes("ret[key] = toMerge[key]") && text.includes("key !== \"\"");
|
|
1125
|
+
const isSolidBundledCreateComponent = name === "createComponent" && text.includes("Comp(props || {})") && text.includes("untrack");
|
|
1126
|
+
const isSolidBundledMergeProps = name === "mergeProps" && text.includes("...sources") && text.includes("resolveSource") && text.includes("sources.length");
|
|
1127
|
+
const isPreactBundledJsxHelper = text.includes("type:") && text.includes("props:") && text.includes("__v:") && text.includes("defaultProps") && text.includes(".vnode");
|
|
1128
|
+
if (isVueBundledCreateVNode || isVueBundledCreateVNodeTransform) return {
|
|
1129
|
+
importedName: "createVNode",
|
|
1130
|
+
mod: "vue"
|
|
1131
|
+
};
|
|
1132
|
+
if (isVueBundledMergeProps) return {
|
|
1133
|
+
importedName: "mergeProps",
|
|
1134
|
+
mod: "vue"
|
|
1135
|
+
};
|
|
1136
|
+
if (isSolidBundledCreateComponent) return {
|
|
1137
|
+
importedName: "createComponent",
|
|
1138
|
+
mod: "solid-js/web"
|
|
1139
|
+
};
|
|
1140
|
+
if (isSolidBundledMergeProps) return {
|
|
1141
|
+
importedName: "mergeProps",
|
|
1142
|
+
mod: "solid-js"
|
|
1143
|
+
};
|
|
1144
|
+
if (isPreactBundledJsxHelper) return {
|
|
1145
|
+
importedName: "jsx",
|
|
1146
|
+
mod: "preact/jsx-runtime"
|
|
1147
|
+
};
|
|
1252
1148
|
};
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
sourceFile.getDescendantsOfKind(SyntaxKind.FunctionDeclaration).forEach((declaration) => {
|
|
1351
|
-
const bundledImport = resolveBundledHelperImport(declaration.getName() ?? "", declaration);
|
|
1352
|
-
if (!bundledImport || !declaration.getName()) return;
|
|
1353
|
-
bundledNamed.set(declaration.getName(), bundledImport);
|
|
1354
|
-
});
|
|
1355
|
-
const resolveBundledAliasImport = (node) => {
|
|
1356
|
-
if (!node) return;
|
|
1357
|
-
const expression = unwrapExpression(node);
|
|
1358
|
-
if (MorphNode.isIdentifier(expression)) {
|
|
1359
|
-
return bundledNamed.get(expression.getText());
|
|
1360
|
-
}
|
|
1361
|
-
if (MorphNode.isConditionalExpression(expression)) {
|
|
1362
|
-
return resolveBundledAliasImport(expression.getWhenTrue()) ?? resolveBundledAliasImport(expression.getWhenFalse());
|
|
1363
|
-
}
|
|
1364
|
-
if (MorphNode.isBinaryExpression(expression) && expression.getOperatorToken().getKind() === SyntaxKind.CommaToken) {
|
|
1365
|
-
return resolveBundledAliasImport(expression.getRight());
|
|
1366
|
-
}
|
|
1367
|
-
};
|
|
1368
|
-
sourceFile.getVariableDeclarations().forEach((declaration) => {
|
|
1369
|
-
if (!MorphNode.isIdentifier(declaration.getNameNode())) return;
|
|
1370
|
-
if (bundledNamed.has(declaration.getName())) return;
|
|
1371
|
-
const bundledAlias = resolveBundledAliasImport(declaration.getInitializer());
|
|
1372
|
-
if (!bundledAlias) return;
|
|
1373
|
-
bundledNamed.set(declaration.getName(), bundledAlias);
|
|
1374
|
-
});
|
|
1375
|
-
return { named, default: defaultImports, namespace, bundledNamed, bundledNamespace };
|
|
1149
|
+
const collectImports = (sourceFile) => {
|
|
1150
|
+
const named = /* @__PURE__ */ new Map();
|
|
1151
|
+
const defaultImports = /* @__PURE__ */ new Map();
|
|
1152
|
+
const namespace = /* @__PURE__ */ new Map();
|
|
1153
|
+
const bundledNamed = /* @__PURE__ */ new Map();
|
|
1154
|
+
const bundledNamespace = /* @__PURE__ */ new Map();
|
|
1155
|
+
const getBundledRuntimeModFromName = (name) => {
|
|
1156
|
+
const normalized = name.replace(/[^a-z]/gi, "").toLowerCase();
|
|
1157
|
+
if (normalized.includes("jsxdevruntime")) return "react/jsx-dev-runtime";
|
|
1158
|
+
if (normalized.includes("jsxruntime")) return "react/jsx-runtime";
|
|
1159
|
+
if (normalized === "react" || normalized.endsWith("react")) return "react";
|
|
1160
|
+
};
|
|
1161
|
+
const parcelRuntimeModuleIds = /* @__PURE__ */ new Map();
|
|
1162
|
+
const resolveBundledNamespaceMod = (node) => {
|
|
1163
|
+
if (!node) return;
|
|
1164
|
+
const expression = unwrapExpression(node);
|
|
1165
|
+
if (Node.isCallExpression(expression)) {
|
|
1166
|
+
const callee = unwrapExpression(expression.getExpression());
|
|
1167
|
+
if (!Node.isIdentifier(callee)) return;
|
|
1168
|
+
const calleeName = callee.getText();
|
|
1169
|
+
if (/requirejsxdevruntime/i.test(calleeName)) return "react/jsx-dev-runtime";
|
|
1170
|
+
if (/requirejsxruntime/i.test(calleeName)) return "react/jsx-runtime";
|
|
1171
|
+
if (/requirereact/i.test(calleeName)) return "react";
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).forEach((callExpression) => {
|
|
1175
|
+
const callee = unwrapExpression(callExpression.getExpression());
|
|
1176
|
+
if (!Node.isIdentifier(callee) || callee.getText() !== "parcelRegister") return;
|
|
1177
|
+
const [idArg, factoryArg] = callExpression.getArguments();
|
|
1178
|
+
if (!Node.isStringLiteral(idArg)) return;
|
|
1179
|
+
if (!Node.isArrowFunction(factoryArg) && !Node.isFunctionExpression(factoryArg)) return;
|
|
1180
|
+
const factoryText = factoryArg.getBody().getText();
|
|
1181
|
+
if (factoryText.includes("\"Fragment\"") && factoryText.includes("\"jsx\"") && factoryText.includes("\"jsxs\"") && factoryText.includes("module.exports")) parcelRuntimeModuleIds.set(idArg.getLiteralValue(), "react/jsx-runtime");
|
|
1182
|
+
});
|
|
1183
|
+
sourceFile.getImportDeclarations().forEach((declaration) => {
|
|
1184
|
+
const mod = declaration.getModuleSpecifierValue();
|
|
1185
|
+
if (!mod) return;
|
|
1186
|
+
const defaultImport = declaration.getDefaultImport();
|
|
1187
|
+
if (defaultImport) defaultImports.set(defaultImport.getText(), mod);
|
|
1188
|
+
const namespaceImport = declaration.getNamespaceImport();
|
|
1189
|
+
if (namespaceImport) namespace.set(namespaceImport.getText(), mod);
|
|
1190
|
+
declaration.getNamedImports().forEach((specifier) => {
|
|
1191
|
+
const importedName = specifier.getNameNode().getText();
|
|
1192
|
+
const alias = specifier.getAliasNode()?.getText() || importedName;
|
|
1193
|
+
named.set(alias, {
|
|
1194
|
+
importedName,
|
|
1195
|
+
mod
|
|
1196
|
+
});
|
|
1197
|
+
});
|
|
1198
|
+
});
|
|
1199
|
+
sourceFile.getVariableDeclarations().forEach((declaration) => {
|
|
1200
|
+
if (!Node.isIdentifier(declaration.getNameNode())) return;
|
|
1201
|
+
const variableName = declaration.getName();
|
|
1202
|
+
const initializer = declaration.getInitializer();
|
|
1203
|
+
const bundledImport = resolveBundledHelperImport(variableName, initializer);
|
|
1204
|
+
if (bundledImport) bundledNamed.set(variableName, bundledImport);
|
|
1205
|
+
let mod = getBundledRuntimeModFromName(variableName) ?? resolveBundledNamespaceMod(initializer);
|
|
1206
|
+
if (!mod && initializer && Node.isCallExpression(initializer)) {
|
|
1207
|
+
const callee = unwrapExpression(initializer.getExpression());
|
|
1208
|
+
const [firstArg] = initializer.getArguments();
|
|
1209
|
+
if (Node.isIdentifier(callee) && callee.getText() === "parcelRequire" && Node.isStringLiteral(firstArg)) mod = parcelRuntimeModuleIds.get(firstArg.getLiteralValue());
|
|
1210
|
+
}
|
|
1211
|
+
if (!mod && initializer && Node.isObjectLiteralExpression(initializer)) {
|
|
1212
|
+
const propertyNames = new Set(initializer.getProperties().map((property) => {
|
|
1213
|
+
if (Node.isPropertyAssignment(property)) return property.getName();
|
|
1214
|
+
}).filter(Boolean));
|
|
1215
|
+
if (propertyNames.has("jsx") && propertyNames.has("Fragment")) mod = "preact/jsx-runtime";
|
|
1216
|
+
}
|
|
1217
|
+
if (!mod) return;
|
|
1218
|
+
bundledNamespace.set(variableName, mod);
|
|
1219
|
+
});
|
|
1220
|
+
sourceFile.getDescendantsOfKind(SyntaxKind.FunctionDeclaration).forEach((declaration) => {
|
|
1221
|
+
const bundledImport = resolveBundledHelperImport(declaration.getName() ?? "", declaration);
|
|
1222
|
+
if (!bundledImport || !declaration.getName()) return;
|
|
1223
|
+
bundledNamed.set(declaration.getName(), bundledImport);
|
|
1224
|
+
});
|
|
1225
|
+
const resolveBundledAliasImport = (node) => {
|
|
1226
|
+
if (!node) return;
|
|
1227
|
+
const expression = unwrapExpression(node);
|
|
1228
|
+
if (Node.isIdentifier(expression)) return bundledNamed.get(expression.getText());
|
|
1229
|
+
if (Node.isConditionalExpression(expression)) return resolveBundledAliasImport(expression.getWhenTrue()) ?? resolveBundledAliasImport(expression.getWhenFalse());
|
|
1230
|
+
if (Node.isBinaryExpression(expression) && expression.getOperatorToken().getKind() === SyntaxKind.CommaToken) return resolveBundledAliasImport(expression.getRight());
|
|
1231
|
+
};
|
|
1232
|
+
sourceFile.getVariableDeclarations().forEach((declaration) => {
|
|
1233
|
+
if (!Node.isIdentifier(declaration.getNameNode())) return;
|
|
1234
|
+
if (bundledNamed.has(declaration.getName())) return;
|
|
1235
|
+
const bundledAlias = resolveBundledAliasImport(declaration.getInitializer());
|
|
1236
|
+
if (!bundledAlias) return;
|
|
1237
|
+
bundledNamed.set(declaration.getName(), bundledAlias);
|
|
1238
|
+
});
|
|
1239
|
+
return {
|
|
1240
|
+
named,
|
|
1241
|
+
default: defaultImports,
|
|
1242
|
+
namespace,
|
|
1243
|
+
bundledNamed,
|
|
1244
|
+
bundledNamespace
|
|
1245
|
+
};
|
|
1376
1246
|
};
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
return text;
|
|
1247
|
+
const normalizeTagName = (text) => {
|
|
1248
|
+
const parcelVarMatch = text.match(/\$[^$]+\$var\$(.+)$/);
|
|
1249
|
+
if (parcelVarMatch?.[1]) return parcelVarMatch[1];
|
|
1250
|
+
return text;
|
|
1383
1251
|
};
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
if (MorphNode.isIdentifier(expression) || MorphNode.isPropertyAccessExpression(expression) || MorphNode.isElementAccessExpression(expression)) {
|
|
1391
|
-
return normalizeTagName(expression.getText());
|
|
1392
|
-
}
|
|
1252
|
+
const getTagName = (node) => {
|
|
1253
|
+
if (!node) return;
|
|
1254
|
+
const expression = unwrapExpression(node);
|
|
1255
|
+
if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) return expression.getLiteralValue();
|
|
1256
|
+
if (Node.isIdentifier(expression) || Node.isPropertyAccessExpression(expression) || Node.isElementAccessExpression(expression)) return normalizeTagName(expression.getText());
|
|
1393
1257
|
};
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1258
|
+
const isQwikMod = (mod) => mod.includes("qwik");
|
|
1259
|
+
const getArgsAt = (...indices) => (args) => indices.map((index) => args[index]).filter(Boolean);
|
|
1260
|
+
const runtimeProfiles = [
|
|
1261
|
+
{
|
|
1262
|
+
framework: "react",
|
|
1263
|
+
matches: ({ mod, importedName }) => reactRuntimeMods.has(mod) && [
|
|
1264
|
+
"jsx",
|
|
1265
|
+
"jsxs",
|
|
1266
|
+
"jsxDEV"
|
|
1267
|
+
].includes(importedName),
|
|
1268
|
+
getPropNodes: getArgsAt(1)
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
framework: "preact",
|
|
1272
|
+
matches: ({ mod, importedName }) => preactRuntimeMods.has(mod) && [
|
|
1273
|
+
"jsx",
|
|
1274
|
+
"jsxs",
|
|
1275
|
+
"jsxDEV"
|
|
1276
|
+
].includes(importedName),
|
|
1277
|
+
getPropNodes: getArgsAt(1)
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
framework: "react",
|
|
1281
|
+
matches: ({ mod, importedName }) => classicReactMods.has(mod) && importedName === "createElement",
|
|
1282
|
+
getPropNodes: getArgsAt(1)
|
|
1283
|
+
},
|
|
1284
|
+
{
|
|
1285
|
+
framework: "preact",
|
|
1286
|
+
matches: ({ mod, importedName }) => classicPreactMods.has(mod) && ["createElement", "h"].includes(importedName),
|
|
1287
|
+
getPropNodes: getArgsAt(1)
|
|
1288
|
+
},
|
|
1289
|
+
{
|
|
1290
|
+
framework: "vue",
|
|
1291
|
+
matches: ({ mod, importedName }) => vueMods.has(mod) && ["createVNode", "h"].includes(importedName),
|
|
1292
|
+
getPropNodes: getArgsAt(1)
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
framework: "solid",
|
|
1296
|
+
matches: ({ mod, importedName }) => solidMods.has(mod) && importedName === "createComponent",
|
|
1297
|
+
getPropNodes: getArgsAt(1)
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
framework: "qwik",
|
|
1301
|
+
matches: ({ mod, importedName }) => isQwikMod(mod) && ["_jsxQ", "_jsxS"].includes(importedName),
|
|
1302
|
+
getPropNodes: getArgsAt(1, 2)
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
framework: "qwik",
|
|
1306
|
+
matches: ({ mod, importedName }) => isQwikMod(mod) && [
|
|
1307
|
+
"_jsxC",
|
|
1308
|
+
"jsx",
|
|
1309
|
+
"jsxs",
|
|
1310
|
+
"jsxDEV"
|
|
1311
|
+
].includes(importedName),
|
|
1312
|
+
getPropNodes: getArgsAt(1)
|
|
1313
|
+
}
|
|
1437
1314
|
];
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1315
|
+
const createCompiledJsxContext = (sourceFile) => {
|
|
1316
|
+
const imports = collectImports(sourceFile);
|
|
1317
|
+
const normalizeCallee = (node) => {
|
|
1318
|
+
const expression = unwrapExpression(node);
|
|
1319
|
+
if (Node.isBinaryExpression(expression) && expression.getOperatorToken().getKind() === SyntaxKind.CommaToken) return normalizeCallee(expression.getRight());
|
|
1320
|
+
return expression;
|
|
1321
|
+
};
|
|
1322
|
+
const localDefinitionCache = /* @__PURE__ */ new Map();
|
|
1323
|
+
const resolveIdentifierDefinition = (identifier) => {
|
|
1324
|
+
const name = identifier.getText();
|
|
1325
|
+
if (localDefinitionCache.has(name)) return localDefinitionCache.get(name) ?? void 0;
|
|
1326
|
+
localDefinitionCache.set(name, null);
|
|
1327
|
+
const resolveLocalAlias = (aliasNode) => {
|
|
1328
|
+
if (!aliasNode) return;
|
|
1329
|
+
const expression = unwrapExpression(aliasNode);
|
|
1330
|
+
if (Node.isIdentifier(expression)) {
|
|
1331
|
+
const imported = imports.bundledNamed.get(expression.getText());
|
|
1332
|
+
if (imported) return {
|
|
1333
|
+
mod: imported.mod,
|
|
1334
|
+
importedName: imported.importedName
|
|
1335
|
+
};
|
|
1336
|
+
return resolveIdentifierDefinition(expression);
|
|
1337
|
+
}
|
|
1338
|
+
if (Node.isConditionalExpression(expression)) return resolveLocalAlias(expression.getWhenTrue()) ?? resolveLocalAlias(expression.getWhenFalse());
|
|
1339
|
+
if (Node.isBinaryExpression(expression) && expression.getOperatorToken().getKind() === SyntaxKind.CommaToken) return resolveLocalAlias(expression.getRight());
|
|
1340
|
+
};
|
|
1341
|
+
for (const definition of identifier.getDefinitions()) {
|
|
1342
|
+
const declaration = definition.getDeclarationNode();
|
|
1343
|
+
if (!declaration) continue;
|
|
1344
|
+
if (Node.isFunctionDeclaration(declaration)) {
|
|
1345
|
+
const imported = resolveBundledHelperImport(declaration.getName() ?? name, declaration);
|
|
1346
|
+
if (!imported) continue;
|
|
1347
|
+
const resolved = {
|
|
1348
|
+
mod: imported.mod,
|
|
1349
|
+
importedName: imported.importedName
|
|
1350
|
+
};
|
|
1351
|
+
localDefinitionCache.set(name, resolved);
|
|
1352
|
+
return resolved;
|
|
1353
|
+
}
|
|
1354
|
+
if (Node.isVariableDeclaration(declaration)) {
|
|
1355
|
+
const directImport = resolveBundledHelperImport(declaration.getName(), declaration.getInitializer());
|
|
1356
|
+
const aliasImport = directImport ? {
|
|
1357
|
+
mod: directImport.mod,
|
|
1358
|
+
importedName: directImport.importedName
|
|
1359
|
+
} : resolveLocalAlias(declaration.getInitializer());
|
|
1360
|
+
if (!aliasImport) continue;
|
|
1361
|
+
localDefinitionCache.set(name, aliasImport);
|
|
1362
|
+
return aliasImport;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
const resolveCallee = (node) => {
|
|
1367
|
+
const expression = normalizeCallee(node);
|
|
1368
|
+
if (Node.isIdentifier(expression)) {
|
|
1369
|
+
const imported = imports.named.get(expression.getText()) ?? imports.bundledNamed.get(expression.getText());
|
|
1370
|
+
if (imported) return {
|
|
1371
|
+
mod: imported.mod,
|
|
1372
|
+
importedName: imported.importedName
|
|
1373
|
+
};
|
|
1374
|
+
return resolveIdentifierDefinition(expression);
|
|
1375
|
+
}
|
|
1376
|
+
if (Node.isPropertyAccessExpression(expression)) {
|
|
1377
|
+
const target = normalizeCallee(expression.getExpression());
|
|
1378
|
+
if (!Node.isIdentifier(target)) return;
|
|
1379
|
+
const targetName = target.getText();
|
|
1380
|
+
const mod = imports.default.get(targetName) ?? imports.namespace.get(targetName) ?? imports.bundledNamespace.get(targetName);
|
|
1381
|
+
if (!mod) return;
|
|
1382
|
+
return {
|
|
1383
|
+
mod,
|
|
1384
|
+
importedName: expression.getName()
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
const isMergePropsCall = (node) => {
|
|
1389
|
+
if (!Node.isCallExpression(node)) return false;
|
|
1390
|
+
const resolved = resolveCallee(node.getExpression());
|
|
1391
|
+
if (!resolved) return false;
|
|
1392
|
+
return resolved.importedName === "mergeProps" && (solidMods.has(resolved.mod) || vueMods.has(resolved.mod));
|
|
1393
|
+
};
|
|
1394
|
+
const getCallInfo = (node) => {
|
|
1395
|
+
const resolved = resolveCallee(node.getExpression());
|
|
1396
|
+
if (!resolved) return;
|
|
1397
|
+
const args = node.getArguments().map((arg) => unwrapExpression(arg));
|
|
1398
|
+
const tagName = getTagName(args[0]);
|
|
1399
|
+
if (!tagName) return;
|
|
1400
|
+
const baseInfo = {
|
|
1401
|
+
tagName,
|
|
1402
|
+
isFactory: tagName.includes(".")
|
|
1403
|
+
};
|
|
1404
|
+
for (const profile of runtimeProfiles) if (profile.matches(resolved)) return {
|
|
1405
|
+
framework: profile.framework,
|
|
1406
|
+
...baseInfo,
|
|
1407
|
+
propNodes: profile.getPropNodes(args)
|
|
1408
|
+
};
|
|
1409
|
+
};
|
|
1410
|
+
return {
|
|
1411
|
+
getCallInfo,
|
|
1412
|
+
isMergePropsCall
|
|
1413
|
+
};
|
|
1534
1414
|
};
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1415
|
+
//#endregion
|
|
1416
|
+
//#region src/jsx-attribute.ts
|
|
1417
|
+
const extractJsxAttribute = (jsxAttribute, ctx) => {
|
|
1418
|
+
const initializer = jsxAttribute.getInitializer();
|
|
1419
|
+
const stack = [jsxAttribute, initializer];
|
|
1420
|
+
if (!initializer) {
|
|
1421
|
+
const nameNode = jsxAttribute.getNameNode();
|
|
1422
|
+
return box.emptyInitializer(nameNode, stack);
|
|
1423
|
+
}
|
|
1424
|
+
if (Node.isStringLiteral(initializer)) {
|
|
1425
|
+
const literalText = initializer.getLiteralText();
|
|
1426
|
+
return box.literal(trimWhitespace(literalText), initializer, stack);
|
|
1427
|
+
}
|
|
1428
|
+
if (Node.isJsxExpression(initializer)) {
|
|
1429
|
+
const expr = initializer.getExpression();
|
|
1430
|
+
if (!expr) return;
|
|
1431
|
+
const expression = unwrapExpression(expr);
|
|
1432
|
+
if (!expression) return;
|
|
1433
|
+
stack.push(expression);
|
|
1434
|
+
const maybeValue = maybeBoxNode(expression, stack, ctx);
|
|
1435
|
+
if (maybeValue) return maybeValue;
|
|
1436
|
+
}
|
|
1558
1437
|
};
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
const stack = [];
|
|
1564
|
-
return maybeBoxNode(expr, stack, ctx, matchProp);
|
|
1438
|
+
//#endregion
|
|
1439
|
+
//#region src/jsx-spread-attribute.ts
|
|
1440
|
+
const extractJsxSpreadAttributeValues = (node, ctx, matchProp) => {
|
|
1441
|
+
return maybeBoxNode(unwrapExpression(node.getExpression()), [], ctx, matchProp);
|
|
1565
1442
|
};
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
return /* @__PURE__ */ new Map();
|
|
1577
|
-
}
|
|
1578
|
-
if (box.isMap(maybeObject)) {
|
|
1579
|
-
return maybeObject.value;
|
|
1580
|
-
}
|
|
1581
|
-
return new Map(
|
|
1582
|
-
Object.entries(maybeObject.value).map(([key, value]) => {
|
|
1583
|
-
const boxed = box.from(value, maybeObject.getNode() ?? node, maybeObject.getStack() ?? []);
|
|
1584
|
-
return [key, boxed || null];
|
|
1585
|
-
}).filter(([, value]) => value !== null)
|
|
1586
|
-
);
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/object-like-to-map.ts
|
|
1445
|
+
const objectLikeToMap = (maybeObject, node) => {
|
|
1446
|
+
if (!maybeObject) return /* @__PURE__ */ new Map();
|
|
1447
|
+
if (!isBoxNode(maybeObject)) return new Map(Object.entries(maybeObject));
|
|
1448
|
+
if (box.isUnresolvable(maybeObject) || box.isConditional(maybeObject)) return /* @__PURE__ */ new Map();
|
|
1449
|
+
if (box.isMap(maybeObject)) return maybeObject.value;
|
|
1450
|
+
return new Map(Object.entries(maybeObject.value).map(([key, value]) => {
|
|
1451
|
+
return [key, box.from(value, maybeObject.getNode() ?? node, maybeObject.getStack() ?? []) || null];
|
|
1452
|
+
}).filter(([, value]) => value !== null));
|
|
1587
1453
|
};
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1454
|
+
//#endregion
|
|
1455
|
+
//#region src/extract.ts
|
|
1456
|
+
const isImportOrExport = (node) => Node.isImportDeclaration(node) || Node.isExportDeclaration(node);
|
|
1457
|
+
const isJsxElement = (node) => Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node);
|
|
1458
|
+
const extract = ({ ast, ...ctx }) => {
|
|
1459
|
+
const { components, functions, taggedTemplates } = ctx;
|
|
1460
|
+
const compiledJsx = createCompiledJsxContext(ast);
|
|
1461
|
+
/** contains all the extracted nodes from this ast parsing */
|
|
1462
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1463
|
+
/**
|
|
1464
|
+
* associate a component node with its props and (spread) conditionals
|
|
1465
|
+
* since js es6 map preserve insertion order, we can use it to keep the order of the props
|
|
1466
|
+
* so we can keep the last one
|
|
1467
|
+
* ex: <ColorBox padding="4" {...{ color: "blue.100" }} color="red" margin={2} />
|
|
1468
|
+
* => color: "red"
|
|
1469
|
+
*/
|
|
1470
|
+
const componentByNode = /* @__PURE__ */ new Map();
|
|
1471
|
+
const ensureComponent = (componentNode, componentName) => {
|
|
1472
|
+
if (!byName.has(componentName)) byName.set(componentName, {
|
|
1473
|
+
kind: "component",
|
|
1474
|
+
nodesByProp: /* @__PURE__ */ new Map(),
|
|
1475
|
+
queryList: []
|
|
1476
|
+
});
|
|
1477
|
+
if (!componentByNode.has(componentNode)) componentByNode.set(componentNode, {
|
|
1478
|
+
name: componentName,
|
|
1479
|
+
props: /* @__PURE__ */ new Map(),
|
|
1480
|
+
conditionals: []
|
|
1481
|
+
});
|
|
1482
|
+
return {
|
|
1483
|
+
component: componentByNode.get(componentNode),
|
|
1484
|
+
boxByProp: byName.get(componentName).nodesByProp
|
|
1485
|
+
};
|
|
1486
|
+
};
|
|
1487
|
+
const addComponentProp = (component, boxByProp, propName, propValue) => {
|
|
1488
|
+
component.props.set(propName, propValue);
|
|
1489
|
+
boxByProp.set(propName, (boxByProp.get(propName) ?? []).concat(propValue));
|
|
1490
|
+
};
|
|
1491
|
+
const processComponentObjectLike = (component, boxByProp, propNode, objLike, matchProp, trackSpreadConditions = false) => {
|
|
1492
|
+
if (trackSpreadConditions && box.isMap(objLike) && objLike.spreadConditions?.length) component.conditionals.push(...objLike.spreadConditions);
|
|
1493
|
+
objectLikeToMap(objLike, propNode).forEach((propValue, propName) => {
|
|
1494
|
+
if (matchProp({
|
|
1495
|
+
propName,
|
|
1496
|
+
propNode
|
|
1497
|
+
})) addComponentProp(component, boxByProp, propName, propValue);
|
|
1498
|
+
});
|
|
1499
|
+
};
|
|
1500
|
+
const processComponentBoxNode = (component, boxByProp, propNode, boxNode, matchProp, trackSpreadConditions = false) => {
|
|
1501
|
+
if (box.isConditional(boxNode)) {
|
|
1502
|
+
component.conditionals.push(boxNode);
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
if (box.isObject(boxNode) || box.isMap(boxNode)) processComponentObjectLike(component, boxByProp, propNode, boxNode, matchProp, trackSpreadConditions);
|
|
1506
|
+
};
|
|
1507
|
+
const processCompiledPropSource = (componentNode, component, boxByProp, propNode, matchProp) => {
|
|
1508
|
+
const expression = unwrapExpression(propNode);
|
|
1509
|
+
const stack = [componentNode, expression];
|
|
1510
|
+
if (Node.isObjectLiteralExpression(expression)) {
|
|
1511
|
+
processComponentBoxNode(component, boxByProp, expression, getObjectLiteralExpressionPropPairs(expression, stack, ctx, matchProp), matchProp, true);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
if (Node.isCallExpression(expression) && compiledJsx.isMergePropsCall(expression)) {
|
|
1515
|
+
expression.getArguments().forEach((arg) => {
|
|
1516
|
+
processCompiledPropSource(componentNode, component, boxByProp, arg, matchProp);
|
|
1517
|
+
});
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
const maybeValue = maybeBoxNode(expression, stack, ctx, matchProp);
|
|
1521
|
+
if (!maybeValue) return;
|
|
1522
|
+
processComponentBoxNode(component, boxByProp, expression, maybeValue, matchProp, true);
|
|
1523
|
+
};
|
|
1524
|
+
ast.forEachDescendant((node, traversal) => {
|
|
1525
|
+
if (isImportOrExport(node)) {
|
|
1526
|
+
traversal.skip();
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
if (components) {
|
|
1530
|
+
if (Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node)) {
|
|
1531
|
+
const componentNode = node;
|
|
1532
|
+
const componentName = getComponentName(componentNode);
|
|
1533
|
+
const isFactory = componentName.includes(".");
|
|
1534
|
+
if (!components.matchTag({
|
|
1535
|
+
tagNode: componentNode,
|
|
1536
|
+
tagName: componentName,
|
|
1537
|
+
isFactory
|
|
1538
|
+
})) return;
|
|
1539
|
+
ensureComponent(componentNode, componentName);
|
|
1540
|
+
}
|
|
1541
|
+
if (Node.isJsxSpreadAttribute(node)) {
|
|
1542
|
+
const componentNode = node.getFirstAncestor(isJsxElement);
|
|
1543
|
+
const component = componentByNode.get(componentNode);
|
|
1544
|
+
if (!componentNode || !component) return;
|
|
1545
|
+
const componentName = getComponentName(componentNode);
|
|
1546
|
+
const boxByProp = byName.get(componentName).nodesByProp;
|
|
1547
|
+
const matchProp = ({ propName, propNode }) => components.matchProp({
|
|
1548
|
+
tagNode: componentNode,
|
|
1549
|
+
tagName: componentName,
|
|
1550
|
+
propName,
|
|
1551
|
+
propNode
|
|
1552
|
+
});
|
|
1553
|
+
const spreadNode = extractJsxSpreadAttributeValues(node, ctx, matchProp);
|
|
1554
|
+
if (!spreadNode) return;
|
|
1555
|
+
processComponentBoxNode(component, boxByProp, node, spreadNode, matchProp);
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
if (Node.isJsxAttribute(node)) {
|
|
1559
|
+
const componentNode = node.getFirstAncestor(isJsxElement);
|
|
1560
|
+
const component = componentByNode.get(componentNode);
|
|
1561
|
+
if (!componentNode || !component) return;
|
|
1562
|
+
const componentName = getComponentName(componentNode);
|
|
1563
|
+
const boxByProp = byName.get(componentName).nodesByProp;
|
|
1564
|
+
const propName = node.getNameNode().getText();
|
|
1565
|
+
if (!components.matchProp({
|
|
1566
|
+
tagNode: componentNode,
|
|
1567
|
+
tagName: componentName,
|
|
1568
|
+
propName,
|
|
1569
|
+
propNode: node
|
|
1570
|
+
})) return;
|
|
1571
|
+
const maybeBox = extractJsxAttribute(node, ctx);
|
|
1572
|
+
if (!maybeBox) return;
|
|
1573
|
+
addComponentProp(component, boxByProp, propName, maybeBox);
|
|
1574
|
+
}
|
|
1575
|
+
if (Node.isCallExpression(node)) {
|
|
1576
|
+
const compiledCall = compiledJsx.getCallInfo(node);
|
|
1577
|
+
if (compiledCall) {
|
|
1578
|
+
const { tagName, isFactory, propNodes } = compiledCall;
|
|
1579
|
+
if (!components.matchTag({
|
|
1580
|
+
tagNode: node,
|
|
1581
|
+
tagName,
|
|
1582
|
+
isFactory
|
|
1583
|
+
})) return;
|
|
1584
|
+
const { component, boxByProp } = ensureComponent(node, tagName);
|
|
1585
|
+
const matchProp = ({ propName, propNode }) => components.matchProp({
|
|
1586
|
+
tagNode: node,
|
|
1587
|
+
tagName,
|
|
1588
|
+
propName,
|
|
1589
|
+
propNode
|
|
1590
|
+
});
|
|
1591
|
+
propNodes.forEach((propNode) => {
|
|
1592
|
+
processCompiledPropSource(node, component, boxByProp, propNode, matchProp);
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
if (functions && Node.isCallExpression(node)) {
|
|
1598
|
+
const expr = node.getExpression();
|
|
1599
|
+
const fnName = Node.isCallExpression(expr) ? expr.getExpression().getText() : expr.getText();
|
|
1600
|
+
if (!functions.matchFn({
|
|
1601
|
+
fnNode: node,
|
|
1602
|
+
fnName
|
|
1603
|
+
})) return;
|
|
1604
|
+
const matchProp = ({ propName, propNode }) => functions.matchProp({
|
|
1605
|
+
fnNode: node,
|
|
1606
|
+
fnName,
|
|
1607
|
+
propName,
|
|
1608
|
+
propNode
|
|
1609
|
+
});
|
|
1610
|
+
if (!byName.has(fnName)) byName.set(fnName, {
|
|
1611
|
+
kind: "function",
|
|
1612
|
+
nodesByProp: /* @__PURE__ */ new Map(),
|
|
1613
|
+
queryList: []
|
|
1614
|
+
});
|
|
1615
|
+
const fnResultMap = byName.get(fnName);
|
|
1616
|
+
const boxByProp = fnResultMap.nodesByProp;
|
|
1617
|
+
const nodeList = extractCallExpressionArguments(node, ctx, matchProp, functions.matchArg).value.map((boxNode) => {
|
|
1618
|
+
if (box.isObject(boxNode) || box.isMap(boxNode)) {
|
|
1619
|
+
const mapValue = objectLikeToMap(boxNode, node);
|
|
1620
|
+
const isMap = box.isMap(boxNode);
|
|
1621
|
+
mapValue.forEach((propValue, propName) => {
|
|
1622
|
+
if (isMap ? true : matchProp({
|
|
1623
|
+
propName,
|
|
1624
|
+
propNode: node
|
|
1625
|
+
})) boxByProp.set(propName, (boxByProp.get(propName) ?? []).concat(propValue));
|
|
1626
|
+
});
|
|
1627
|
+
const boxMap = box.map(mapValue, node, boxNode.getStack());
|
|
1628
|
+
if (box.isMap(boxNode) && boxNode.spreadConditions?.length) boxMap.spreadConditions = boxNode.spreadConditions;
|
|
1629
|
+
return boxMap;
|
|
1630
|
+
}
|
|
1631
|
+
return boxNode;
|
|
1632
|
+
});
|
|
1633
|
+
const query = {
|
|
1634
|
+
kind: "call-expression",
|
|
1635
|
+
name: fnName,
|
|
1636
|
+
box: box.array(nodeList, node, [])
|
|
1637
|
+
};
|
|
1638
|
+
fnResultMap.queryList.push(query);
|
|
1639
|
+
}
|
|
1640
|
+
if (taggedTemplates && Node.isTaggedTemplateExpression(node)) {
|
|
1641
|
+
const tag = node.getTag();
|
|
1642
|
+
const fnName = Node.isCallExpression(tag) ? tag.getExpression().getText() : tag.getText();
|
|
1643
|
+
if (!taggedTemplates.matchTaggedTemplate({
|
|
1644
|
+
taggedTemplateNode: node,
|
|
1645
|
+
fnName
|
|
1646
|
+
})) return;
|
|
1647
|
+
if (!byName.has(fnName)) byName.set(fnName, {
|
|
1648
|
+
kind: "function",
|
|
1649
|
+
nodesByProp: /* @__PURE__ */ new Map(),
|
|
1650
|
+
queryList: []
|
|
1651
|
+
});
|
|
1652
|
+
const fnResultMap = byName.get(fnName);
|
|
1653
|
+
const query = {
|
|
1654
|
+
kind: "tagged-template",
|
|
1655
|
+
name: fnName,
|
|
1656
|
+
box: maybeBoxNode(node, [], ctx)
|
|
1657
|
+
};
|
|
1658
|
+
fnResultMap.queryList.push(query);
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
componentByNode.forEach((parentRef, componentNode) => {
|
|
1662
|
+
const component = componentByNode.get(componentNode);
|
|
1663
|
+
if (!component) return;
|
|
1664
|
+
if (Node.isCallExpression(componentNode) && component.props.size === 0 && component.conditionals.length === 0) return;
|
|
1665
|
+
const query = {
|
|
1666
|
+
name: parentRef.name,
|
|
1667
|
+
box: box.map(component.props, componentNode, [])
|
|
1668
|
+
};
|
|
1669
|
+
if (component.conditionals?.length) query.box.spreadConditions = component.conditionals;
|
|
1670
|
+
const componentName = parentRef.name;
|
|
1671
|
+
byName.get(componentName).queryList.push(query);
|
|
1672
|
+
});
|
|
1673
|
+
byName.forEach((result, name) => {
|
|
1674
|
+
if (result.kind === "component" && result.queryList.length === 0) byName.delete(name);
|
|
1675
|
+
});
|
|
1676
|
+
return byName;
|
|
1780
1677
|
};
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
});
|
|
1812
|
-
return { name: tagName, props };
|
|
1678
|
+
//#endregion
|
|
1679
|
+
//#region src/jsx-element-props.ts
|
|
1680
|
+
const isObjectLike = (node) => box.isObject(node) || box.isMap(node);
|
|
1681
|
+
const extractJsxElementProps = (node, ctx) => {
|
|
1682
|
+
const tagName = node.getTagNameNode().getText();
|
|
1683
|
+
const jsxAttributes = node.getAttributes();
|
|
1684
|
+
const props = /* @__PURE__ */ new Map();
|
|
1685
|
+
jsxAttributes.forEach((attrNode) => {
|
|
1686
|
+
if (Node.isJsxAttribute(attrNode)) {
|
|
1687
|
+
const nameNode = attrNode.getNameNode();
|
|
1688
|
+
const maybeValue = extractJsxAttribute(attrNode, ctx);
|
|
1689
|
+
if (!maybeValue) return;
|
|
1690
|
+
props.set(nameNode.getText(), maybeValue);
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (Node.isJsxSpreadAttribute(attrNode)) {
|
|
1694
|
+
const maybeValue = extractJsxSpreadAttributeValues(attrNode, ctx, () => true);
|
|
1695
|
+
if (!isObjectLike(maybeValue)) return;
|
|
1696
|
+
if (box.isMap(maybeValue)) maybeValue.value.forEach((value, propName) => {
|
|
1697
|
+
props.set(propName, value);
|
|
1698
|
+
});
|
|
1699
|
+
if (box.isObject(maybeValue)) Object.entries(maybeValue.value).forEach(([propName, value]) => {
|
|
1700
|
+
props.set(propName, box.literal(value, node, []));
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
});
|
|
1704
|
+
return {
|
|
1705
|
+
name: tagName,
|
|
1706
|
+
props
|
|
1707
|
+
};
|
|
1813
1708
|
};
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
return obj;
|
|
1709
|
+
//#endregion
|
|
1710
|
+
//#region src/unbox.ts
|
|
1711
|
+
const makeObjAt = (path, value) => {
|
|
1712
|
+
if (!path.length) return value;
|
|
1713
|
+
const obj = {};
|
|
1714
|
+
path.reduce((acc, key, i) => {
|
|
1715
|
+
const isLast = i === path.length - 1;
|
|
1716
|
+
acc[key] = isLast ? value : {};
|
|
1717
|
+
return isLast ? obj : acc[key];
|
|
1718
|
+
}, obj);
|
|
1719
|
+
return obj;
|
|
1826
1720
|
};
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1833
|
-
return arr;
|
|
1721
|
+
const makeArrayWithValueAt = (index, value) => {
|
|
1722
|
+
if (index < 0) return [];
|
|
1723
|
+
const arr = [];
|
|
1724
|
+
for (let i = 0; i <= index; i++) arr[i] = i === index ? value : void 0;
|
|
1725
|
+
return arr;
|
|
1834
1726
|
};
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
return node.value.flatMap(
|
|
1892
|
-
(elementNode, index) => getLiteralValue(elementNode, Object.assign({}, ctx, { path: ctx.path.concat(String(index)), parent: node }))
|
|
1893
|
-
);
|
|
1894
|
-
}
|
|
1727
|
+
const getLiteralValue = (node, ctx) => {
|
|
1728
|
+
if (!node) return;
|
|
1729
|
+
if (box.isConditional(node)) {
|
|
1730
|
+
const path = ctx.path;
|
|
1731
|
+
const whenTrue = getLiteralValue(node.whenTrue, Object.assign({}, ctx, {
|
|
1732
|
+
path,
|
|
1733
|
+
parent: node
|
|
1734
|
+
}));
|
|
1735
|
+
const whenFalse = getLiteralValue(node.whenFalse, Object.assign({}, ctx, {
|
|
1736
|
+
path,
|
|
1737
|
+
parent: node
|
|
1738
|
+
}));
|
|
1739
|
+
const last = node.getStack().at(-1);
|
|
1740
|
+
const maybeIndex = Number(path[path.length - 1]);
|
|
1741
|
+
if (last && Node.isArrayLiteralExpression(last) && !Number.isNaN(maybeIndex)) {
|
|
1742
|
+
const sliced = path.slice(0, -1);
|
|
1743
|
+
if (whenTrue) ctx.conditions.push(makeObjAt(sliced, makeArrayWithValueAt(maybeIndex, whenTrue)));
|
|
1744
|
+
if (whenFalse) ctx.conditions.push(makeObjAt(sliced, makeArrayWithValueAt(maybeIndex, whenFalse)));
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
if (isTruthyOrZero(whenTrue)) ctx.conditions.push(makeObjAt(path, whenTrue));
|
|
1748
|
+
if (isTruthyOrZero(whenFalse)) ctx.conditions.push(makeObjAt(path, whenFalse));
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
if (box.isLiteral(node) || box.isObject(node)) return node.value;
|
|
1752
|
+
if (box.isEmptyInitializer(node)) return true;
|
|
1753
|
+
if (box.isMap(node)) {
|
|
1754
|
+
if (node.spreadConditions) {
|
|
1755
|
+
const path = ctx.path;
|
|
1756
|
+
node.spreadConditions.forEach((spread) => {
|
|
1757
|
+
const whenTrue = getLiteralValue(spread.whenTrue, Object.assign({}, ctx, {
|
|
1758
|
+
path,
|
|
1759
|
+
parent: node
|
|
1760
|
+
}));
|
|
1761
|
+
const whenFalse = getLiteralValue(spread.whenFalse, Object.assign({}, ctx, {
|
|
1762
|
+
path,
|
|
1763
|
+
parent: node
|
|
1764
|
+
}));
|
|
1765
|
+
if (whenTrue) ctx.spreadConditions.push(makeObjAt(path, whenTrue));
|
|
1766
|
+
if (whenFalse) ctx.spreadConditions.push(makeObjAt(path, whenFalse));
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
const obj = {};
|
|
1770
|
+
node.value.forEach((propNode, key) => {
|
|
1771
|
+
const value = getLiteralValue(propNode, Object.assign({}, ctx, {
|
|
1772
|
+
path: ctx.path.concat(key),
|
|
1773
|
+
parent: node
|
|
1774
|
+
}));
|
|
1775
|
+
if (isNotNullish(value)) obj[key] = value;
|
|
1776
|
+
});
|
|
1777
|
+
return obj;
|
|
1778
|
+
}
|
|
1779
|
+
if (box.isArray(node)) return node.value.flatMap((elementNode, index) => getLiteralValue(elementNode, Object.assign({}, ctx, {
|
|
1780
|
+
path: ctx.path.concat(String(index)),
|
|
1781
|
+
parent: node
|
|
1782
|
+
})));
|
|
1895
1783
|
};
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1784
|
+
const cacheMap = /* @__PURE__ */ new WeakMap();
|
|
1785
|
+
const createCache = (map) => ({
|
|
1786
|
+
value: map,
|
|
1787
|
+
has: (node) => map.has(node),
|
|
1788
|
+
get: (node) => map.get(node),
|
|
1789
|
+
set: (node, value) => map.set(node, value)
|
|
1902
1790
|
});
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
cache.set(node, result);
|
|
1925
|
-
}
|
|
1926
|
-
return result;
|
|
1927
|
-
};
|
|
1928
|
-
export {
|
|
1929
|
-
BoxNodeArray,
|
|
1930
|
-
BoxNodeConditional,
|
|
1931
|
-
BoxNodeEmptyInitializer,
|
|
1932
|
-
BoxNodeLiteral,
|
|
1933
|
-
BoxNodeMap,
|
|
1934
|
-
BoxNodeObject,
|
|
1935
|
-
BoxNodeUnresolvable,
|
|
1936
|
-
box,
|
|
1937
|
-
extract,
|
|
1938
|
-
extractCallExpressionArguments,
|
|
1939
|
-
extractJsxAttribute,
|
|
1940
|
-
extractJsxElementProps,
|
|
1941
|
-
extractJsxSpreadAttributeValues,
|
|
1942
|
-
findIdentifierValueDeclaration,
|
|
1943
|
-
isBoxNode,
|
|
1944
|
-
maybeBoxNode,
|
|
1945
|
-
maybeIdentifierValue,
|
|
1946
|
-
unbox
|
|
1791
|
+
const unbox = (node, ctx) => {
|
|
1792
|
+
const _ctx = {
|
|
1793
|
+
cache: ctx?.cache ?? cacheMap,
|
|
1794
|
+
...ctx,
|
|
1795
|
+
path: [],
|
|
1796
|
+
parent: void 0,
|
|
1797
|
+
conditions: [],
|
|
1798
|
+
spreadConditions: []
|
|
1799
|
+
};
|
|
1800
|
+
const cache = createCache(_ctx.cache);
|
|
1801
|
+
if (cache.has(node)) return cache.get(node);
|
|
1802
|
+
let raw;
|
|
1803
|
+
if (Array.isArray(node)) raw = node.map((boxNode) => getLiteralValue(boxNode, _ctx)).filter(isNotNullish)[0];
|
|
1804
|
+
else raw = getLiteralValue(node, _ctx);
|
|
1805
|
+
const result = {
|
|
1806
|
+
raw: raw ?? {},
|
|
1807
|
+
conditions: _ctx.conditions,
|
|
1808
|
+
spreadConditions: _ctx.spreadConditions
|
|
1809
|
+
};
|
|
1810
|
+
if (raw) cache.set(node, result);
|
|
1811
|
+
return result;
|
|
1947
1812
|
};
|
|
1813
|
+
//#endregion
|
|
1814
|
+
export { BoxNodeArray, BoxNodeConditional, BoxNodeEmptyInitializer, BoxNodeLiteral, BoxNodeMap, BoxNodeObject, BoxNodeUnresolvable, box, extract, extractCallExpressionArguments, extractJsxAttribute, extractJsxElementProps, extractJsxSpreadAttributeValues, findIdentifierValueDeclaration, isBoxNode, maybeBoxNode, maybeIdentifierValue, unbox };
|