@litsx/babel-preset-litsx 0.3.0 → 0.4.0
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 +7 -1
- package/dist/index.cjs.map +1 -1
- package/dist/internal/transform-litsx-components.cjs +529 -586
- package/dist/internal/transform-litsx-components.cjs.map +1 -1
- package/dist/internal/transform-litsx-renderer-props.cjs +21 -5
- package/dist/internal/transform-litsx-renderer-props.cjs.map +1 -1
- package/dist/pipeline.cjs +8 -1
- package/dist/pipeline.cjs.map +1 -1
- package/dist/shared/transform-litsx-element-candidates-JMFlPFXK.cjs +1170 -0
- package/dist/shared/transform-litsx-element-candidates-JMFlPFXK.cjs.map +1 -0
- package/package.json +4 -2
- package/src/internal/transform-litsx-components.js +46 -231
- package/src/internal/transform-litsx-element-candidates.js +1173 -0
- package/src/internal/transform-litsx-param-rewrites.js +0 -71
- package/src/internal/transform-litsx-render-body.js +113 -0
- package/src/internal/transform-litsx-renderer-calls.js +92 -0
- package/src/internal/transform-litsx-renderer-props.js +13 -5
- package/src/pipeline.js +1 -0
|
@@ -4,19 +4,25 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxSyntaxPlugin = require('@babel/plugin-syntax-jsx');
|
|
6
6
|
var internal_transformLitsxProperties = require('./transform-litsx-properties.cjs');
|
|
7
|
+
var transformLitsxElementCandidates = require('../shared/transform-litsx-element-candidates-JMFlPFXK.cjs');
|
|
7
8
|
require('module');
|
|
8
9
|
require('@litsx/typescript-session');
|
|
10
|
+
require('@babel/helper-plugin-utils');
|
|
11
|
+
require('@babel/traverse');
|
|
12
|
+
require('@litsx/babel-parser');
|
|
13
|
+
require('node:fs');
|
|
14
|
+
require('node:path');
|
|
9
15
|
|
|
10
|
-
let t$
|
|
16
|
+
let t$9;
|
|
11
17
|
|
|
12
18
|
function setStaticHoistsBabelTypes(types) {
|
|
13
|
-
t$
|
|
19
|
+
t$9 = types;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
function isLightDomHoist(statement) {
|
|
17
|
-
if (!t$
|
|
18
|
-
if (!t$
|
|
19
|
-
if (!t$
|
|
23
|
+
if (!t$9.isExpressionStatement(statement)) return false;
|
|
24
|
+
if (!t$9.isCallExpression(statement.expression)) return false;
|
|
25
|
+
if (!t$9.isIdentifier(statement.expression.callee, { name: "__litsx_static_lightDom" })) {
|
|
20
26
|
return false;
|
|
21
27
|
}
|
|
22
28
|
if (statement.expression.arguments.length !== 0) {
|
|
@@ -26,17 +32,17 @@ function isLightDomHoist(statement) {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
function createStaticHoistGetter(name, symbolId, expression) {
|
|
29
|
-
const getter = t$
|
|
35
|
+
const getter = t$9.classMethod(
|
|
30
36
|
"get",
|
|
31
|
-
t$
|
|
37
|
+
t$9.identifier(name),
|
|
32
38
|
[],
|
|
33
|
-
t$
|
|
34
|
-
t$
|
|
35
|
-
t$
|
|
36
|
-
t$
|
|
39
|
+
t$9.blockStatement([
|
|
40
|
+
t$9.returnStatement(
|
|
41
|
+
t$9.callExpression(
|
|
42
|
+
t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxStatic")),
|
|
37
43
|
[
|
|
38
|
-
t$
|
|
39
|
-
t$
|
|
44
|
+
t$9.cloneNode(symbolId),
|
|
45
|
+
t$9.arrowFunctionExpression([], expression),
|
|
40
46
|
]
|
|
41
47
|
)
|
|
42
48
|
),
|
|
@@ -47,22 +53,22 @@ function createStaticHoistGetter(name, symbolId, expression) {
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
function resolveStaticHoistExpression(expression) {
|
|
50
|
-
return t$
|
|
51
|
-
t$
|
|
52
|
-
[t$
|
|
56
|
+
return t$9.callExpression(
|
|
57
|
+
t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxResolveStaticValue")),
|
|
58
|
+
[t$9.cloneNode(expression)]
|
|
53
59
|
);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
function createPropertiesHoistResolver(propertiesStatic, staticProps, expression) {
|
|
57
|
-
const mergedProperties = propertiesStatic.map((property) => t$
|
|
63
|
+
const mergedProperties = propertiesStatic.map((property) => t$9.cloneNode(property));
|
|
58
64
|
if (staticProps.length > 0) {
|
|
59
65
|
mergeStaticPropsIntoProperties(mergedProperties, staticProps);
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
return t$
|
|
63
|
-
t$
|
|
68
|
+
return t$9.callExpression(
|
|
69
|
+
t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxMergeProperties")),
|
|
64
70
|
[
|
|
65
|
-
t$
|
|
71
|
+
t$9.objectExpression(mergedProperties),
|
|
66
72
|
resolveStaticHoistExpression(expression),
|
|
67
73
|
]
|
|
68
74
|
);
|
|
@@ -76,17 +82,17 @@ function createStylesHoistResolver(staticStyles, expression) {
|
|
|
76
82
|
|
|
77
83
|
const baseStyles =
|
|
78
84
|
staticStyles.length === 1
|
|
79
|
-
? t$
|
|
80
|
-
: t$
|
|
85
|
+
? t$9.cloneNode(staticStyles[0])
|
|
86
|
+
: t$9.arrayExpression(staticStyles.map((style) => t$9.cloneNode(style)));
|
|
81
87
|
|
|
82
|
-
return t$
|
|
88
|
+
return t$9.logicalExpression("||", resolvedExpression, baseStyles);
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
function getStaticPropsExpression(statement) {
|
|
86
|
-
if (!t$
|
|
87
|
-
if (!t$
|
|
88
|
-
const isLegacyStaticProps = t$
|
|
89
|
-
const isHoistedProperties = t$
|
|
92
|
+
if (!t$9.isExpressionStatement(statement)) return null;
|
|
93
|
+
if (!t$9.isCallExpression(statement.expression)) return null;
|
|
94
|
+
const isLegacyStaticProps = t$9.isIdentifier(statement.expression.callee, { name: "staticProps" });
|
|
95
|
+
const isHoistedProperties = t$9.isIdentifier(
|
|
90
96
|
statement.expression.callee,
|
|
91
97
|
{ name: "__litsx_static_properties" }
|
|
92
98
|
);
|
|
@@ -99,47 +105,47 @@ function getStaticPropsExpression(statement) {
|
|
|
99
105
|
if (statement.expression.arguments.length !== 1) return null;
|
|
100
106
|
|
|
101
107
|
const [argument] = statement.expression.arguments;
|
|
102
|
-
if (isHoistedProperties && (t$
|
|
108
|
+
if (isHoistedProperties && (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument))) {
|
|
103
109
|
throw new Error("^properties(...) only accepts an object literal with static Lit property options.");
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
if (!t$
|
|
112
|
+
if (!t$9.isObjectExpression(argument)) {
|
|
107
113
|
throw new Error("^properties(...) only accepts an object literal with static Lit property options.");
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
return isHoistedProperties ? {
|
|
111
117
|
__litsxHoistedProperties: true,
|
|
112
|
-
expression: t$
|
|
113
|
-
} : t$
|
|
118
|
+
expression: t$9.cloneNode(argument),
|
|
119
|
+
} : t$9.cloneNode(argument);
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
function getStaticPropertyName(node) {
|
|
117
|
-
if (t$
|
|
118
|
-
if (t$
|
|
123
|
+
if (t$9.isIdentifier(node)) return node.name;
|
|
124
|
+
if (t$9.isStringLiteral(node)) return node.value;
|
|
119
125
|
return null;
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
function normalizeStaticPropOverrideValue(value) {
|
|
123
129
|
if (
|
|
124
|
-
t$
|
|
130
|
+
t$9.isIdentifier(value) &&
|
|
125
131
|
["String", "Number", "Boolean", "Object", "Array", "Date"].includes(value.name)
|
|
126
132
|
) {
|
|
127
|
-
return internal_transformLitsxProperties.createPropertyConfig(t$
|
|
133
|
+
return internal_transformLitsxProperties.createPropertyConfig(t$9.identifier(value.name));
|
|
128
134
|
}
|
|
129
135
|
|
|
130
|
-
if (t$
|
|
136
|
+
if (t$9.isObjectExpression(value)) {
|
|
131
137
|
const typeProperty = value.properties.find(
|
|
132
138
|
(prop) =>
|
|
133
|
-
t$
|
|
134
|
-
t$
|
|
135
|
-
t$
|
|
139
|
+
t$9.isObjectProperty(prop) &&
|
|
140
|
+
t$9.isIdentifier(prop.key, { name: "type" }) &&
|
|
141
|
+
t$9.isIdentifier(prop.value)
|
|
136
142
|
);
|
|
137
143
|
|
|
138
144
|
const attributeProperty = value.properties.find(
|
|
139
145
|
(prop) =>
|
|
140
|
-
t$
|
|
141
|
-
t$
|
|
142
|
-
t$
|
|
146
|
+
t$9.isObjectProperty(prop) &&
|
|
147
|
+
t$9.isIdentifier(prop.key, { name: "attribute" }) &&
|
|
148
|
+
t$9.isBooleanLiteral(prop.value) &&
|
|
143
149
|
prop.value.value === false
|
|
144
150
|
);
|
|
145
151
|
|
|
@@ -154,12 +160,12 @@ function normalizeStaticPropOverrideValue(value) {
|
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
function mergeStaticPropertyObject(targetNode, overrideObject) {
|
|
157
|
-
if (!t$
|
|
163
|
+
if (!t$9.isObjectProperty(targetNode) || !t$9.isObjectExpression(targetNode.value)) {
|
|
158
164
|
return;
|
|
159
165
|
}
|
|
160
166
|
|
|
161
167
|
overrideObject.properties.forEach((property) => {
|
|
162
|
-
if (!t$
|
|
168
|
+
if (!t$9.isObjectProperty(property) && !t$9.isObjectMethod(property)) {
|
|
163
169
|
throw new Error("^properties(...) only accepts plain object members.");
|
|
164
170
|
}
|
|
165
171
|
|
|
@@ -170,16 +176,16 @@ function mergeStaticPropertyObject(targetNode, overrideObject) {
|
|
|
170
176
|
|
|
171
177
|
const existing = targetNode.value.properties.find(
|
|
172
178
|
(candidate) =>
|
|
173
|
-
(t$
|
|
179
|
+
(t$9.isObjectProperty(candidate) || t$9.isObjectMethod(candidate)) &&
|
|
174
180
|
getStaticPropertyName(candidate.key) === keyName
|
|
175
181
|
);
|
|
176
182
|
|
|
177
183
|
if (existing) {
|
|
178
|
-
const nextNode = t$
|
|
184
|
+
const nextNode = t$9.cloneNode(property);
|
|
179
185
|
const index = targetNode.value.properties.indexOf(existing);
|
|
180
186
|
targetNode.value.properties.splice(index, 1, nextNode);
|
|
181
187
|
} else {
|
|
182
|
-
targetNode.value.properties.push(t$
|
|
188
|
+
targetNode.value.properties.push(t$9.cloneNode(property));
|
|
183
189
|
}
|
|
184
190
|
});
|
|
185
191
|
}
|
|
@@ -188,7 +194,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
188
194
|
const propertyMap = new Map();
|
|
189
195
|
|
|
190
196
|
propertiesStatic.forEach((propertyNode) => {
|
|
191
|
-
if (!t$
|
|
197
|
+
if (!t$9.isObjectProperty(propertyNode)) return;
|
|
192
198
|
const keyName = getStaticPropertyName(propertyNode.key);
|
|
193
199
|
if (!keyName) return;
|
|
194
200
|
propertyMap.set(keyName, propertyNode);
|
|
@@ -196,7 +202,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
196
202
|
|
|
197
203
|
staticProps.forEach((optionsObject) => {
|
|
198
204
|
optionsObject.properties.forEach((property) => {
|
|
199
|
-
if (!t$
|
|
205
|
+
if (!t$9.isObjectProperty(property)) {
|
|
200
206
|
throw new Error("^properties(...) only accepts plain object properties.");
|
|
201
207
|
}
|
|
202
208
|
|
|
@@ -209,11 +215,11 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
209
215
|
const normalized = normalizeStaticPropOverrideValue(property.value);
|
|
210
216
|
|
|
211
217
|
if (!existing) {
|
|
212
|
-
const node = t$
|
|
213
|
-
t$
|
|
218
|
+
const node = t$9.objectProperty(
|
|
219
|
+
t$9.identifier(keyName),
|
|
214
220
|
internal_transformLitsxProperties.createPropertyValue(normalized, false)
|
|
215
221
|
);
|
|
216
|
-
if (t$
|
|
222
|
+
if (t$9.isObjectExpression(property.value)) {
|
|
217
223
|
mergeStaticPropertyObject(node, property.value);
|
|
218
224
|
}
|
|
219
225
|
propertiesStatic.push(node);
|
|
@@ -227,7 +233,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
227
233
|
false
|
|
228
234
|
);
|
|
229
235
|
|
|
230
|
-
if (t$
|
|
236
|
+
if (t$9.isObjectExpression(property.value)) {
|
|
231
237
|
mergeStaticPropertyObject(existing, property.value);
|
|
232
238
|
}
|
|
233
239
|
});
|
|
@@ -235,7 +241,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
235
241
|
}
|
|
236
242
|
|
|
237
243
|
function normalizeStylesTemplate(argument, functionPath) {
|
|
238
|
-
if (t$
|
|
244
|
+
if (t$9.isTemplateLiteral(argument)) {
|
|
239
245
|
if (
|
|
240
246
|
!argument.expressions.every((expression) =>
|
|
241
247
|
isStaticStylesExpression(expression, functionPath)
|
|
@@ -243,7 +249,7 @@ function normalizeStylesTemplate(argument, functionPath) {
|
|
|
243
249
|
) {
|
|
244
250
|
return null;
|
|
245
251
|
}
|
|
246
|
-
return t$
|
|
252
|
+
return t$9.templateLiteral(
|
|
247
253
|
argument.quasis,
|
|
248
254
|
argument.expressions.map((expression) =>
|
|
249
255
|
wrapStaticStylesInterpolation(expression)
|
|
@@ -251,18 +257,18 @@ function normalizeStylesTemplate(argument, functionPath) {
|
|
|
251
257
|
);
|
|
252
258
|
}
|
|
253
259
|
|
|
254
|
-
if (t$
|
|
255
|
-
return t$
|
|
256
|
-
[t$
|
|
260
|
+
if (t$9.isStringLiteral(argument)) {
|
|
261
|
+
return t$9.templateLiteral(
|
|
262
|
+
[t$9.templateElement({ raw: argument.value, cooked: argument.value }, true)],
|
|
257
263
|
[]
|
|
258
264
|
);
|
|
259
265
|
}
|
|
260
266
|
|
|
261
267
|
if (isStaticStylesExpression(argument, functionPath)) {
|
|
262
|
-
return t$
|
|
268
|
+
return t$9.templateLiteral(
|
|
263
269
|
[
|
|
264
|
-
t$
|
|
265
|
-
t$
|
|
270
|
+
t$9.templateElement({ raw: "", cooked: "" }, false),
|
|
271
|
+
t$9.templateElement({ raw: "", cooked: "" }, true),
|
|
266
272
|
],
|
|
267
273
|
[wrapStaticStylesInterpolation(argument)]
|
|
268
274
|
);
|
|
@@ -273,27 +279,27 @@ function normalizeStylesTemplate(argument, functionPath) {
|
|
|
273
279
|
|
|
274
280
|
function wrapStaticStylesInterpolation(expression) {
|
|
275
281
|
if (
|
|
276
|
-
t$
|
|
277
|
-
t$
|
|
282
|
+
t$9.isTaggedTemplateExpression(expression) &&
|
|
283
|
+
t$9.isIdentifier(expression.tag, { name: "css" })
|
|
278
284
|
) {
|
|
279
285
|
return expression;
|
|
280
286
|
}
|
|
281
287
|
|
|
282
|
-
if (t$
|
|
288
|
+
if (t$9.isNumericLiteral(expression)) {
|
|
283
289
|
return expression;
|
|
284
290
|
}
|
|
285
291
|
|
|
286
|
-
return t$
|
|
287
|
-
t$
|
|
292
|
+
return t$9.callExpression(
|
|
293
|
+
t$9.identifier("unsafeCSS"),
|
|
288
294
|
[expression]
|
|
289
295
|
);
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
function getStaticStylesExpression(statement, functionPath) {
|
|
293
|
-
if (!t$
|
|
294
|
-
if (!t$
|
|
295
|
-
const isLegacyStaticStyles = t$
|
|
296
|
-
const isHoistedStyles = t$
|
|
299
|
+
if (!t$9.isExpressionStatement(statement)) return null;
|
|
300
|
+
if (!t$9.isCallExpression(statement.expression)) return null;
|
|
301
|
+
const isLegacyStaticStyles = t$9.isIdentifier(statement.expression.callee, { name: "staticStyles" });
|
|
302
|
+
const isHoistedStyles = t$9.isIdentifier(statement.expression.callee, { name: "__litsx_static_styles" });
|
|
297
303
|
if (
|
|
298
304
|
!isLegacyStaticStyles &&
|
|
299
305
|
!isHoistedStyles
|
|
@@ -304,7 +310,7 @@ function getStaticStylesExpression(statement, functionPath) {
|
|
|
304
310
|
|
|
305
311
|
const [argument] = statement.expression.arguments;
|
|
306
312
|
|
|
307
|
-
if (isHoistedStyles && (t$
|
|
313
|
+
if (isHoistedStyles && (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument))) {
|
|
308
314
|
throw new Error("^styles(...) only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
|
|
309
315
|
}
|
|
310
316
|
|
|
@@ -316,16 +322,16 @@ function getStaticStylesExpression(statement, functionPath) {
|
|
|
316
322
|
throw new Error("^styles(...) only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
|
|
317
323
|
}
|
|
318
324
|
|
|
319
|
-
const expression = t$
|
|
325
|
+
const expression = t$9.taggedTemplateExpression(t$9.identifier("css"), template);
|
|
320
326
|
return isHoistedStyles
|
|
321
327
|
? { __litsxHoistedStyles: true, expression }
|
|
322
328
|
: expression;
|
|
323
329
|
}
|
|
324
330
|
|
|
325
331
|
function getStaticHoistExpression(statement, functionPath) {
|
|
326
|
-
if (!t$
|
|
327
|
-
if (!t$
|
|
328
|
-
if (!t$
|
|
332
|
+
if (!t$9.isExpressionStatement(statement)) return null;
|
|
333
|
+
if (!t$9.isCallExpression(statement.expression)) return null;
|
|
334
|
+
if (!t$9.isIdentifier(statement.expression.callee)) return null;
|
|
329
335
|
|
|
330
336
|
const calleeName = statement.expression.callee.name;
|
|
331
337
|
if (!calleeName.startsWith("__litsx_static_")) {
|
|
@@ -343,17 +349,17 @@ function getStaticHoistExpression(statement, functionPath) {
|
|
|
343
349
|
|
|
344
350
|
const [argument] = statement.expression.arguments;
|
|
345
351
|
if (name === "expose") {
|
|
346
|
-
if (t$
|
|
352
|
+
if (t$9.isObjectExpression(argument)) {
|
|
347
353
|
return {
|
|
348
354
|
name,
|
|
349
|
-
expression: t$
|
|
355
|
+
expression: t$9.cloneNode(argument),
|
|
350
356
|
};
|
|
351
357
|
}
|
|
352
358
|
|
|
353
359
|
throw new Error("^expose(...) only accepts an object literal.");
|
|
354
360
|
}
|
|
355
361
|
|
|
356
|
-
if (t$
|
|
362
|
+
if (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument)) {
|
|
357
363
|
throw new Error(`^${name}(...) only accepts a direct static value.`);
|
|
358
364
|
}
|
|
359
365
|
|
|
@@ -363,7 +369,7 @@ function getStaticHoistExpression(statement, functionPath) {
|
|
|
363
369
|
|
|
364
370
|
return {
|
|
365
371
|
name,
|
|
366
|
-
expression: t$
|
|
372
|
+
expression: t$9.cloneNode(argument),
|
|
367
373
|
};
|
|
368
374
|
}
|
|
369
375
|
|
|
@@ -376,9 +382,9 @@ function createExposeHoistMembers(expression) {
|
|
|
376
382
|
}
|
|
377
383
|
|
|
378
384
|
function normalizeExposeHoistExpression(expression) {
|
|
379
|
-
if (t$
|
|
385
|
+
if (t$9.isObjectExpression(expression)) {
|
|
380
386
|
return {
|
|
381
|
-
methodsExpression: t$
|
|
387
|
+
methodsExpression: t$9.cloneNode(expression),
|
|
382
388
|
};
|
|
383
389
|
}
|
|
384
390
|
|
|
@@ -392,41 +398,41 @@ function createExposeClassMethod(property) {
|
|
|
392
398
|
}
|
|
393
399
|
|
|
394
400
|
function normalizeExposePropertyToClassMethod(property) {
|
|
395
|
-
if (t$
|
|
401
|
+
if (t$9.isSpreadElement(property)) {
|
|
396
402
|
throw new Error("^expose(...) does not accept spread elements.");
|
|
397
403
|
}
|
|
398
404
|
|
|
399
|
-
if (t$
|
|
405
|
+
if (t$9.isObjectMethod(property)) {
|
|
400
406
|
if (property.kind !== "method") {
|
|
401
407
|
throw new Error("^expose(...) only accepts plain methods.");
|
|
402
408
|
}
|
|
403
409
|
|
|
404
|
-
return t$
|
|
410
|
+
return t$9.classMethod(
|
|
405
411
|
"method",
|
|
406
|
-
t$
|
|
407
|
-
property.params.map((param) => t$
|
|
408
|
-
t$
|
|
412
|
+
t$9.cloneNode(property.key),
|
|
413
|
+
property.params.map((param) => t$9.cloneNode(param)),
|
|
414
|
+
t$9.cloneNode(property.body),
|
|
409
415
|
property.computed
|
|
410
416
|
);
|
|
411
417
|
}
|
|
412
418
|
|
|
413
|
-
if (!t$
|
|
419
|
+
if (!t$9.isObjectProperty(property)) {
|
|
414
420
|
throw new Error("^expose(...) only accepts plain methods.");
|
|
415
421
|
}
|
|
416
422
|
|
|
417
423
|
const value = property.value;
|
|
418
|
-
if (!t$
|
|
424
|
+
if (!t$9.isFunctionExpression(value) && !t$9.isArrowFunctionExpression(value)) {
|
|
419
425
|
throw new Error("^expose(...) values must be functions.");
|
|
420
426
|
}
|
|
421
427
|
|
|
422
|
-
const body = t$
|
|
423
|
-
? t$
|
|
424
|
-
: t$
|
|
428
|
+
const body = t$9.isBlockStatement(value.body)
|
|
429
|
+
? t$9.cloneNode(value.body)
|
|
430
|
+
: t$9.blockStatement([t$9.returnStatement(t$9.cloneNode(value.body))]);
|
|
425
431
|
|
|
426
|
-
const method = t$
|
|
432
|
+
const method = t$9.classMethod(
|
|
427
433
|
"method",
|
|
428
|
-
t$
|
|
429
|
-
value.params.map((param) => t$
|
|
434
|
+
t$9.cloneNode(property.key),
|
|
435
|
+
value.params.map((param) => t$9.cloneNode(param)),
|
|
430
436
|
body,
|
|
431
437
|
property.computed
|
|
432
438
|
);
|
|
@@ -438,7 +444,7 @@ function normalizeExposePropertyToClassMethod(property) {
|
|
|
438
444
|
function assertStaticHoistsStayTopLevel(functionPath) {
|
|
439
445
|
functionPath.traverse({
|
|
440
446
|
CallExpression(callPath) {
|
|
441
|
-
if (!t$
|
|
447
|
+
if (!t$9.isIdentifier(callPath.node.callee)) return;
|
|
442
448
|
if (!callPath.node.callee.name.startsWith("__litsx_static_")) return;
|
|
443
449
|
|
|
444
450
|
const statementParent = callPath.parentPath;
|
|
@@ -463,8 +469,8 @@ function assertStaticHoistsStayTopLevel(functionPath) {
|
|
|
463
469
|
function containsUnsafeCssCall(node) {
|
|
464
470
|
if (!node || typeof node !== "object") return false;
|
|
465
471
|
if (
|
|
466
|
-
t$
|
|
467
|
-
t$
|
|
472
|
+
t$9.isCallExpression(node) &&
|
|
473
|
+
t$9.isIdentifier(node.callee, { name: "unsafeCSS" })
|
|
468
474
|
) {
|
|
469
475
|
return true;
|
|
470
476
|
}
|
|
@@ -479,37 +485,37 @@ function containsUnsafeCssCall(node) {
|
|
|
479
485
|
|
|
480
486
|
function isStaticStylesExpression(node, functionPath, seenBindings = new Set()) {
|
|
481
487
|
if (
|
|
482
|
-
t$
|
|
483
|
-
t$
|
|
484
|
-
t$
|
|
485
|
-
t$
|
|
486
|
-
t$
|
|
488
|
+
t$9.isStringLiteral(node) ||
|
|
489
|
+
t$9.isNumericLiteral(node) ||
|
|
490
|
+
t$9.isBooleanLiteral(node) ||
|
|
491
|
+
t$9.isNullLiteral(node) ||
|
|
492
|
+
t$9.isBigIntLiteral?.(node)
|
|
487
493
|
) {
|
|
488
494
|
return true;
|
|
489
495
|
}
|
|
490
496
|
|
|
491
|
-
if (t$
|
|
497
|
+
if (t$9.isTemplateLiteral(node)) {
|
|
492
498
|
return node.expressions.every((expression) =>
|
|
493
499
|
isStaticStylesExpression(expression, functionPath, seenBindings)
|
|
494
500
|
);
|
|
495
501
|
}
|
|
496
502
|
|
|
497
|
-
if (t$
|
|
503
|
+
if (t$9.isIdentifier(node)) {
|
|
498
504
|
return isStaticStylesIdentifier(node, functionPath, seenBindings);
|
|
499
505
|
}
|
|
500
506
|
|
|
501
|
-
if (t$
|
|
507
|
+
if (t$9.isUnaryExpression(node)) {
|
|
502
508
|
return isStaticStylesExpression(node.argument, functionPath, seenBindings);
|
|
503
509
|
}
|
|
504
510
|
|
|
505
|
-
if (t$
|
|
511
|
+
if (t$9.isBinaryExpression(node) || t$9.isLogicalExpression(node)) {
|
|
506
512
|
return (
|
|
507
513
|
isStaticStylesExpression(node.left, functionPath, seenBindings) &&
|
|
508
514
|
isStaticStylesExpression(node.right, functionPath, seenBindings)
|
|
509
515
|
);
|
|
510
516
|
}
|
|
511
517
|
|
|
512
|
-
if (t$
|
|
518
|
+
if (t$9.isConditionalExpression(node)) {
|
|
513
519
|
return (
|
|
514
520
|
isStaticStylesExpression(node.test, functionPath, seenBindings) &&
|
|
515
521
|
isStaticStylesExpression(node.consequent, functionPath, seenBindings) &&
|
|
@@ -517,15 +523,15 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
|
|
|
517
523
|
);
|
|
518
524
|
}
|
|
519
525
|
|
|
520
|
-
if (t$
|
|
526
|
+
if (t$9.isArrayExpression(node)) {
|
|
521
527
|
return node.elements.every((element) =>
|
|
522
528
|
element == null || isStaticStylesExpression(element, functionPath, seenBindings)
|
|
523
529
|
);
|
|
524
530
|
}
|
|
525
531
|
|
|
526
|
-
if (t$
|
|
532
|
+
if (t$9.isObjectExpression(node)) {
|
|
527
533
|
return node.properties.every((property) => {
|
|
528
|
-
if (t$
|
|
534
|
+
if (t$9.isObjectProperty(property)) {
|
|
529
535
|
return (
|
|
530
536
|
(!property.computed ||
|
|
531
537
|
isStaticStylesExpression(property.key, functionPath, seenBindings)) &&
|
|
@@ -536,7 +542,7 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
|
|
|
536
542
|
});
|
|
537
543
|
}
|
|
538
544
|
|
|
539
|
-
if (t$
|
|
545
|
+
if (t$9.isMemberExpression(node)) {
|
|
540
546
|
return (
|
|
541
547
|
isStaticStylesExpression(node.object, functionPath, seenBindings) &&
|
|
542
548
|
(!node.computed ||
|
|
@@ -544,18 +550,18 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
|
|
|
544
550
|
);
|
|
545
551
|
}
|
|
546
552
|
|
|
547
|
-
if (t$
|
|
553
|
+
if (t$9.isCallExpression(node)) {
|
|
548
554
|
return (
|
|
549
555
|
isStaticStylesExpression(node.callee, functionPath, seenBindings) &&
|
|
550
556
|
node.arguments.every((argument) =>
|
|
551
|
-
t$
|
|
557
|
+
t$9.isSpreadElement(argument)
|
|
552
558
|
? false
|
|
553
559
|
: isStaticStylesExpression(argument, functionPath, seenBindings)
|
|
554
560
|
)
|
|
555
561
|
);
|
|
556
562
|
}
|
|
557
563
|
|
|
558
|
-
if (t$
|
|
564
|
+
if (t$9.isTaggedTemplateExpression(node)) {
|
|
559
565
|
return (
|
|
560
566
|
isStaticStylesExpression(node.tag, functionPath, seenBindings) &&
|
|
561
567
|
isStaticStylesExpression(node.quasi, functionPath, seenBindings)
|
|
@@ -621,7 +627,7 @@ function processStaticHoists({
|
|
|
621
627
|
const staticHoists = [];
|
|
622
628
|
let lightDomRequested = options.defaultDomMode === "light";
|
|
623
629
|
|
|
624
|
-
if (t$
|
|
630
|
+
if (t$9.isBlockStatement(node.body)) {
|
|
625
631
|
for (let index = renderStatements.length - 1; index >= 0; index -= 1) {
|
|
626
632
|
const propertyOptions = getStaticPropsExpression(renderStatements[index]);
|
|
627
633
|
if (propertyOptions) {
|
|
@@ -675,9 +681,9 @@ function processStaticHoists({
|
|
|
675
681
|
|
|
676
682
|
const hasHoistedProperties = staticHoists.some((entry) => entry.name === "properties");
|
|
677
683
|
if (propertiesStatic.length > 0 && !hasHoistedProperties) {
|
|
678
|
-
const classProperties = t$
|
|
679
|
-
t$
|
|
680
|
-
t$
|
|
684
|
+
const classProperties = t$9.classProperty(
|
|
685
|
+
t$9.identifier("properties"),
|
|
686
|
+
t$9.objectExpression(propertiesStatic),
|
|
681
687
|
null,
|
|
682
688
|
[],
|
|
683
689
|
false
|
|
@@ -689,9 +695,9 @@ function processStaticHoists({
|
|
|
689
695
|
|
|
690
696
|
const hasHoistedStyles = staticHoists.some((entry) => entry.name === "styles");
|
|
691
697
|
if (staticStyles.length > 0 && !hasHoistedStyles) {
|
|
692
|
-
const stylesProperty = t$
|
|
693
|
-
t$
|
|
694
|
-
staticStyles.length === 1 ? staticStyles[0] : t$
|
|
698
|
+
const stylesProperty = t$9.classProperty(
|
|
699
|
+
t$9.identifier("styles"),
|
|
700
|
+
staticStyles.length === 1 ? staticStyles[0] : t$9.arrayExpression(staticStyles),
|
|
695
701
|
null,
|
|
696
702
|
[],
|
|
697
703
|
false
|
|
@@ -756,10 +762,10 @@ function processStaticHoists({
|
|
|
756
762
|
};
|
|
757
763
|
}
|
|
758
764
|
|
|
759
|
-
let t$
|
|
765
|
+
let t$8;
|
|
760
766
|
|
|
761
767
|
function setHandlersBabelTypes(types) {
|
|
762
|
-
t$
|
|
768
|
+
t$8 = types;
|
|
763
769
|
}
|
|
764
770
|
|
|
765
771
|
function isHoistableHandler(exprPath, componentPath) {
|
|
@@ -806,11 +812,11 @@ function generateHandlerName(attrName, usedNames) {
|
|
|
806
812
|
}
|
|
807
813
|
|
|
808
814
|
function normalizeHandlerBody(body) {
|
|
809
|
-
if (t$
|
|
810
|
-
return t$
|
|
815
|
+
if (t$8.isBlockStatement(body)) {
|
|
816
|
+
return t$8.cloneNode(body, true);
|
|
811
817
|
}
|
|
812
818
|
|
|
813
|
-
return t$
|
|
819
|
+
return t$8.blockStatement([t$8.returnStatement(t$8.cloneNode(body, true))]);
|
|
814
820
|
}
|
|
815
821
|
|
|
816
822
|
function hoistDeclaredHandlers(functionPath, usedNames) {
|
|
@@ -825,7 +831,7 @@ function hoistDeclaredHandlers(functionPath, usedNames) {
|
|
|
825
831
|
if (path.getFunctionParent() !== functionPath) return;
|
|
826
832
|
|
|
827
833
|
const id = path.node.id;
|
|
828
|
-
if (!t$
|
|
834
|
+
if (!t$8.isIdentifier(id)) return;
|
|
829
835
|
|
|
830
836
|
const initPath = path.get("init");
|
|
831
837
|
if (!initPath.isArrowFunctionExpression() && !initPath.isFunctionExpression()) {
|
|
@@ -849,13 +855,13 @@ function hoistDeclaredHandlers(functionPath, usedNames) {
|
|
|
849
855
|
binding.referencePaths.slice().forEach((refPath) => {
|
|
850
856
|
if (!refPath.node || refPath.removed) return;
|
|
851
857
|
refPath.replaceWith(
|
|
852
|
-
t$
|
|
858
|
+
t$8.memberExpression(t$8.thisExpression(), t$8.identifier(handlerName))
|
|
853
859
|
);
|
|
854
860
|
});
|
|
855
861
|
|
|
856
862
|
handlerInfos.push({
|
|
857
863
|
name: handlerName,
|
|
858
|
-
params: initPath.node.params.map((param) => t$
|
|
864
|
+
params: initPath.node.params.map((param) => t$8.cloneNode(param, true)),
|
|
859
865
|
body: normalizeHandlerBody(initPath.node.body),
|
|
860
866
|
async: initPath.node.async,
|
|
861
867
|
generator: initPath.node.generator,
|
|
@@ -885,7 +891,7 @@ function hoistEventHandlers(functionPath, usedNames) {
|
|
|
885
891
|
if (attrPath.getFunctionParent() !== functionPath) return;
|
|
886
892
|
|
|
887
893
|
const { node } = attrPath;
|
|
888
|
-
if (!t$
|
|
894
|
+
if (!t$8.isJSXIdentifier(node.name)) return;
|
|
889
895
|
|
|
890
896
|
const attrName = node.name.name;
|
|
891
897
|
if (!/^on[A-Z]/.test(attrName)) return;
|
|
@@ -907,15 +913,15 @@ function hoistEventHandlers(functionPath, usedNames) {
|
|
|
907
913
|
|
|
908
914
|
handlerInfos.push({
|
|
909
915
|
name: handlerName,
|
|
910
|
-
params: exprPath.node.params.map((param) => t$
|
|
916
|
+
params: exprPath.node.params.map((param) => t$8.cloneNode(param, true)),
|
|
911
917
|
body: normalizeHandlerBody(exprPath.node.body),
|
|
912
918
|
async: exprPath.node.async,
|
|
913
919
|
generator: exprPath.node.generator,
|
|
914
920
|
});
|
|
915
921
|
|
|
916
922
|
valuePath.replaceWith(
|
|
917
|
-
t$
|
|
918
|
-
t$
|
|
923
|
+
t$8.jsxExpressionContainer(
|
|
924
|
+
t$8.memberExpression(t$8.thisExpression(), t$8.identifier(handlerName))
|
|
919
925
|
)
|
|
920
926
|
);
|
|
921
927
|
},
|
|
@@ -925,7 +931,7 @@ function hoistEventHandlers(functionPath, usedNames) {
|
|
|
925
931
|
}
|
|
926
932
|
|
|
927
933
|
function isNativeIntrinsicJsxElement(nameNode) {
|
|
928
|
-
return t$
|
|
934
|
+
return t$8.isJSXIdentifier(nameNode) && /^[a-z]/.test(nameNode.name);
|
|
929
935
|
}
|
|
930
936
|
|
|
931
937
|
function collectNativeClassNameWarnings(functionPath, warn, options = {}) {
|
|
@@ -942,7 +948,7 @@ function collectNativeClassNameWarnings(functionPath, warn, options = {}) {
|
|
|
942
948
|
if (!isNativeIntrinsicJsxElement(openingElement.node.name)) return;
|
|
943
949
|
|
|
944
950
|
const { node } = attrPath;
|
|
945
|
-
if (!t$
|
|
951
|
+
if (!t$8.isJSXIdentifier(node.name, { name: "className" })) return;
|
|
946
952
|
|
|
947
953
|
warn({
|
|
948
954
|
code: "LITSX_NATIVE_CLASSNAME",
|
|
@@ -964,11 +970,11 @@ function processHandlers(functionPath, usedNames) {
|
|
|
964
970
|
}
|
|
965
971
|
|
|
966
972
|
function createHandlerClassMember({ name, params, body, async, generator }) {
|
|
967
|
-
const method = t$
|
|
973
|
+
const method = t$8.classMethod(
|
|
968
974
|
"method",
|
|
969
|
-
t$
|
|
970
|
-
params.map((param) => t$
|
|
971
|
-
t$
|
|
975
|
+
t$8.identifier(name),
|
|
976
|
+
params.map((param) => t$8.cloneNode(param, true)),
|
|
977
|
+
t$8.cloneNode(body, true)
|
|
972
978
|
);
|
|
973
979
|
|
|
974
980
|
method.async = Boolean(async);
|
|
@@ -977,7 +983,7 @@ function createHandlerClassMember({ name, params, body, async, generator }) {
|
|
|
977
983
|
return method;
|
|
978
984
|
}
|
|
979
985
|
|
|
980
|
-
let t$
|
|
986
|
+
let t$7;
|
|
981
987
|
|
|
982
988
|
function isCapitalizedComponentName$1(name) {
|
|
983
989
|
if (typeof name !== "string" || name.length === 0) {
|
|
@@ -989,7 +995,7 @@ function isCapitalizedComponentName$1(name) {
|
|
|
989
995
|
}
|
|
990
996
|
|
|
991
997
|
function setWrapperUtilsBabelTypes(nextTypes) {
|
|
992
|
-
t$
|
|
998
|
+
t$7 = nextTypes;
|
|
993
999
|
}
|
|
994
1000
|
|
|
995
1001
|
function emitWrapperWarnings(meta, warn) {
|
|
@@ -1044,7 +1050,7 @@ function maybeTransformWrappedVariableDeclarator({
|
|
|
1044
1050
|
});
|
|
1045
1051
|
|
|
1046
1052
|
const programPath = varPath.findParent((p) => p.isProgram());
|
|
1047
|
-
const localName = t$
|
|
1053
|
+
const localName = t$7.isIdentifier(varPath.node.id)
|
|
1048
1054
|
? varPath.node.id.name
|
|
1049
1055
|
: undefined;
|
|
1050
1056
|
|
|
@@ -1067,7 +1073,7 @@ function maybeTransformWrappedVariableDeclarator({
|
|
|
1067
1073
|
return true;
|
|
1068
1074
|
}
|
|
1069
1075
|
|
|
1070
|
-
if (t$
|
|
1076
|
+
if (t$7.isIdentifier(varPath.node.id)) {
|
|
1071
1077
|
varPath.scope.removeBinding(varPath.node.id.name);
|
|
1072
1078
|
}
|
|
1073
1079
|
|
|
@@ -1099,21 +1105,21 @@ function handlePotentialComponentExport({
|
|
|
1099
1105
|
}
|
|
1100
1106
|
|
|
1101
1107
|
if (
|
|
1102
|
-
t$
|
|
1103
|
-
(t$
|
|
1108
|
+
t$7.isFunctionDeclaration(declaration) ||
|
|
1109
|
+
(t$7.isVariableDeclaration(declaration) &&
|
|
1104
1110
|
declaration.declarations.length === 1 &&
|
|
1105
|
-
t$
|
|
1111
|
+
t$7.isArrowFunctionExpression(declaration.declarations[0].init))
|
|
1106
1112
|
) {
|
|
1107
1113
|
const funcPath = exportPath.get("declaration");
|
|
1108
1114
|
const declarationPath = funcPath.isVariableDeclaration()
|
|
1109
1115
|
? funcPath.get("declarations.0.init")
|
|
1110
1116
|
: funcPath;
|
|
1111
1117
|
let exportName;
|
|
1112
|
-
if (t$
|
|
1118
|
+
if (t$7.isFunctionDeclaration(declaration) && declaration.id) {
|
|
1113
1119
|
exportName = declaration.id.name;
|
|
1114
1120
|
} else if (
|
|
1115
|
-
t$
|
|
1116
|
-
t$
|
|
1121
|
+
t$7.isVariableDeclaration(declaration) &&
|
|
1122
|
+
t$7.isIdentifier(declaration.declarations[0].id)
|
|
1117
1123
|
) {
|
|
1118
1124
|
exportName = declaration.declarations[0].id.name;
|
|
1119
1125
|
}
|
|
@@ -1144,8 +1150,8 @@ function handlePotentialComponentExport({
|
|
|
1144
1150
|
|
|
1145
1151
|
exportPath.insertBefore(
|
|
1146
1152
|
isDefault
|
|
1147
|
-
? t$
|
|
1148
|
-
: t$
|
|
1153
|
+
? t$7.exportDefaultDeclaration(classNode)
|
|
1154
|
+
: t$7.exportNamedDeclaration(classNode, [])
|
|
1149
1155
|
);
|
|
1150
1156
|
exportPath.remove();
|
|
1151
1157
|
updateTransformState?.(state, classNode);
|
|
@@ -1154,12 +1160,12 @@ function handlePotentialComponentExport({
|
|
|
1154
1160
|
|
|
1155
1161
|
if (
|
|
1156
1162
|
typeof getWrapperMetadata === "function" &&
|
|
1157
|
-
t$
|
|
1163
|
+
t$7.isVariableDeclaration(declaration) &&
|
|
1158
1164
|
declaration.declarations.length === 1
|
|
1159
1165
|
) {
|
|
1160
1166
|
const declaratorPath = exportPath.get("declaration.declarations.0");
|
|
1161
1167
|
const initPath = declaratorPath.get("init");
|
|
1162
|
-
const exportName = t$
|
|
1168
|
+
const exportName = t$7.isIdentifier(declaratorPath.node.id)
|
|
1163
1169
|
? declaratorPath.node.id.name
|
|
1164
1170
|
: undefined;
|
|
1165
1171
|
const programPath = exportPath.findParent((p) => p.isProgram());
|
|
@@ -1197,8 +1203,8 @@ function handlePotentialComponentExport({
|
|
|
1197
1203
|
|
|
1198
1204
|
exportPath.replaceWith(
|
|
1199
1205
|
isDefault
|
|
1200
|
-
? t$
|
|
1201
|
-
: t$
|
|
1206
|
+
? t$7.exportDefaultDeclaration(classNode)
|
|
1207
|
+
: t$7.exportNamedDeclaration(classNode, [])
|
|
1202
1208
|
);
|
|
1203
1209
|
exportPath.requeue();
|
|
1204
1210
|
pruneWrapperImports(wrapperMeta);
|
|
@@ -1207,7 +1213,7 @@ function handlePotentialComponentExport({
|
|
|
1207
1213
|
}
|
|
1208
1214
|
}
|
|
1209
1215
|
|
|
1210
|
-
if (typeof getWrapperMetadata === "function" && isDefault && t$
|
|
1216
|
+
if (typeof getWrapperMetadata === "function" && isDefault && t$7.isCallExpression(declaration)) {
|
|
1211
1217
|
const callPath = exportPath.get("declaration");
|
|
1212
1218
|
const wrapperMeta = getWrapperMetadata(callPath);
|
|
1213
1219
|
if (!wrapperMeta) return false;
|
|
@@ -1240,7 +1246,7 @@ function handlePotentialComponentExport({
|
|
|
1240
1246
|
);
|
|
1241
1247
|
if (!classNode) return true;
|
|
1242
1248
|
|
|
1243
|
-
exportPath.replaceWith(t$
|
|
1249
|
+
exportPath.replaceWith(t$7.exportDefaultDeclaration(classNode));
|
|
1244
1250
|
exportPath.requeue();
|
|
1245
1251
|
pruneWrapperImports(wrapperMeta);
|
|
1246
1252
|
updateTransformState?.(state, classNode);
|
|
@@ -1250,23 +1256,23 @@ function handlePotentialComponentExport({
|
|
|
1250
1256
|
return false;
|
|
1251
1257
|
}
|
|
1252
1258
|
|
|
1253
|
-
let t$
|
|
1259
|
+
let t$6;
|
|
1254
1260
|
|
|
1255
1261
|
function setRefsBabelTypes(nextTypes) {
|
|
1256
|
-
t$
|
|
1262
|
+
t$6 = nextTypes;
|
|
1257
1263
|
}
|
|
1258
1264
|
|
|
1259
|
-
function createThisMemberExpression$
|
|
1260
|
-
return t$
|
|
1265
|
+
function createThisMemberExpression$4(propName) {
|
|
1266
|
+
return t$6.memberExpression(t$6.thisExpression(), t$6.identifier(propName));
|
|
1261
1267
|
}
|
|
1262
1268
|
|
|
1263
1269
|
function createManagedRefLookupExpression(refName) {
|
|
1264
|
-
const selectorLiteral = t$
|
|
1270
|
+
const selectorLiteral = t$6.stringLiteral(`[data-ref="${refName}"]`);
|
|
1265
1271
|
|
|
1266
|
-
const renderRootQuery = t$
|
|
1267
|
-
t$
|
|
1268
|
-
t$
|
|
1269
|
-
t$
|
|
1272
|
+
const renderRootQuery = t$6.optionalCallExpression(
|
|
1273
|
+
t$6.optionalMemberExpression(
|
|
1274
|
+
t$6.memberExpression(t$6.thisExpression(), t$6.identifier("renderRoot")),
|
|
1275
|
+
t$6.identifier("querySelector"),
|
|
1270
1276
|
false,
|
|
1271
1277
|
true
|
|
1272
1278
|
),
|
|
@@ -1274,55 +1280,55 @@ function createManagedRefLookupExpression(refName) {
|
|
|
1274
1280
|
false
|
|
1275
1281
|
);
|
|
1276
1282
|
|
|
1277
|
-
const hostQuery = t$
|
|
1278
|
-
t$
|
|
1279
|
-
[t$
|
|
1283
|
+
const hostQuery = t$6.callExpression(
|
|
1284
|
+
t$6.memberExpression(t$6.thisExpression(), t$6.identifier("querySelector")),
|
|
1285
|
+
[t$6.cloneNode(selectorLiteral)]
|
|
1280
1286
|
);
|
|
1281
1287
|
|
|
1282
|
-
return t$
|
|
1288
|
+
return t$6.logicalExpression("??", renderRootQuery, hostQuery);
|
|
1283
1289
|
}
|
|
1284
1290
|
|
|
1285
1291
|
function createForwardedTargetRefSyncStatement(propName, refName) {
|
|
1286
|
-
return t$
|
|
1287
|
-
t$
|
|
1288
|
-
t$
|
|
1289
|
-
t$
|
|
1290
|
-
t$
|
|
1291
|
-
[t$
|
|
1292
|
-
t$
|
|
1293
|
-
t$
|
|
1294
|
-
t$
|
|
1295
|
-
t$
|
|
1296
|
-
createThisMemberExpression$
|
|
1292
|
+
return t$6.expressionStatement(
|
|
1293
|
+
t$6.callExpression(t$6.identifier("useCallbackRef"), [
|
|
1294
|
+
t$6.thisExpression(),
|
|
1295
|
+
t$6.arrowFunctionExpression([], createManagedRefLookupExpression(refName)),
|
|
1296
|
+
t$6.arrowFunctionExpression(
|
|
1297
|
+
[t$6.identifier("node")],
|
|
1298
|
+
t$6.blockStatement([
|
|
1299
|
+
t$6.variableDeclaration("const", [
|
|
1300
|
+
t$6.variableDeclarator(
|
|
1301
|
+
t$6.identifier("componentRef"),
|
|
1302
|
+
createThisMemberExpression$4(propName)
|
|
1297
1303
|
),
|
|
1298
1304
|
]),
|
|
1299
|
-
t$
|
|
1300
|
-
t$
|
|
1305
|
+
t$6.ifStatement(
|
|
1306
|
+
t$6.binaryExpression(
|
|
1301
1307
|
"===",
|
|
1302
|
-
t$
|
|
1303
|
-
t$
|
|
1308
|
+
t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
|
|
1309
|
+
t$6.stringLiteral("function")
|
|
1304
1310
|
),
|
|
1305
|
-
t$
|
|
1306
|
-
t$
|
|
1307
|
-
t$
|
|
1311
|
+
t$6.blockStatement([
|
|
1312
|
+
t$6.expressionStatement(
|
|
1313
|
+
t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
|
|
1308
1314
|
),
|
|
1309
1315
|
]),
|
|
1310
|
-
t$
|
|
1311
|
-
t$
|
|
1316
|
+
t$6.ifStatement(
|
|
1317
|
+
t$6.logicalExpression(
|
|
1312
1318
|
"&&",
|
|
1313
|
-
t$
|
|
1314
|
-
t$
|
|
1319
|
+
t$6.identifier("componentRef"),
|
|
1320
|
+
t$6.binaryExpression(
|
|
1315
1321
|
"===",
|
|
1316
|
-
t$
|
|
1317
|
-
t$
|
|
1322
|
+
t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
|
|
1323
|
+
t$6.stringLiteral("object")
|
|
1318
1324
|
)
|
|
1319
1325
|
),
|
|
1320
|
-
t$
|
|
1321
|
-
t$
|
|
1322
|
-
t$
|
|
1326
|
+
t$6.blockStatement([
|
|
1327
|
+
t$6.expressionStatement(
|
|
1328
|
+
t$6.assignmentExpression(
|
|
1323
1329
|
"=",
|
|
1324
|
-
t$
|
|
1325
|
-
t$
|
|
1330
|
+
t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
|
|
1331
|
+
t$6.identifier("node")
|
|
1326
1332
|
)
|
|
1327
1333
|
),
|
|
1328
1334
|
])
|
|
@@ -1330,13 +1336,13 @@ function createForwardedTargetRefSyncStatement(propName, refName) {
|
|
|
1330
1336
|
),
|
|
1331
1337
|
])
|
|
1332
1338
|
),
|
|
1333
|
-
t$
|
|
1339
|
+
t$6.arrayExpression([createThisMemberExpression$4(propName)]),
|
|
1334
1340
|
])
|
|
1335
1341
|
);
|
|
1336
1342
|
}
|
|
1337
1343
|
|
|
1338
1344
|
function isStandardElementJsxName(nameNode) {
|
|
1339
|
-
if (!t$
|
|
1345
|
+
if (!t$6.isJSXIdentifier(nameNode)) {
|
|
1340
1346
|
return false;
|
|
1341
1347
|
}
|
|
1342
1348
|
|
|
@@ -1345,46 +1351,46 @@ function isStandardElementJsxName(nameNode) {
|
|
|
1345
1351
|
}
|
|
1346
1352
|
|
|
1347
1353
|
function createComponentInstanceRefSyncStatement() {
|
|
1348
|
-
return t$
|
|
1349
|
-
t$
|
|
1350
|
-
t$
|
|
1351
|
-
t$
|
|
1352
|
-
t$
|
|
1353
|
-
[t$
|
|
1354
|
-
t$
|
|
1355
|
-
t$
|
|
1356
|
-
t$
|
|
1357
|
-
t$
|
|
1358
|
-
createThisMemberExpression$
|
|
1354
|
+
return t$6.expressionStatement(
|
|
1355
|
+
t$6.callExpression(t$6.identifier("useCallbackRef"), [
|
|
1356
|
+
t$6.thisExpression(),
|
|
1357
|
+
t$6.arrowFunctionExpression([], t$6.thisExpression()),
|
|
1358
|
+
t$6.arrowFunctionExpression(
|
|
1359
|
+
[t$6.identifier("node")],
|
|
1360
|
+
t$6.blockStatement([
|
|
1361
|
+
t$6.variableDeclaration("const", [
|
|
1362
|
+
t$6.variableDeclarator(
|
|
1363
|
+
t$6.identifier("componentRef"),
|
|
1364
|
+
createThisMemberExpression$4("ref")
|
|
1359
1365
|
),
|
|
1360
1366
|
]),
|
|
1361
|
-
t$
|
|
1362
|
-
t$
|
|
1367
|
+
t$6.ifStatement(
|
|
1368
|
+
t$6.binaryExpression(
|
|
1363
1369
|
"===",
|
|
1364
|
-
t$
|
|
1365
|
-
t$
|
|
1370
|
+
t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
|
|
1371
|
+
t$6.stringLiteral("function")
|
|
1366
1372
|
),
|
|
1367
|
-
t$
|
|
1368
|
-
t$
|
|
1369
|
-
t$
|
|
1373
|
+
t$6.blockStatement([
|
|
1374
|
+
t$6.expressionStatement(
|
|
1375
|
+
t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
|
|
1370
1376
|
),
|
|
1371
1377
|
]),
|
|
1372
|
-
t$
|
|
1373
|
-
t$
|
|
1378
|
+
t$6.ifStatement(
|
|
1379
|
+
t$6.logicalExpression(
|
|
1374
1380
|
"&&",
|
|
1375
|
-
t$
|
|
1376
|
-
t$
|
|
1381
|
+
t$6.identifier("componentRef"),
|
|
1382
|
+
t$6.binaryExpression(
|
|
1377
1383
|
"===",
|
|
1378
|
-
t$
|
|
1379
|
-
t$
|
|
1384
|
+
t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
|
|
1385
|
+
t$6.stringLiteral("object")
|
|
1380
1386
|
)
|
|
1381
1387
|
),
|
|
1382
|
-
t$
|
|
1383
|
-
t$
|
|
1384
|
-
t$
|
|
1388
|
+
t$6.blockStatement([
|
|
1389
|
+
t$6.expressionStatement(
|
|
1390
|
+
t$6.assignmentExpression(
|
|
1385
1391
|
"=",
|
|
1386
|
-
t$
|
|
1387
|
-
t$
|
|
1392
|
+
t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
|
|
1393
|
+
t$6.identifier("node")
|
|
1388
1394
|
)
|
|
1389
1395
|
),
|
|
1390
1396
|
])
|
|
@@ -1392,7 +1398,7 @@ function createComponentInstanceRefSyncStatement() {
|
|
|
1392
1398
|
),
|
|
1393
1399
|
])
|
|
1394
1400
|
),
|
|
1395
|
-
t$
|
|
1401
|
+
t$6.arrayExpression([createThisMemberExpression$4("ref")]),
|
|
1396
1402
|
])
|
|
1397
1403
|
);
|
|
1398
1404
|
}
|
|
@@ -1403,27 +1409,27 @@ function hasRefProp(functionPath) {
|
|
|
1403
1409
|
return false;
|
|
1404
1410
|
}
|
|
1405
1411
|
|
|
1406
|
-
if (t$
|
|
1412
|
+
if (t$6.isObjectPattern(firstParam)) {
|
|
1407
1413
|
return firstParam.properties.some((property) => {
|
|
1408
|
-
if (!t$
|
|
1414
|
+
if (!t$6.isObjectProperty(property)) return false;
|
|
1409
1415
|
return (
|
|
1410
|
-
t$
|
|
1411
|
-
t$
|
|
1416
|
+
t$6.isIdentifier(property.key, { name: "ref" }) ||
|
|
1417
|
+
t$6.isStringLiteral(property.key, { value: "ref" })
|
|
1412
1418
|
);
|
|
1413
1419
|
});
|
|
1414
1420
|
}
|
|
1415
1421
|
|
|
1416
|
-
if (t$
|
|
1422
|
+
if (t$6.isAssignmentPattern(firstParam) && t$6.isObjectPattern(firstParam.left)) {
|
|
1417
1423
|
return firstParam.left.properties.some((property) => {
|
|
1418
|
-
if (!t$
|
|
1424
|
+
if (!t$6.isObjectProperty(property)) return false;
|
|
1419
1425
|
return (
|
|
1420
|
-
t$
|
|
1421
|
-
t$
|
|
1426
|
+
t$6.isIdentifier(property.key, { name: "ref" }) ||
|
|
1427
|
+
t$6.isStringLiteral(property.key, { value: "ref" })
|
|
1422
1428
|
);
|
|
1423
1429
|
});
|
|
1424
1430
|
}
|
|
1425
1431
|
|
|
1426
|
-
if (t$
|
|
1432
|
+
if (t$6.isIdentifier(firstParam)) {
|
|
1427
1433
|
const binding = functionPath.scope.getBinding(firstParam.name);
|
|
1428
1434
|
if (!binding) return false;
|
|
1429
1435
|
return binding.referencePaths.some((refPath) => {
|
|
@@ -1432,7 +1438,7 @@ function hasRefProp(functionPath) {
|
|
|
1432
1438
|
parentPath &&
|
|
1433
1439
|
parentPath.isMemberExpression() &&
|
|
1434
1440
|
parentPath.node.object === refPath.node &&
|
|
1435
|
-
t$
|
|
1441
|
+
t$6.isIdentifier(parentPath.node.property, { name: "ref" }) &&
|
|
1436
1442
|
!parentPath.node.computed
|
|
1437
1443
|
);
|
|
1438
1444
|
});
|
|
@@ -1451,14 +1457,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
|
|
|
1451
1457
|
|
|
1452
1458
|
functionPath.traverse({
|
|
1453
1459
|
JSXAttribute(attrPath) {
|
|
1454
|
-
if (!t$
|
|
1460
|
+
if (!t$6.isJSXIdentifier(attrPath.node.name, { name: "ref" })) return;
|
|
1455
1461
|
|
|
1456
1462
|
const value = attrPath.node.value;
|
|
1457
|
-
if (!t$
|
|
1463
|
+
if (!t$6.isJSXExpressionContainer(value)) return;
|
|
1458
1464
|
if (
|
|
1459
|
-
!t$
|
|
1460
|
-
!t$
|
|
1461
|
-
!t$
|
|
1465
|
+
!t$6.isMemberExpression(value.expression) ||
|
|
1466
|
+
!t$6.isThisExpression(value.expression.object) ||
|
|
1467
|
+
!t$6.isIdentifier(value.expression.property, { name: propName }) ||
|
|
1462
1468
|
value.expression.computed
|
|
1463
1469
|
) {
|
|
1464
1470
|
return;
|
|
@@ -1470,7 +1476,7 @@ function lowerForwardedElementRefs(functionPath, propName) {
|
|
|
1470
1476
|
|
|
1471
1477
|
const managedRefName = functionPath.scope.generateUidIdentifier(`${propName}Element`).name;
|
|
1472
1478
|
attrPath.replaceWith(
|
|
1473
|
-
t$
|
|
1479
|
+
t$6.jsxAttribute(t$6.jsxIdentifier("data-ref"), t$6.stringLiteral(managedRefName))
|
|
1474
1480
|
);
|
|
1475
1481
|
|
|
1476
1482
|
if (seenRefNames.has(managedRefName)) return;
|
|
@@ -1482,14 +1488,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
|
|
|
1482
1488
|
return callbackStatements;
|
|
1483
1489
|
}
|
|
1484
1490
|
|
|
1485
|
-
let t$
|
|
1491
|
+
let t$5;
|
|
1486
1492
|
|
|
1487
1493
|
function setClassGenerationBabelTypes(nextTypes) {
|
|
1488
|
-
t$
|
|
1494
|
+
t$5 = nextTypes;
|
|
1489
1495
|
}
|
|
1490
1496
|
|
|
1491
|
-
function createThisMemberExpression$
|
|
1492
|
-
return t$
|
|
1497
|
+
function createThisMemberExpression$3(propName) {
|
|
1498
|
+
return t$5.memberExpression(t$5.thisExpression(), t$5.identifier(propName));
|
|
1493
1499
|
}
|
|
1494
1500
|
|
|
1495
1501
|
function buildClassMembers({
|
|
@@ -1501,26 +1507,26 @@ function buildClassMembers({
|
|
|
1501
1507
|
}) {
|
|
1502
1508
|
if (defaults.size > 0) {
|
|
1503
1509
|
const constructorStatements = [
|
|
1504
|
-
t$
|
|
1510
|
+
t$5.expressionStatement(t$5.callExpression(t$5.super(), [])),
|
|
1505
1511
|
];
|
|
1506
1512
|
|
|
1507
1513
|
defaults.forEach((defaultExpression, propName) => {
|
|
1508
1514
|
constructorStatements.push(
|
|
1509
|
-
t$
|
|
1510
|
-
t$
|
|
1515
|
+
t$5.expressionStatement(
|
|
1516
|
+
t$5.assignmentExpression(
|
|
1511
1517
|
"??=",
|
|
1512
|
-
createThisMemberExpression$
|
|
1513
|
-
t$
|
|
1518
|
+
createThisMemberExpression$3(propName),
|
|
1519
|
+
t$5.cloneNode(defaultExpression)
|
|
1514
1520
|
)
|
|
1515
1521
|
)
|
|
1516
1522
|
);
|
|
1517
1523
|
});
|
|
1518
1524
|
|
|
1519
|
-
const constructorMethod = t$
|
|
1525
|
+
const constructorMethod = t$5.classMethod(
|
|
1520
1526
|
"constructor",
|
|
1521
|
-
t$
|
|
1527
|
+
t$5.identifier("constructor"),
|
|
1522
1528
|
[],
|
|
1523
|
-
t$
|
|
1529
|
+
t$5.blockStatement(constructorStatements)
|
|
1524
1530
|
);
|
|
1525
1531
|
|
|
1526
1532
|
const insertionIndex = classMembers.findIndex((member) => !member.static);
|
|
@@ -1535,11 +1541,11 @@ function buildClassMembers({
|
|
|
1535
1541
|
createHandlerClassMember(handler)
|
|
1536
1542
|
);
|
|
1537
1543
|
|
|
1538
|
-
const renderMethod = t$
|
|
1544
|
+
const renderMethod = t$5.classMethod(
|
|
1539
1545
|
"method",
|
|
1540
|
-
t$
|
|
1546
|
+
t$5.identifier("render"),
|
|
1541
1547
|
[],
|
|
1542
|
-
t$
|
|
1548
|
+
t$5.blockStatement(renderStatements)
|
|
1543
1549
|
);
|
|
1544
1550
|
|
|
1545
1551
|
classMembers.push(...handlerMembers, renderMethod);
|
|
@@ -1557,10 +1563,10 @@ function createComponentClass({
|
|
|
1557
1563
|
needsUnsafeCss,
|
|
1558
1564
|
needsCallbackRef = false,
|
|
1559
1565
|
}) {
|
|
1560
|
-
const classNode = t$
|
|
1561
|
-
t$
|
|
1562
|
-
t$
|
|
1563
|
-
t$
|
|
1566
|
+
const classNode = t$5.classDeclaration(
|
|
1567
|
+
t$5.identifier(className),
|
|
1568
|
+
t$5.identifier("LitElement"),
|
|
1569
|
+
t$5.classBody(classMembers)
|
|
1564
1570
|
);
|
|
1565
1571
|
|
|
1566
1572
|
if (hoistMembers.length > 0) {
|
|
@@ -1569,8 +1575,8 @@ function createComponentClass({
|
|
|
1569
1575
|
classNode._litsxStaticSymbolDeclarations = hoistSymbolDeclarations;
|
|
1570
1576
|
}
|
|
1571
1577
|
if (needsStaticHoistsMixin) {
|
|
1572
|
-
classNode.superClass = t$
|
|
1573
|
-
t$
|
|
1578
|
+
classNode.superClass = t$5.callExpression(
|
|
1579
|
+
t$5.identifier("LitsxStaticHoistsMixin"),
|
|
1574
1580
|
[classNode.superClass]
|
|
1575
1581
|
);
|
|
1576
1582
|
classNode._needsStaticHoistsMixin = true;
|
|
@@ -1578,8 +1584,8 @@ function createComponentClass({
|
|
|
1578
1584
|
}
|
|
1579
1585
|
|
|
1580
1586
|
if (lightDomRequested) {
|
|
1581
|
-
classNode.superClass = t$
|
|
1582
|
-
t$
|
|
1587
|
+
classNode.superClass = t$5.callExpression(
|
|
1588
|
+
t$5.identifier("LightDomMixin"),
|
|
1583
1589
|
[classNode.superClass]
|
|
1584
1590
|
);
|
|
1585
1591
|
classNode._needsLightDomMixin = true;
|
|
@@ -1592,68 +1598,14 @@ function createComponentClass({
|
|
|
1592
1598
|
return classNode;
|
|
1593
1599
|
}
|
|
1594
1600
|
|
|
1595
|
-
let t$
|
|
1601
|
+
let t$4;
|
|
1596
1602
|
|
|
1597
1603
|
function setParamRewriteBabelTypes(nextTypes) {
|
|
1598
|
-
t$
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
function createThisMemberExpression$1(propName) {
|
|
1602
|
-
return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
function getBoundPropName(bindingInfo) {
|
|
1606
|
-
if (typeof bindingInfo === "string") {
|
|
1607
|
-
return bindingInfo;
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
if (bindingInfo && typeof bindingInfo === "object") {
|
|
1611
|
-
return bindingInfo.bindKey ?? null;
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
return null;
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
function isPropBackedCallee(node, localNames) {
|
|
1618
|
-
if (t$2.isIdentifier(node)) {
|
|
1619
|
-
return localNames.includes(node.name);
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
if (
|
|
1623
|
-
t$2.isMemberExpression(node) &&
|
|
1624
|
-
!node.computed &&
|
|
1625
|
-
t$2.isIdentifier(node.object)
|
|
1626
|
-
) {
|
|
1627
|
-
return localNames.includes(node.object.name) && node.object.name === "props";
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
return false;
|
|
1604
|
+
t$4 = nextTypes;
|
|
1631
1605
|
}
|
|
1632
1606
|
|
|
1633
|
-
function
|
|
1634
|
-
|
|
1635
|
-
const propName = getBoundPropName(bindings.get(node.name));
|
|
1636
|
-
return propName ? createThisMemberExpression$1(propName) : node;
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
if (
|
|
1640
|
-
t$2.isMemberExpression(node) &&
|
|
1641
|
-
!node.computed &&
|
|
1642
|
-
t$2.isIdentifier(node.object)
|
|
1643
|
-
) {
|
|
1644
|
-
const propName = getBoundPropName(bindings.get(node.object.name));
|
|
1645
|
-
if (!propName) {
|
|
1646
|
-
return node;
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
return t$2.memberExpression(
|
|
1650
|
-
createThisMemberExpression$1(propName),
|
|
1651
|
-
t$2.cloneNode(node.property),
|
|
1652
|
-
false
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
return node;
|
|
1607
|
+
function createThisMemberExpression$2(propName) {
|
|
1608
|
+
return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
|
|
1657
1609
|
}
|
|
1658
1610
|
|
|
1659
1611
|
function transformJSXExpressions(jsxPath, bindings, state = null) {
|
|
@@ -1661,30 +1613,13 @@ function transformJSXExpressions(jsxPath, bindings, state = null) {
|
|
|
1661
1613
|
|
|
1662
1614
|
jsxPath.traverse({
|
|
1663
1615
|
JSXExpressionContainer(expressionPath) {
|
|
1664
|
-
if (t$
|
|
1665
|
-
const { callee, arguments: args } = expressionPath.node.expression;
|
|
1666
|
-
if (isPropBackedCallee(callee, localNames)) {
|
|
1667
|
-
if (state) {
|
|
1668
|
-
state.__litsxNeedsRendererCallImport = true;
|
|
1669
|
-
}
|
|
1670
|
-
expressionPath.node.expression = t$2.callExpression(
|
|
1671
|
-
t$2.identifier("renderRendererCall"),
|
|
1672
|
-
[
|
|
1673
|
-
getPropBackedCalleeReplacement(callee, bindings),
|
|
1674
|
-
...args,
|
|
1675
|
-
]
|
|
1676
|
-
);
|
|
1677
|
-
return;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
if (t$2.isIdentifier(expressionPath.node.expression)) {
|
|
1616
|
+
if (t$4.isIdentifier(expressionPath.node.expression)) {
|
|
1682
1617
|
const name = expressionPath.node.expression.name;
|
|
1683
1618
|
if (localNames.includes(name)) {
|
|
1684
1619
|
const propName = bindings.get(name) || name;
|
|
1685
|
-
expressionPath.node.expression = t$
|
|
1686
|
-
t$
|
|
1687
|
-
t$
|
|
1620
|
+
expressionPath.node.expression = t$4.memberExpression(
|
|
1621
|
+
t$4.thisExpression(),
|
|
1622
|
+
t$4.identifier(propName)
|
|
1688
1623
|
);
|
|
1689
1624
|
}
|
|
1690
1625
|
}
|
|
@@ -1703,16 +1638,16 @@ function registerLocalPropAliases(functionPath, bindings) {
|
|
|
1703
1638
|
if (path.getFunctionParent() !== functionPath) return;
|
|
1704
1639
|
|
|
1705
1640
|
const { id, init } = path.node;
|
|
1706
|
-
if (!t$
|
|
1641
|
+
if (!t$4.isIdentifier(init)) return;
|
|
1707
1642
|
|
|
1708
|
-
if (t$
|
|
1643
|
+
if (t$4.isIdentifier(id)) {
|
|
1709
1644
|
if (bindings.has(id.name) || !bindings.has(init.name)) return;
|
|
1710
1645
|
bindings.set(id.name, bindings.get(init.name));
|
|
1711
1646
|
changed = true;
|
|
1712
1647
|
return;
|
|
1713
1648
|
}
|
|
1714
1649
|
|
|
1715
|
-
if (!t$
|
|
1650
|
+
if (!t$4.isObjectPattern(id)) return;
|
|
1716
1651
|
|
|
1717
1652
|
const bindingInfo = bindings.get(init.name);
|
|
1718
1653
|
if (!bindingInfo || typeof bindingInfo !== "object" || bindingInfo.kind !== "alias") {
|
|
@@ -1720,17 +1655,17 @@ function registerLocalPropAliases(functionPath, bindings) {
|
|
|
1720
1655
|
}
|
|
1721
1656
|
|
|
1722
1657
|
id.properties.forEach((property) => {
|
|
1723
|
-
if (!t$
|
|
1658
|
+
if (!t$4.isObjectProperty(property)) return;
|
|
1724
1659
|
|
|
1725
|
-
const keyName = t$
|
|
1660
|
+
const keyName = t$4.isIdentifier(property.key)
|
|
1726
1661
|
? property.key.name
|
|
1727
|
-
: t$
|
|
1662
|
+
: t$4.isStringLiteral(property.key)
|
|
1728
1663
|
? property.key.value
|
|
1729
1664
|
: null;
|
|
1730
1665
|
|
|
1731
1666
|
if (!keyName || !bindingInfo.properties.has(keyName)) return;
|
|
1732
1667
|
|
|
1733
|
-
if (t$
|
|
1668
|
+
if (t$4.isIdentifier(property.value)) {
|
|
1734
1669
|
if (!bindings.has(property.value.name)) {
|
|
1735
1670
|
bindings.set(property.value.name, keyName);
|
|
1736
1671
|
changed = true;
|
|
@@ -1739,8 +1674,8 @@ function registerLocalPropAliases(functionPath, bindings) {
|
|
|
1739
1674
|
}
|
|
1740
1675
|
|
|
1741
1676
|
if (
|
|
1742
|
-
t$
|
|
1743
|
-
t$
|
|
1677
|
+
t$4.isAssignmentPattern(property.value) &&
|
|
1678
|
+
t$4.isIdentifier(property.value.left) &&
|
|
1744
1679
|
!bindings.has(property.value.left.name)
|
|
1745
1680
|
) {
|
|
1746
1681
|
bindings.set(property.value.left.name, keyName);
|
|
@@ -1773,10 +1708,10 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1773
1708
|
aliasId = functionPath.scope.generateUidIdentifier(propName);
|
|
1774
1709
|
capturedPropAliases.set(propName, aliasId);
|
|
1775
1710
|
}
|
|
1776
|
-
return t$
|
|
1711
|
+
return t$4.cloneNode(aliasId);
|
|
1777
1712
|
}
|
|
1778
1713
|
|
|
1779
|
-
return t$
|
|
1714
|
+
return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
|
|
1780
1715
|
}
|
|
1781
1716
|
|
|
1782
1717
|
bindings.forEach((bindingInfo, localName) => {
|
|
@@ -1805,7 +1740,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1805
1740
|
return;
|
|
1806
1741
|
}
|
|
1807
1742
|
|
|
1808
|
-
refPath.replaceWith(t$
|
|
1743
|
+
refPath.replaceWith(t$4.thisExpression());
|
|
1809
1744
|
return;
|
|
1810
1745
|
}
|
|
1811
1746
|
|
|
@@ -1816,7 +1751,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1816
1751
|
refPath.parentPath &&
|
|
1817
1752
|
refPath.parentPath.isMemberExpression() &&
|
|
1818
1753
|
refPath.parentKey === "object" &&
|
|
1819
|
-
t$
|
|
1754
|
+
t$4.isIdentifier(refPath.parentPath.node.property) &&
|
|
1820
1755
|
!refPath.parentPath.node.computed
|
|
1821
1756
|
) {
|
|
1822
1757
|
const propName = refPath.parentPath.node.property.name;
|
|
@@ -1838,7 +1773,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1838
1773
|
refPath.parentPath &&
|
|
1839
1774
|
refPath.parentPath.isMemberExpression() &&
|
|
1840
1775
|
refPath.parentKey === "object" &&
|
|
1841
|
-
t$
|
|
1776
|
+
t$4.isIdentifier(refPath.parentPath.node.property) &&
|
|
1842
1777
|
!refPath.parentPath.node.computed
|
|
1843
1778
|
) {
|
|
1844
1779
|
const propName = refPath.parentPath.node.property.name;
|
|
@@ -1864,7 +1799,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1864
1799
|
refPath.parentKey === "value"
|
|
1865
1800
|
) {
|
|
1866
1801
|
refPath.replaceWith(
|
|
1867
|
-
t$
|
|
1802
|
+
t$4.jsxExpressionContainer(
|
|
1868
1803
|
getReplacementForProp(targetProp || localName, refPath)
|
|
1869
1804
|
)
|
|
1870
1805
|
);
|
|
@@ -1885,12 +1820,208 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
|
|
|
1885
1820
|
});
|
|
1886
1821
|
|
|
1887
1822
|
return Array.from(capturedPropAliases.entries()).map(([propName, aliasId]) =>
|
|
1888
|
-
t$
|
|
1889
|
-
t$
|
|
1823
|
+
t$4.variableDeclaration("const", [
|
|
1824
|
+
t$4.variableDeclarator(t$4.cloneNode(aliasId), createThisMemberExpression$2(propName)),
|
|
1890
1825
|
])
|
|
1891
1826
|
);
|
|
1892
1827
|
}
|
|
1893
1828
|
|
|
1829
|
+
let t$3;
|
|
1830
|
+
|
|
1831
|
+
function setRendererCallsBabelTypes(nextTypes) {
|
|
1832
|
+
t$3 = nextTypes;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
function createThisMemberExpression$1(propName) {
|
|
1836
|
+
return t$3.memberExpression(t$3.thisExpression(), t$3.identifier(propName));
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
function getBoundPropName(bindingInfo) {
|
|
1840
|
+
if (typeof bindingInfo === "string") {
|
|
1841
|
+
return bindingInfo;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
if (bindingInfo && typeof bindingInfo === "object") {
|
|
1845
|
+
return bindingInfo.bindKey ?? null;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
return null;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
function isPropBackedCallee(node, localNames) {
|
|
1852
|
+
if (t$3.isIdentifier(node)) {
|
|
1853
|
+
return localNames.includes(node.name);
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
if (
|
|
1857
|
+
t$3.isMemberExpression(node) &&
|
|
1858
|
+
!node.computed &&
|
|
1859
|
+
t$3.isIdentifier(node.object)
|
|
1860
|
+
) {
|
|
1861
|
+
return localNames.includes(node.object.name) && node.object.name === "props";
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
return false;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
function getPropBackedCalleeReplacement(node, bindings) {
|
|
1868
|
+
if (t$3.isIdentifier(node)) {
|
|
1869
|
+
const propName = getBoundPropName(bindings.get(node.name));
|
|
1870
|
+
return propName ? createThisMemberExpression$1(propName) : node;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
if (
|
|
1874
|
+
t$3.isMemberExpression(node) &&
|
|
1875
|
+
!node.computed &&
|
|
1876
|
+
t$3.isIdentifier(node.object)
|
|
1877
|
+
) {
|
|
1878
|
+
const propName = getBoundPropName(bindings.get(node.object.name));
|
|
1879
|
+
if (!propName) {
|
|
1880
|
+
return node;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
return t$3.memberExpression(
|
|
1884
|
+
createThisMemberExpression$1(propName),
|
|
1885
|
+
t$3.cloneNode(node.property),
|
|
1886
|
+
false
|
|
1887
|
+
);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
return node;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
function transformJSXRendererCalls(jsxPath, bindings, state = null) {
|
|
1894
|
+
const localNames = Array.from(bindings.keys());
|
|
1895
|
+
|
|
1896
|
+
jsxPath.traverse({
|
|
1897
|
+
JSXExpressionContainer(expressionPath) {
|
|
1898
|
+
if (!t$3.isCallExpression(expressionPath.node.expression)) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
const { callee, arguments: args } = expressionPath.node.expression;
|
|
1903
|
+
if (!isPropBackedCallee(callee, localNames)) {
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
if (state) {
|
|
1908
|
+
state.__litsxNeedsRendererCallImport = true;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
expressionPath.node.expression = t$3.callExpression(
|
|
1912
|
+
t$3.identifier("renderRendererCall"),
|
|
1913
|
+
[
|
|
1914
|
+
getPropBackedCalleeReplacement(callee, bindings),
|
|
1915
|
+
...args,
|
|
1916
|
+
]
|
|
1917
|
+
);
|
|
1918
|
+
},
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
let t$2;
|
|
1923
|
+
|
|
1924
|
+
function setRenderBodyBabelTypes(nextTypes) {
|
|
1925
|
+
t$2 = nextTypes;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
function createThisMemberExpression(propName) {
|
|
1929
|
+
return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function createNestedInitializerStatement(pattern, root, defaultValue) {
|
|
1933
|
+
const rootAccess = createThisMemberExpression(root);
|
|
1934
|
+
let sourceExpression = rootAccess;
|
|
1935
|
+
|
|
1936
|
+
if (defaultValue) {
|
|
1937
|
+
sourceExpression = t$2.logicalExpression(
|
|
1938
|
+
"??",
|
|
1939
|
+
t$2.cloneNode(rootAccess),
|
|
1940
|
+
t$2.cloneNode(defaultValue)
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
return t$2.variableDeclaration("const", [
|
|
1945
|
+
t$2.variableDeclarator(t$2.cloneNode(pattern), sourceExpression),
|
|
1946
|
+
]);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
function collectReturnStatement(functionPath, bindings, state) {
|
|
1950
|
+
let returnStatement = null;
|
|
1951
|
+
|
|
1952
|
+
functionPath.traverse({
|
|
1953
|
+
ReturnStatement(returnPath) {
|
|
1954
|
+
if (t$2.isJSXElement(returnPath.node.argument)) {
|
|
1955
|
+
returnStatement = returnPath.node;
|
|
1956
|
+
transformJSXRendererCalls(returnPath, bindings, state);
|
|
1957
|
+
transformJSXExpressions(returnPath, bindings, state);
|
|
1958
|
+
}
|
|
1959
|
+
},
|
|
1960
|
+
});
|
|
1961
|
+
|
|
1962
|
+
return returnStatement;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
function prepareComponentRender(functionPath, node, propertyNames, bindings, nestedInitializers, options = {}) {
|
|
1966
|
+
const returnStatement = collectReturnStatement(
|
|
1967
|
+
functionPath,
|
|
1968
|
+
bindings,
|
|
1969
|
+
options.state ?? null
|
|
1970
|
+
);
|
|
1971
|
+
|
|
1972
|
+
if (!returnStatement) {
|
|
1973
|
+
return null;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
const capturedPropAliasStatements = replaceParamReferences(
|
|
1977
|
+
functionPath,
|
|
1978
|
+
bindings,
|
|
1979
|
+
propertyNames
|
|
1980
|
+
);
|
|
1981
|
+
const prefixStatements = [];
|
|
1982
|
+
|
|
1983
|
+
const forwardRefOptions = options.forwardRef || null;
|
|
1984
|
+
const resolvedRefPropName =
|
|
1985
|
+
forwardRefOptions?.propName ||
|
|
1986
|
+
(propertyNames.has("ref") || hasRefProp(functionPath) ? "ref" : null);
|
|
1987
|
+
let needsCallbackRef = false;
|
|
1988
|
+
|
|
1989
|
+
if (resolvedRefPropName) {
|
|
1990
|
+
prefixStatements.push(
|
|
1991
|
+
...lowerForwardedElementRefs(functionPath, resolvedRefPropName)
|
|
1992
|
+
);
|
|
1993
|
+
needsCallbackRef =
|
|
1994
|
+
prefixStatements.some(
|
|
1995
|
+
(statement) =>
|
|
1996
|
+
t$2.isExpressionStatement(statement) &&
|
|
1997
|
+
t$2.isCallExpression(statement.expression) &&
|
|
1998
|
+
t$2.isIdentifier(statement.expression.callee, { name: "useCallbackRef" })
|
|
1999
|
+
) || needsCallbackRef;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
if (resolvedRefPropName && !forwardRefOptions) {
|
|
2003
|
+
prefixStatements.push(createComponentInstanceRefSyncStatement());
|
|
2004
|
+
needsCallbackRef = true;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
if (capturedPropAliasStatements.length > 0) {
|
|
2008
|
+
prefixStatements.push(...capturedPropAliasStatements);
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
if (nestedInitializers.length > 0) {
|
|
2012
|
+
const initializerStatements = nestedInitializers.map(({ pattern, root, defaultValue }) =>
|
|
2013
|
+
createNestedInitializerStatement(pattern, root, defaultValue)
|
|
2014
|
+
);
|
|
2015
|
+
prefixStatements.push(...initializerStatements);
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
return {
|
|
2019
|
+
needsCallbackRef,
|
|
2020
|
+
prefixStatements,
|
|
2021
|
+
returnStatement,
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
|
|
1894
2025
|
let t$1;
|
|
1895
2026
|
|
|
1896
2027
|
function setProgramBabelTypes(nextTypes) {
|
|
@@ -2175,6 +2306,9 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
|
|
|
2175
2306
|
setRefsBabelTypes(t);
|
|
2176
2307
|
setClassGenerationBabelTypes(t);
|
|
2177
2308
|
setParamRewriteBabelTypes(t);
|
|
2309
|
+
setRendererCallsBabelTypes(t);
|
|
2310
|
+
transformLitsxElementCandidates.setElementCandidatesBabelTypes(t);
|
|
2311
|
+
setRenderBodyBabelTypes(t);
|
|
2178
2312
|
setProgramBabelTypes(t);
|
|
2179
2313
|
const resolvedPluginOptions = {
|
|
2180
2314
|
...defaultPluginOptions,
|
|
@@ -2475,8 +2609,8 @@ function getTypeResolverForFunction(functionPath, state) {
|
|
|
2475
2609
|
|
|
2476
2610
|
function transformFunction(functionPath, programPath, className, options = {}) {
|
|
2477
2611
|
const { node } = functionPath;
|
|
2478
|
-
const elementCandidates =
|
|
2479
|
-
const
|
|
2612
|
+
const elementCandidates = transformLitsxElementCandidates.getAnnotatedElementCandidates(functionPath, programPath, options);
|
|
2613
|
+
const importedElementCandidates = transformLitsxElementCandidates.getAnnotatedImportedElementCandidates(functionPath, programPath, options);
|
|
2480
2614
|
let resolvedName = className;
|
|
2481
2615
|
if (!resolvedName && node && node.id && t.isIdentifier(node.id)) {
|
|
2482
2616
|
resolvedName = node.id.name;
|
|
@@ -2502,19 +2636,21 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2502
2636
|
assertStaticHoistsStayTopLevel(functionPath);
|
|
2503
2637
|
collectNativeClassNameWarnings(functionPath, options.warn, options);
|
|
2504
2638
|
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
});
|
|
2639
|
+
const renderPreparation = prepareComponentRender(
|
|
2640
|
+
functionPath,
|
|
2641
|
+
node,
|
|
2642
|
+
propertyNames,
|
|
2643
|
+
bindings,
|
|
2644
|
+
nestedInitializers,
|
|
2645
|
+
options
|
|
2646
|
+
);
|
|
2514
2647
|
|
|
2515
|
-
if (!returnStatement) return;
|
|
2648
|
+
if (!renderPreparation?.returnStatement) return;
|
|
2516
2649
|
|
|
2517
|
-
const
|
|
2650
|
+
const {
|
|
2651
|
+
needsCallbackRef,
|
|
2652
|
+
prefixStatements,
|
|
2653
|
+
} = renderPreparation;
|
|
2518
2654
|
|
|
2519
2655
|
const usedNames = new Set([
|
|
2520
2656
|
...Object.keys(functionPath.scope.bindings || {}),
|
|
@@ -2524,41 +2660,12 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2524
2660
|
]);
|
|
2525
2661
|
|
|
2526
2662
|
const handlerInfos = processHandlers(functionPath, usedNames);
|
|
2527
|
-
|
|
2528
2663
|
const renderStatements = t.isBlockStatement(node.body)
|
|
2529
2664
|
? [...node.body.body]
|
|
2530
2665
|
: [t.returnStatement(node.body)];
|
|
2531
2666
|
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
let needsCallbackRef = false;
|
|
2535
|
-
|
|
2536
|
-
if (resolvedRefPropName) {
|
|
2537
|
-
renderStatements.unshift(
|
|
2538
|
-
...lowerForwardedElementRefs(functionPath, resolvedRefPropName)
|
|
2539
|
-
);
|
|
2540
|
-
needsCallbackRef = renderStatements.some(
|
|
2541
|
-
(statement) =>
|
|
2542
|
-
t.isExpressionStatement(statement) &&
|
|
2543
|
-
t.isCallExpression(statement.expression) &&
|
|
2544
|
-
t.isIdentifier(statement.expression.callee, { name: "useCallbackRef" })
|
|
2545
|
-
) || needsCallbackRef;
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
|
-
if (resolvedRefPropName && !forwardRefOptions) {
|
|
2549
|
-
renderStatements.unshift(createComponentInstanceRefSyncStatement());
|
|
2550
|
-
needsCallbackRef = true;
|
|
2551
|
-
}
|
|
2552
|
-
|
|
2553
|
-
if (capturedPropAliasStatements.length > 0) {
|
|
2554
|
-
renderStatements.unshift(...capturedPropAliasStatements);
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
if (nestedInitializers.length > 0) {
|
|
2558
|
-
const initializerStatements = nestedInitializers.map(({ pattern, root, defaultValue }) =>
|
|
2559
|
-
createNestedInitializerStatement(pattern, root, defaultValue, t)
|
|
2560
|
-
);
|
|
2561
|
-
renderStatements.unshift(...initializerStatements);
|
|
2667
|
+
if (prefixStatements.length > 0) {
|
|
2668
|
+
renderStatements.unshift(...prefixStatements);
|
|
2562
2669
|
}
|
|
2563
2670
|
|
|
2564
2671
|
const classMembers = [];
|
|
@@ -2607,185 +2714,21 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2607
2714
|
elementCandidates.forEach((candidate) => elementSet.add(candidate));
|
|
2608
2715
|
}
|
|
2609
2716
|
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
if (defaultValue) {
|
|
2622
|
-
sourceExpression = t.logicalExpression(
|
|
2623
|
-
"??",
|
|
2624
|
-
t.cloneNode(rootAccess),
|
|
2625
|
-
t.cloneNode(defaultValue)
|
|
2626
|
-
);
|
|
2627
|
-
}
|
|
2628
|
-
|
|
2629
|
-
return t.variableDeclaration("const", [
|
|
2630
|
-
t.variableDeclarator(t.cloneNode(pattern), sourceExpression),
|
|
2631
|
-
]);
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
function collectElementCandidates(functionPath, programPath, options = {}) {
|
|
2635
|
-
const candidates = new Set();
|
|
2636
|
-
if (!programPath) return candidates;
|
|
2637
|
-
programPath.scope.crawl();
|
|
2638
|
-
const compatPascalNames =
|
|
2639
|
-
programPath.getData("__litsxCompatPascalNames") || new Set();
|
|
2640
|
-
|
|
2641
|
-
const availableNames = new Set();
|
|
2642
|
-
const helperPaths = new Map();
|
|
2643
|
-
programPath.get("body").forEach((nodePath) => {
|
|
2644
|
-
if (nodePath.isImportDeclaration()) {
|
|
2645
|
-
nodePath.node.specifiers.forEach((specifier) => {
|
|
2646
|
-
if (specifier.local?.name) {
|
|
2647
|
-
availableNames.add(specifier.local.name);
|
|
2648
|
-
}
|
|
2649
|
-
});
|
|
2650
|
-
return;
|
|
2651
|
-
}
|
|
2652
|
-
|
|
2653
|
-
if (nodePath.isClassDeclaration() && nodePath.node.id?.name) {
|
|
2654
|
-
availableNames.add(nodePath.node.id.name);
|
|
2655
|
-
return;
|
|
2656
|
-
}
|
|
2657
|
-
|
|
2658
|
-
if (
|
|
2659
|
-
(nodePath.isExportNamedDeclaration() || nodePath.isExportDefaultDeclaration()) &&
|
|
2660
|
-
nodePath.get("declaration")?.isClassDeclaration?.() &&
|
|
2661
|
-
nodePath.node.declaration?.id?.name
|
|
2662
|
-
) {
|
|
2663
|
-
availableNames.add(nodePath.node.declaration.id.name);
|
|
2664
|
-
return;
|
|
2665
|
-
}
|
|
2666
|
-
|
|
2667
|
-
if (nodePath.isFunctionDeclaration() && nodePath.node.id?.name) {
|
|
2668
|
-
availableNames.add(nodePath.node.id.name);
|
|
2669
|
-
helperPaths.set(nodePath.node.id.name, nodePath);
|
|
2670
|
-
return;
|
|
2671
|
-
}
|
|
2672
|
-
|
|
2673
|
-
if (!nodePath.isVariableDeclaration()) return;
|
|
2674
|
-
nodePath.get("declarations").forEach((declaratorPath) => {
|
|
2675
|
-
const declarator = declaratorPath.node;
|
|
2676
|
-
if (!t.isIdentifier(declarator.id)) {
|
|
2677
|
-
return;
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
availableNames.add(declarator.id.name);
|
|
2681
|
-
|
|
2682
|
-
const initPath = declaratorPath.get("init");
|
|
2683
|
-
if (
|
|
2684
|
-
initPath?.isArrowFunctionExpression?.() ||
|
|
2685
|
-
initPath?.isFunctionExpression?.()
|
|
2686
|
-
) {
|
|
2687
|
-
helperPaths.set(declarator.id.name, initPath);
|
|
2717
|
+
if (classNode && importedElementCandidates.length > 0) {
|
|
2718
|
+
classNode._litsxImportedElementCandidates ||= [];
|
|
2719
|
+
importedElementCandidates.forEach((candidate) => {
|
|
2720
|
+
if (!classNode._litsxImportedElementCandidates.some(
|
|
2721
|
+
(entry) =>
|
|
2722
|
+
entry.sourceFile === candidate.sourceFile &&
|
|
2723
|
+
entry.importedName === candidate.importedName &&
|
|
2724
|
+
entry.tagName === candidate.tagName
|
|
2725
|
+
)) {
|
|
2726
|
+
classNode._litsxImportedElementCandidates.push(candidate);
|
|
2688
2727
|
}
|
|
2689
2728
|
});
|
|
2690
|
-
});
|
|
2691
|
-
|
|
2692
|
-
const helperCandidateCache = new Map();
|
|
2693
|
-
|
|
2694
|
-
function isCapitalizedName(name) {
|
|
2695
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
2696
|
-
return false;
|
|
2697
|
-
}
|
|
2698
|
-
|
|
2699
|
-
const first = name[0];
|
|
2700
|
-
return first === first.toUpperCase() && first !== first.toLowerCase();
|
|
2701
|
-
}
|
|
2702
|
-
|
|
2703
|
-
function isProgramLevelBinding(binding) {
|
|
2704
|
-
return binding?.scope?.path?.isProgram?.() === true;
|
|
2705
2729
|
}
|
|
2706
2730
|
|
|
2707
|
-
|
|
2708
|
-
if (!nameNode || nameNode.type !== "JSXIdentifier") return null;
|
|
2709
|
-
const originalName = nameNode.__scopedOriginal || nameNode.name;
|
|
2710
|
-
if (!isCapitalizedName(originalName)) return null;
|
|
2711
|
-
const binding = pathForErrors?.scope?.getBinding?.(originalName) || null;
|
|
2712
|
-
if (!binding) {
|
|
2713
|
-
if (availableNames.has(originalName)) {
|
|
2714
|
-
return originalName;
|
|
2715
|
-
}
|
|
2716
|
-
if (compatPascalNames.has(originalName)) {
|
|
2717
|
-
return null;
|
|
2718
|
-
}
|
|
2719
|
-
if (options?.allowUnknownPascalCase === true) {
|
|
2720
|
-
return null;
|
|
2721
|
-
}
|
|
2722
|
-
throw (pathForErrors?.buildCodeFrameError?.(
|
|
2723
|
-
`Unknown LitSX component "${originalName}". Add an import or declare it in this module before using it in JSX.`
|
|
2724
|
-
) || new Error(
|
|
2725
|
-
`Unknown LitSX component "${originalName}". Add an import or declare it in this module before using it in JSX.`
|
|
2726
|
-
));
|
|
2727
|
-
}
|
|
2728
|
-
|
|
2729
|
-
if (!isProgramLevelBinding(binding)) {
|
|
2730
|
-
return null;
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
return originalName;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
function scanFunction(path, seen = new Set()) {
|
|
2737
|
-
if (!path?.node) {
|
|
2738
|
-
return new Set();
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
if (helperCandidateCache.has(path.node)) {
|
|
2742
|
-
return new Set(helperCandidateCache.get(path.node));
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
if (seen.has(path.node)) {
|
|
2746
|
-
return new Set();
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
const nextSeen = new Set(seen);
|
|
2750
|
-
nextSeen.add(path.node);
|
|
2751
|
-
const localCandidates = new Set();
|
|
2752
|
-
const referencedHelpers = new Set();
|
|
2753
|
-
|
|
2754
|
-
path.traverse({
|
|
2755
|
-
JSXOpeningElement(jsxPath) {
|
|
2756
|
-
const candidate = maybeRewriteComponentName(jsxPath.node.name, jsxPath);
|
|
2757
|
-
if (candidate) {
|
|
2758
|
-
localCandidates.add(candidate);
|
|
2759
|
-
}
|
|
2760
|
-
},
|
|
2761
|
-
JSXClosingElement(jsxPath) {
|
|
2762
|
-
maybeRewriteComponentName(jsxPath.node.name, jsxPath);
|
|
2763
|
-
},
|
|
2764
|
-
Identifier(identifierPath) {
|
|
2765
|
-
if (!identifierPath.isReferencedIdentifier()) {
|
|
2766
|
-
return;
|
|
2767
|
-
}
|
|
2768
|
-
|
|
2769
|
-
if (!helperPaths.has(identifierPath.node.name)) {
|
|
2770
|
-
return;
|
|
2771
|
-
}
|
|
2772
|
-
|
|
2773
|
-
referencedHelpers.add(identifierPath.node.name);
|
|
2774
|
-
},
|
|
2775
|
-
});
|
|
2776
|
-
|
|
2777
|
-
referencedHelpers.forEach((helperName) => {
|
|
2778
|
-
const helperCandidates = scanFunction(helperPaths.get(helperName), nextSeen);
|
|
2779
|
-
helperCandidates.forEach((candidate) => localCandidates.add(candidate));
|
|
2780
|
-
});
|
|
2781
|
-
|
|
2782
|
-
helperCandidateCache.set(path.node, new Set(localCandidates));
|
|
2783
|
-
return localCandidates;
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
|
-
scanFunction(functionPath).forEach((candidate) => candidates.add(candidate));
|
|
2787
|
-
|
|
2788
|
-
return candidates;
|
|
2731
|
+
return classNode;
|
|
2789
2732
|
}
|
|
2790
2733
|
|
|
2791
2734
|
exports.createTransformFunctionToClassPlugin = createTransformFunctionToClassPlugin;
|