@litsx/babel-preset-litsx 0.3.0 → 0.5.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,39 +4,52 @@ 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
- if (statement.expression.arguments.length !== 0) {
23
- throw new Error("^lightDom() does not accept arguments.");
28
+
29
+ const args = statement.expression.arguments;
30
+ if (args.length === 0) {
31
+ return true;
24
32
  }
25
- return true;
33
+
34
+ if (args.length === 1 && t$9.isBooleanLiteral(args[0], { value: true })) {
35
+ return true;
36
+ }
37
+
38
+ throw new Error("static lightDom = true only accepts the literal value true.");
26
39
  }
27
40
 
28
41
  function createStaticHoistGetter(name, symbolId, expression) {
29
- const getter = t$7.classMethod(
42
+ const getter = t$9.classMethod(
30
43
  "get",
31
- t$7.identifier(name),
44
+ t$9.identifier(name),
32
45
  [],
33
- t$7.blockStatement([
34
- t$7.returnStatement(
35
- t$7.callExpression(
36
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxStatic")),
46
+ t$9.blockStatement([
47
+ t$9.returnStatement(
48
+ t$9.callExpression(
49
+ t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxStatic")),
37
50
  [
38
- t$7.cloneNode(symbolId),
39
- t$7.arrowFunctionExpression([], expression),
51
+ t$9.cloneNode(symbolId),
52
+ t$9.arrowFunctionExpression([], expression),
40
53
  ]
41
54
  )
42
55
  ),
@@ -47,22 +60,22 @@ function createStaticHoistGetter(name, symbolId, expression) {
47
60
  }
48
61
 
49
62
  function resolveStaticHoistExpression(expression) {
50
- return t$7.callExpression(
51
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxResolveStaticValue")),
52
- [t$7.cloneNode(expression)]
63
+ return t$9.callExpression(
64
+ t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxResolveStaticValue")),
65
+ [t$9.cloneNode(expression)]
53
66
  );
54
67
  }
55
68
 
56
69
  function createPropertiesHoistResolver(propertiesStatic, staticProps, expression) {
57
- const mergedProperties = propertiesStatic.map((property) => t$7.cloneNode(property));
70
+ const mergedProperties = propertiesStatic.map((property) => t$9.cloneNode(property));
58
71
  if (staticProps.length > 0) {
59
72
  mergeStaticPropsIntoProperties(mergedProperties, staticProps);
60
73
  }
61
74
 
62
- return t$7.callExpression(
63
- t$7.memberExpression(t$7.thisExpression(), t$7.identifier("__litsxMergeProperties")),
75
+ return t$9.callExpression(
76
+ t$9.memberExpression(t$9.thisExpression(), t$9.identifier("__litsxMergeProperties")),
64
77
  [
65
- t$7.objectExpression(mergedProperties),
78
+ t$9.objectExpression(mergedProperties),
66
79
  resolveStaticHoistExpression(expression),
67
80
  ]
68
81
  );
@@ -76,17 +89,17 @@ function createStylesHoistResolver(staticStyles, expression) {
76
89
 
77
90
  const baseStyles =
78
91
  staticStyles.length === 1
79
- ? t$7.cloneNode(staticStyles[0])
80
- : t$7.arrayExpression(staticStyles.map((style) => t$7.cloneNode(style)));
92
+ ? t$9.cloneNode(staticStyles[0])
93
+ : t$9.arrayExpression(staticStyles.map((style) => t$9.cloneNode(style)));
81
94
 
82
- return t$7.logicalExpression("||", resolvedExpression, baseStyles);
95
+ return t$9.logicalExpression("||", resolvedExpression, baseStyles);
83
96
  }
84
97
 
85
98
  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(
99
+ if (!t$9.isExpressionStatement(statement)) return null;
100
+ if (!t$9.isCallExpression(statement.expression)) return null;
101
+ const isLegacyStaticProps = t$9.isIdentifier(statement.expression.callee, { name: "staticProps" });
102
+ const isHoistedProperties = t$9.isIdentifier(
90
103
  statement.expression.callee,
91
104
  { name: "__litsx_static_properties" }
92
105
  );
@@ -99,47 +112,47 @@ function getStaticPropsExpression(statement) {
99
112
  if (statement.expression.arguments.length !== 1) return null;
100
113
 
101
114
  const [argument] = statement.expression.arguments;
102
- if (isHoistedProperties && (t$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument))) {
103
- throw new Error("^properties(...) only accepts an object literal with static Lit property options.");
115
+ if (isHoistedProperties && (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument))) {
116
+ throw new Error("static properties = ... only accepts an object literal with static Lit property options.");
104
117
  }
105
118
 
106
- if (!t$7.isObjectExpression(argument)) {
107
- throw new Error("^properties(...) only accepts an object literal with static Lit property options.");
119
+ if (!t$9.isObjectExpression(argument)) {
120
+ throw new Error("static properties = ... only accepts an object literal with static Lit property options.");
108
121
  }
109
122
 
110
123
  return isHoistedProperties ? {
111
124
  __litsxHoistedProperties: true,
112
- expression: t$7.cloneNode(argument),
113
- } : t$7.cloneNode(argument);
125
+ expression: t$9.cloneNode(argument),
126
+ } : t$9.cloneNode(argument);
114
127
  }
115
128
 
116
129
  function getStaticPropertyName(node) {
117
- if (t$7.isIdentifier(node)) return node.name;
118
- if (t$7.isStringLiteral(node)) return node.value;
130
+ if (t$9.isIdentifier(node)) return node.name;
131
+ if (t$9.isStringLiteral(node)) return node.value;
119
132
  return null;
120
133
  }
121
134
 
122
135
  function normalizeStaticPropOverrideValue(value) {
123
136
  if (
124
- t$7.isIdentifier(value) &&
137
+ t$9.isIdentifier(value) &&
125
138
  ["String", "Number", "Boolean", "Object", "Array", "Date"].includes(value.name)
126
139
  ) {
127
- return internal_transformLitsxProperties.createPropertyConfig(t$7.identifier(value.name));
140
+ return internal_transformLitsxProperties.createPropertyConfig(t$9.identifier(value.name));
128
141
  }
129
142
 
130
- if (t$7.isObjectExpression(value)) {
143
+ if (t$9.isObjectExpression(value)) {
131
144
  const typeProperty = value.properties.find(
132
145
  (prop) =>
133
- t$7.isObjectProperty(prop) &&
134
- t$7.isIdentifier(prop.key, { name: "type" }) &&
135
- t$7.isIdentifier(prop.value)
146
+ t$9.isObjectProperty(prop) &&
147
+ t$9.isIdentifier(prop.key, { name: "type" }) &&
148
+ t$9.isIdentifier(prop.value)
136
149
  );
137
150
 
138
151
  const attributeProperty = value.properties.find(
139
152
  (prop) =>
140
- t$7.isObjectProperty(prop) &&
141
- t$7.isIdentifier(prop.key, { name: "attribute" }) &&
142
- t$7.isBooleanLiteral(prop.value) &&
153
+ t$9.isObjectProperty(prop) &&
154
+ t$9.isIdentifier(prop.key, { name: "attribute" }) &&
155
+ t$9.isBooleanLiteral(prop.value) &&
143
156
  prop.value.value === false
144
157
  );
145
158
 
@@ -149,37 +162,37 @@ function normalizeStaticPropOverrideValue(value) {
149
162
  }
150
163
 
151
164
  throw new Error(
152
- "^properties(...) values must be Lit property option objects or constructor references."
165
+ "static properties = ... values must be Lit property option objects or constructor references."
153
166
  );
154
167
  }
155
168
 
156
169
  function mergeStaticPropertyObject(targetNode, overrideObject) {
157
- if (!t$7.isObjectProperty(targetNode) || !t$7.isObjectExpression(targetNode.value)) {
170
+ if (!t$9.isObjectProperty(targetNode) || !t$9.isObjectExpression(targetNode.value)) {
158
171
  return;
159
172
  }
160
173
 
161
174
  overrideObject.properties.forEach((property) => {
162
- if (!t$7.isObjectProperty(property) && !t$7.isObjectMethod(property)) {
163
- throw new Error("^properties(...) only accepts plain object members.");
175
+ if (!t$9.isObjectProperty(property) && !t$9.isObjectMethod(property)) {
176
+ throw new Error("static properties = ... only accepts plain object members.");
164
177
  }
165
178
 
166
179
  const keyName = getStaticPropertyName(property.key);
167
180
  if (!keyName) {
168
- throw new Error("^properties(...) property option names must be static identifiers or strings.");
181
+ throw new Error("static properties = ... property option names must be static identifiers or strings.");
169
182
  }
170
183
 
171
184
  const existing = targetNode.value.properties.find(
172
185
  (candidate) =>
173
- (t$7.isObjectProperty(candidate) || t$7.isObjectMethod(candidate)) &&
186
+ (t$9.isObjectProperty(candidate) || t$9.isObjectMethod(candidate)) &&
174
187
  getStaticPropertyName(candidate.key) === keyName
175
188
  );
176
189
 
177
190
  if (existing) {
178
- const nextNode = t$7.cloneNode(property);
191
+ const nextNode = t$9.cloneNode(property);
179
192
  const index = targetNode.value.properties.indexOf(existing);
180
193
  targetNode.value.properties.splice(index, 1, nextNode);
181
194
  } else {
182
- targetNode.value.properties.push(t$7.cloneNode(property));
195
+ targetNode.value.properties.push(t$9.cloneNode(property));
183
196
  }
184
197
  });
185
198
  }
@@ -188,7 +201,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
188
201
  const propertyMap = new Map();
189
202
 
190
203
  propertiesStatic.forEach((propertyNode) => {
191
- if (!t$7.isObjectProperty(propertyNode)) return;
204
+ if (!t$9.isObjectProperty(propertyNode)) return;
192
205
  const keyName = getStaticPropertyName(propertyNode.key);
193
206
  if (!keyName) return;
194
207
  propertyMap.set(keyName, propertyNode);
@@ -196,24 +209,24 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
196
209
 
197
210
  staticProps.forEach((optionsObject) => {
198
211
  optionsObject.properties.forEach((property) => {
199
- if (!t$7.isObjectProperty(property)) {
200
- throw new Error("^properties(...) only accepts plain object properties.");
212
+ if (!t$9.isObjectProperty(property)) {
213
+ throw new Error("static properties = ... only accepts plain object properties.");
201
214
  }
202
215
 
203
216
  const keyName = getStaticPropertyName(property.key);
204
217
  if (!keyName) {
205
- throw new Error("^properties(...) property names must be static identifiers or strings.");
218
+ throw new Error("static properties = ... property names must be static identifiers or strings.");
206
219
  }
207
220
 
208
221
  const existing = propertyMap.get(keyName);
209
222
  const normalized = normalizeStaticPropOverrideValue(property.value);
210
223
 
211
224
  if (!existing) {
212
- const node = t$7.objectProperty(
213
- t$7.identifier(keyName),
225
+ const node = t$9.objectProperty(
226
+ t$9.identifier(keyName),
214
227
  internal_transformLitsxProperties.createPropertyValue(normalized, false)
215
228
  );
216
- if (t$7.isObjectExpression(property.value)) {
229
+ if (t$9.isObjectExpression(property.value)) {
217
230
  mergeStaticPropertyObject(node, property.value);
218
231
  }
219
232
  propertiesStatic.push(node);
@@ -227,7 +240,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
227
240
  false
228
241
  );
229
242
 
230
- if (t$7.isObjectExpression(property.value)) {
243
+ if (t$9.isObjectExpression(property.value)) {
231
244
  mergeStaticPropertyObject(existing, property.value);
232
245
  }
233
246
  });
@@ -235,7 +248,7 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
235
248
  }
236
249
 
237
250
  function normalizeStylesTemplate(argument, functionPath) {
238
- if (t$7.isTemplateLiteral(argument)) {
251
+ if (t$9.isTemplateLiteral(argument)) {
239
252
  if (
240
253
  !argument.expressions.every((expression) =>
241
254
  isStaticStylesExpression(expression, functionPath)
@@ -243,7 +256,7 @@ function normalizeStylesTemplate(argument, functionPath) {
243
256
  ) {
244
257
  return null;
245
258
  }
246
- return t$7.templateLiteral(
259
+ return t$9.templateLiteral(
247
260
  argument.quasis,
248
261
  argument.expressions.map((expression) =>
249
262
  wrapStaticStylesInterpolation(expression)
@@ -251,18 +264,18 @@ function normalizeStylesTemplate(argument, functionPath) {
251
264
  );
252
265
  }
253
266
 
254
- if (t$7.isStringLiteral(argument)) {
255
- return t$7.templateLiteral(
256
- [t$7.templateElement({ raw: argument.value, cooked: argument.value }, true)],
267
+ if (t$9.isStringLiteral(argument)) {
268
+ return t$9.templateLiteral(
269
+ [t$9.templateElement({ raw: argument.value, cooked: argument.value }, true)],
257
270
  []
258
271
  );
259
272
  }
260
273
 
261
274
  if (isStaticStylesExpression(argument, functionPath)) {
262
- return t$7.templateLiteral(
275
+ return t$9.templateLiteral(
263
276
  [
264
- t$7.templateElement({ raw: "", cooked: "" }, false),
265
- t$7.templateElement({ raw: "", cooked: "" }, true),
277
+ t$9.templateElement({ raw: "", cooked: "" }, false),
278
+ t$9.templateElement({ raw: "", cooked: "" }, true),
266
279
  ],
267
280
  [wrapStaticStylesInterpolation(argument)]
268
281
  );
@@ -273,27 +286,27 @@ function normalizeStylesTemplate(argument, functionPath) {
273
286
 
274
287
  function wrapStaticStylesInterpolation(expression) {
275
288
  if (
276
- t$7.isTaggedTemplateExpression(expression) &&
277
- t$7.isIdentifier(expression.tag, { name: "css" })
289
+ t$9.isTaggedTemplateExpression(expression) &&
290
+ t$9.isIdentifier(expression.tag, { name: "css" })
278
291
  ) {
279
292
  return expression;
280
293
  }
281
294
 
282
- if (t$7.isNumericLiteral(expression)) {
295
+ if (t$9.isNumericLiteral(expression)) {
283
296
  return expression;
284
297
  }
285
298
 
286
- return t$7.callExpression(
287
- t$7.identifier("unsafeCSS"),
299
+ return t$9.callExpression(
300
+ t$9.identifier("unsafeCSS"),
288
301
  [expression]
289
302
  );
290
303
  }
291
304
 
292
305
  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" });
306
+ if (!t$9.isExpressionStatement(statement)) return null;
307
+ if (!t$9.isCallExpression(statement.expression)) return null;
308
+ const isLegacyStaticStyles = t$9.isIdentifier(statement.expression.callee, { name: "staticStyles" });
309
+ const isHoistedStyles = t$9.isIdentifier(statement.expression.callee, { name: "__litsx_static_styles" });
297
310
  if (
298
311
  !isLegacyStaticStyles &&
299
312
  !isHoistedStyles
@@ -304,8 +317,8 @@ function getStaticStylesExpression(statement, functionPath) {
304
317
 
305
318
  const [argument] = statement.expression.arguments;
306
319
 
307
- if (isHoistedStyles && (t$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument))) {
308
- throw new Error("^styles(...) only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
320
+ if (isHoistedStyles && (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument))) {
321
+ throw new Error("static styles = ... only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
309
322
  }
310
323
 
311
324
  const template = normalizeStylesTemplate(
@@ -313,19 +326,19 @@ function getStaticStylesExpression(statement, functionPath) {
313
326
  functionPath
314
327
  );
315
328
  if (!template) {
316
- throw new Error("^styles(...) only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
329
+ throw new Error("static styles = ... only accepts static values. Move dynamic values to useStyle(...) or CSS custom properties.");
317
330
  }
318
331
 
319
- const expression = t$7.taggedTemplateExpression(t$7.identifier("css"), template);
332
+ const expression = t$9.taggedTemplateExpression(t$9.identifier("css"), template);
320
333
  return isHoistedStyles
321
334
  ? { __litsxHoistedStyles: true, expression }
322
335
  : expression;
323
336
  }
324
337
 
325
338
  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;
339
+ if (!t$9.isExpressionStatement(statement)) return null;
340
+ if (!t$9.isCallExpression(statement.expression)) return null;
341
+ if (!t$9.isIdentifier(statement.expression.callee)) return null;
329
342
 
330
343
  const calleeName = statement.expression.callee.name;
331
344
  if (!calleeName.startsWith("__litsx_static_")) {
@@ -338,32 +351,32 @@ function getStaticHoistExpression(statement, functionPath) {
338
351
  }
339
352
 
340
353
  if (statement.expression.arguments.length !== 1) {
341
- throw new Error(`^${name}(...) expects exactly one argument.`);
354
+ throw new Error(`static ${name} = ... expects exactly one argument.`);
342
355
  }
343
356
 
344
357
  const [argument] = statement.expression.arguments;
345
358
  if (name === "expose") {
346
- if (t$7.isObjectExpression(argument)) {
359
+ if (t$9.isObjectExpression(argument)) {
347
360
  return {
348
361
  name,
349
- expression: t$7.cloneNode(argument),
362
+ expression: t$9.cloneNode(argument),
350
363
  };
351
364
  }
352
365
 
353
- throw new Error("^expose(...) only accepts an object literal.");
366
+ throw new Error("static expose = ... only accepts an object literal.");
354
367
  }
355
368
 
356
- if (t$7.isFunctionExpression(argument) || t$7.isArrowFunctionExpression(argument)) {
357
- throw new Error(`^${name}(...) only accepts a direct static value.`);
369
+ if (t$9.isFunctionExpression(argument) || t$9.isArrowFunctionExpression(argument)) {
370
+ throw new Error(`static ${name} = ... only accepts a direct static value.`);
358
371
  }
359
372
 
360
373
  if (!isStaticStylesExpression(argument, functionPath)) {
361
- throw new Error(`^${name}(...) only accepts a direct static value.`);
374
+ throw new Error(`static ${name} = ... only accepts a direct static value.`);
362
375
  }
363
376
 
364
377
  return {
365
378
  name,
366
- expression: t$7.cloneNode(argument),
379
+ expression: t$9.cloneNode(argument),
367
380
  };
368
381
  }
369
382
 
@@ -376,13 +389,13 @@ function createExposeHoistMembers(expression) {
376
389
  }
377
390
 
378
391
  function normalizeExposeHoistExpression(expression) {
379
- if (t$7.isObjectExpression(expression)) {
392
+ if (t$9.isObjectExpression(expression)) {
380
393
  return {
381
- methodsExpression: t$7.cloneNode(expression),
394
+ methodsExpression: t$9.cloneNode(expression),
382
395
  };
383
396
  }
384
397
 
385
- throw new Error("^expose(...) only accepts an object literal.");
398
+ throw new Error("static expose = ... only accepts an object literal.");
386
399
  }
387
400
 
388
401
  function createExposeClassMethod(property) {
@@ -392,41 +405,41 @@ function createExposeClassMethod(property) {
392
405
  }
393
406
 
394
407
  function normalizeExposePropertyToClassMethod(property) {
395
- if (t$7.isSpreadElement(property)) {
396
- throw new Error("^expose(...) does not accept spread elements.");
408
+ if (t$9.isSpreadElement(property)) {
409
+ throw new Error("static expose = ... does not accept spread elements.");
397
410
  }
398
411
 
399
- if (t$7.isObjectMethod(property)) {
412
+ if (t$9.isObjectMethod(property)) {
400
413
  if (property.kind !== "method") {
401
- throw new Error("^expose(...) only accepts plain methods.");
414
+ throw new Error("static expose = ... only accepts plain methods.");
402
415
  }
403
416
 
404
- return t$7.classMethod(
417
+ return t$9.classMethod(
405
418
  "method",
406
- t$7.cloneNode(property.key),
407
- property.params.map((param) => t$7.cloneNode(param)),
408
- t$7.cloneNode(property.body),
419
+ t$9.cloneNode(property.key),
420
+ property.params.map((param) => t$9.cloneNode(param)),
421
+ t$9.cloneNode(property.body),
409
422
  property.computed
410
423
  );
411
424
  }
412
425
 
413
- if (!t$7.isObjectProperty(property)) {
414
- throw new Error("^expose(...) only accepts plain methods.");
426
+ if (!t$9.isObjectProperty(property)) {
427
+ throw new Error("static expose = ... only accepts plain methods.");
415
428
  }
416
429
 
417
430
  const value = property.value;
418
- if (!t$7.isFunctionExpression(value) && !t$7.isArrowFunctionExpression(value)) {
419
- throw new Error("^expose(...) values must be functions.");
431
+ if (!t$9.isFunctionExpression(value) && !t$9.isArrowFunctionExpression(value)) {
432
+ throw new Error("static expose = ... values must be functions.");
420
433
  }
421
434
 
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))]);
435
+ const body = t$9.isBlockStatement(value.body)
436
+ ? t$9.cloneNode(value.body)
437
+ : t$9.blockStatement([t$9.returnStatement(t$9.cloneNode(value.body))]);
425
438
 
426
- const method = t$7.classMethod(
439
+ const method = t$9.classMethod(
427
440
  "method",
428
- t$7.cloneNode(property.key),
429
- value.params.map((param) => t$7.cloneNode(param)),
441
+ t$9.cloneNode(property.key),
442
+ value.params.map((param) => t$9.cloneNode(param)),
430
443
  body,
431
444
  property.computed
432
445
  );
@@ -438,7 +451,7 @@ function normalizeExposePropertyToClassMethod(property) {
438
451
  function assertStaticHoistsStayTopLevel(functionPath) {
439
452
  functionPath.traverse({
440
453
  CallExpression(callPath) {
441
- if (!t$7.isIdentifier(callPath.node.callee)) return;
454
+ if (!t$9.isIdentifier(callPath.node.callee)) return;
442
455
  if (!callPath.node.callee.name.startsWith("__litsx_static_")) return;
443
456
 
444
457
  const statementParent = callPath.parentPath;
@@ -454,7 +467,7 @@ function assertStaticHoistsStayTopLevel(functionPath) {
454
467
 
455
468
  const macroName = callPath.node.callee.name.slice("__litsx_static_".length);
456
469
  throw callPath.buildCodeFrameError(
457
- `^${macroName}(...) must appear as a top-level statement in the component body.`
470
+ `static ${macroName} = ... must appear as a top-level statement in the component body.`
458
471
  );
459
472
  },
460
473
  });
@@ -463,8 +476,8 @@ function assertStaticHoistsStayTopLevel(functionPath) {
463
476
  function containsUnsafeCssCall(node) {
464
477
  if (!node || typeof node !== "object") return false;
465
478
  if (
466
- t$7.isCallExpression(node) &&
467
- t$7.isIdentifier(node.callee, { name: "unsafeCSS" })
479
+ t$9.isCallExpression(node) &&
480
+ t$9.isIdentifier(node.callee, { name: "unsafeCSS" })
468
481
  ) {
469
482
  return true;
470
483
  }
@@ -479,37 +492,37 @@ function containsUnsafeCssCall(node) {
479
492
 
480
493
  function isStaticStylesExpression(node, functionPath, seenBindings = new Set()) {
481
494
  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)
495
+ t$9.isStringLiteral(node) ||
496
+ t$9.isNumericLiteral(node) ||
497
+ t$9.isBooleanLiteral(node) ||
498
+ t$9.isNullLiteral(node) ||
499
+ t$9.isBigIntLiteral?.(node)
487
500
  ) {
488
501
  return true;
489
502
  }
490
503
 
491
- if (t$7.isTemplateLiteral(node)) {
504
+ if (t$9.isTemplateLiteral(node)) {
492
505
  return node.expressions.every((expression) =>
493
506
  isStaticStylesExpression(expression, functionPath, seenBindings)
494
507
  );
495
508
  }
496
509
 
497
- if (t$7.isIdentifier(node)) {
510
+ if (t$9.isIdentifier(node)) {
498
511
  return isStaticStylesIdentifier(node, functionPath, seenBindings);
499
512
  }
500
513
 
501
- if (t$7.isUnaryExpression(node)) {
514
+ if (t$9.isUnaryExpression(node)) {
502
515
  return isStaticStylesExpression(node.argument, functionPath, seenBindings);
503
516
  }
504
517
 
505
- if (t$7.isBinaryExpression(node) || t$7.isLogicalExpression(node)) {
518
+ if (t$9.isBinaryExpression(node) || t$9.isLogicalExpression(node)) {
506
519
  return (
507
520
  isStaticStylesExpression(node.left, functionPath, seenBindings) &&
508
521
  isStaticStylesExpression(node.right, functionPath, seenBindings)
509
522
  );
510
523
  }
511
524
 
512
- if (t$7.isConditionalExpression(node)) {
525
+ if (t$9.isConditionalExpression(node)) {
513
526
  return (
514
527
  isStaticStylesExpression(node.test, functionPath, seenBindings) &&
515
528
  isStaticStylesExpression(node.consequent, functionPath, seenBindings) &&
@@ -517,15 +530,15 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
517
530
  );
518
531
  }
519
532
 
520
- if (t$7.isArrayExpression(node)) {
533
+ if (t$9.isArrayExpression(node)) {
521
534
  return node.elements.every((element) =>
522
535
  element == null || isStaticStylesExpression(element, functionPath, seenBindings)
523
536
  );
524
537
  }
525
538
 
526
- if (t$7.isObjectExpression(node)) {
539
+ if (t$9.isObjectExpression(node)) {
527
540
  return node.properties.every((property) => {
528
- if (t$7.isObjectProperty(property)) {
541
+ if (t$9.isObjectProperty(property)) {
529
542
  return (
530
543
  (!property.computed ||
531
544
  isStaticStylesExpression(property.key, functionPath, seenBindings)) &&
@@ -536,7 +549,7 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
536
549
  });
537
550
  }
538
551
 
539
- if (t$7.isMemberExpression(node)) {
552
+ if (t$9.isMemberExpression(node)) {
540
553
  return (
541
554
  isStaticStylesExpression(node.object, functionPath, seenBindings) &&
542
555
  (!node.computed ||
@@ -544,18 +557,18 @@ function isStaticStylesExpression(node, functionPath, seenBindings = new Set())
544
557
  );
545
558
  }
546
559
 
547
- if (t$7.isCallExpression(node)) {
560
+ if (t$9.isCallExpression(node)) {
548
561
  return (
549
562
  isStaticStylesExpression(node.callee, functionPath, seenBindings) &&
550
563
  node.arguments.every((argument) =>
551
- t$7.isSpreadElement(argument)
564
+ t$9.isSpreadElement(argument)
552
565
  ? false
553
566
  : isStaticStylesExpression(argument, functionPath, seenBindings)
554
567
  )
555
568
  );
556
569
  }
557
570
 
558
- if (t$7.isTaggedTemplateExpression(node)) {
571
+ if (t$9.isTaggedTemplateExpression(node)) {
559
572
  return (
560
573
  isStaticStylesExpression(node.tag, functionPath, seenBindings) &&
561
574
  isStaticStylesExpression(node.quasi, functionPath, seenBindings)
@@ -621,7 +634,7 @@ function processStaticHoists({
621
634
  const staticHoists = [];
622
635
  let lightDomRequested = options.defaultDomMode === "light";
623
636
 
624
- if (t$7.isBlockStatement(node.body)) {
637
+ if (t$9.isBlockStatement(node.body)) {
625
638
  for (let index = renderStatements.length - 1; index >= 0; index -= 1) {
626
639
  const propertyOptions = getStaticPropsExpression(renderStatements[index]);
627
640
  if (propertyOptions) {
@@ -665,8 +678,12 @@ function processStaticHoists({
665
678
  }
666
679
  }
667
680
 
668
- if (lightDomRequested && staticHoists.some((entry) => entry.name === "shadowRootOptions")) {
669
- throw new Error("^lightDom() cannot be combined with ^shadowRootOptions(...).");
681
+ if (lightDomRequested) {
682
+ for (let index = staticHoists.length - 1; index >= 0; index -= 1) {
683
+ if (staticHoists[index]?.name === "shadowRootOptions") {
684
+ staticHoists.splice(index, 1);
685
+ }
686
+ }
670
687
  }
671
688
 
672
689
  if (staticProps.length > 0) {
@@ -675,9 +692,9 @@ function processStaticHoists({
675
692
 
676
693
  const hasHoistedProperties = staticHoists.some((entry) => entry.name === "properties");
677
694
  if (propertiesStatic.length > 0 && !hasHoistedProperties) {
678
- const classProperties = t$7.classProperty(
679
- t$7.identifier("properties"),
680
- t$7.objectExpression(propertiesStatic),
695
+ const classProperties = t$9.classProperty(
696
+ t$9.identifier("properties"),
697
+ t$9.objectExpression(propertiesStatic),
681
698
  null,
682
699
  [],
683
700
  false
@@ -689,9 +706,9 @@ function processStaticHoists({
689
706
 
690
707
  const hasHoistedStyles = staticHoists.some((entry) => entry.name === "styles");
691
708
  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),
709
+ const stylesProperty = t$9.classProperty(
710
+ t$9.identifier("styles"),
711
+ staticStyles.length === 1 ? staticStyles[0] : t$9.arrayExpression(staticStyles),
695
712
  null,
696
713
  [],
697
714
  false
@@ -756,10 +773,10 @@ function processStaticHoists({
756
773
  };
757
774
  }
758
775
 
759
- let t$6;
776
+ let t$8;
760
777
 
761
778
  function setHandlersBabelTypes(types) {
762
- t$6 = types;
779
+ t$8 = types;
763
780
  }
764
781
 
765
782
  function isHoistableHandler(exprPath, componentPath) {
@@ -806,11 +823,11 @@ function generateHandlerName(attrName, usedNames) {
806
823
  }
807
824
 
808
825
  function normalizeHandlerBody(body) {
809
- if (t$6.isBlockStatement(body)) {
810
- return t$6.cloneNode(body, true);
826
+ if (t$8.isBlockStatement(body)) {
827
+ return t$8.cloneNode(body, true);
811
828
  }
812
829
 
813
- return t$6.blockStatement([t$6.returnStatement(t$6.cloneNode(body, true))]);
830
+ return t$8.blockStatement([t$8.returnStatement(t$8.cloneNode(body, true))]);
814
831
  }
815
832
 
816
833
  function hoistDeclaredHandlers(functionPath, usedNames) {
@@ -825,7 +842,7 @@ function hoistDeclaredHandlers(functionPath, usedNames) {
825
842
  if (path.getFunctionParent() !== functionPath) return;
826
843
 
827
844
  const id = path.node.id;
828
- if (!t$6.isIdentifier(id)) return;
845
+ if (!t$8.isIdentifier(id)) return;
829
846
 
830
847
  const initPath = path.get("init");
831
848
  if (!initPath.isArrowFunctionExpression() && !initPath.isFunctionExpression()) {
@@ -849,13 +866,13 @@ function hoistDeclaredHandlers(functionPath, usedNames) {
849
866
  binding.referencePaths.slice().forEach((refPath) => {
850
867
  if (!refPath.node || refPath.removed) return;
851
868
  refPath.replaceWith(
852
- t$6.memberExpression(t$6.thisExpression(), t$6.identifier(handlerName))
869
+ t$8.memberExpression(t$8.thisExpression(), t$8.identifier(handlerName))
853
870
  );
854
871
  });
855
872
 
856
873
  handlerInfos.push({
857
874
  name: handlerName,
858
- params: initPath.node.params.map((param) => t$6.cloneNode(param, true)),
875
+ params: initPath.node.params.map((param) => t$8.cloneNode(param, true)),
859
876
  body: normalizeHandlerBody(initPath.node.body),
860
877
  async: initPath.node.async,
861
878
  generator: initPath.node.generator,
@@ -885,7 +902,7 @@ function hoistEventHandlers(functionPath, usedNames) {
885
902
  if (attrPath.getFunctionParent() !== functionPath) return;
886
903
 
887
904
  const { node } = attrPath;
888
- if (!t$6.isJSXIdentifier(node.name)) return;
905
+ if (!t$8.isJSXIdentifier(node.name)) return;
889
906
 
890
907
  const attrName = node.name.name;
891
908
  if (!/^on[A-Z]/.test(attrName)) return;
@@ -907,15 +924,15 @@ function hoistEventHandlers(functionPath, usedNames) {
907
924
 
908
925
  handlerInfos.push({
909
926
  name: handlerName,
910
- params: exprPath.node.params.map((param) => t$6.cloneNode(param, true)),
927
+ params: exprPath.node.params.map((param) => t$8.cloneNode(param, true)),
911
928
  body: normalizeHandlerBody(exprPath.node.body),
912
929
  async: exprPath.node.async,
913
930
  generator: exprPath.node.generator,
914
931
  });
915
932
 
916
933
  valuePath.replaceWith(
917
- t$6.jsxExpressionContainer(
918
- t$6.memberExpression(t$6.thisExpression(), t$6.identifier(handlerName))
934
+ t$8.jsxExpressionContainer(
935
+ t$8.memberExpression(t$8.thisExpression(), t$8.identifier(handlerName))
919
936
  )
920
937
  );
921
938
  },
@@ -925,7 +942,7 @@ function hoistEventHandlers(functionPath, usedNames) {
925
942
  }
926
943
 
927
944
  function isNativeIntrinsicJsxElement(nameNode) {
928
- return t$6.isJSXIdentifier(nameNode) && /^[a-z]/.test(nameNode.name);
945
+ return t$8.isJSXIdentifier(nameNode) && /^[a-z]/.test(nameNode.name);
929
946
  }
930
947
 
931
948
  function collectNativeClassNameWarnings(functionPath, warn, options = {}) {
@@ -942,7 +959,7 @@ function collectNativeClassNameWarnings(functionPath, warn, options = {}) {
942
959
  if (!isNativeIntrinsicJsxElement(openingElement.node.name)) return;
943
960
 
944
961
  const { node } = attrPath;
945
- if (!t$6.isJSXIdentifier(node.name, { name: "className" })) return;
962
+ if (!t$8.isJSXIdentifier(node.name, { name: "className" })) return;
946
963
 
947
964
  warn({
948
965
  code: "LITSX_NATIVE_CLASSNAME",
@@ -964,11 +981,11 @@ function processHandlers(functionPath, usedNames) {
964
981
  }
965
982
 
966
983
  function createHandlerClassMember({ name, params, body, async, generator }) {
967
- const method = t$6.classMethod(
984
+ const method = t$8.classMethod(
968
985
  "method",
969
- t$6.identifier(name),
970
- params.map((param) => t$6.cloneNode(param, true)),
971
- t$6.cloneNode(body, true)
986
+ t$8.identifier(name),
987
+ params.map((param) => t$8.cloneNode(param, true)),
988
+ t$8.cloneNode(body, true)
972
989
  );
973
990
 
974
991
  method.async = Boolean(async);
@@ -977,7 +994,7 @@ function createHandlerClassMember({ name, params, body, async, generator }) {
977
994
  return method;
978
995
  }
979
996
 
980
- let t$5;
997
+ let t$7;
981
998
 
982
999
  function isCapitalizedComponentName$1(name) {
983
1000
  if (typeof name !== "string" || name.length === 0) {
@@ -989,7 +1006,7 @@ function isCapitalizedComponentName$1(name) {
989
1006
  }
990
1007
 
991
1008
  function setWrapperUtilsBabelTypes(nextTypes) {
992
- t$5 = nextTypes;
1009
+ t$7 = nextTypes;
993
1010
  }
994
1011
 
995
1012
  function emitWrapperWarnings(meta, warn) {
@@ -1044,7 +1061,7 @@ function maybeTransformWrappedVariableDeclarator({
1044
1061
  });
1045
1062
 
1046
1063
  const programPath = varPath.findParent((p) => p.isProgram());
1047
- const localName = t$5.isIdentifier(varPath.node.id)
1064
+ const localName = t$7.isIdentifier(varPath.node.id)
1048
1065
  ? varPath.node.id.name
1049
1066
  : undefined;
1050
1067
 
@@ -1067,7 +1084,7 @@ function maybeTransformWrappedVariableDeclarator({
1067
1084
  return true;
1068
1085
  }
1069
1086
 
1070
- if (t$5.isIdentifier(varPath.node.id)) {
1087
+ if (t$7.isIdentifier(varPath.node.id)) {
1071
1088
  varPath.scope.removeBinding(varPath.node.id.name);
1072
1089
  }
1073
1090
 
@@ -1099,21 +1116,21 @@ function handlePotentialComponentExport({
1099
1116
  }
1100
1117
 
1101
1118
  if (
1102
- t$5.isFunctionDeclaration(declaration) ||
1103
- (t$5.isVariableDeclaration(declaration) &&
1119
+ t$7.isFunctionDeclaration(declaration) ||
1120
+ (t$7.isVariableDeclaration(declaration) &&
1104
1121
  declaration.declarations.length === 1 &&
1105
- t$5.isArrowFunctionExpression(declaration.declarations[0].init))
1122
+ t$7.isArrowFunctionExpression(declaration.declarations[0].init))
1106
1123
  ) {
1107
1124
  const funcPath = exportPath.get("declaration");
1108
1125
  const declarationPath = funcPath.isVariableDeclaration()
1109
1126
  ? funcPath.get("declarations.0.init")
1110
1127
  : funcPath;
1111
1128
  let exportName;
1112
- if (t$5.isFunctionDeclaration(declaration) && declaration.id) {
1129
+ if (t$7.isFunctionDeclaration(declaration) && declaration.id) {
1113
1130
  exportName = declaration.id.name;
1114
1131
  } else if (
1115
- t$5.isVariableDeclaration(declaration) &&
1116
- t$5.isIdentifier(declaration.declarations[0].id)
1132
+ t$7.isVariableDeclaration(declaration) &&
1133
+ t$7.isIdentifier(declaration.declarations[0].id)
1117
1134
  ) {
1118
1135
  exportName = declaration.declarations[0].id.name;
1119
1136
  }
@@ -1144,8 +1161,8 @@ function handlePotentialComponentExport({
1144
1161
 
1145
1162
  exportPath.insertBefore(
1146
1163
  isDefault
1147
- ? t$5.exportDefaultDeclaration(classNode)
1148
- : t$5.exportNamedDeclaration(classNode, [])
1164
+ ? t$7.exportDefaultDeclaration(classNode)
1165
+ : t$7.exportNamedDeclaration(classNode, [])
1149
1166
  );
1150
1167
  exportPath.remove();
1151
1168
  updateTransformState?.(state, classNode);
@@ -1154,12 +1171,12 @@ function handlePotentialComponentExport({
1154
1171
 
1155
1172
  if (
1156
1173
  typeof getWrapperMetadata === "function" &&
1157
- t$5.isVariableDeclaration(declaration) &&
1174
+ t$7.isVariableDeclaration(declaration) &&
1158
1175
  declaration.declarations.length === 1
1159
1176
  ) {
1160
1177
  const declaratorPath = exportPath.get("declaration.declarations.0");
1161
1178
  const initPath = declaratorPath.get("init");
1162
- const exportName = t$5.isIdentifier(declaratorPath.node.id)
1179
+ const exportName = t$7.isIdentifier(declaratorPath.node.id)
1163
1180
  ? declaratorPath.node.id.name
1164
1181
  : undefined;
1165
1182
  const programPath = exportPath.findParent((p) => p.isProgram());
@@ -1197,8 +1214,8 @@ function handlePotentialComponentExport({
1197
1214
 
1198
1215
  exportPath.replaceWith(
1199
1216
  isDefault
1200
- ? t$5.exportDefaultDeclaration(classNode)
1201
- : t$5.exportNamedDeclaration(classNode, [])
1217
+ ? t$7.exportDefaultDeclaration(classNode)
1218
+ : t$7.exportNamedDeclaration(classNode, [])
1202
1219
  );
1203
1220
  exportPath.requeue();
1204
1221
  pruneWrapperImports(wrapperMeta);
@@ -1207,7 +1224,7 @@ function handlePotentialComponentExport({
1207
1224
  }
1208
1225
  }
1209
1226
 
1210
- if (typeof getWrapperMetadata === "function" && isDefault && t$5.isCallExpression(declaration)) {
1227
+ if (typeof getWrapperMetadata === "function" && isDefault && t$7.isCallExpression(declaration)) {
1211
1228
  const callPath = exportPath.get("declaration");
1212
1229
  const wrapperMeta = getWrapperMetadata(callPath);
1213
1230
  if (!wrapperMeta) return false;
@@ -1240,7 +1257,7 @@ function handlePotentialComponentExport({
1240
1257
  );
1241
1258
  if (!classNode) return true;
1242
1259
 
1243
- exportPath.replaceWith(t$5.exportDefaultDeclaration(classNode));
1260
+ exportPath.replaceWith(t$7.exportDefaultDeclaration(classNode));
1244
1261
  exportPath.requeue();
1245
1262
  pruneWrapperImports(wrapperMeta);
1246
1263
  updateTransformState?.(state, classNode);
@@ -1250,23 +1267,23 @@ function handlePotentialComponentExport({
1250
1267
  return false;
1251
1268
  }
1252
1269
 
1253
- let t$4;
1270
+ let t$6;
1254
1271
 
1255
1272
  function setRefsBabelTypes(nextTypes) {
1256
- t$4 = nextTypes;
1273
+ t$6 = nextTypes;
1257
1274
  }
1258
1275
 
1259
- function createThisMemberExpression$3(propName) {
1260
- return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1276
+ function createThisMemberExpression$4(propName) {
1277
+ return t$6.memberExpression(t$6.thisExpression(), t$6.identifier(propName));
1261
1278
  }
1262
1279
 
1263
1280
  function createManagedRefLookupExpression(refName) {
1264
- const selectorLiteral = t$4.stringLiteral(`[data-ref="${refName}"]`);
1281
+ const selectorLiteral = t$6.stringLiteral(`[data-ref="${refName}"]`);
1265
1282
 
1266
- const renderRootQuery = t$4.optionalCallExpression(
1267
- t$4.optionalMemberExpression(
1268
- t$4.memberExpression(t$4.thisExpression(), t$4.identifier("renderRoot")),
1269
- t$4.identifier("querySelector"),
1283
+ const renderRootQuery = t$6.optionalCallExpression(
1284
+ t$6.optionalMemberExpression(
1285
+ t$6.memberExpression(t$6.thisExpression(), t$6.identifier("renderRoot")),
1286
+ t$6.identifier("querySelector"),
1270
1287
  false,
1271
1288
  true
1272
1289
  ),
@@ -1274,55 +1291,55 @@ function createManagedRefLookupExpression(refName) {
1274
1291
  false
1275
1292
  );
1276
1293
 
1277
- const hostQuery = t$4.callExpression(
1278
- t$4.memberExpression(t$4.thisExpression(), t$4.identifier("querySelector")),
1279
- [t$4.cloneNode(selectorLiteral)]
1294
+ const hostQuery = t$6.callExpression(
1295
+ t$6.memberExpression(t$6.thisExpression(), t$6.identifier("querySelector")),
1296
+ [t$6.cloneNode(selectorLiteral)]
1280
1297
  );
1281
1298
 
1282
- return t$4.logicalExpression("??", renderRootQuery, hostQuery);
1299
+ return t$6.logicalExpression("??", renderRootQuery, hostQuery);
1283
1300
  }
1284
1301
 
1285
1302
  function createForwardedTargetRefSyncStatement(propName, refName) {
1286
- return t$4.expressionStatement(
1287
- t$4.callExpression(t$4.identifier("useCallbackRef"), [
1288
- t$4.thisExpression(),
1289
- t$4.arrowFunctionExpression([], createManagedRefLookupExpression(refName)),
1290
- t$4.arrowFunctionExpression(
1291
- [t$4.identifier("node")],
1292
- t$4.blockStatement([
1293
- t$4.variableDeclaration("const", [
1294
- t$4.variableDeclarator(
1295
- t$4.identifier("componentRef"),
1296
- createThisMemberExpression$3(propName)
1303
+ return t$6.expressionStatement(
1304
+ t$6.callExpression(t$6.identifier("useCallbackRef"), [
1305
+ t$6.thisExpression(),
1306
+ t$6.arrowFunctionExpression([], createManagedRefLookupExpression(refName)),
1307
+ t$6.arrowFunctionExpression(
1308
+ [t$6.identifier("node")],
1309
+ t$6.blockStatement([
1310
+ t$6.variableDeclaration("const", [
1311
+ t$6.variableDeclarator(
1312
+ t$6.identifier("componentRef"),
1313
+ createThisMemberExpression$4(propName)
1297
1314
  ),
1298
1315
  ]),
1299
- t$4.ifStatement(
1300
- t$4.binaryExpression(
1316
+ t$6.ifStatement(
1317
+ t$6.binaryExpression(
1301
1318
  "===",
1302
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1303
- t$4.stringLiteral("function")
1319
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1320
+ t$6.stringLiteral("function")
1304
1321
  ),
1305
- t$4.blockStatement([
1306
- t$4.expressionStatement(
1307
- t$4.callExpression(t$4.identifier("componentRef"), [t$4.identifier("node")])
1322
+ t$6.blockStatement([
1323
+ t$6.expressionStatement(
1324
+ t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
1308
1325
  ),
1309
1326
  ]),
1310
- t$4.ifStatement(
1311
- t$4.logicalExpression(
1327
+ t$6.ifStatement(
1328
+ t$6.logicalExpression(
1312
1329
  "&&",
1313
- t$4.identifier("componentRef"),
1314
- t$4.binaryExpression(
1330
+ t$6.identifier("componentRef"),
1331
+ t$6.binaryExpression(
1315
1332
  "===",
1316
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1317
- t$4.stringLiteral("object")
1333
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1334
+ t$6.stringLiteral("object")
1318
1335
  )
1319
1336
  ),
1320
- t$4.blockStatement([
1321
- t$4.expressionStatement(
1322
- t$4.assignmentExpression(
1337
+ t$6.blockStatement([
1338
+ t$6.expressionStatement(
1339
+ t$6.assignmentExpression(
1323
1340
  "=",
1324
- t$4.memberExpression(t$4.identifier("componentRef"), t$4.identifier("current")),
1325
- t$4.identifier("node")
1341
+ t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
1342
+ t$6.identifier("node")
1326
1343
  )
1327
1344
  ),
1328
1345
  ])
@@ -1330,13 +1347,13 @@ function createForwardedTargetRefSyncStatement(propName, refName) {
1330
1347
  ),
1331
1348
  ])
1332
1349
  ),
1333
- t$4.arrayExpression([createThisMemberExpression$3(propName)]),
1350
+ t$6.arrayExpression([createThisMemberExpression$4(propName)]),
1334
1351
  ])
1335
1352
  );
1336
1353
  }
1337
1354
 
1338
1355
  function isStandardElementJsxName(nameNode) {
1339
- if (!t$4.isJSXIdentifier(nameNode)) {
1356
+ if (!t$6.isJSXIdentifier(nameNode)) {
1340
1357
  return false;
1341
1358
  }
1342
1359
 
@@ -1345,46 +1362,46 @@ function isStandardElementJsxName(nameNode) {
1345
1362
  }
1346
1363
 
1347
1364
  function createComponentInstanceRefSyncStatement() {
1348
- return t$4.expressionStatement(
1349
- t$4.callExpression(t$4.identifier("useCallbackRef"), [
1350
- t$4.thisExpression(),
1351
- t$4.arrowFunctionExpression([], t$4.thisExpression()),
1352
- t$4.arrowFunctionExpression(
1353
- [t$4.identifier("node")],
1354
- t$4.blockStatement([
1355
- t$4.variableDeclaration("const", [
1356
- t$4.variableDeclarator(
1357
- t$4.identifier("componentRef"),
1358
- createThisMemberExpression$3("ref")
1365
+ return t$6.expressionStatement(
1366
+ t$6.callExpression(t$6.identifier("useCallbackRef"), [
1367
+ t$6.thisExpression(),
1368
+ t$6.arrowFunctionExpression([], t$6.thisExpression()),
1369
+ t$6.arrowFunctionExpression(
1370
+ [t$6.identifier("node")],
1371
+ t$6.blockStatement([
1372
+ t$6.variableDeclaration("const", [
1373
+ t$6.variableDeclarator(
1374
+ t$6.identifier("componentRef"),
1375
+ createThisMemberExpression$4("ref")
1359
1376
  ),
1360
1377
  ]),
1361
- t$4.ifStatement(
1362
- t$4.binaryExpression(
1378
+ t$6.ifStatement(
1379
+ t$6.binaryExpression(
1363
1380
  "===",
1364
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1365
- t$4.stringLiteral("function")
1381
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1382
+ t$6.stringLiteral("function")
1366
1383
  ),
1367
- t$4.blockStatement([
1368
- t$4.expressionStatement(
1369
- t$4.callExpression(t$4.identifier("componentRef"), [t$4.identifier("node")])
1384
+ t$6.blockStatement([
1385
+ t$6.expressionStatement(
1386
+ t$6.callExpression(t$6.identifier("componentRef"), [t$6.identifier("node")])
1370
1387
  ),
1371
1388
  ]),
1372
- t$4.ifStatement(
1373
- t$4.logicalExpression(
1389
+ t$6.ifStatement(
1390
+ t$6.logicalExpression(
1374
1391
  "&&",
1375
- t$4.identifier("componentRef"),
1376
- t$4.binaryExpression(
1392
+ t$6.identifier("componentRef"),
1393
+ t$6.binaryExpression(
1377
1394
  "===",
1378
- t$4.unaryExpression("typeof", t$4.identifier("componentRef")),
1379
- t$4.stringLiteral("object")
1395
+ t$6.unaryExpression("typeof", t$6.identifier("componentRef")),
1396
+ t$6.stringLiteral("object")
1380
1397
  )
1381
1398
  ),
1382
- t$4.blockStatement([
1383
- t$4.expressionStatement(
1384
- t$4.assignmentExpression(
1399
+ t$6.blockStatement([
1400
+ t$6.expressionStatement(
1401
+ t$6.assignmentExpression(
1385
1402
  "=",
1386
- t$4.memberExpression(t$4.identifier("componentRef"), t$4.identifier("current")),
1387
- t$4.identifier("node")
1403
+ t$6.memberExpression(t$6.identifier("componentRef"), t$6.identifier("current")),
1404
+ t$6.identifier("node")
1388
1405
  )
1389
1406
  ),
1390
1407
  ])
@@ -1392,7 +1409,7 @@ function createComponentInstanceRefSyncStatement() {
1392
1409
  ),
1393
1410
  ])
1394
1411
  ),
1395
- t$4.arrayExpression([createThisMemberExpression$3("ref")]),
1412
+ t$6.arrayExpression([createThisMemberExpression$4("ref")]),
1396
1413
  ])
1397
1414
  );
1398
1415
  }
@@ -1403,27 +1420,27 @@ function hasRefProp(functionPath) {
1403
1420
  return false;
1404
1421
  }
1405
1422
 
1406
- if (t$4.isObjectPattern(firstParam)) {
1423
+ if (t$6.isObjectPattern(firstParam)) {
1407
1424
  return firstParam.properties.some((property) => {
1408
- if (!t$4.isObjectProperty(property)) return false;
1425
+ if (!t$6.isObjectProperty(property)) return false;
1409
1426
  return (
1410
- t$4.isIdentifier(property.key, { name: "ref" }) ||
1411
- t$4.isStringLiteral(property.key, { value: "ref" })
1427
+ t$6.isIdentifier(property.key, { name: "ref" }) ||
1428
+ t$6.isStringLiteral(property.key, { value: "ref" })
1412
1429
  );
1413
1430
  });
1414
1431
  }
1415
1432
 
1416
- if (t$4.isAssignmentPattern(firstParam) && t$4.isObjectPattern(firstParam.left)) {
1433
+ if (t$6.isAssignmentPattern(firstParam) && t$6.isObjectPattern(firstParam.left)) {
1417
1434
  return firstParam.left.properties.some((property) => {
1418
- if (!t$4.isObjectProperty(property)) return false;
1435
+ if (!t$6.isObjectProperty(property)) return false;
1419
1436
  return (
1420
- t$4.isIdentifier(property.key, { name: "ref" }) ||
1421
- t$4.isStringLiteral(property.key, { value: "ref" })
1437
+ t$6.isIdentifier(property.key, { name: "ref" }) ||
1438
+ t$6.isStringLiteral(property.key, { value: "ref" })
1422
1439
  );
1423
1440
  });
1424
1441
  }
1425
1442
 
1426
- if (t$4.isIdentifier(firstParam)) {
1443
+ if (t$6.isIdentifier(firstParam)) {
1427
1444
  const binding = functionPath.scope.getBinding(firstParam.name);
1428
1445
  if (!binding) return false;
1429
1446
  return binding.referencePaths.some((refPath) => {
@@ -1432,7 +1449,7 @@ function hasRefProp(functionPath) {
1432
1449
  parentPath &&
1433
1450
  parentPath.isMemberExpression() &&
1434
1451
  parentPath.node.object === refPath.node &&
1435
- t$4.isIdentifier(parentPath.node.property, { name: "ref" }) &&
1452
+ t$6.isIdentifier(parentPath.node.property, { name: "ref" }) &&
1436
1453
  !parentPath.node.computed
1437
1454
  );
1438
1455
  });
@@ -1451,14 +1468,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
1451
1468
 
1452
1469
  functionPath.traverse({
1453
1470
  JSXAttribute(attrPath) {
1454
- if (!t$4.isJSXIdentifier(attrPath.node.name, { name: "ref" })) return;
1471
+ if (!t$6.isJSXIdentifier(attrPath.node.name, { name: "ref" })) return;
1455
1472
 
1456
1473
  const value = attrPath.node.value;
1457
- if (!t$4.isJSXExpressionContainer(value)) return;
1474
+ if (!t$6.isJSXExpressionContainer(value)) return;
1458
1475
  if (
1459
- !t$4.isMemberExpression(value.expression) ||
1460
- !t$4.isThisExpression(value.expression.object) ||
1461
- !t$4.isIdentifier(value.expression.property, { name: propName }) ||
1476
+ !t$6.isMemberExpression(value.expression) ||
1477
+ !t$6.isThisExpression(value.expression.object) ||
1478
+ !t$6.isIdentifier(value.expression.property, { name: propName }) ||
1462
1479
  value.expression.computed
1463
1480
  ) {
1464
1481
  return;
@@ -1470,7 +1487,7 @@ function lowerForwardedElementRefs(functionPath, propName) {
1470
1487
 
1471
1488
  const managedRefName = functionPath.scope.generateUidIdentifier(`${propName}Element`).name;
1472
1489
  attrPath.replaceWith(
1473
- t$4.jsxAttribute(t$4.jsxIdentifier("data-ref"), t$4.stringLiteral(managedRefName))
1490
+ t$6.jsxAttribute(t$6.jsxIdentifier("data-ref"), t$6.stringLiteral(managedRefName))
1474
1491
  );
1475
1492
 
1476
1493
  if (seenRefNames.has(managedRefName)) return;
@@ -1482,14 +1499,14 @@ function lowerForwardedElementRefs(functionPath, propName) {
1482
1499
  return callbackStatements;
1483
1500
  }
1484
1501
 
1485
- let t$3;
1502
+ let t$5;
1486
1503
 
1487
1504
  function setClassGenerationBabelTypes(nextTypes) {
1488
- t$3 = nextTypes;
1505
+ t$5 = nextTypes;
1489
1506
  }
1490
1507
 
1491
- function createThisMemberExpression$2(propName) {
1492
- return t$3.memberExpression(t$3.thisExpression(), t$3.identifier(propName));
1508
+ function createThisMemberExpression$3(propName) {
1509
+ return t$5.memberExpression(t$5.thisExpression(), t$5.identifier(propName));
1493
1510
  }
1494
1511
 
1495
1512
  function buildClassMembers({
@@ -1501,26 +1518,26 @@ function buildClassMembers({
1501
1518
  }) {
1502
1519
  if (defaults.size > 0) {
1503
1520
  const constructorStatements = [
1504
- t$3.expressionStatement(t$3.callExpression(t$3.super(), [])),
1521
+ t$5.expressionStatement(t$5.callExpression(t$5.super(), [])),
1505
1522
  ];
1506
1523
 
1507
1524
  defaults.forEach((defaultExpression, propName) => {
1508
1525
  constructorStatements.push(
1509
- t$3.expressionStatement(
1510
- t$3.assignmentExpression(
1526
+ t$5.expressionStatement(
1527
+ t$5.assignmentExpression(
1511
1528
  "??=",
1512
- createThisMemberExpression$2(propName),
1513
- t$3.cloneNode(defaultExpression)
1529
+ createThisMemberExpression$3(propName),
1530
+ t$5.cloneNode(defaultExpression)
1514
1531
  )
1515
1532
  )
1516
1533
  );
1517
1534
  });
1518
1535
 
1519
- const constructorMethod = t$3.classMethod(
1536
+ const constructorMethod = t$5.classMethod(
1520
1537
  "constructor",
1521
- t$3.identifier("constructor"),
1538
+ t$5.identifier("constructor"),
1522
1539
  [],
1523
- t$3.blockStatement(constructorStatements)
1540
+ t$5.blockStatement(constructorStatements)
1524
1541
  );
1525
1542
 
1526
1543
  const insertionIndex = classMembers.findIndex((member) => !member.static);
@@ -1535,11 +1552,11 @@ function buildClassMembers({
1535
1552
  createHandlerClassMember(handler)
1536
1553
  );
1537
1554
 
1538
- const renderMethod = t$3.classMethod(
1555
+ const renderMethod = t$5.classMethod(
1539
1556
  "method",
1540
- t$3.identifier("render"),
1557
+ t$5.identifier("render"),
1541
1558
  [],
1542
- t$3.blockStatement(renderStatements)
1559
+ t$5.blockStatement(renderStatements)
1543
1560
  );
1544
1561
 
1545
1562
  classMembers.push(...handlerMembers, renderMethod);
@@ -1557,10 +1574,10 @@ function createComponentClass({
1557
1574
  needsUnsafeCss,
1558
1575
  needsCallbackRef = false,
1559
1576
  }) {
1560
- const classNode = t$3.classDeclaration(
1561
- t$3.identifier(className),
1562
- t$3.identifier("LitElement"),
1563
- t$3.classBody(classMembers)
1577
+ const classNode = t$5.classDeclaration(
1578
+ t$5.identifier(className),
1579
+ t$5.identifier("LitElement"),
1580
+ t$5.classBody(classMembers)
1564
1581
  );
1565
1582
 
1566
1583
  if (hoistMembers.length > 0) {
@@ -1569,8 +1586,8 @@ function createComponentClass({
1569
1586
  classNode._litsxStaticSymbolDeclarations = hoistSymbolDeclarations;
1570
1587
  }
1571
1588
  if (needsStaticHoistsMixin) {
1572
- classNode.superClass = t$3.callExpression(
1573
- t$3.identifier("LitsxStaticHoistsMixin"),
1589
+ classNode.superClass = t$5.callExpression(
1590
+ t$5.identifier("LitsxStaticHoistsMixin"),
1574
1591
  [classNode.superClass]
1575
1592
  );
1576
1593
  classNode._needsStaticHoistsMixin = true;
@@ -1578,8 +1595,8 @@ function createComponentClass({
1578
1595
  }
1579
1596
 
1580
1597
  if (lightDomRequested) {
1581
- classNode.superClass = t$3.callExpression(
1582
- t$3.identifier("LightDomMixin"),
1598
+ classNode.superClass = t$5.callExpression(
1599
+ t$5.identifier("LightDomMixin"),
1583
1600
  [classNode.superClass]
1584
1601
  );
1585
1602
  classNode._needsLightDomMixin = true;
@@ -1592,68 +1609,14 @@ function createComponentClass({
1592
1609
  return classNode;
1593
1610
  }
1594
1611
 
1595
- let t$2;
1612
+ let t$4;
1596
1613
 
1597
1614
  function setParamRewriteBabelTypes(nextTypes) {
1598
- t$2 = nextTypes;
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;
1615
+ t$4 = nextTypes;
1631
1616
  }
1632
1617
 
1633
- function getPropBackedCalleeReplacement(node, bindings) {
1634
- if (t$2.isIdentifier(node)) {
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;
1618
+ function createThisMemberExpression$2(propName) {
1619
+ return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1657
1620
  }
1658
1621
 
1659
1622
  function transformJSXExpressions(jsxPath, bindings, state = null) {
@@ -1661,30 +1624,13 @@ function transformJSXExpressions(jsxPath, bindings, state = null) {
1661
1624
 
1662
1625
  jsxPath.traverse({
1663
1626
  JSXExpressionContainer(expressionPath) {
1664
- if (t$2.isCallExpression(expressionPath.node.expression)) {
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)) {
1627
+ if (t$4.isIdentifier(expressionPath.node.expression)) {
1682
1628
  const name = expressionPath.node.expression.name;
1683
1629
  if (localNames.includes(name)) {
1684
1630
  const propName = bindings.get(name) || name;
1685
- expressionPath.node.expression = t$2.memberExpression(
1686
- t$2.thisExpression(),
1687
- t$2.identifier(propName)
1631
+ expressionPath.node.expression = t$4.memberExpression(
1632
+ t$4.thisExpression(),
1633
+ t$4.identifier(propName)
1688
1634
  );
1689
1635
  }
1690
1636
  }
@@ -1703,16 +1649,16 @@ function registerLocalPropAliases(functionPath, bindings) {
1703
1649
  if (path.getFunctionParent() !== functionPath) return;
1704
1650
 
1705
1651
  const { id, init } = path.node;
1706
- if (!t$2.isIdentifier(init)) return;
1652
+ if (!t$4.isIdentifier(init)) return;
1707
1653
 
1708
- if (t$2.isIdentifier(id)) {
1654
+ if (t$4.isIdentifier(id)) {
1709
1655
  if (bindings.has(id.name) || !bindings.has(init.name)) return;
1710
1656
  bindings.set(id.name, bindings.get(init.name));
1711
1657
  changed = true;
1712
1658
  return;
1713
1659
  }
1714
1660
 
1715
- if (!t$2.isObjectPattern(id)) return;
1661
+ if (!t$4.isObjectPattern(id)) return;
1716
1662
 
1717
1663
  const bindingInfo = bindings.get(init.name);
1718
1664
  if (!bindingInfo || typeof bindingInfo !== "object" || bindingInfo.kind !== "alias") {
@@ -1720,17 +1666,17 @@ function registerLocalPropAliases(functionPath, bindings) {
1720
1666
  }
1721
1667
 
1722
1668
  id.properties.forEach((property) => {
1723
- if (!t$2.isObjectProperty(property)) return;
1669
+ if (!t$4.isObjectProperty(property)) return;
1724
1670
 
1725
- const keyName = t$2.isIdentifier(property.key)
1671
+ const keyName = t$4.isIdentifier(property.key)
1726
1672
  ? property.key.name
1727
- : t$2.isStringLiteral(property.key)
1673
+ : t$4.isStringLiteral(property.key)
1728
1674
  ? property.key.value
1729
1675
  : null;
1730
1676
 
1731
1677
  if (!keyName || !bindingInfo.properties.has(keyName)) return;
1732
1678
 
1733
- if (t$2.isIdentifier(property.value)) {
1679
+ if (t$4.isIdentifier(property.value)) {
1734
1680
  if (!bindings.has(property.value.name)) {
1735
1681
  bindings.set(property.value.name, keyName);
1736
1682
  changed = true;
@@ -1739,8 +1685,8 @@ function registerLocalPropAliases(functionPath, bindings) {
1739
1685
  }
1740
1686
 
1741
1687
  if (
1742
- t$2.isAssignmentPattern(property.value) &&
1743
- t$2.isIdentifier(property.value.left) &&
1688
+ t$4.isAssignmentPattern(property.value) &&
1689
+ t$4.isIdentifier(property.value.left) &&
1744
1690
  !bindings.has(property.value.left.name)
1745
1691
  ) {
1746
1692
  bindings.set(property.value.left.name, keyName);
@@ -1773,10 +1719,10 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1773
1719
  aliasId = functionPath.scope.generateUidIdentifier(propName);
1774
1720
  capturedPropAliases.set(propName, aliasId);
1775
1721
  }
1776
- return t$2.cloneNode(aliasId);
1722
+ return t$4.cloneNode(aliasId);
1777
1723
  }
1778
1724
 
1779
- return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
1725
+ return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1780
1726
  }
1781
1727
 
1782
1728
  bindings.forEach((bindingInfo, localName) => {
@@ -1805,7 +1751,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1805
1751
  return;
1806
1752
  }
1807
1753
 
1808
- refPath.replaceWith(t$2.thisExpression());
1754
+ refPath.replaceWith(t$4.thisExpression());
1809
1755
  return;
1810
1756
  }
1811
1757
 
@@ -1816,7 +1762,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1816
1762
  refPath.parentPath &&
1817
1763
  refPath.parentPath.isMemberExpression() &&
1818
1764
  refPath.parentKey === "object" &&
1819
- t$2.isIdentifier(refPath.parentPath.node.property) &&
1765
+ t$4.isIdentifier(refPath.parentPath.node.property) &&
1820
1766
  !refPath.parentPath.node.computed
1821
1767
  ) {
1822
1768
  const propName = refPath.parentPath.node.property.name;
@@ -1838,7 +1784,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1838
1784
  refPath.parentPath &&
1839
1785
  refPath.parentPath.isMemberExpression() &&
1840
1786
  refPath.parentKey === "object" &&
1841
- t$2.isIdentifier(refPath.parentPath.node.property) &&
1787
+ t$4.isIdentifier(refPath.parentPath.node.property) &&
1842
1788
  !refPath.parentPath.node.computed
1843
1789
  ) {
1844
1790
  const propName = refPath.parentPath.node.property.name;
@@ -1864,7 +1810,7 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1864
1810
  refPath.parentKey === "value"
1865
1811
  ) {
1866
1812
  refPath.replaceWith(
1867
- t$2.jsxExpressionContainer(
1813
+ t$4.jsxExpressionContainer(
1868
1814
  getReplacementForProp(targetProp || localName, refPath)
1869
1815
  )
1870
1816
  );
@@ -1885,12 +1831,208 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1885
1831
  });
1886
1832
 
1887
1833
  return Array.from(capturedPropAliases.entries()).map(([propName, aliasId]) =>
1888
- t$2.variableDeclaration("const", [
1889
- t$2.variableDeclarator(t$2.cloneNode(aliasId), createThisMemberExpression$1(propName)),
1834
+ t$4.variableDeclaration("const", [
1835
+ t$4.variableDeclarator(t$4.cloneNode(aliasId), createThisMemberExpression$2(propName)),
1890
1836
  ])
1891
1837
  );
1892
1838
  }
1893
1839
 
1840
+ let t$3;
1841
+
1842
+ function setRendererCallsBabelTypes(nextTypes) {
1843
+ t$3 = nextTypes;
1844
+ }
1845
+
1846
+ function createThisMemberExpression$1(propName) {
1847
+ return t$3.memberExpression(t$3.thisExpression(), t$3.identifier(propName));
1848
+ }
1849
+
1850
+ function getBoundPropName(bindingInfo) {
1851
+ if (typeof bindingInfo === "string") {
1852
+ return bindingInfo;
1853
+ }
1854
+
1855
+ if (bindingInfo && typeof bindingInfo === "object") {
1856
+ return bindingInfo.bindKey ?? null;
1857
+ }
1858
+
1859
+ return null;
1860
+ }
1861
+
1862
+ function isPropBackedCallee(node, localNames) {
1863
+ if (t$3.isIdentifier(node)) {
1864
+ return localNames.includes(node.name);
1865
+ }
1866
+
1867
+ if (
1868
+ t$3.isMemberExpression(node) &&
1869
+ !node.computed &&
1870
+ t$3.isIdentifier(node.object)
1871
+ ) {
1872
+ return localNames.includes(node.object.name) && node.object.name === "props";
1873
+ }
1874
+
1875
+ return false;
1876
+ }
1877
+
1878
+ function getPropBackedCalleeReplacement(node, bindings) {
1879
+ if (t$3.isIdentifier(node)) {
1880
+ const propName = getBoundPropName(bindings.get(node.name));
1881
+ return propName ? createThisMemberExpression$1(propName) : node;
1882
+ }
1883
+
1884
+ if (
1885
+ t$3.isMemberExpression(node) &&
1886
+ !node.computed &&
1887
+ t$3.isIdentifier(node.object)
1888
+ ) {
1889
+ const propName = getBoundPropName(bindings.get(node.object.name));
1890
+ if (!propName) {
1891
+ return node;
1892
+ }
1893
+
1894
+ return t$3.memberExpression(
1895
+ createThisMemberExpression$1(propName),
1896
+ t$3.cloneNode(node.property),
1897
+ false
1898
+ );
1899
+ }
1900
+
1901
+ return node;
1902
+ }
1903
+
1904
+ function transformJSXRendererCalls(jsxPath, bindings, state = null) {
1905
+ const localNames = Array.from(bindings.keys());
1906
+
1907
+ jsxPath.traverse({
1908
+ JSXExpressionContainer(expressionPath) {
1909
+ if (!t$3.isCallExpression(expressionPath.node.expression)) {
1910
+ return;
1911
+ }
1912
+
1913
+ const { callee, arguments: args } = expressionPath.node.expression;
1914
+ if (!isPropBackedCallee(callee, localNames)) {
1915
+ return;
1916
+ }
1917
+
1918
+ if (state) {
1919
+ state.__litsxNeedsRendererCallImport = true;
1920
+ }
1921
+
1922
+ expressionPath.node.expression = t$3.callExpression(
1923
+ t$3.identifier("renderRendererCall"),
1924
+ [
1925
+ getPropBackedCalleeReplacement(callee, bindings),
1926
+ ...args,
1927
+ ]
1928
+ );
1929
+ },
1930
+ });
1931
+ }
1932
+
1933
+ let t$2;
1934
+
1935
+ function setRenderBodyBabelTypes(nextTypes) {
1936
+ t$2 = nextTypes;
1937
+ }
1938
+
1939
+ function createThisMemberExpression(propName) {
1940
+ return t$2.memberExpression(t$2.thisExpression(), t$2.identifier(propName));
1941
+ }
1942
+
1943
+ function createNestedInitializerStatement(pattern, root, defaultValue) {
1944
+ const rootAccess = createThisMemberExpression(root);
1945
+ let sourceExpression = rootAccess;
1946
+
1947
+ if (defaultValue) {
1948
+ sourceExpression = t$2.logicalExpression(
1949
+ "??",
1950
+ t$2.cloneNode(rootAccess),
1951
+ t$2.cloneNode(defaultValue)
1952
+ );
1953
+ }
1954
+
1955
+ return t$2.variableDeclaration("const", [
1956
+ t$2.variableDeclarator(t$2.cloneNode(pattern), sourceExpression),
1957
+ ]);
1958
+ }
1959
+
1960
+ function collectReturnStatement(functionPath, bindings, state) {
1961
+ let returnStatement = null;
1962
+
1963
+ functionPath.traverse({
1964
+ ReturnStatement(returnPath) {
1965
+ if (t$2.isJSXElement(returnPath.node.argument)) {
1966
+ returnStatement = returnPath.node;
1967
+ transformJSXRendererCalls(returnPath, bindings, state);
1968
+ transformJSXExpressions(returnPath, bindings, state);
1969
+ }
1970
+ },
1971
+ });
1972
+
1973
+ return returnStatement;
1974
+ }
1975
+
1976
+ function prepareComponentRender(functionPath, node, propertyNames, bindings, nestedInitializers, options = {}) {
1977
+ const returnStatement = collectReturnStatement(
1978
+ functionPath,
1979
+ bindings,
1980
+ options.state ?? null
1981
+ );
1982
+
1983
+ if (!returnStatement) {
1984
+ return null;
1985
+ }
1986
+
1987
+ const capturedPropAliasStatements = replaceParamReferences(
1988
+ functionPath,
1989
+ bindings,
1990
+ propertyNames
1991
+ );
1992
+ const prefixStatements = [];
1993
+
1994
+ const forwardRefOptions = options.forwardRef || null;
1995
+ const resolvedRefPropName =
1996
+ forwardRefOptions?.propName ||
1997
+ (propertyNames.has("ref") || hasRefProp(functionPath) ? "ref" : null);
1998
+ let needsCallbackRef = false;
1999
+
2000
+ if (resolvedRefPropName) {
2001
+ prefixStatements.push(
2002
+ ...lowerForwardedElementRefs(functionPath, resolvedRefPropName)
2003
+ );
2004
+ needsCallbackRef =
2005
+ prefixStatements.some(
2006
+ (statement) =>
2007
+ t$2.isExpressionStatement(statement) &&
2008
+ t$2.isCallExpression(statement.expression) &&
2009
+ t$2.isIdentifier(statement.expression.callee, { name: "useCallbackRef" })
2010
+ ) || needsCallbackRef;
2011
+ }
2012
+
2013
+ if (resolvedRefPropName && !forwardRefOptions) {
2014
+ prefixStatements.push(createComponentInstanceRefSyncStatement());
2015
+ needsCallbackRef = true;
2016
+ }
2017
+
2018
+ if (capturedPropAliasStatements.length > 0) {
2019
+ prefixStatements.push(...capturedPropAliasStatements);
2020
+ }
2021
+
2022
+ if (nestedInitializers.length > 0) {
2023
+ const initializerStatements = nestedInitializers.map(({ pattern, root, defaultValue }) =>
2024
+ createNestedInitializerStatement(pattern, root, defaultValue)
2025
+ );
2026
+ prefixStatements.push(...initializerStatements);
2027
+ }
2028
+
2029
+ return {
2030
+ needsCallbackRef,
2031
+ prefixStatements,
2032
+ returnStatement,
2033
+ };
2034
+ }
2035
+
1894
2036
  let t$1;
1895
2037
 
1896
2038
  function setProgramBabelTypes(nextTypes) {
@@ -2175,6 +2317,9 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
2175
2317
  setRefsBabelTypes(t);
2176
2318
  setClassGenerationBabelTypes(t);
2177
2319
  setParamRewriteBabelTypes(t);
2320
+ setRendererCallsBabelTypes(t);
2321
+ transformLitsxElementCandidates.setElementCandidatesBabelTypes(t);
2322
+ setRenderBodyBabelTypes(t);
2178
2323
  setProgramBabelTypes(t);
2179
2324
  const resolvedPluginOptions = {
2180
2325
  ...defaultPluginOptions,
@@ -2475,8 +2620,8 @@ function getTypeResolverForFunction(functionPath, state) {
2475
2620
 
2476
2621
  function transformFunction(functionPath, programPath, className, options = {}) {
2477
2622
  const { node } = functionPath;
2478
- const elementCandidates = collectElementCandidates(functionPath, programPath, options);
2479
- const forwardRefOptions = options.forwardRef || null;
2623
+ const elementCandidates = transformLitsxElementCandidates.getAnnotatedElementCandidates(functionPath, programPath, options);
2624
+ const importedElementCandidates = transformLitsxElementCandidates.getAnnotatedImportedElementCandidates(functionPath, programPath, options);
2480
2625
  let resolvedName = className;
2481
2626
  if (!resolvedName && node && node.id && t.isIdentifier(node.id)) {
2482
2627
  resolvedName = node.id.name;
@@ -2502,19 +2647,21 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2502
2647
  assertStaticHoistsStayTopLevel(functionPath);
2503
2648
  collectNativeClassNameWarnings(functionPath, options.warn, options);
2504
2649
 
2505
- let returnStatement;
2506
- functionPath.traverse({
2507
- ReturnStatement(returnPath) {
2508
- if (t.isJSXElement(returnPath.node.argument)) {
2509
- returnStatement = returnPath.node;
2510
- transformJSXExpressions(returnPath, bindings, options.state ?? null);
2511
- }
2512
- },
2513
- });
2650
+ const renderPreparation = prepareComponentRender(
2651
+ functionPath,
2652
+ node,
2653
+ propertyNames,
2654
+ bindings,
2655
+ nestedInitializers,
2656
+ options
2657
+ );
2514
2658
 
2515
- if (!returnStatement) return;
2659
+ if (!renderPreparation?.returnStatement) return;
2516
2660
 
2517
- const capturedPropAliasStatements = replaceParamReferences(functionPath, bindings, propertyNames);
2661
+ const {
2662
+ needsCallbackRef,
2663
+ prefixStatements,
2664
+ } = renderPreparation;
2518
2665
 
2519
2666
  const usedNames = new Set([
2520
2667
  ...Object.keys(functionPath.scope.bindings || {}),
@@ -2524,41 +2671,12 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2524
2671
  ]);
2525
2672
 
2526
2673
  const handlerInfos = processHandlers(functionPath, usedNames);
2527
-
2528
2674
  const renderStatements = t.isBlockStatement(node.body)
2529
2675
  ? [...node.body.body]
2530
2676
  : [t.returnStatement(node.body)];
2531
2677
 
2532
- const resolvedRefPropName = forwardRefOptions?.propName ||
2533
- (propertyNames.has("ref") || hasRefProp(functionPath) ? "ref" : null);
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);
2678
+ if (prefixStatements.length > 0) {
2679
+ renderStatements.unshift(...prefixStatements);
2562
2680
  }
2563
2681
 
2564
2682
  const classMembers = [];
@@ -2607,185 +2725,21 @@ function transformFunction(functionPath, programPath, className, options = {}) {
2607
2725
  elementCandidates.forEach((candidate) => elementSet.add(candidate));
2608
2726
  }
2609
2727
 
2610
- return classNode;
2611
- }
2612
-
2613
- function createThisMemberExpression(propName) {
2614
- return t.memberExpression(t.thisExpression(), t.identifier(propName));
2615
- }
2616
-
2617
- function createNestedInitializerStatement(pattern, root, defaultValue, t) {
2618
- const rootAccess = createThisMemberExpression(root);
2619
- let sourceExpression = rootAccess;
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);
2688
- }
2689
- });
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
- }
2706
-
2707
- function maybeRewriteComponentName(nameNode, pathForErrors = null) {
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;
2728
+ if (classNode && importedElementCandidates.length > 0) {
2729
+ classNode._litsxImportedElementCandidates ||= [];
2730
+ importedElementCandidates.forEach((candidate) => {
2731
+ if (!classNode._litsxImportedElementCandidates.some(
2732
+ (entry) =>
2733
+ entry.sourceFile === candidate.sourceFile &&
2734
+ entry.importedName === candidate.importedName &&
2735
+ entry.tagName === candidate.tagName
2736
+ )) {
2737
+ classNode._litsxImportedElementCandidates.push(candidate);
2721
2738
  }
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
2739
  });
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
2740
  }
2785
2741
 
2786
- scanFunction(functionPath).forEach((candidate) => candidates.add(candidate));
2787
-
2788
- return candidates;
2742
+ return classNode;
2789
2743
  }
2790
2744
 
2791
2745
  exports.createTransformFunctionToClassPlugin = createTransformFunctionToClassPlugin;