@litsx/babel-preset-litsx 0.1.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.
@@ -0,0 +1,1254 @@
1
+ 'use strict';
2
+
3
+ var module$1 = require('module');
4
+ var typescriptSession = require('@litsx/typescript-session');
5
+
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
+ let ts;
8
+ let t;
9
+ const TYPE_RESOLVER_CACHE = new Map();
10
+ const TYPE_RESOLVER_CACHE_LIMIT = 200;
11
+ const nodeRequire = (() => {
12
+ try {
13
+ return module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('internal/transform-litsx-properties.cjs', document.baseURI).href)));
14
+ } catch {
15
+ return null;
16
+ }
17
+ })();
18
+
19
+ const TYPE_RESOLUTION_MODES = {
20
+ AUTO: "auto",
21
+ IN_MEMORY: "in-memory",
22
+ };
23
+
24
+ const VIRTUAL_SOURCE_FILENAME = "/__litsx_virtual__/inline-input.tsx";
25
+ const VIRTUAL_LIB_FILENAME = "/__litsx_virtual__/lib.playground.d.ts";
26
+ const DEFAULT_IN_MEMORY_LIB = `
27
+ type PropertyKey = string | number | symbol;
28
+ interface Object {}
29
+ interface Function {}
30
+ interface CallableFunction extends Function {}
31
+ interface NewableFunction extends Function {}
32
+ interface IArguments {
33
+ length: number;
34
+ callee: Function;
35
+ [index: number]: any;
36
+ }
37
+ interface String {}
38
+ interface Number {}
39
+ interface Boolean {}
40
+ interface Symbol {}
41
+ interface Array<T> {
42
+ length: number;
43
+ [n: number]: T;
44
+ }
45
+ interface ReadonlyArray<T> {
46
+ readonly length: number;
47
+ readonly [n: number]: T;
48
+ }
49
+ interface Date {}
50
+ type Partial<T> = { [P in keyof T]?: T[P] };
51
+ type Required<T> = { [P in keyof T]-?: T[P] };
52
+ type Readonly<T> = { readonly [P in keyof T]: T[P] };
53
+ type Pick<T, K extends keyof T> = { [P in K]: T[P] };
54
+ type Exclude<T, U> = T extends U ? never : T;
55
+ type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
56
+ type Record<K extends keyof any, T> = { [P in K]: T };
57
+ `;
58
+
59
+ const DEFAULT_IN_MEMORY_FILES = {
60
+ [VIRTUAL_LIB_FILENAME]: DEFAULT_IN_MEMORY_LIB,
61
+ };
62
+
63
+ function normalizeTypescriptModule(moduleValue) {
64
+ return moduleValue?.default ?? moduleValue ?? null;
65
+ }
66
+
67
+ function ensureTypescriptModule() {
68
+ if (ts) {
69
+ return ts;
70
+ }
71
+
72
+ if (
73
+ nodeRequire &&
74
+ (typeof process === "undefined" || process.browser !== true)
75
+ ) {
76
+ try {
77
+ ts = normalizeTypescriptModule(nodeRequire("typescript"));
78
+ return ts;
79
+ } catch {
80
+ // Fall through to the explicit runtime error below.
81
+ }
82
+ }
83
+
84
+ throw new Error(
85
+ "The LitSX transform needs a TypeScript runtime. Load it before using the transform in browser workers, or install the local 'typescript' package for Node-based transforms."
86
+ );
87
+ }
88
+
89
+ function setTypescriptModule(moduleValue) {
90
+ ts = normalizeTypescriptModule(moduleValue);
91
+ return ts;
92
+ }
93
+
94
+ function setPropertyBabelTypes(types) {
95
+ t = types;
96
+ }
97
+
98
+ function normalizeInMemoryFiles(files = {}) {
99
+ const normalizedFiles = new Map();
100
+ Object.entries({
101
+ ...DEFAULT_IN_MEMORY_FILES,
102
+ ...files,
103
+ }).forEach(([filePath, fileSource]) => {
104
+ normalizedFiles.set(typescriptSession.normalizeFilePath(filePath), fileSource);
105
+ });
106
+ return normalizedFiles;
107
+ }
108
+
109
+ function hashSource(text) {
110
+ let hash = 2166136261;
111
+ for (let index = 0; index < text.length; index += 1) {
112
+ hash ^= text.charCodeAt(index);
113
+ hash = Math.imul(hash, 16777619);
114
+ }
115
+ return (hash >>> 0).toString(16);
116
+ }
117
+
118
+ function getTypeResolverCacheKey(
119
+ filename,
120
+ source,
121
+ mode = TYPE_RESOLUTION_MODES.AUTO,
122
+ sessionKey = "",
123
+ ) {
124
+ const normalizedFilename = filename
125
+ ? typescriptSession.normalizeFilePath(filename)
126
+ : VIRTUAL_SOURCE_FILENAME;
127
+ return `${mode}:${sessionKey}:${normalizedFilename}:${hashSource(source)}`;
128
+ }
129
+
130
+ function getTypeResolutionSessionKey(filename, compilerOptions, sessionKey = "") {
131
+ return JSON.stringify({
132
+ directory: typescriptSession.dirname(filename),
133
+ compilerOptions,
134
+ sessionKey,
135
+ });
136
+ }
137
+
138
+ function rememberTypeResolver(cacheKey, resolver) {
139
+ TYPE_RESOLVER_CACHE.set(cacheKey, resolver);
140
+ if (TYPE_RESOLVER_CACHE.size <= TYPE_RESOLVER_CACHE_LIMIT) return resolver;
141
+
142
+ const oldestKey = TYPE_RESOLVER_CACHE.keys().next().value;
143
+ if (oldestKey) {
144
+ TYPE_RESOLVER_CACHE.delete(oldestKey);
145
+ }
146
+ return resolver;
147
+ }
148
+
149
+ function createSpanNodeLookup(sourceFile) {
150
+ const baseCache = new Map();
151
+ const predicateCache = new WeakMap();
152
+
153
+ function getCacheKey(start, end) {
154
+ return `${start}:${end}`;
155
+ }
156
+
157
+ function lookup(start, end, predicate) {
158
+ const cacheKey = getCacheKey(start, end);
159
+ if (!predicate) {
160
+ if (baseCache.has(cacheKey)) {
161
+ return baseCache.get(cacheKey);
162
+ }
163
+ const resolved = findTsNodeAtSpan(sourceFile, start, end, null);
164
+ baseCache.set(cacheKey, resolved);
165
+ return resolved;
166
+ }
167
+
168
+ let cache = predicateCache.get(predicate);
169
+ if (!cache) {
170
+ cache = new Map();
171
+ predicateCache.set(predicate, cache);
172
+ }
173
+
174
+ if (cache.has(cacheKey)) {
175
+ return cache.get(cacheKey);
176
+ }
177
+
178
+ const resolved = findTsNodeAtSpan(sourceFile, start, end, predicate);
179
+ cache.set(cacheKey, resolved);
180
+ return resolved;
181
+ }
182
+
183
+ return lookup;
184
+ }
185
+
186
+ function createTypeResolver(filename, source, options = {}) {
187
+ if (!source) {
188
+ return null;
189
+ }
190
+
191
+ ensureTypescriptModule();
192
+
193
+ const providedTypescriptSession =
194
+ options?.typescriptSession?.projectSession || options?.typescriptSession || null;
195
+ const typeResolutionMode =
196
+ options?.typeResolutionMode === TYPE_RESOLUTION_MODES.IN_MEMORY
197
+ ? TYPE_RESOLUTION_MODES.IN_MEMORY
198
+ : TYPE_RESOLUTION_MODES.AUTO;
199
+
200
+ const cacheKey = providedTypescriptSession
201
+ ? null
202
+ : getTypeResolverCacheKey(
203
+ filename,
204
+ source,
205
+ typeResolutionMode,
206
+ "",
207
+ );
208
+ if (cacheKey) {
209
+ const cached = TYPE_RESOLVER_CACHE.get(cacheKey);
210
+ if (cached) {
211
+ TYPE_RESOLVER_CACHE.delete(cacheKey);
212
+ TYPE_RESOLVER_CACHE.set(cacheKey, cached);
213
+ return cached;
214
+ }
215
+ }
216
+
217
+ const shouldUseInMemoryResolution = typeResolutionMode === TYPE_RESOLUTION_MODES.IN_MEMORY;
218
+ const resolvedFilename =
219
+ shouldUseInMemoryResolution || !filename
220
+ ? VIRTUAL_SOURCE_FILENAME
221
+ : typescriptSession.normalizeFilePath(filename);
222
+ const normalizedFilename = typescriptSession.normalizeFilePath(resolvedFilename);
223
+ const compilerOptions = {
224
+ target: ts.ScriptTarget.ESNext,
225
+ module: ts.ModuleKind.ESNext,
226
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
227
+ jsx: ts.JsxEmit.Preserve,
228
+ allowJs: true,
229
+ checkJs: false,
230
+ skipLibCheck: true,
231
+ strict: false,
232
+ esModuleInterop: true,
233
+ allowSyntheticDefaultImports: true,
234
+ types: [],
235
+ };
236
+
237
+ if (shouldUseInMemoryResolution || !filename) {
238
+ return createInMemoryTypeResolver(
239
+ normalizedFilename,
240
+ source,
241
+ compilerOptions,
242
+ cacheKey,
243
+ options?.inMemoryFiles,
244
+ providedTypescriptSession,
245
+ );
246
+ }
247
+
248
+ try {
249
+ const sharedSession =
250
+ providedTypescriptSession ||
251
+ typescriptSession.getOrCreateStandaloneTsSession(
252
+ getTypeResolutionSessionKey(normalizedFilename, compilerOptions),
253
+ {
254
+ typescript: ts,
255
+ compilerOptions,
256
+ },
257
+ );
258
+
259
+ return createResolvedTypeResolver(
260
+ cacheKey ? rememberTypeResolver : (_, resolver) => resolver,
261
+ cacheKey,
262
+ sharedSession.getTypeResolver(normalizedFilename, source),
263
+ );
264
+ } catch {
265
+ return null;
266
+ }
267
+ }
268
+
269
+ function createInMemoryTypeResolver(
270
+ filename,
271
+ source,
272
+ compilerOptions,
273
+ cacheKey,
274
+ inMemoryFiles = {},
275
+ providedSession = null,
276
+ ) {
277
+ const sourceFilename = typescriptSession.normalizeFilePath(filename || VIRTUAL_SOURCE_FILENAME);
278
+ const files = normalizeInMemoryFiles(inMemoryFiles);
279
+ files.set(sourceFilename, source);
280
+
281
+ const inMemoryCompilerOptions = {
282
+ ...compilerOptions,
283
+ noLib: true,
284
+ };
285
+
286
+ try {
287
+ const session = providedSession || typescriptSession.createInMemoryTsSession({
288
+ typescript: ts,
289
+ compilerOptions: inMemoryCompilerOptions,
290
+ files: Object.fromEntries(files),
291
+ sourceFilename,
292
+ defaultLibFileName: VIRTUAL_LIB_FILENAME,
293
+ rootNames: [sourceFilename, VIRTUAL_LIB_FILENAME],
294
+ });
295
+
296
+ return createResolvedTypeResolver(
297
+ cacheKey ? rememberTypeResolver : (_, resolver) => resolver,
298
+ cacheKey,
299
+ session.getTypeResolver(sourceFilename, source),
300
+ );
301
+ } catch {
302
+ return null;
303
+ }
304
+ }
305
+
306
+ function createResolvedTypeResolver(remember, cacheKey, resolved) {
307
+ if (!resolved?.sourceFile || !resolved?.checker) {
308
+ return null;
309
+ }
310
+
311
+ return remember(cacheKey, {
312
+ filename: resolved.filename,
313
+ sourceFile: resolved.sourceFile,
314
+ checker: resolved.checker,
315
+ checkerTypeCache: new Map(),
316
+ checkerPropertyMapCache: new Map(),
317
+ checkerTypeConfigCache:
318
+ resolved.getSemanticCache?.("checkerTypeConfigCache", () => new WeakMap()) ?? new WeakMap(),
319
+ checkerTypeConfigInProgress: new WeakSet(),
320
+ checkerPropertyMapByTypeCache:
321
+ resolved.getSemanticCache?.("checkerPropertyMapByTypeCache", () => new WeakMap()) ?? new WeakMap(),
322
+ getNodeAtSpan: createSpanNodeLookup(resolved.sourceFile),
323
+ });
324
+ }
325
+
326
+ function findTsNodeAtSpan(sourceFile, start, end, predicate) {
327
+ let found = null;
328
+
329
+ function visit(node) {
330
+ if (found) return;
331
+ if (start < node.pos || end > node.end) return;
332
+
333
+ if (node.pos === start && node.end === end && (!predicate || predicate(node))) {
334
+ found = node;
335
+ return;
336
+ }
337
+
338
+ ts.forEachChild(node, visit);
339
+
340
+ if (!found && start >= node.getStart(sourceFile) && end <= node.end && (!predicate || predicate(node))) {
341
+ found = node;
342
+ }
343
+ }
344
+
345
+ visit(sourceFile);
346
+ return found;
347
+ }
348
+
349
+ function createPropertyConfig(type = null, options = {}) {
350
+ return {
351
+ type: type ? t.cloneNode(type) : null,
352
+ attribute: options.attribute,
353
+ };
354
+ }
355
+
356
+ function normalizePropertyConfigInput(input) {
357
+ if (!input) return createPropertyConfig();
358
+ if (t.isIdentifier(input)) return createPropertyConfig(input);
359
+ return clonePropertyConfig(input);
360
+ }
361
+
362
+ function clonePropertyConfig(config) {
363
+ return createPropertyConfig(config?.type || null, { attribute: config?.attribute });
364
+ }
365
+
366
+ function createPropertyValue(config, defaultType = true) {
367
+ const normalized = config || createPropertyConfig();
368
+ const properties = [];
369
+ const typeNode = normalized.type || (defaultType ? t.identifier("String") : null);
370
+
371
+ if (typeNode) {
372
+ properties.push(t.objectProperty(t.identifier("type"), t.cloneNode(typeNode)));
373
+ }
374
+
375
+ if (normalized.attribute === false) {
376
+ properties.push(
377
+ t.objectProperty(t.identifier("attribute"), t.booleanLiteral(false))
378
+ );
379
+ }
380
+
381
+ return t.objectExpression(properties);
382
+ }
383
+
384
+ function mergePropertyConfig(entry, config, defaultType = false) {
385
+ if (!entry || !entry.node || !t.isObjectExpression(entry.node.value) || !config) {
386
+ return;
387
+ }
388
+
389
+ const value = entry.node.value;
390
+
391
+ if (config.type) {
392
+ const typeProp = value.properties.find(
393
+ (prop) =>
394
+ t.isObjectProperty(prop) &&
395
+ t.isIdentifier(prop.key, { name: "type" })
396
+ );
397
+
398
+ if (!typeProp) {
399
+ value.properties.unshift(
400
+ t.objectProperty(t.identifier("type"), t.cloneNode(config.type))
401
+ );
402
+ } else if (
403
+ t.isIdentifier(typeProp.value) &&
404
+ typeProp.value.name === "String" &&
405
+ t.isIdentifier(config.type) &&
406
+ config.type.name !== "String"
407
+ ) {
408
+ typeProp.value = t.cloneNode(config.type);
409
+ }
410
+ } else if (defaultType) {
411
+ const hasType = value.properties.some(
412
+ (prop) =>
413
+ t.isObjectProperty(prop) &&
414
+ t.isIdentifier(prop.key, { name: "type" })
415
+ );
416
+ if (!hasType) {
417
+ value.properties.unshift(
418
+ t.objectProperty(t.identifier("type"), t.identifier("String"))
419
+ );
420
+ }
421
+ }
422
+
423
+ if (config.attribute === false) {
424
+ const attributeProp = value.properties.find(
425
+ (prop) =>
426
+ t.isObjectProperty(prop) &&
427
+ t.isIdentifier(prop.key, { name: "attribute" })
428
+ );
429
+
430
+ if (!attributeProp) {
431
+ value.properties.push(
432
+ t.objectProperty(t.identifier("attribute"), t.booleanLiteral(false))
433
+ );
434
+ } else {
435
+ attributeProp.value = t.booleanLiteral(false);
436
+ }
437
+ }
438
+ }
439
+
440
+ function mapLiteralTypeToLit(tsType) {
441
+ if (!t.isTSLiteralType(tsType)) return null;
442
+ const literal = tsType.literal;
443
+ if (t.isStringLiteral(literal)) return t.identifier("String");
444
+ if (t.isNumericLiteral(literal)) return t.identifier("Number");
445
+ if (literal.type === "BooleanLiteral") return t.identifier("Boolean");
446
+ return null;
447
+ }
448
+
449
+ function mapCheckerTypeToPropertyConfig(type, checker, cacheState = null, seen = new Set()) {
450
+ if (!type) return createPropertyConfig(t.identifier("Object"));
451
+
452
+ const nonNullable = checker.getNonNullableType
453
+ ? checker.getNonNullableType(type)
454
+ : type;
455
+ const typeConfigCache = cacheState?.cache;
456
+ const inProgress = cacheState?.inProgress;
457
+
458
+ if (typeConfigCache?.has(nonNullable)) {
459
+ return typeConfigCache.get(nonNullable);
460
+ }
461
+
462
+ if (inProgress?.has(nonNullable)) {
463
+ return createPropertyConfig(t.identifier("Object"));
464
+ }
465
+
466
+ inProgress?.add(nonNullable);
467
+
468
+ let resolvedConfig;
469
+
470
+ if (nonNullable.isUnion?.()) {
471
+ const configs = nonNullable.types.map((item) =>
472
+ mapCheckerTypeToPropertyConfig(item, checker, cacheState, seen)
473
+ );
474
+ const uniqueTypes = [...new Set(
475
+ configs
476
+ .map((config) => (config?.type && t.isIdentifier(config.type) ? config.type.name : null))
477
+ .filter(Boolean)
478
+ )];
479
+ const attributeFalse = configs.every((config) => config?.attribute === false);
480
+ if (uniqueTypes.length === 1) {
481
+ resolvedConfig = createPropertyConfig(t.identifier(uniqueTypes[0]), {
482
+ attribute: attributeFalse ? false : undefined,
483
+ });
484
+ } else {
485
+ resolvedConfig = createPropertyConfig(t.identifier("Object"), {
486
+ attribute: attributeFalse ? false : undefined,
487
+ });
488
+ }
489
+ } else if (nonNullable.isIntersection?.()) {
490
+ const configs = nonNullable.types.map((item) =>
491
+ mapCheckerTypeToPropertyConfig(item, checker, cacheState, seen)
492
+ );
493
+ const primitiveNames = ["String", "Number", "Boolean", "Array", "Date"];
494
+ const uniqueTypes = [...new Set(
495
+ configs
496
+ .map((config) => (config?.type && t.isIdentifier(config.type) ? config.type.name : null))
497
+ .filter(Boolean)
498
+ )];
499
+ const preferredPrimitive = primitiveNames.find((name) => uniqueTypes.includes(name));
500
+ const attributeFalse = configs.every((config) => config?.attribute === false);
501
+ if (preferredPrimitive) {
502
+ resolvedConfig = createPropertyConfig(t.identifier(preferredPrimitive), {
503
+ attribute: attributeFalse ? false : undefined,
504
+ });
505
+ } else if (uniqueTypes.length === 1) {
506
+ resolvedConfig = createPropertyConfig(t.identifier(uniqueTypes[0]), {
507
+ attribute: attributeFalse ? false : undefined,
508
+ });
509
+ } else {
510
+ resolvedConfig = createPropertyConfig(t.identifier("Object"), {
511
+ attribute: attributeFalse ? false : undefined,
512
+ });
513
+ }
514
+ } else {
515
+ const callSignatures = checker.getSignaturesOfType(nonNullable, ts.SignatureKind.Call);
516
+ if (callSignatures.length) {
517
+ resolvedConfig = createPropertyConfig(t.identifier("Object"), { attribute: false });
518
+ } else if (nonNullable.flags & (ts.TypeFlags.String | ts.TypeFlags.StringLike)) {
519
+ resolvedConfig = createPropertyConfig(t.identifier("String"));
520
+ } else if (nonNullable.flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLike)) {
521
+ resolvedConfig = createPropertyConfig(t.identifier("Number"));
522
+ } else if (nonNullable.flags & (ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLike)) {
523
+ resolvedConfig = createPropertyConfig(t.identifier("Boolean"));
524
+ } else if (nonNullable.flags & ts.TypeFlags.BigIntLike) {
525
+ resolvedConfig = createPropertyConfig(t.identifier("Object"));
526
+ } else if (checker.isArrayType?.(nonNullable) || checker.isTupleType?.(nonNullable)) {
527
+ resolvedConfig = createPropertyConfig(t.identifier("Array"));
528
+ } else {
529
+ const symbol = nonNullable.getSymbol?.();
530
+ const symbolName = symbol?.getName?.();
531
+ if (symbolName === "Date") {
532
+ resolvedConfig = createPropertyConfig(t.identifier("Date"));
533
+ } else {
534
+ if (symbol && !seen.has(symbol)) {
535
+ seen.add(symbol);
536
+ }
537
+ resolvedConfig = createPropertyConfig(t.identifier("Object"));
538
+ }
539
+ }
540
+ }
541
+
542
+ inProgress?.delete(nonNullable);
543
+ typeConfigCache?.set(nonNullable, resolvedConfig);
544
+ return resolvedConfig;
545
+ }
546
+
547
+ function getBabelNodeSpanCacheKey(node) {
548
+ if (typeof node?.start !== "number" || typeof node?.end !== "number") {
549
+ return null;
550
+ }
551
+ return `${node.start}:${node.end}`;
552
+ }
553
+
554
+ function getCheckerTypeForBabelNode(node, typeResolver) {
555
+ const cacheKey = getBabelNodeSpanCacheKey(node);
556
+ if (!typeResolver || !cacheKey) {
557
+ return null;
558
+ }
559
+
560
+ const typeCache = typeResolver.checkerTypeCache;
561
+ if (typeCache?.has(cacheKey)) {
562
+ return typeCache.get(cacheKey);
563
+ }
564
+
565
+ const tsNode = typeResolver.getNodeAtSpan(node.start, node.end);
566
+ if (!tsNode) {
567
+ typeCache?.set(cacheKey, null);
568
+ return null;
569
+ }
570
+
571
+ try {
572
+ const resolvedType = typeResolver.checker.getTypeAtLocation(tsNode);
573
+ typeCache?.set(cacheKey, resolvedType);
574
+ return resolvedType;
575
+ } catch {
576
+ typeCache?.set(cacheKey, null);
577
+ return null;
578
+ }
579
+ }
580
+
581
+ function getCheckerPropertyMapForPattern(node, typeResolver) {
582
+ const cacheKey = getBabelNodeSpanCacheKey(node);
583
+ if (!typeResolver || !cacheKey) {
584
+ return null;
585
+ }
586
+
587
+ const propertyMapCache = typeResolver.checkerPropertyMapCache;
588
+ if (propertyMapCache?.has(cacheKey)) {
589
+ return propertyMapCache.get(cacheKey);
590
+ }
591
+
592
+ const type = getCheckerTypeForBabelNode(node, typeResolver);
593
+ if (!type) {
594
+ propertyMapCache?.set(cacheKey, null);
595
+ return null;
596
+ }
597
+ const checker = typeResolver.checker;
598
+ const nonNullable = checker.getNonNullableType
599
+ ? checker.getNonNullableType(type)
600
+ : type;
601
+ const propertyMapByTypeCache = typeResolver.checkerPropertyMapByTypeCache;
602
+
603
+ if (propertyMapByTypeCache?.has(nonNullable)) {
604
+ const cachedPropertyMap = propertyMapByTypeCache.get(nonNullable);
605
+ propertyMapCache?.set(cacheKey, cachedPropertyMap);
606
+ return cachedPropertyMap;
607
+ }
608
+
609
+ if (
610
+ checker.isArrayType?.(nonNullable) ||
611
+ checker.isTupleType?.(nonNullable) ||
612
+ (nonNullable.flags & (
613
+ ts.TypeFlags.StringLike |
614
+ ts.TypeFlags.NumberLike |
615
+ ts.TypeFlags.BooleanLike |
616
+ ts.TypeFlags.BigIntLike
617
+ ))
618
+ ) {
619
+ propertyMapCache?.set(cacheKey, null);
620
+ return null;
621
+ }
622
+
623
+ if (checker.getSignaturesOfType(nonNullable, ts.SignatureKind.Call).length) {
624
+ propertyMapCache?.set(cacheKey, null);
625
+ return null;
626
+ }
627
+
628
+ const typeConfigCacheState = {
629
+ cache: typeResolver.checkerTypeConfigCache,
630
+ inProgress: typeResolver.checkerTypeConfigInProgress,
631
+ };
632
+ const propertyMap = new Map();
633
+ for (const symbol of checker.getPropertiesOfType(nonNullable)) {
634
+ const valueDeclaration = symbol.valueDeclaration || symbol.declarations?.[0];
635
+ if (!valueDeclaration) continue;
636
+ const symbolType = checker.getTypeOfSymbolAtLocation(symbol, valueDeclaration);
637
+ propertyMap.set(
638
+ symbol.getName(),
639
+ mapCheckerTypeToPropertyConfig(symbolType, checker, typeConfigCacheState)
640
+ );
641
+ }
642
+
643
+ const resolvedPropertyMap = propertyMap.size ? propertyMap : null;
644
+ propertyMapByTypeCache?.set(nonNullable, resolvedPropertyMap);
645
+ propertyMapCache?.set(cacheKey, resolvedPropertyMap);
646
+ return resolvedPropertyMap;
647
+ }
648
+
649
+ function findTypeDeclaration(programPath, name) {
650
+ if (!programPath) return null;
651
+ const bodyPaths = programPath.get("body");
652
+ for (const path of bodyPaths) {
653
+ if (path.isTSTypeAliasDeclaration() && path.node.id.name === name) {
654
+ return path.node;
655
+ }
656
+ if (path.isTSInterfaceDeclaration() && path.node.id.name === name) {
657
+ return path.node;
658
+ }
659
+ }
660
+ return null;
661
+ }
662
+
663
+ function getTypeLiteralMembers(node, programPath, seen = new Set()) {
664
+ if (!node) return [];
665
+
666
+ if (t.isTSTypeAliasDeclaration(node)) {
667
+ return getTypeLiteralMembers(node.typeAnnotation, programPath, seen);
668
+ }
669
+
670
+ if (t.isTSInterfaceDeclaration(node)) {
671
+ const members = [...node.body.body];
672
+ for (const extension of node.extends || []) {
673
+ if (!t.isIdentifier(extension.expression)) continue;
674
+ const name = extension.expression.name;
675
+ if (seen.has(name)) continue;
676
+ seen.add(name);
677
+ const declaration = findTypeDeclaration(programPath, name);
678
+ members.unshift(...getTypeLiteralMembers(declaration, programPath, seen));
679
+ }
680
+ return members;
681
+ }
682
+
683
+ if (t.isTSTypeLiteral(node)) {
684
+ return [...node.members];
685
+ }
686
+
687
+ if (t.isTSIntersectionType(node)) {
688
+ return node.types.flatMap((typeNode) =>
689
+ getTypeLiteralMembers(typeNode, programPath, seen)
690
+ );
691
+ }
692
+
693
+ if (t.isTSParenthesizedType(node)) {
694
+ return getTypeLiteralMembers(node.typeAnnotation, programPath, seen);
695
+ }
696
+
697
+ if (t.isTSTypeReference(node) && programPath && t.isIdentifier(node.typeName)) {
698
+ const name = node.typeName.name;
699
+ if (seen.has(name)) return [];
700
+ seen.add(name);
701
+ const declaration = findTypeDeclaration(programPath, name);
702
+ return getTypeLiteralMembers(declaration, programPath, seen);
703
+ }
704
+
705
+ return [];
706
+ }
707
+
708
+ function mapTsTypeToLit(tsType, programPath, seen = new Set()) {
709
+ if (!tsType) return createPropertyConfig(t.identifier("Object"));
710
+
711
+ if (t.isTSParenthesizedType(tsType)) {
712
+ return mapTsTypeToLit(tsType.typeAnnotation, programPath, seen);
713
+ }
714
+
715
+ switch (tsType.type) {
716
+ case "TSStringKeyword":
717
+ return createPropertyConfig(t.identifier("String"));
718
+ case "TSNumberKeyword":
719
+ return createPropertyConfig(t.identifier("Number"));
720
+ case "TSBooleanKeyword":
721
+ return createPropertyConfig(t.identifier("Boolean"));
722
+ case "TSArrayType":
723
+ case "TSTupleType":
724
+ return createPropertyConfig(t.identifier("Array"));
725
+ case "TSFunctionType":
726
+ case "TSConstructorType":
727
+ return createPropertyConfig(t.identifier("Object"), { attribute: false });
728
+ case "TSLiteralType": {
729
+ const literalType = mapLiteralTypeToLit(tsType);
730
+ return createPropertyConfig(literalType || t.identifier("Object"));
731
+ }
732
+ case "TSUnionType": {
733
+ const inferred = tsType.types
734
+ .map((typeNode) => mapTsTypeToLit(typeNode, programPath, seen))
735
+ .filter(Boolean);
736
+ const uniqueTypes = [...new Set(
737
+ inferred
738
+ .map((config) => (t.isIdentifier(config.type) ? config.type.name : null))
739
+ .filter(Boolean)
740
+ )];
741
+ const attributeFalse = inferred.every((config) => config.attribute === false);
742
+ if (uniqueTypes.length === 1) {
743
+ return createPropertyConfig(t.identifier(uniqueTypes[0]), {
744
+ attribute: attributeFalse ? false : undefined,
745
+ });
746
+ }
747
+ return createPropertyConfig(t.identifier("Object"), {
748
+ attribute: attributeFalse ? false : undefined,
749
+ });
750
+ }
751
+ case "TSIntersectionType": {
752
+ if (
753
+ getTypeLiteralMembers(tsType, programPath, new Set(seen)).length > 0
754
+ ) {
755
+ return createPropertyConfig(t.identifier("Object"));
756
+ }
757
+ return createPropertyConfig(t.identifier("Object"));
758
+ }
759
+ case "TSTypeReference": {
760
+ if (
761
+ t.isIdentifier(tsType.typeName) &&
762
+ (tsType.typeName.name === "Array" || tsType.typeName.name === "ReadonlyArray")
763
+ ) {
764
+ return createPropertyConfig(t.identifier("Array"));
765
+ }
766
+ if (t.isIdentifier(tsType.typeName) && tsType.typeName.name === "Record") {
767
+ return createPropertyConfig(t.identifier("Object"));
768
+ }
769
+ if (t.isIdentifier(tsType.typeName) && tsType.typeName.name === "Date") {
770
+ return createPropertyConfig(t.identifier("Date"));
771
+ }
772
+ if (t.isIdentifier(tsType.typeName)) {
773
+ const name = tsType.typeName.name;
774
+ if (seen.has(name)) {
775
+ return createPropertyConfig(t.identifier("Object"));
776
+ }
777
+ const nextSeen = new Set(seen);
778
+ nextSeen.add(name);
779
+ const declaration = findTypeDeclaration(programPath, name);
780
+ if (declaration) {
781
+ if (getTypeLiteralMembers(declaration, programPath, nextSeen).length > 0) {
782
+ return createPropertyConfig(t.identifier("Object"));
783
+ }
784
+ if (t.isTSTypeAliasDeclaration(declaration)) {
785
+ return mapTsTypeToLit(declaration.typeAnnotation, programPath, nextSeen);
786
+ }
787
+ if (t.isTSInterfaceDeclaration(declaration)) {
788
+ return createPropertyConfig(t.identifier("Object"));
789
+ }
790
+ }
791
+ }
792
+ return createPropertyConfig(t.identifier("Object"));
793
+ }
794
+ default:
795
+ return createPropertyConfig(t.identifier("Object"));
796
+ }
797
+ }
798
+
799
+ function inferTypeFromDefault(node) {
800
+ if (t.isNumericLiteral(node)) {
801
+ return t.identifier("Number");
802
+ }
803
+ if (t.isBooleanLiteral(node)) {
804
+ return t.identifier("Boolean");
805
+ }
806
+ if (t.isArrayExpression(node)) {
807
+ return t.identifier("Array");
808
+ }
809
+ if (t.isObjectExpression(node)) {
810
+ return t.identifier("Object");
811
+ }
812
+ return t.identifier("String");
813
+ }
814
+
815
+ function extractParamName(param) {
816
+ if (t.isIdentifier(param)) return param.name;
817
+ if (t.isRestElement(param) && t.isIdentifier(param.argument)) {
818
+ return param.argument.name;
819
+ }
820
+ if (t.isAssignmentPattern(param) && t.isIdentifier(param.left)) {
821
+ return param.left.name;
822
+ }
823
+ if (t.isObjectProperty(param) && t.isIdentifier(param.value)) {
824
+ return param.value.name;
825
+ }
826
+ if (
827
+ t.isObjectProperty(param) &&
828
+ t.isAssignmentPattern(param.value) &&
829
+ t.isIdentifier(param.value.left)
830
+ ) {
831
+ return param.value.left.name;
832
+ }
833
+ if (
834
+ t.isObjectProperty(param) &&
835
+ t.isIdentifier(param.key) &&
836
+ !param.shorthand &&
837
+ !t.isIdentifier(param.value)
838
+ ) {
839
+ return param.key.name;
840
+ }
841
+ return null;
842
+ }
843
+
844
+ function getTsLiteralPropertyTypes(typeAnnotation, programPath, seen = new Set()) {
845
+ const map = new Map();
846
+ if (!typeAnnotation) return map;
847
+ const tsType =
848
+ typeAnnotation.type === "TSTypeAnnotation"
849
+ ? typeAnnotation.typeAnnotation
850
+ : typeAnnotation;
851
+ if (!tsType) return map;
852
+
853
+ if (t.isTSTypeAliasDeclaration(tsType)) {
854
+ return getTsLiteralPropertyTypes(tsType.typeAnnotation, programPath, seen);
855
+ } else if (t.isTSTypeLiteral(tsType)) {
856
+ tsType.members.forEach((member) => {
857
+ if (
858
+ t.isTSPropertySignature(member) &&
859
+ t.isIdentifier(member.key) &&
860
+ member.typeAnnotation
861
+ ) {
862
+ map.set(
863
+ member.key.name,
864
+ mapTsTypeToLit(member.typeAnnotation.typeAnnotation, programPath, seen)
865
+ );
866
+ }
867
+ });
868
+ } else if (t.isTSInterfaceDeclaration(tsType)) {
869
+ getTypeLiteralMembers(tsType, programPath, seen).forEach((member) => {
870
+ if (
871
+ t.isTSPropertySignature(member) &&
872
+ t.isIdentifier(member.key) &&
873
+ member.typeAnnotation
874
+ ) {
875
+ map.set(
876
+ member.key.name,
877
+ mapTsTypeToLit(member.typeAnnotation.typeAnnotation, programPath, seen)
878
+ );
879
+ }
880
+ });
881
+ } else if (t.isTSIntersectionType(tsType)) {
882
+ tsType.types.forEach((typeNode) => {
883
+ const nextMap = getTsLiteralPropertyTypes(typeNode, programPath, seen);
884
+ nextMap.forEach((value, key) => {
885
+ if (!map.has(key)) map.set(key, value);
886
+ });
887
+ });
888
+ } else if (t.isTSMappedType(tsType)) {
889
+ map.set("default", createPropertyConfig(t.identifier("Object")));
890
+ } else if (t.isTSTypeReference(tsType) && programPath) {
891
+ const typeName = tsType.typeName;
892
+ if (t.isIdentifier(typeName)) {
893
+ const aliasName = typeName.name;
894
+ if (!seen.has(aliasName)) {
895
+ seen.add(aliasName);
896
+ const declaration = findTypeDeclaration(programPath, aliasName);
897
+ if (declaration) {
898
+ const aliasMap = getTsLiteralPropertyTypes(
899
+ declaration,
900
+ programPath,
901
+ seen
902
+ );
903
+ aliasMap.forEach((value, key) => {
904
+ if (!map.has(key)) {
905
+ map.set(key, value);
906
+ }
907
+ });
908
+ }
909
+ }
910
+ }
911
+ }
912
+
913
+ return map;
914
+ }
915
+
916
+ function extractProperties(functionPath, programPath, options = {}) {
917
+ const typeResolver = options.typeResolver || null;
918
+ const warn =
919
+ typeof options.warn === "function"
920
+ ? options.warn
921
+ : null;
922
+ const propertyMap = new Map();
923
+ const bindings = new Map();
924
+ const defaults = new Map();
925
+ const nestedInitializers = [];
926
+ const forwardRefOptions = options.forwardRef;
927
+
928
+ function isSpecialRefPropName(name) {
929
+ return name === "ref";
930
+ }
931
+
932
+ function getSpecialRefPropertyConfig() {
933
+ return createPropertyConfig(t.identifier("Object"), { attribute: false });
934
+ }
935
+
936
+ function addNestedInitializer(pattern, rootName, defaultValue) {
937
+ nestedInitializers.push({
938
+ pattern: t.cloneNode(pattern),
939
+ root: rootName,
940
+ defaultValue: defaultValue ? t.cloneNode(defaultValue) : null,
941
+ });
942
+ }
943
+
944
+ function ensureProperty(propName, config, options = {}) {
945
+ if (!propName || propName === "props") return null;
946
+ let normalizedConfig = normalizePropertyConfigInput(config);
947
+ if (isSpecialRefPropName(propName)) {
948
+ const refConfig = getSpecialRefPropertyConfig();
949
+ normalizedConfig = createPropertyConfig(
950
+ normalizedConfig.type || refConfig.type,
951
+ {
952
+ attribute:
953
+ normalizedConfig.attribute === false || refConfig.attribute === false
954
+ ? false
955
+ : normalizedConfig.attribute,
956
+ }
957
+ );
958
+ }
959
+ let entry = propertyMap.get(propName);
960
+
961
+ if (!entry) {
962
+ entry = {
963
+ node: t.objectProperty(
964
+ t.identifier(propName),
965
+ createPropertyValue(normalizedConfig, options.defaultType !== false)
966
+ ),
967
+ };
968
+ propertyMap.set(propName, entry);
969
+ return entry;
970
+ }
971
+
972
+ mergePropertyConfig(entry, normalizedConfig, options.defaultType !== false);
973
+
974
+ return entry;
975
+ }
976
+
977
+ function registerBinding(localName, propName) {
978
+ if (!localName || !propName) return;
979
+ bindings.set(localName, propName);
980
+ }
981
+
982
+ function recordDefault(propName, expression) {
983
+ if (!propName || !expression) return;
984
+ if (!defaults.has(propName)) {
985
+ defaults.set(propName, t.cloneNode(expression));
986
+ }
987
+ }
988
+
989
+ function handleIdentifier(identifier, config, options = {}) {
990
+ const propertyConfig = isSpecialRefPropName(identifier.name)
991
+ ? getSpecialRefPropertyConfig()
992
+ : config || createPropertyConfig(t.identifier("String"));
993
+ ensureProperty(identifier.name, propertyConfig);
994
+ if (options.bindKey) {
995
+ registerBinding(identifier.name, options.bindKey);
996
+ } else {
997
+ registerBinding(identifier.name, identifier.name);
998
+ }
999
+ }
1000
+
1001
+ function handleRestElement(restEl, explicitType, options = {}) {
1002
+ const name = extractParamName(restEl);
1003
+ if (!name) return;
1004
+ const propertyConfig = isSpecialRefPropName(name)
1005
+ ? getSpecialRefPropertyConfig()
1006
+ : explicitType || createPropertyConfig(t.identifier("Array"));
1007
+ ensureProperty(name, propertyConfig);
1008
+ registerBinding(name, options.bindKey || name);
1009
+ }
1010
+
1011
+ function handleAssignmentPattern(pattern, explicitType) {
1012
+ const name = extractParamName(pattern);
1013
+ if (!name) return;
1014
+ let propertyConfig = isSpecialRefPropName(name)
1015
+ ? getSpecialRefPropertyConfig()
1016
+ : explicitType || createPropertyConfig(t.identifier("String"));
1017
+ if (!explicitType && pattern.right) {
1018
+ propertyConfig = createPropertyConfig(inferTypeFromDefault(pattern.right));
1019
+ }
1020
+ if (isSpecialRefPropName(name)) {
1021
+ propertyConfig = getSpecialRefPropertyConfig();
1022
+ }
1023
+ ensureProperty(name, propertyConfig);
1024
+ registerBinding(name, name);
1025
+ if (pattern.right) {
1026
+ recordDefault(name, pattern.right);
1027
+ }
1028
+ }
1029
+
1030
+ function handleObjectPattern(pattern) {
1031
+ const typeMap =
1032
+ getCheckerPropertyMapForPattern(pattern, typeResolver) ||
1033
+ getTsLiteralPropertyTypes(pattern.typeAnnotation, programPath);
1034
+ pattern.properties.forEach((prop) => {
1035
+ if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
1036
+ const restName = prop.argument.name;
1037
+ ensureProperty(restName, createPropertyConfig(t.identifier("Object")));
1038
+ registerBinding(restName, restName);
1039
+ return;
1040
+ }
1041
+
1042
+ if (!t.isObjectProperty(prop)) return;
1043
+
1044
+ const keyName = t.isIdentifier(prop.key)
1045
+ ? prop.key.name
1046
+ : t.isStringLiteral(prop.key)
1047
+ ? prop.key.value
1048
+ : null;
1049
+
1050
+ if (!keyName) return;
1051
+
1052
+ let localName;
1053
+ let propertyConfig = isSpecialRefPropName(keyName)
1054
+ ? getSpecialRefPropertyConfig()
1055
+ : typeMap.get(keyName) || createPropertyConfig(t.identifier("String"));
1056
+
1057
+ if (t.isIdentifier(prop.value)) {
1058
+ localName = prop.value.name;
1059
+ } else if (t.isAssignmentPattern(prop.value)) {
1060
+ const assignment = prop.value;
1061
+ if (t.isIdentifier(assignment.left)) {
1062
+ localName = assignment.left.name;
1063
+ if (
1064
+ t.isIdentifier(propertyConfig.type) &&
1065
+ propertyConfig.type.name === "String"
1066
+ ) {
1067
+ propertyConfig = createPropertyConfig(inferTypeFromDefault(assignment.right));
1068
+ }
1069
+ } else if (t.isObjectPattern(assignment.left)) {
1070
+ propertyConfig = createPropertyConfig(t.identifier("Object"));
1071
+ addNestedInitializer(assignment.left, keyName, assignment.right);
1072
+ } else if (t.isArrayPattern(assignment.left)) {
1073
+ propertyConfig = createPropertyConfig(t.identifier("Array"));
1074
+ addNestedInitializer(assignment.left, keyName, assignment.right);
1075
+ }
1076
+ } else if (prop.shorthand && t.isIdentifier(prop.key)) {
1077
+ localName = prop.key.name;
1078
+ } else if (t.isObjectPattern(prop.value)) {
1079
+ propertyConfig = createPropertyConfig(t.identifier("Object"));
1080
+ addNestedInitializer(prop.value, keyName, null);
1081
+ } else if (t.isArrayPattern(prop.value)) {
1082
+ propertyConfig = createPropertyConfig(t.identifier("Array"));
1083
+ addNestedInitializer(prop.value, keyName, null);
1084
+ }
1085
+
1086
+ ensureProperty(keyName, propertyConfig);
1087
+ registerBinding(localName || keyName, keyName);
1088
+ if (t.isAssignmentPattern(prop.value)) {
1089
+ recordDefault(keyName, prop.value.right);
1090
+ }
1091
+ });
1092
+ }
1093
+
1094
+ function ensureAttributeFalse(entry) {
1095
+ mergePropertyConfig(entry, createPropertyConfig(null, { attribute: false }));
1096
+ }
1097
+
1098
+ function inferOpaquePropsMemberAccess(bindingName) {
1099
+ if (!bindingName) return;
1100
+
1101
+ const binding = functionPath.scope.getBinding(bindingName);
1102
+ if (!binding) return;
1103
+
1104
+ binding.referencePaths.forEach((refPath) => {
1105
+ if (!refPath.node) return;
1106
+ if (!refPath.parentPath || !refPath.parentPath.isMemberExpression()) return;
1107
+ if (refPath.parentKey !== "object") return;
1108
+
1109
+ const memberPath = refPath.parentPath;
1110
+ if (memberPath.node.computed || !t.isIdentifier(memberPath.node.property)) return;
1111
+
1112
+ const propName = memberPath.node.property.name;
1113
+ if (!propName || propName === "props") return;
1114
+
1115
+ if (!propertyMap.has(propName) && warn) {
1116
+ warn({
1117
+ code: 91018,
1118
+ message: `Falling back to String for prop "${propName}" inferred from opaque props access. Prefer destructuring, TypeScript types, or ^properties(...) for stronger property metadata.`,
1119
+ propName,
1120
+ localName: bindingName,
1121
+ line: memberPath.node.loc?.start?.line ?? null,
1122
+ column: memberPath.node.loc?.start?.column ?? null,
1123
+ });
1124
+ }
1125
+
1126
+ ensureProperty(propName, createPropertyConfig(t.identifier("String")));
1127
+ });
1128
+ }
1129
+
1130
+ function tryRegisterTypedAliasBinding(identifier) {
1131
+ if (!t.isIdentifier(identifier)) return false;
1132
+
1133
+ const checkerPropertyMap = getCheckerPropertyMapForPattern(identifier, typeResolver);
1134
+ if (checkerPropertyMap?.size) {
1135
+ registerBinding(identifier.name, {
1136
+ kind: "alias",
1137
+ properties: checkerPropertyMap,
1138
+ });
1139
+ checkerPropertyMap.forEach((propType, propName) => {
1140
+ ensureProperty(propName, propType);
1141
+ });
1142
+ return true;
1143
+ }
1144
+
1145
+ const typeAnnotation = identifier.typeAnnotation && identifier.typeAnnotation.typeAnnotation;
1146
+ if (t.isTSTypeReference(typeAnnotation) && t.isIdentifier(typeAnnotation.typeName)) {
1147
+ const declaration = findTypeDeclaration(programPath, typeAnnotation.typeName.name);
1148
+ if (declaration) {
1149
+ const typeMembers = getTypeLiteralMembers(declaration, programPath, new Set());
1150
+ if (typeMembers.length > 0) {
1151
+ const aliasProperties = new Map();
1152
+ typeMembers.forEach((member) => {
1153
+ if (
1154
+ t.isTSPropertySignature(member) &&
1155
+ t.isIdentifier(member.key) &&
1156
+ member.typeAnnotation
1157
+ ) {
1158
+ const propName = member.key.name;
1159
+ const propType = mapTsTypeToLit(member.typeAnnotation.typeAnnotation, programPath);
1160
+ ensureProperty(propName, propType);
1161
+ aliasProperties.set(propName, propType);
1162
+ }
1163
+ });
1164
+ registerBinding(identifier.name, {
1165
+ kind: "alias",
1166
+ properties: aliasProperties,
1167
+ });
1168
+ return true;
1169
+ }
1170
+ }
1171
+ }
1172
+
1173
+ return false;
1174
+ }
1175
+
1176
+ functionPath.node.params.forEach((param, paramIndex) => {
1177
+ if (
1178
+ forwardRefOptions &&
1179
+ paramIndex === forwardRefOptions.paramIndex &&
1180
+ t.isIdentifier(param)
1181
+ ) {
1182
+ const propName = forwardRefOptions.propName || param.name;
1183
+ const entry = ensureProperty(propName, createPropertyConfig(t.identifier("Object")));
1184
+ ensureAttributeFalse(entry);
1185
+ registerBinding(param.name, propName);
1186
+ return;
1187
+ }
1188
+
1189
+ if (t.isIdentifier(param)) {
1190
+ let propertyConfig = createPropertyConfig(t.identifier("String"));
1191
+ const checkerType = getCheckerTypeForBabelNode(param, typeResolver);
1192
+ if (checkerType) {
1193
+ propertyConfig = mapCheckerTypeToPropertyConfig(checkerType, typeResolver.checker, {
1194
+ cache: typeResolver.checkerTypeConfigCache,
1195
+ inProgress: typeResolver.checkerTypeConfigInProgress,
1196
+ });
1197
+ } else if (param.typeAnnotation) {
1198
+ propertyConfig = mapTsTypeToLit(param.typeAnnotation.typeAnnotation, programPath);
1199
+ }
1200
+ if (tryRegisterTypedAliasBinding(param)) return;
1201
+
1202
+ handleIdentifier(param, propertyConfig);
1203
+
1204
+ if (param.name === "props") {
1205
+ inferOpaquePropsMemberAccess(param.name);
1206
+ }
1207
+
1208
+ return;
1209
+ }
1210
+
1211
+ if (t.isRestElement(param)) {
1212
+ const typeAnnotation = param.typeAnnotation
1213
+ ? mapTsTypeToLit(param.typeAnnotation.typeAnnotation, programPath)
1214
+ : createPropertyConfig(t.identifier("Array"));
1215
+ handleRestElement(param, typeAnnotation);
1216
+ return;
1217
+ }
1218
+
1219
+ if (t.isAssignmentPattern(param)) {
1220
+ if (t.isIdentifier(param.left) && tryRegisterTypedAliasBinding(param.left)) {
1221
+ if (param.left.name === "props") {
1222
+ inferOpaquePropsMemberAccess(param.left.name);
1223
+ }
1224
+ return;
1225
+ }
1226
+
1227
+ const explicitType = param.left.typeAnnotation
1228
+ ? mapTsTypeToLit(param.left.typeAnnotation.typeAnnotation, programPath)
1229
+ : null;
1230
+ handleAssignmentPattern(param, explicitType);
1231
+ return;
1232
+ }
1233
+
1234
+ if (t.isObjectPattern(param)) {
1235
+ handleObjectPattern(param);
1236
+ return;
1237
+ }
1238
+ });
1239
+
1240
+ const properties = Array.from(propertyMap.values()).map((entry) => entry.node);
1241
+ const propertyNames = new Set(propertyMap.keys());
1242
+
1243
+ return { properties, propertyNames, bindings, defaults, nestedInitializers };
1244
+ }
1245
+
1246
+ exports.createPropertyConfig = createPropertyConfig;
1247
+ exports.createPropertyValue = createPropertyValue;
1248
+ exports.createTypeResolver = createTypeResolver;
1249
+ exports.ensureTypescriptModule = ensureTypescriptModule;
1250
+ exports.extractProperties = extractProperties;
1251
+ exports.mergePropertyConfig = mergePropertyConfig;
1252
+ exports.setPropertyBabelTypes = setPropertyBabelTypes;
1253
+ exports.setTypescriptModule = setTypescriptModule;
1254
+ //# sourceMappingURL=transform-litsx-properties.cjs.map