@litsx/babel-preset-litsx 0.2.1 → 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.
@@ -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$7;
16
+ let t$9;
11
17
 
12
18
  function setStaticHoistsBabelTypes(types) {
13
- t$7 = types;
19
+ t$9 = types;
14
20
  }
15
21
 
16
22
  function isLightDomHoist(statement) {
17
- if (!t$7.isExpressionStatement(statement)) return false;
18
- if (!t$7.isCallExpression(statement.expression)) return false;
19
- if (!t$7.isIdentifier(statement.expression.callee, { name: "__litsx_static_lightDom" })) {
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$7.classMethod(
35
+ const getter = t$9.classMethod(
30
36
  "get",
31
- t$7.identifier(name),
37
+ t$9.identifier(name),
32
38
  [],
33
- t$7.blockStatement([
34
- t$7.returnStatement(
35
- t$7.callExpression(
36
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxStatic")),
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$7.cloneNode(symbolId),
39
- t$7.arrowFunctionExpression([], expression),
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$7.callExpression(
51
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxResolveStaticValue")),
52
- [t$7.cloneNode(expression)]
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$7.cloneNode(property));
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$7.callExpression(
63
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxMergeProperties")),
68
+ return t$9.callExpression(
69
+ t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxMergeProperties")),
64
70
  [
65
- t$7.objectExpression(mergedProperties),
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$7.cloneNode(staticStyles[0])
80
- : t$7.arrayExpression(staticStyles.map((style) => t$7.cloneNode(style)));
85
+ ? t$9.cloneNode(staticStyles[0])
86
+ : t$9.arrayExpression(staticStyles.map((style) => t$9.cloneNode(style)));
81
87
 
82
- return t$7.logicalExpression("||", resolvedExpression, baseStyles);
88
+ return t$9.logicalExpression("||", resolvedExpression, baseStyles);
83
89
  }
84
90
 
85
91
  function getStaticPropsExpression(statement) {
86
- if (!t$7.isExpressionStatement(statement)) return null;
87
- if (!t$7.isCallExpression(statement.expression)) return null;
88
- const isLegacyStaticProps = t$7.isIdentifier(statement.expression.callee, { name: "staticProps" });
89
- const isHoistedProperties = t$7.isIdentifier(
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$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument))) {
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$7.isObjectExpression(argument)) {
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$7.cloneNode(argument),
113
- } : t$7.cloneNode(argument);
118
+ expression: t$9.cloneNode(argument),
119
+ } : t$9.cloneNode(argument);
114
120
  }
115
121
 
116
122
  function getStaticPropertyName(node) {
117
- if (t$7.isIdentifier(node)) return node.name;
118
- if (t$7.isStringLiteral(node)) return node.value;
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$7.isIdentifier(value) &&
130
+ t$9.isIdentifier(value) &&
125
131
  ["String", "Number", "Boolean", "Object", "Array", "Date"].includes(value.name)
126
132
  ) {
127
- return internal_transformLitsxProperties.createPropertyConfig(t$7.identifier(value.name));
133
+ return internal_transformLitsxProperties.createPropertyConfig(t$9.identifier(value.name));
128
134
  }
129
135
 
130
- if (t$7.isObjectExpression(value)) {
136
+ if (t$9.isObjectExpression(value)) {
131
137
  const typeProperty = value.properties.find(
132
138
  (prop) =>
133
- t$7.isObjectProperty(prop) &&
134
- t$7.isIdentifier(prop.key, { name: "type" }) &&
135
- t$7.isIdentifier(prop.value)
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$7.isObjectProperty(prop) &&
141
- t$7.isIdentifier(prop.key, { name: "attribute" }) &&
142
- t$7.isBooleanLiteral(prop.value) &&
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$7.isObjectProperty(targetNode) || !t$7.isObjectExpression(targetNode.value)) {
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$7.isObjectProperty(property) && !t$7.isObjectMethod(property)) {
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$7.isObjectProperty(candidate) || t$7.isObjectMethod(candidate)) &&
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$7.cloneNode(property);
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$7.cloneNode(property));
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$7.isObjectProperty(propertyNode)) return;
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$7.isObjectProperty(property)) {
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$7.objectProperty(
213
- t$7.identifier(keyName),
218
+ const node = t$9.objectProperty(
219
+ t$9.identifier(keyName),
214
220
  internal_transformLitsxProperties.createPropertyValue(normalized, false)
215
221
  );
216
- if (t$7.isObjectExpression(property.value)) {
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$7.isObjectExpression(property.value)) {
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$7.isTemplateLiteral(argument)) {
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$7.templateLiteral(
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$7.isStringLiteral(argument)) {
255
- return t$7.templateLiteral(
256
- [t$7.templateElement({ raw: argument.value, cooked: argument.value }, true)],
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$7.templateLiteral(
268
+ return t$9.templateLiteral(
263
269
  [
264
- t$7.templateElement({ raw: "", cooked: "" }, false),
265
- t$7.templateElement({ raw: "", cooked: "" }, true),
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$7.isTaggedTemplateExpression(expression) &&
277
- t$7.isIdentifier(expression.tag, { name: "css" })
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$7.isNumericLiteral(expression)) {
288
+ if (t$9.isNumericLiteral(expression)) {
283
289
  return expression;
284
290
  }
285
291
 
286
- return t$7.callExpression(
287
- t$7.identifier("unsafeCSS"),
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$7.isExpressionStatement(statement)) return null;
294
- if (!t$7.isCallExpression(statement.expression)) return null;
295
- const isLegacyStaticStyles = t$7.isIdentifier(statement.expression.callee, { name: "staticStyles" });
296
- const isHoistedStyles = t$7.isIdentifier(statement.expression.callee, { name: "__litsx_static_styles" });
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$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument))) {
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$7.taggedTemplateExpression(t$7.identifier("css"), template);
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$7.isExpressionStatement(statement)) return null;
327
- if (!t$7.isCallExpression(statement.expression)) return null;
328
- if (!t$7.isIdentifier(statement.expression.callee)) return null;
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$7.isObjectExpression(argument)) {
352
+ if (t$9.isObjectExpression(argument)) {
347
353
  return {
348
354
  name,
349
- expression: t$7.cloneNode(argument),
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$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument)) {
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$7.cloneNode(argument),
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$7.isObjectExpression(expression)) {
385
+ if (t$9.isObjectExpression(expression)) {
380
386
  return {
381
- methodsExpression: t$7.cloneNode(expression),
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$7.isSpreadElement(property)) {
401
+ if (t$9.isSpreadElement(property)) {
396
402
  throw new Error("^expose(...) does not accept spread elements.");
397
403
  }
398
404
 
399
- if (t$7.isObjectMethod(property)) {
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$7.classMethod(
410
+ return t$9.classMethod(
405
411
  "method",
406
- t$7.cloneNode(property.key),
407
- property.params.map((param) => t$7.cloneNode(param)),
408
- t$7.cloneNode(property.body),
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$7.isObjectProperty(property)) {
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$7.isFunctionExpression(value) && !t$7.isArrowFunctionExpression(value)) {
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$7.isBlockStatement(value.body)
423
- ? t$7.cloneNode(value.body)
424
- : t$7.blockStatement([t$7.returnStatement(t$7.cloneNode(value.body))]);
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$7.classMethod(
432
+ const method = t$9.classMethod(
427
433
  "method",
428
- t$7.cloneNode(property.key),
429
- value.params.map((param) => t$7.cloneNode(param)),
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$7.isIdentifier(callPath.node.callee)) return;
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$7.isCallExpression(node) &&
467
- t$7.isIdentifier(node.callee, { name: "unsafeCSS" })
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$7.isStringLiteral(node) ||
483
- t$7.isNumericLiteral(node) ||
484
- t$7.isBooleanLiteral(node) ||
485
- t$7.isNullLiteral(node) ||
486
- t$7.isBigIntLiteral?.(node)
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$7.isTemplateLiteral(node)) {
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$7.isIdentifier(node)) {
503
+ if (t$9.isIdentifier(node)) {
498
504
  return isStaticStylesIdentifier(node, functionPath, seenBindings);
499
505
  }
500
506
 
501
- if (t$7.isUnaryExpression(node)) {
507
+ if (t$9.isUnaryExpression(node)) {
502
508
  return isStaticStylesExpression(node.argument, functionPath, seenBindings);
503
509
  }
504
510
 
505
- if (t$7.isBinaryExpression(node) || t$7.isLogicalExpression(node)) {
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$7.isConditionalExpression(node)) {
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$7.isArrayExpression(node)) {
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$7.isObjectExpression(node)) {
532
+ if (t$9.isObjectExpression(node)) {
527
533
  return node.properties.every((property) => {
528
- if (t$7.isObjectProperty(property)) {
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$7.isMemberExpression(node)) {
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$7.isCallExpression(node)) {
553
+ if (t$9.isCallExpression(node)) {
548
554
  return (
549
555
  isStaticStylesExpression(node.callee, functionPath, seenBindings) &&
550
556
  node.arguments.every((argument) =>
551
- t$7.isSpreadElement(argument)
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$7.isTaggedTemplateExpression(node)) {
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$7.isBlockStatement(node.body)) {
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$7.classProperty(
679
- t$7.identifier("properties"),
680
- t$7.objectExpression(propertiesStatic),
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$7.classProperty(
693
- t$7.identifier("styles"),
694
- staticStyles.length === 1 ? staticStyles[0] : t$7.arrayExpression(staticStyles),
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$6;
765
+ let t$8;
760
766
 
761
767
  function setHandlersBabelTypes(types) {
762
- t$6 = types;
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$6.isBlockStatement(body)) {
810
- return t$6.cloneNode(body, true);
815
+ if (t$8.isBlockStatement(body)) {
816
+ return t$8.cloneNode(body, true);
811
817
  }
812
818
 
813
- return t$6.blockStatement([t$6.returnStatement(t$6.cloneNode(body, true))]);
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$6.isIdentifier(id)) return;
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$6.memberExpression(t$6.thisExpression(), t$6.identifier(handlerName))
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$6.cloneNode(param, true)),
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$6.isJSXIdentifier(node.name)) return;
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$6.cloneNode(param, true)),
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$6.jsxExpressionContainer(
918
- t$6.memberExpression(t$6.thisExpression(), t$6.identifier(handlerName))
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$6.isJSXIdentifier(nameNode) && /^[a-z]/.test(nameNode.name);
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$6.isJSXIdentifier(node.name, { name: "className" })) return;
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$6.classMethod(
973
+ const method = t$8.classMethod(
968
974
  "method",
969
- t$6.identifier(name),
970
- params.map((param) => t$6.cloneNode(param, true)),
971
- t$6.cloneNode(body, true)
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,10 +983,19 @@ function createHandlerClassMember({ name, params, body, async, generator }) {
977
983
  return method;
978
984
  }
979
985
 
980
- let t$5;
986
+ let t$7;
987
+
988
+ function isCapitalizedComponentName$1(name) {
989
+ if (typeof name !== "string" || name.length === 0) {
990
+ return false;
991
+ }
992
+
993
+ const first = name[0];
994
+ return first === first.toUpperCase() && first !== first.toLowerCase();
995
+ }
981
996
 
982
997
  function setWrapperUtilsBabelTypes(nextTypes) {
983
- t$5 = nextTypes;
998
+ t$7 = nextTypes;
984
999
  }
985
1000
 
986
1001
  function emitWrapperWarnings(meta, warn) {
@@ -1035,7 +1050,7 @@ function maybeTransformWrappedVariableDeclarator({
1035
1050
  });
1036
1051
 
1037
1052
  const programPath = varPath.findParent((p) => p.isProgram());
1038
- const localName = t$5.isIdentifier(varPath.node.id)
1053
+ const localName = t$7.isIdentifier(varPath.node.id)
1039
1054
  ? varPath.node.id.name
1040
1055
  : undefined;
1041
1056
 
@@ -1046,6 +1061,7 @@ function maybeTransformWrappedVariableDeclarator({
1046
1061
  {
1047
1062
  ...resolvedPluginOptions,
1048
1063
  ...wrapperMeta.options,
1064
+ state,
1049
1065
  typeResolver: state?.__litsxTypeResolver,
1050
1066
  warn: (warning) => {
1051
1067
  state?.__litsxWarnings?.push(warning);
@@ -1057,7 +1073,7 @@ function maybeTransformWrappedVariableDeclarator({
1057
1073
  return true;
1058
1074
  }
1059
1075
 
1060
- if (t$5.isIdentifier(varPath.node.id)) {
1076
+ if (t$7.isIdentifier(varPath.node.id)) {
1061
1077
  varPath.scope.removeBinding(varPath.node.id.name);
1062
1078
  }
1063
1079
 
@@ -1089,31 +1105,36 @@ function handlePotentialComponentExport({
1089
1105
  }
1090
1106
 
1091
1107
  if (
1092
- t$5.isFunctionDeclaration(declaration) ||
1093
- (t$5.isVariableDeclaration(declaration) &&
1108
+ t$7.isFunctionDeclaration(declaration) ||
1109
+ (t$7.isVariableDeclaration(declaration) &&
1094
1110
  declaration.declarations.length === 1 &&
1095
- t$5.isArrowFunctionExpression(declaration.declarations[0].init))
1111
+ t$7.isArrowFunctionExpression(declaration.declarations[0].init))
1096
1112
  ) {
1097
1113
  const funcPath = exportPath.get("declaration");
1098
1114
  const declarationPath = funcPath.isVariableDeclaration()
1099
1115
  ? funcPath.get("declarations.0.init")
1100
1116
  : funcPath;
1101
1117
  let exportName;
1102
- if (t$5.isFunctionDeclaration(declaration) && declaration.id) {
1118
+ if (t$7.isFunctionDeclaration(declaration) && declaration.id) {
1103
1119
  exportName = declaration.id.name;
1104
1120
  } else if (
1105
- t$5.isVariableDeclaration(declaration) &&
1106
- t$5.isIdentifier(declaration.declarations[0].id)
1121
+ t$7.isVariableDeclaration(declaration) &&
1122
+ t$7.isIdentifier(declaration.declarations[0].id)
1107
1123
  ) {
1108
1124
  exportName = declaration.declarations[0].id.name;
1109
1125
  }
1110
1126
 
1127
+ if (exportName && !isCapitalizedComponentName$1(exportName)) {
1128
+ return false;
1129
+ }
1130
+
1111
1131
  const classNode = transformFunction(
1112
1132
  declarationPath,
1113
1133
  exportPath.findParent((p) => p.isProgram()),
1114
1134
  exportName,
1115
1135
  {
1116
1136
  ...state?.__litsxResolvedPluginOptions,
1137
+ state,
1117
1138
  typeResolver,
1118
1139
  warn: (warning) => {
1119
1140
  state?.__litsxWarnings?.push(warning);
@@ -1129,8 +1150,8 @@ function handlePotentialComponentExport({
1129
1150
 
1130
1151
  exportPath.insertBefore(
1131
1152
  isDefault
1132
- ? t$5.exportDefaultDeclaration(classNode)
1133
- : t$5.exportNamedDeclaration(classNode, [])
1153
+ ? t$7.exportDefaultDeclaration(classNode)
1154
+ : t$7.exportNamedDeclaration(classNode, [])
1134
1155
  );
1135
1156
  exportPath.remove();
1136
1157
  updateTransformState?.(state, classNode);
@@ -1139,16 +1160,20 @@ function handlePotentialComponentExport({
1139
1160
 
1140
1161
  if (
1141
1162
  typeof getWrapperMetadata === "function" &&
1142
- t$5.isVariableDeclaration(declaration) &&
1163
+ t$7.isVariableDeclaration(declaration) &&
1143
1164
  declaration.declarations.length === 1
1144
1165
  ) {
1145
1166
  const declaratorPath = exportPath.get("declaration.declarations.0");
1146
1167
  const initPath = declaratorPath.get("init");
1147
- const exportName = t$5.isIdentifier(declaratorPath.node.id)
1168
+ const exportName = t$7.isIdentifier(declaratorPath.node.id)
1148
1169
  ? declaratorPath.node.id.name
1149
1170
  : undefined;
1150
1171
  const programPath = exportPath.findParent((p) => p.isProgram());
1151
1172
 
1173
+ if (exportName && !isCapitalizedComponentName$1(exportName)) {
1174
+ return false;
1175
+ }
1176
+
1152
1177
  if (initPath.isCallExpression()) {
1153
1178
  const wrapperMeta = getWrapperMetadata(initPath);
1154
1179
  if (!wrapperMeta) return false;
@@ -1163,6 +1188,7 @@ function handlePotentialComponentExport({
1163
1188
  {
1164
1189
  ...state?.__litsxResolvedPluginOptions,
1165
1190
  ...wrapperMeta.options,
1191
+ state,
1166
1192
  typeResolver,
1167
1193
  warn: (warning) => {
1168
1194
  state?.__litsxWarnings?.push(warning);
@@ -1175,7 +1201,11 @@ function handlePotentialComponentExport({
1175
1201
  exportPath.scope.removeBinding(exportName);
1176
1202
  }
1177
1203
 
1178
- exportPath.replaceWith(t$5.exportNamedDeclaration(classNode, []));
1204
+ exportPath.replaceWith(
1205
+ isDefault
1206
+ ? t$7.exportDefaultDeclaration(classNode)
1207
+ : t$7.exportNamedDeclaration(classNode, [])
1208
+ );
1179
1209
  exportPath.requeue();
1180
1210
  pruneWrapperImports(wrapperMeta);
1181
1211
  updateTransformState?.(state, classNode);
@@ -1183,7 +1213,7 @@ function handlePotentialComponentExport({
1183
1213
  }
1184
1214
  }
1185
1215
 
1186
- if (typeof getWrapperMetadata === "function" && isDefault && t$5.isCallExpression(declaration)) {
1216
+ if (typeof getWrapperMetadata === "function" && isDefault && t$7.isCallExpression(declaration)) {
1187
1217
  const callPath = exportPath.get("declaration");
1188
1218
  const wrapperMeta = getWrapperMetadata(callPath);
1189
1219
  if (!wrapperMeta) return false;
@@ -1196,6 +1226,10 @@ function handlePotentialComponentExport({
1196
1226
  ? wrapperMeta.functionPath.node.id.name
1197
1227
  : undefined;
1198
1228
 
1229
+ if (!inferredName || !isCapitalizedComponentName$1(inferredName)) {
1230
+ return false;
1231
+ }
1232
+
1199
1233
  const classNode = transformFunction(
1200
1234
  wrapperMeta.functionPath,
1201
1235
  programPath,
@@ -1203,6 +1237,7 @@ function handlePotentialComponentExport({
1203
1237
  {
1204
1238
  ...state?.__litsxResolvedPluginOptions,
1205
1239
  ...wrapperMeta.options,
1240
+ state,
1206
1241
  typeResolver,
1207
1242
  warn: (warning) => {
1208
1243
  state?.__litsxWarnings?.push(warning);
@@ -1211,7 +1246,7 @@ function handlePotentialComponentExport({
1211
1246
  );
1212
1247
  if (!classNode) return true;
1213
1248
 
1214
- exportPath.replaceWith(t$5.exportDefaultDeclaration(classNode));
1249
+ exportPath.replaceWith(t$7.exportDefaultDeclaration(classNode));
1215
1250
  exportPath.requeue();
1216
1251
  pruneWrapperImports(wrapperMeta);
1217
1252
  updateTransformState?.(state, classNode);
@@ -1221,23 +1256,23 @@ function handlePotentialComponentExport({
1221
1256
  return false;
1222
1257
  }
1223
1258
 
1224
- let t$4;
1259
+ let t$6;
1225
1260
 
1226
1261
  function setRefsBabelTypes(nextTypes) {
1227
- t$4 = nextTypes;
1262
+ t$6 = nextTypes;
1228
1263
  }
1229
1264
 
1230
- function createThisMemberExpression$3(propName) {
1231
- return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1265
+ function createThisMemberExpression$4(propName) {
1266
+ return t$6.memberExpression(t$6.thisExpression(), t$6.identifier(propName));
1232
1267
  }
1233
1268
 
1234
1269
  function createManagedRefLookupExpression(refName) {
1235
- const selectorLiteral = t$4.stringLiteral(`[data-ref="${refName}"]`);
1270
+ const selectorLiteral = t$6.stringLiteral(`[data-ref="${refName}"]`);
1236
1271
 
1237
- const renderRootQuery = t$4.optionalCallExpression(
1238
- t$4.optionalMemberExpression(
1239
- t$4.memberExpression(t$4.thisExpression(), t$4.identifier("renderRoot")),
1240
- t$4.identifier("querySelector"),
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"),
1241
1276
  false,
1242
1277
  true
1243
1278
  ),
@@ -1245,55 +1280,55 @@ function createManagedRefLookupExpression(refName) {
1245
1280
  false
1246
1281
  );
1247
1282
 
1248
- const hostQuery = t$4.callExpression(
1249
- t$4.memberExpression(t$4.thisExpression(), t$4.identifier("querySelector")),
1250
- [t$4.cloneNode(selectorLiteral)]
1283
+ const hostQuery = t$6.callExpression(
1284
+ t$6.memberExpression(t$6.thisExpression(), t$6.identifier("querySelector")),
1285
+ [t$6.cloneNode(selectorLiteral)]
1251
1286
  );
1252
1287
 
1253
- return t$4.logicalExpression("??", renderRootQuery, hostQuery);
1288
+ return t$6.logicalExpression("??", renderRootQuery, hostQuery);
1254
1289
  }
1255
1290
 
1256
1291
  function createForwardedTargetRefSyncStatement(propName, refName) {
1257
- return t$4.expressionStatement(
1258
- t$4.callExpression(t$4.identifier("useCallbackRef"), [
1259
- t$4.thisExpression(),
1260
- t$4.arrowFunctionExpression([], createManagedRefLookupExpression(refName)),
1261
- t$4.arrowFunctionExpression(
1262
- [t$4.identifier("node")],
1263
- t$4.blockStatement([
1264
- t$4.variableDeclaration("const", [
1265
- t$4.variableDeclarator(
1266
- t$4.identifier("componentRef"),
1267
- createThisMemberExpression$3(propName)
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)
1268
1303
  ),
1269
1304
  ]),
1270
- t$4.ifStatement(
1271
- t$4.binaryExpression(
1305
+ t$6.ifStatement(
1306
+ t$6.binaryExpression(
1272
1307
  "===",
1273
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1274
- t$4.stringLiteral("function")
1308
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1309
+ t$6.stringLiteral("function")
1275
1310
  ),
1276
- t$4.blockStatement([
1277
- t$4.expressionStatement(
1278
- t$4.callExpression(t$4.identifier("componentRef"), [t$4.identifier("node")])
1311
+ t$6.blockStatement([
1312
+ t$6.expressionStatement(
1313
+ t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
1279
1314
  ),
1280
1315
  ]),
1281
- t$4.ifStatement(
1282
- t$4.logicalExpression(
1316
+ t$6.ifStatement(
1317
+ t$6.logicalExpression(
1283
1318
  "&&",
1284
- t$4.identifier("componentRef"),
1285
- t$4.binaryExpression(
1319
+ t$6.identifier("componentRef"),
1320
+ t$6.binaryExpression(
1286
1321
  "===",
1287
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1288
- t$4.stringLiteral("object")
1322
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1323
+ t$6.stringLiteral("object")
1289
1324
  )
1290
1325
  ),
1291
- t$4.blockStatement([
1292
- t$4.expressionStatement(
1293
- t$4.assignmentExpression(
1326
+ t$6.blockStatement([
1327
+ t$6.expressionStatement(
1328
+ t$6.assignmentExpression(
1294
1329
  "=",
1295
- t$4.memberExpression(t$4.identifier("componentRef"), t$4.identifier("current")),
1296
- t$4.identifier("node")
1330
+ t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
1331
+ t$6.identifier("node")
1297
1332
  )
1298
1333
  ),
1299
1334
  ])
@@ -1301,13 +1336,13 @@ function createForwardedTargetRefSyncStatement(propName, refName) {
1301
1336
  ),
1302
1337
  ])
1303
1338
  ),
1304
- t$4.arrayExpression([createThisMemberExpression$3(propName)]),
1339
+ t$6.arrayExpression([createThisMemberExpression$4(propName)]),
1305
1340
  ])
1306
1341
  );
1307
1342
  }
1308
1343
 
1309
1344
  function isStandardElementJsxName(nameNode) {
1310
- if (!t$4.isJSXIdentifier(nameNode)) {
1345
+ if (!t$6.isJSXIdentifier(nameNode)) {
1311
1346
  return false;
1312
1347
  }
1313
1348
 
@@ -1316,46 +1351,46 @@ function isStandardElementJsxName(nameNode) {
1316
1351
  }
1317
1352
 
1318
1353
  function createComponentInstanceRefSyncStatement() {
1319
- return t$4.expressionStatement(
1320
- t$4.callExpression(t$4.identifier("useCallbackRef"), [
1321
- t$4.thisExpression(),
1322
- t$4.arrowFunctionExpression([], t$4.thisExpression()),
1323
- t$4.arrowFunctionExpression(
1324
- [t$4.identifier("node")],
1325
- t$4.blockStatement([
1326
- t$4.variableDeclaration("const", [
1327
- t$4.variableDeclarator(
1328
- t$4.identifier("componentRef"),
1329
- createThisMemberExpression$3("ref")
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")
1330
1365
  ),
1331
1366
  ]),
1332
- t$4.ifStatement(
1333
- t$4.binaryExpression(
1367
+ t$6.ifStatement(
1368
+ t$6.binaryExpression(
1334
1369
  "===",
1335
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1336
- t$4.stringLiteral("function")
1370
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1371
+ t$6.stringLiteral("function")
1337
1372
  ),
1338
- t$4.blockStatement([
1339
- t$4.expressionStatement(
1340
- t$4.callExpression(t$4.identifier("componentRef"), [t$4.identifier("node")])
1373
+ t$6.blockStatement([
1374
+ t$6.expressionStatement(
1375
+ t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
1341
1376
  ),
1342
1377
  ]),
1343
- t$4.ifStatement(
1344
- t$4.logicalExpression(
1378
+ t$6.ifStatement(
1379
+ t$6.logicalExpression(
1345
1380
  "&&",
1346
- t$4.identifier("componentRef"),
1347
- t$4.binaryExpression(
1381
+ t$6.identifier("componentRef"),
1382
+ t$6.binaryExpression(
1348
1383
  "===",
1349
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1350
- t$4.stringLiteral("object")
1384
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1385
+ t$6.stringLiteral("object")
1351
1386
  )
1352
1387
  ),
1353
- t$4.blockStatement([
1354
- t$4.expressionStatement(
1355
- t$4.assignmentExpression(
1388
+ t$6.blockStatement([
1389
+ t$6.expressionStatement(
1390
+ t$6.assignmentExpression(
1356
1391
  "=",
1357
- t$4.memberExpression(t$4.identifier("componentRef"), t$4.identifier("current")),
1358
- t$4.identifier("node")
1392
+ t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
1393
+ t$6.identifier("node")
1359
1394
  )
1360
1395
  ),
1361
1396
  ])
@@ -1363,7 +1398,7 @@ function createComponentInstanceRefSyncStatement() {
1363
1398
  ),
1364
1399
  ])
1365
1400
  ),
1366
- t$4.arrayExpression([createThisMemberExpression$3("ref")]),
1401
+ t$6.arrayExpression([createThisMemberExpression$4("ref")]),
1367
1402
  ])
1368
1403
  );
1369
1404
  }
@@ -1374,27 +1409,27 @@ function hasRefProp(functionPath) {
1374
1409
  return false;
1375
1410
  }
1376
1411
 
1377
- if (t$4.isObjectPattern(firstParam)) {
1412
+ if (t$6.isObjectPattern(firstParam)) {
1378
1413
  return firstParam.properties.some((property) => {
1379
- if (!t$4.isObjectProperty(property)) return false;
1414
+ if (!t$6.isObjectProperty(property)) return false;
1380
1415
  return (
1381
- t$4.isIdentifier(property.key, { name: "ref" }) ||
1382
- t$4.isStringLiteral(property.key, { value: "ref" })
1416
+ t$6.isIdentifier(property.key, { name: "ref" }) ||
1417
+ t$6.isStringLiteral(property.key, { value: "ref" })
1383
1418
  );
1384
1419
  });
1385
1420
  }
1386
1421
 
1387
- if (t$4.isAssignmentPattern(firstParam) && t$4.isObjectPattern(firstParam.left)) {
1422
+ if (t$6.isAssignmentPattern(firstParam) && t$6.isObjectPattern(firstParam.left)) {
1388
1423
  return firstParam.left.properties.some((property) => {
1389
- if (!t$4.isObjectProperty(property)) return false;
1424
+ if (!t$6.isObjectProperty(property)) return false;
1390
1425
  return (
1391
- t$4.isIdentifier(property.key, { name: "ref" }) ||
1392
- t$4.isStringLiteral(property.key, { value: "ref" })
1426
+ t$6.isIdentifier(property.key, { name: "ref" }) ||
1427
+ t$6.isStringLiteral(property.key, { value: "ref" })
1393
1428
  );
1394
1429
  });
1395
1430
  }
1396
1431
 
1397
- if (t$4.isIdentifier(firstParam)) {
1432
+ if (t$6.isIdentifier(firstParam)) {
1398
1433
  const binding = functionPath.scope.getBinding(firstParam.name);
1399
1434
  if (!binding) return false;
1400
1435
  return binding.referencePaths.some((refPath) => {
@@ -1403,7 +1438,7 @@ function hasRefProp(functionPath) {
1403
1438
  parentPath &&
1404
1439
  parentPath.isMemberExpression() &&
1405
1440
  parentPath.node.object === refPath.node &&
1406
- t$4.isIdentifier(parentPath.node.property, { name: "ref" }) &&
1441
+ t$6.isIdentifier(parentPath.node.property, { name: "ref" }) &&
1407
1442
  !parentPath.node.computed
1408
1443
  );
1409
1444
  });
@@ -1422,14 +1457,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
1422
1457
 
1423
1458
  functionPath.traverse({
1424
1459
  JSXAttribute(attrPath) {
1425
- if (!t$4.isJSXIdentifier(attrPath.node.name, { name: "ref" })) return;
1460
+ if (!t$6.isJSXIdentifier(attrPath.node.name, { name: "ref" })) return;
1426
1461
 
1427
1462
  const value = attrPath.node.value;
1428
- if (!t$4.isJSXExpressionContainer(value)) return;
1463
+ if (!t$6.isJSXExpressionContainer(value)) return;
1429
1464
  if (
1430
- !t$4.isMemberExpression(value.expression) ||
1431
- !t$4.isThisExpression(value.expression.object) ||
1432
- !t$4.isIdentifier(value.expression.property, { name: propName }) ||
1465
+ !t$6.isMemberExpression(value.expression) ||
1466
+ !t$6.isThisExpression(value.expression.object) ||
1467
+ !t$6.isIdentifier(value.expression.property, { name: propName }) ||
1433
1468
  value.expression.computed
1434
1469
  ) {
1435
1470
  return;
@@ -1441,7 +1476,7 @@ function lowerForwardedElementRefs(functionPath, propName) {
1441
1476
 
1442
1477
  const managedRefName = functionPath.scope.generateUidIdentifier(`${propName}Element`).name;
1443
1478
  attrPath.replaceWith(
1444
- t$4.jsxAttribute(t$4.jsxIdentifier("data-ref"), t$4.stringLiteral(managedRefName))
1479
+ t$6.jsxAttribute(t$6.jsxIdentifier("data-ref"), t$6.stringLiteral(managedRefName))
1445
1480
  );
1446
1481
 
1447
1482
  if (seenRefNames.has(managedRefName)) return;
@@ -1453,14 +1488,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
1453
1488
  return callbackStatements;
1454
1489
  }
1455
1490
 
1456
- let t$3;
1491
+ let t$5;
1457
1492
 
1458
1493
  function setClassGenerationBabelTypes(nextTypes) {
1459
- t$3 = nextTypes;
1494
+ t$5 = nextTypes;
1460
1495
  }
1461
1496
 
1462
- function createThisMemberExpression$2(propName) {
1463
- return t$3.memberExpression(t$3.thisExpression(), t$3.identifier(propName));
1497
+ function createThisMemberExpression$3(propName) {
1498
+ return t$5.memberExpression(t$5.thisExpression(), t$5.identifier(propName));
1464
1499
  }
1465
1500
 
1466
1501
  function buildClassMembers({
@@ -1472,26 +1507,26 @@ function buildClassMembers({
1472
1507
  }) {
1473
1508
  if (defaults.size > 0) {
1474
1509
  const constructorStatements = [
1475
- t$3.expressionStatement(t$3.callExpression(t$3.super(), [])),
1510
+ t$5.expressionStatement(t$5.callExpression(t$5.super(), [])),
1476
1511
  ];
1477
1512
 
1478
1513
  defaults.forEach((defaultExpression, propName) => {
1479
1514
  constructorStatements.push(
1480
- t$3.expressionStatement(
1481
- t$3.assignmentExpression(
1515
+ t$5.expressionStatement(
1516
+ t$5.assignmentExpression(
1482
1517
  "??=",
1483
- createThisMemberExpression$2(propName),
1484
- t$3.cloneNode(defaultExpression)
1518
+ createThisMemberExpression$3(propName),
1519
+ t$5.cloneNode(defaultExpression)
1485
1520
  )
1486
1521
  )
1487
1522
  );
1488
1523
  });
1489
1524
 
1490
- const constructorMethod = t$3.classMethod(
1525
+ const constructorMethod = t$5.classMethod(
1491
1526
  "constructor",
1492
- t$3.identifier("constructor"),
1527
+ t$5.identifier("constructor"),
1493
1528
  [],
1494
- t$3.blockStatement(constructorStatements)
1529
+ t$5.blockStatement(constructorStatements)
1495
1530
  );
1496
1531
 
1497
1532
  const insertionIndex = classMembers.findIndex((member) => !member.static);
@@ -1506,11 +1541,11 @@ function buildClassMembers({
1506
1541
  createHandlerClassMember(handler)
1507
1542
  );
1508
1543
 
1509
- const renderMethod = t$3.classMethod(
1544
+ const renderMethod = t$5.classMethod(
1510
1545
  "method",
1511
- t$3.identifier("render"),
1546
+ t$5.identifier("render"),
1512
1547
  [],
1513
- t$3.blockStatement(renderStatements)
1548
+ t$5.blockStatement(renderStatements)
1514
1549
  );
1515
1550
 
1516
1551
  classMembers.push(...handlerMembers, renderMethod);
@@ -1528,10 +1563,10 @@ function createComponentClass({
1528
1563
  needsUnsafeCss,
1529
1564
  needsCallbackRef = false,
1530
1565
  }) {
1531
- const classNode = t$3.classDeclaration(
1532
- t$3.identifier(className),
1533
- t$3.identifier("LitElement"),
1534
- t$3.classBody(classMembers)
1566
+ const classNode = t$5.classDeclaration(
1567
+ t$5.identifier(className),
1568
+ t$5.identifier("LitElement"),
1569
+ t$5.classBody(classMembers)
1535
1570
  );
1536
1571
 
1537
1572
  if (hoistMembers.length > 0) {
@@ -1540,8 +1575,8 @@ function createComponentClass({
1540
1575
  classNode._litsxStaticSymbolDeclarations = hoistSymbolDeclarations;
1541
1576
  }
1542
1577
  if (needsStaticHoistsMixin) {
1543
- classNode.superClass = t$3.callExpression(
1544
- t$3.identifier("LitsxStaticHoistsMixin"),
1578
+ classNode.superClass = t$5.callExpression(
1579
+ t$5.identifier("LitsxStaticHoistsMixin"),
1545
1580
  [classNode.superClass]
1546
1581
  );
1547
1582
  classNode._needsStaticHoistsMixin = true;
@@ -1549,8 +1584,8 @@ function createComponentClass({
1549
1584
  }
1550
1585
 
1551
1586
  if (lightDomRequested) {
1552
- classNode.superClass = t$3.callExpression(
1553
- t$3.identifier("LightDomMixin"),
1587
+ classNode.superClass = t$5.callExpression(
1588
+ t$5.identifier("LightDomMixin"),
1554
1589
  [classNode.superClass]
1555
1590
  );
1556
1591
  classNode._needsLightDomMixin = true;
@@ -1563,28 +1598,28 @@ function createComponentClass({
1563
1598
  return classNode;
1564
1599
  }
1565
1600
 
1566
- let t$2;
1601
+ let t$4;
1567
1602
 
1568
1603
  function setParamRewriteBabelTypes(nextTypes) {
1569
- t$2 = nextTypes;
1604
+ t$4 = nextTypes;
1570
1605
  }
1571
1606
 
1572
- function createThisMemberExpression$1(propName) {
1573
- return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
1607
+ function createThisMemberExpression$2(propName) {
1608
+ return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1574
1609
  }
1575
1610
 
1576
- function transformJSXExpressions(jsxPath, bindings) {
1611
+ function transformJSXExpressions(jsxPath, bindings, state = null) {
1577
1612
  const localNames = Array.from(bindings.keys());
1578
1613
 
1579
1614
  jsxPath.traverse({
1580
1615
  JSXExpressionContainer(expressionPath) {
1581
- if (t$2.isIdentifier(expressionPath.node.expression)) {
1616
+ if (t$4.isIdentifier(expressionPath.node.expression)) {
1582
1617
  const name = expressionPath.node.expression.name;
1583
1618
  if (localNames.includes(name)) {
1584
1619
  const propName = bindings.get(name) || name;
1585
- expressionPath.node.expression = t$2.memberExpression(
1586
- t$2.thisExpression(),
1587
- t$2.identifier(propName)
1620
+ expressionPath.node.expression = t$4.memberExpression(
1621
+ t$4.thisExpression(),
1622
+ t$4.identifier(propName)
1588
1623
  );
1589
1624
  }
1590
1625
  }
@@ -1603,16 +1638,16 @@ function registerLocalPropAliases(functionPath, bindings) {
1603
1638
  if (path.getFunctionParent() !== functionPath) return;
1604
1639
 
1605
1640
  const { id, init } = path.node;
1606
- if (!t$2.isIdentifier(init)) return;
1641
+ if (!t$4.isIdentifier(init)) return;
1607
1642
 
1608
- if (t$2.isIdentifier(id)) {
1643
+ if (t$4.isIdentifier(id)) {
1609
1644
  if (bindings.has(id.name) || !bindings.has(init.name)) return;
1610
1645
  bindings.set(id.name, bindings.get(init.name));
1611
1646
  changed = true;
1612
1647
  return;
1613
1648
  }
1614
1649
 
1615
- if (!t$2.isObjectPattern(id)) return;
1650
+ if (!t$4.isObjectPattern(id)) return;
1616
1651
 
1617
1652
  const bindingInfo = bindings.get(init.name);
1618
1653
  if (!bindingInfo || typeof bindingInfo !== "object" || bindingInfo.kind !== "alias") {
@@ -1620,17 +1655,17 @@ function registerLocalPropAliases(functionPath, bindings) {
1620
1655
  }
1621
1656
 
1622
1657
  id.properties.forEach((property) => {
1623
- if (!t$2.isObjectProperty(property)) return;
1658
+ if (!t$4.isObjectProperty(property)) return;
1624
1659
 
1625
- const keyName = t$2.isIdentifier(property.key)
1660
+ const keyName = t$4.isIdentifier(property.key)
1626
1661
  ? property.key.name
1627
- : t$2.isStringLiteral(property.key)
1662
+ : t$4.isStringLiteral(property.key)
1628
1663
  ? property.key.value
1629
1664
  : null;
1630
1665
 
1631
1666
  if (!keyName || !bindingInfo.properties.has(keyName)) return;
1632
1667
 
1633
- if (t$2.isIdentifier(property.value)) {
1668
+ if (t$4.isIdentifier(property.value)) {
1634
1669
  if (!bindings.has(property.value.name)) {
1635
1670
  bindings.set(property.value.name, keyName);
1636
1671
  changed = true;
@@ -1639,8 +1674,8 @@ function registerLocalPropAliases(functionPath, bindings) {
1639
1674
  }
1640
1675
 
1641
1676
  if (
1642
- t$2.isAssignmentPattern(property.value) &&
1643
- t$2.isIdentifier(property.value.left) &&
1677
+ t$4.isAssignmentPattern(property.value) &&
1678
+ t$4.isIdentifier(property.value.left) &&
1644
1679
  !bindings.has(property.value.left.name)
1645
1680
  ) {
1646
1681
  bindings.set(property.value.left.name, keyName);
@@ -1673,10 +1708,10 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1673
1708
  aliasId = functionPath.scope.generateUidIdentifier(propName);
1674
1709
  capturedPropAliases.set(propName, aliasId);
1675
1710
  }
1676
- return t$2.cloneNode(aliasId);
1711
+ return t$4.cloneNode(aliasId);
1677
1712
  }
1678
1713
 
1679
- return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
1714
+ return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1680
1715
  }
1681
1716
 
1682
1717
  bindings.forEach((bindingInfo, localName) => {
@@ -1705,7 +1740,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1705
1740
  return;
1706
1741
  }
1707
1742
 
1708
- refPath.replaceWith(t$2.thisExpression());
1743
+ refPath.replaceWith(t$4.thisExpression());
1709
1744
  return;
1710
1745
  }
1711
1746
 
@@ -1716,7 +1751,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1716
1751
  refPath.parentPath &&
1717
1752
  refPath.parentPath.isMemberExpression() &&
1718
1753
  refPath.parentKey === "object" &&
1719
- t$2.isIdentifier(refPath.parentPath.node.property) &&
1754
+ t$4.isIdentifier(refPath.parentPath.node.property) &&
1720
1755
  !refPath.parentPath.node.computed
1721
1756
  ) {
1722
1757
  const propName = refPath.parentPath.node.property.name;
@@ -1738,7 +1773,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1738
1773
  refPath.parentPath &&
1739
1774
  refPath.parentPath.isMemberExpression() &&
1740
1775
  refPath.parentKey === "object" &&
1741
- t$2.isIdentifier(refPath.parentPath.node.property) &&
1776
+ t$4.isIdentifier(refPath.parentPath.node.property) &&
1742
1777
  !refPath.parentPath.node.computed
1743
1778
  ) {
1744
1779
  const propName = refPath.parentPath.node.property.name;
@@ -1764,7 +1799,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1764
1799
  refPath.parentKey === "value"
1765
1800
  ) {
1766
1801
  refPath.replaceWith(
1767
- t$2.jsxExpressionContainer(
1802
+ t$4.jsxExpressionContainer(
1768
1803
  getReplacementForProp(targetProp || localName, refPath)
1769
1804
  )
1770
1805
  );
@@ -1785,12 +1820,208 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1785
1820
  });
1786
1821
 
1787
1822
  return Array.from(capturedPropAliases.entries()).map(([propName, aliasId]) =>
1788
- t$2.variableDeclaration("const", [
1789
- t$2.variableDeclarator(t$2.cloneNode(aliasId), createThisMemberExpression$1(propName)),
1823
+ t$4.variableDeclaration("const", [
1824
+ t$4.variableDeclarator(t$4.cloneNode(aliasId), createThisMemberExpression$2(propName)),
1790
1825
  ])
1791
1826
  );
1792
1827
  }
1793
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
+
1794
2025
  let t$1;
1795
2026
 
1796
2027
  function setProgramBabelTypes(nextTypes) {
@@ -1815,6 +2046,15 @@ function createLitsxInfrastructureImport(importedName) {
1815
2046
  );
1816
2047
  }
1817
2048
 
2049
+ function createLitsxInternalRuntimeImport(importedName) {
2050
+ return t$1.importDeclaration(
2051
+ [
2052
+ t$1.importSpecifier(t$1.identifier(importedName), t$1.identifier(importedName)),
2053
+ ],
2054
+ t$1.stringLiteral("@litsx/litsx/internal/runtime-render-context")
2055
+ );
2056
+ }
2057
+
1818
2058
  function createLitsxImport(importedName) {
1819
2059
  return t$1.importDeclaration(
1820
2060
  [
@@ -2018,11 +2258,43 @@ function finalizeProgram(programPath, state) {
2018
2258
  }
2019
2259
  }
2020
2260
 
2261
+ if (state.__litsxNeedsRendererCallImport) {
2262
+ const bodyPathsWithInternalRuntime = programPath.get("body");
2263
+ const internalRuntimeImports = bodyPathsWithInternalRuntime.filter(
2264
+ (n) =>
2265
+ n.isImportDeclaration() &&
2266
+ n.node.source.value === "@litsx/litsx/internal/runtime-render-context"
2267
+ );
2268
+
2269
+ let internalRuntimeImported = false;
2270
+ internalRuntimeImports.some((importPath) => {
2271
+ if (ensureNamedImport(importPath, "renderRendererCall")) {
2272
+ internalRuntimeImported = true;
2273
+ return true;
2274
+ }
2275
+
2276
+ return false;
2277
+ });
2278
+
2279
+ if (!internalRuntimeImported) {
2280
+ programPath.unshiftContainer("body", createLitsxInternalRuntimeImport("renderRendererCall"));
2281
+ }
2282
+ }
2283
+
2021
2284
  pruneUnusedLitsxStaticImports(programPath);
2022
2285
  }
2023
2286
 
2024
2287
  let t;
2025
2288
 
2289
+ function isCapitalizedComponentName(name) {
2290
+ if (typeof name !== "string" || name.length === 0) {
2291
+ return false;
2292
+ }
2293
+
2294
+ const first = name[0];
2295
+ return first === first.toUpperCase() && first !== first.toLowerCase();
2296
+ }
2297
+
2026
2298
  function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2027
2299
  return function transformFunctionToClassPlugin(_api, pluginOptions = {}) {
2028
2300
  internal_transformLitsxProperties.ensureTypescriptModule();
@@ -2034,6 +2306,9 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2034
2306
  setRefsBabelTypes(t);
2035
2307
  setClassGenerationBabelTypes(t);
2036
2308
  setParamRewriteBabelTypes(t);
2309
+ setRendererCallsBabelTypes(t);
2310
+ transformLitsxElementCandidates.setElementCandidatesBabelTypes(t);
2311
+ setRenderBodyBabelTypes(t);
2037
2312
  setProgramBabelTypes(t);
2038
2313
  const resolvedPluginOptions = {
2039
2314
  ...defaultPluginOptions,
@@ -2055,6 +2330,7 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2055
2330
  this.__litsxNeedsStaticHoistsMixin = false;
2056
2331
  this.__litsxNeedsLightDomMixin = false;
2057
2332
  this.__litsxNeedsCallbackRef = false;
2333
+ this.__litsxNeedsRendererCallImport = false;
2058
2334
  this.__litsxWarnings = [];
2059
2335
  this.__litsxResolvedPluginOptions = resolvedPluginOptions;
2060
2336
  this.__litsxTypeResolver = fileLikelyNeedsTypeResolver(this)
@@ -2121,15 +2397,21 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2121
2397
  return;
2122
2398
  }
2123
2399
 
2124
- if (initPath && initPath.isArrowFunctionExpression() && !isInsideFunctionOrClass(varPath)) {
2400
+ if (
2401
+ initPath &&
2402
+ initPath.isArrowFunctionExpression() &&
2403
+ !isInsideFunctionOrClass(varPath) &&
2404
+ t.isIdentifier(varPath.node.id) &&
2405
+ isCapitalizedComponentName(varPath.node.id.name)
2406
+ ) {
2125
2407
  const programPath = varPath.findParent((p) => p.isProgram());
2126
- const elementCandidates = collectElementCandidates(initPath, programPath);
2127
2408
  const classNode = transformFunction(
2128
2409
  initPath,
2129
2410
  programPath,
2130
2411
  varPath.node.id.name,
2131
2412
  {
2132
2413
  ...resolvedPluginOptions,
2414
+ state: this,
2133
2415
  typeResolver: getTypeResolverForFunction(initPath, this),
2134
2416
  warn: (warning) => {
2135
2417
  this.__litsxWarnings.push(warning);
@@ -2139,12 +2421,6 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2139
2421
 
2140
2422
  if (!classNode) return;
2141
2423
 
2142
- if (elementCandidates.size) {
2143
- classNode._litsxElementCandidates &&= new Set(classNode._litsxElementCandidates);
2144
- const elementSet = classNode._litsxElementCandidates ||= new Set();
2145
- elementCandidates.forEach((candidate) => elementSet.add(candidate));
2146
- }
2147
-
2148
2424
  const declarationPath = varPath.parentPath;
2149
2425
  if (!declarationPath.isVariableDeclaration()) return;
2150
2426
 
@@ -2155,15 +2431,21 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2155
2431
  }
2156
2432
  },
2157
2433
  FunctionDeclaration(funcPath) {
2158
- if (!isInsideFunctionOrClass(funcPath)) {
2434
+ if (
2435
+ !funcPath.parentPath?.isExportNamedDeclaration?.() &&
2436
+ !funcPath.parentPath?.isExportDefaultDeclaration?.() &&
2437
+ !isInsideFunctionOrClass(funcPath) &&
2438
+ funcPath.node.id &&
2439
+ isCapitalizedComponentName(funcPath.node.id.name)
2440
+ ) {
2159
2441
  const programPath = funcPath.findParent((p) => p.isProgram());
2160
- const elementCandidates = collectElementCandidates(funcPath, programPath);
2161
2442
  const classNode = transformFunction(
2162
2443
  funcPath,
2163
2444
  programPath,
2164
2445
  undefined,
2165
2446
  {
2166
2447
  ...resolvedPluginOptions,
2448
+ state: this,
2167
2449
  typeResolver: getTypeResolverForFunction(funcPath, this),
2168
2450
  warn: (warning) => {
2169
2451
  this.__litsxWarnings.push(warning);
@@ -2176,11 +2458,6 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2176
2458
  if (funcPath.node.id) {
2177
2459
  funcPath.scope.removeBinding(funcPath.node.id.name);
2178
2460
  }
2179
- if (elementCandidates.size) {
2180
- classNode._litsxElementCandidates &&= new Set(classNode._litsxElementCandidates);
2181
- const elementSet = classNode._litsxElementCandidates ||= new Set();
2182
- elementCandidates.forEach((candidate) => elementSet.add(candidate));
2183
- }
2184
2461
  funcPath.replaceWith(classNode);
2185
2462
  funcPath.requeue();
2186
2463
  updateTransformState(this, classNode);
@@ -2332,7 +2609,8 @@ function getTypeResolverForFunction(functionPath, state) {
2332
2609
 
2333
2610
  function transformFunction(functionPath, programPath, className, options = {}) {
2334
2611
  const { node } = functionPath;
2335
- const forwardRefOptions = options.forwardRef || null;
2612
+ const elementCandidates = transformLitsxElementCandidates.getAnnotatedElementCandidates(functionPath, programPath, options);
2613
+ const importedElementCandidates = transformLitsxElementCandidates.getAnnotatedImportedElementCandidates(functionPath, programPath, options);
2336
2614
  let resolvedName = className;
2337
2615
  if (!resolvedName && node && node.id && t.isIdentifier(node.id)) {
2338
2616
  resolvedName = node.id.name;
@@ -2358,19 +2636,21 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2358
2636
  assertStaticHoistsStayTopLevel(functionPath);
2359
2637
  collectNativeClassNameWarnings(functionPath, options.warn, options);
2360
2638
 
2361
- let returnStatement;
2362
- functionPath.traverse({
2363
- ReturnStatement(returnPath) {
2364
- if (t.isJSXElement(returnPath.node.argument)) {
2365
- returnStatement = returnPath.node;
2366
- transformJSXExpressions(returnPath, bindings);
2367
- }
2368
- },
2369
- });
2639
+ const renderPreparation = prepareComponentRender(
2640
+ functionPath,
2641
+ node,
2642
+ propertyNames,
2643
+ bindings,
2644
+ nestedInitializers,
2645
+ options
2646
+ );
2370
2647
 
2371
- if (!returnStatement) return;
2648
+ if (!renderPreparation?.returnStatement) return;
2372
2649
 
2373
- const capturedPropAliasStatements = replaceParamReferences(functionPath, bindings, propertyNames);
2650
+ const {
2651
+ needsCallbackRef,
2652
+ prefixStatements,
2653
+ } = renderPreparation;
2374
2654
 
2375
2655
  const usedNames = new Set([
2376
2656
  ...Object.keys(functionPath.scope.bindings || {}),
@@ -2380,41 +2660,12 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2380
2660
  ]);
2381
2661
 
2382
2662
  const handlerInfos = processHandlers(functionPath, usedNames);
2383
-
2384
2663
  const renderStatements = t.isBlockStatement(node.body)
2385
2664
  ? [...node.body.body]
2386
2665
  : [t.returnStatement(node.body)];
2387
2666
 
2388
- const resolvedRefPropName = forwardRefOptions?.propName ||
2389
- (propertyNames.has("ref") || hasRefProp(functionPath) ? "ref" : null);
2390
- let needsCallbackRef = false;
2391
-
2392
- if (resolvedRefPropName) {
2393
- renderStatements.unshift(
2394
- ...lowerForwardedElementRefs(functionPath, resolvedRefPropName)
2395
- );
2396
- needsCallbackRef = renderStatements.some(
2397
- (statement) =>
2398
- t.isExpressionStatement(statement) &&
2399
- t.isCallExpression(statement.expression) &&
2400
- t.isIdentifier(statement.expression.callee, { name: "useCallbackRef" })
2401
- ) || needsCallbackRef;
2402
- }
2403
-
2404
- if (resolvedRefPropName && !forwardRefOptions) {
2405
- renderStatements.unshift(createComponentInstanceRefSyncStatement());
2406
- needsCallbackRef = true;
2407
- }
2408
-
2409
- if (capturedPropAliasStatements.length > 0) {
2410
- renderStatements.unshift(...capturedPropAliasStatements);
2411
- }
2412
-
2413
- if (nestedInitializers.length > 0) {
2414
- const initializerStatements = nestedInitializers.map(({ pattern, root, defaultValue }) =>
2415
- createNestedInitializerStatement(pattern, root, defaultValue, t)
2416
- );
2417
- renderStatements.unshift(...initializerStatements);
2667
+ if (prefixStatements.length > 0) {
2668
+ renderStatements.unshift(...prefixStatements);
2418
2669
  }
2419
2670
 
2420
2671
  const classMembers = [];
@@ -2445,7 +2696,7 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2445
2696
  createHandlerClassMember,
2446
2697
  });
2447
2698
 
2448
- return createComponentClass({
2699
+ const classNode = createComponentClass({
2449
2700
  className,
2450
2701
  classMembers,
2451
2702
  hoistMembers,
@@ -2456,63 +2707,31 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2456
2707
  needsUnsafeCss,
2457
2708
  needsCallbackRef,
2458
2709
  });
2459
- }
2460
-
2461
- function createThisMemberExpression(propName) {
2462
- return t.memberExpression(t.thisExpression(), t.identifier(propName));
2463
- }
2464
-
2465
- function createNestedInitializerStatement(pattern, root, defaultValue, t) {
2466
- const rootAccess = createThisMemberExpression(root);
2467
- let sourceExpression = rootAccess;
2468
2710
 
2469
- if (defaultValue) {
2470
- sourceExpression = t.logicalExpression(
2471
- "??",
2472
- t.cloneNode(rootAccess),
2473
- t.cloneNode(defaultValue)
2474
- );
2475
- }
2476
-
2477
- return t.variableDeclaration("const", [
2478
- t.variableDeclarator(t.cloneNode(pattern), sourceExpression),
2479
- ]);
2480
- }
2481
-
2482
- function collectElementCandidates(functionPath, programPath) {
2483
- const candidates = new Set();
2484
- if (!programPath) return candidates;
2485
-
2486
- const importNames = new Set();
2487
- programPath.get("body").forEach((nodePath) => {
2488
- if (!nodePath.isImportDeclaration()) return;
2489
- nodePath.node.specifiers.forEach((specifier) => {
2490
- if (specifier.local) {
2491
- importNames.add(specifier.local.name);
2711
+ if (classNode && elementCandidates.size) {
2712
+ classNode._litsxElementCandidates &&= new Set(classNode._litsxElementCandidates);
2713
+ const elementSet = classNode._litsxElementCandidates ||= new Set();
2714
+ elementCandidates.forEach((candidate) => elementSet.add(candidate));
2715
+ }
2716
+
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);
2492
2727
  }
2493
2728
  });
2494
- });
2495
-
2496
- functionPath.traverse({
2497
- JSXOpeningElement(path) {
2498
- if (!path.node.name || path.node.name.type !== "JSXIdentifier") return;
2499
- const originalName = path.node.name.name;
2500
- if (!importNames.has(originalName)) return;
2501
-
2502
- path.node.__scopedOriginal = originalName;
2503
- candidates.add(originalName);
2504
- },
2505
- JSXClosingElement(path) {
2506
- if (!path.node.name || path.node.name.type !== "JSXIdentifier") return;
2507
- const originalName = path.node.name.name;
2508
- if (!importNames.has(originalName)) return;
2509
- path.node.__scopedOriginal = originalName;
2510
- },
2511
- });
2729
+ }
2512
2730
 
2513
- return candidates;
2731
+ return classNode;
2514
2732
  }
2515
2733
 
2516
2734
  exports.createTransformFunctionToClassPlugin = createTransformFunctionToClassPlugin;
2517
2735
  exports.default = transformLitsxComponents;
2736
+ exports.isCapitalizedComponentName = isCapitalizedComponentName;
2518
2737
  //# sourceMappingURL=transform-litsx-components.cjs.map