tempo-sdk 0.0.10 → 0.0.11

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,902 @@
1
+ // expo-babel-plugin.ts
2
+ import { existsSync } from "fs";
3
+ import { dirname, resolve } from "path";
4
+ import { createFilter } from "@rollup/pluginutils";
5
+
6
+ // annotation-strategy.ts
7
+ import { realpathSync, statSync } from "fs";
8
+ import { relative } from "path";
9
+ var DEFAULT_EXCLUDE = ["**/node_modules/**"];
10
+ var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
11
+ "area",
12
+ "base",
13
+ "br",
14
+ "col",
15
+ "embed",
16
+ "hr",
17
+ "img",
18
+ "input",
19
+ "link",
20
+ "meta",
21
+ "param",
22
+ "source",
23
+ "track",
24
+ "wbr"
25
+ ]);
26
+ function cleanModuleId(id) {
27
+ return id.replace(/[?#].*$/, "");
28
+ }
29
+ function resolveCanonicalRoot(root) {
30
+ try {
31
+ return realpathSync.native(root);
32
+ } catch {
33
+ return root;
34
+ }
35
+ }
36
+ function isIntrinsicElement(tagName) {
37
+ return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
38
+ }
39
+ function hasJsxAttribute(info, attrName) {
40
+ for (const attr of info.element.openingElement.attributes) {
41
+ const name = attr.name;
42
+ if (name?.name === attrName) return true;
43
+ }
44
+ return false;
45
+ }
46
+ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
47
+ return {
48
+ "data-tempo-filepath": filepath,
49
+ "data-tempo-position": info.element.openingElement.start,
50
+ "data-tempo-modifiedts": modifiedtsMs
51
+ };
52
+ }
53
+ function computeTempoAnnotatedProps(params) {
54
+ const {
55
+ info,
56
+ filepath,
57
+ modifiedtsMs,
58
+ computeAnnotatedProps,
59
+ typeInfo,
60
+ elementSupportOverrides
61
+ } = params;
62
+ const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
63
+ if (isIntrinsicElement(info.tagName)) {
64
+ return {
65
+ ...userProps,
66
+ "data-tempo-supports-children": hasJsxAttribute(
67
+ info,
68
+ "data-tempo-supports-children"
69
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
70
+ };
71
+ }
72
+ const override = elementSupportOverrides?.get(info.tagName);
73
+ if (override) {
74
+ return {
75
+ ...userProps,
76
+ "data-tempo-supports-style": override.supportsStyle,
77
+ "data-tempo-supports-classname": override.supportsClassName,
78
+ "data-tempo-supports-children": hasJsxAttribute(
79
+ info,
80
+ "data-tempo-supports-children"
81
+ ) ? void 0 : override.supportsChildren
82
+ };
83
+ }
84
+ const support = typeInfo?.get(info.element.openingElement.start);
85
+ return {
86
+ ...userProps,
87
+ "data-tempo-supports-style": support?.supportsStyle ?? false,
88
+ "data-tempo-supports-classname": support?.supportsClassName ?? false,
89
+ "data-tempo-supports-children": hasJsxAttribute(
90
+ info,
91
+ "data-tempo-supports-children"
92
+ ) ? void 0 : support?.supportsChildren ?? false
93
+ };
94
+ }
95
+ function getFileAnnotationContext(params) {
96
+ const rawCleanFilename = cleanModuleId(params.filename);
97
+ let cleanFilename = rawCleanFilename;
98
+ if (params.canonicalizeFilename) {
99
+ try {
100
+ cleanFilename = realpathSync.native(rawCleanFilename);
101
+ } catch {
102
+ cleanFilename = rawCleanFilename;
103
+ }
104
+ }
105
+ return {
106
+ cleanFilename,
107
+ filepath: relative(params.root, cleanFilename),
108
+ modifiedtsMs: Math.trunc(statSync(cleanFilename).mtimeMs)
109
+ };
110
+ }
111
+
112
+ // type-analyzer.ts
113
+ import ts2 from "typescript";
114
+ import path2 from "path";
115
+ import { realpathSync as realpathSync3 } from "fs";
116
+
117
+ // ../../modules/typescript/workspace-service.ts
118
+ import { realpathSync as realpathSync2, statSync as statSync2 } from "fs";
119
+ import path from "path";
120
+ import ts from "typescript";
121
+ function canonicalPath(input) {
122
+ const resolved = path.resolve(input);
123
+ try {
124
+ return realpathSync2.native(resolved);
125
+ } catch {
126
+ return resolved;
127
+ }
128
+ }
129
+ function compareProjectPriority(left, right) {
130
+ const depthDelta = right.rootDir.length - left.rootDir.length;
131
+ if (depthDelta !== 0) {
132
+ return depthDelta;
133
+ }
134
+ const priorityDelta = right.priority - left.priority;
135
+ if (priorityDelta !== 0) {
136
+ return priorityDelta;
137
+ }
138
+ return left.id.localeCompare(right.id);
139
+ }
140
+ function isWithinRoot(filePath, rootDir) {
141
+ return filePath === rootDir || filePath.startsWith(`${rootDir}${path.sep}`);
142
+ }
143
+ function loadProject(descriptor) {
144
+ const id = descriptor.id.trim();
145
+ if (!id) {
146
+ throw new Error("Project id must be a non-empty string");
147
+ }
148
+ const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
149
+ const rootDir = canonicalPath(descriptor.rootDir);
150
+ const readResult = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
151
+ if (readResult.error) {
152
+ throw new Error(
153
+ `Failed to read tsconfig at ${tsconfigPath}: ${ts.flattenDiagnosticMessageText(
154
+ readResult.error.messageText,
155
+ "\n"
156
+ )}`
157
+ );
158
+ }
159
+ const parsed = ts.parseJsonConfigFileContent(
160
+ readResult.config,
161
+ ts.sys,
162
+ path.dirname(tsconfigPath)
163
+ );
164
+ if (parsed.errors.length > 0) {
165
+ const message = parsed.errors.map(
166
+ (diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
167
+ ).join("; ");
168
+ throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
169
+ }
170
+ const normalizedFiles = parsed.fileNames.map(
171
+ (fileName) => canonicalPath(fileName)
172
+ );
173
+ return {
174
+ id,
175
+ rootDir,
176
+ tsconfigPath,
177
+ priority: descriptor.priority ?? 0,
178
+ options: parsed.options,
179
+ fileNames: normalizedFiles,
180
+ moduleResolutionCache: ts.createModuleResolutionCache(
181
+ rootDir,
182
+ (value) => value,
183
+ parsed.options
184
+ )
185
+ };
186
+ }
187
+ function getFileMtimeVersion(filePath) {
188
+ try {
189
+ const stats = statSync2(filePath);
190
+ return String(stats.mtimeMs);
191
+ } catch {
192
+ return "0";
193
+ }
194
+ }
195
+ function createTsWorkspaceService(descriptor) {
196
+ if (descriptor.projects.length === 0) {
197
+ throw new Error(
198
+ "TsWorkspaceDescriptor.projects must include at least one project"
199
+ );
200
+ }
201
+ const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
202
+ const loadedProjects = descriptor.projects.map(
203
+ (project) => loadProject(project)
204
+ );
205
+ const projectsById = /* @__PURE__ */ new Map();
206
+ for (const project of loadedProjects) {
207
+ if (projectsById.has(project.id)) {
208
+ throw new Error(`Duplicate project id: ${project.id}`);
209
+ }
210
+ projectsById.set(project.id, project);
211
+ }
212
+ const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
213
+ if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
214
+ throw new Error(
215
+ `Primary project id not found: ${descriptor.primaryProjectId}`
216
+ );
217
+ }
218
+ const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
219
+ const rootFileNames = /* @__PURE__ */ new Set();
220
+ for (const project of loadedProjects) {
221
+ for (const fileName of project.fileNames) {
222
+ rootFileNames.add(fileName);
223
+ }
224
+ }
225
+ const inMemoryFiles = /* @__PURE__ */ new Map();
226
+ let projectVersion = 0;
227
+ function getOwningProject(filePath) {
228
+ const canonicalFilePath = canonicalPath(filePath);
229
+ for (const project of orderedProjects) {
230
+ if (isWithinRoot(canonicalFilePath, project.rootDir)) {
231
+ return project;
232
+ }
233
+ }
234
+ return primaryProject;
235
+ }
236
+ const moduleResolutionHost = {
237
+ fileExists: ts.sys.fileExists,
238
+ readFile: ts.sys.readFile,
239
+ realpath: ts.sys.realpath,
240
+ directoryExists: ts.sys.directoryExists,
241
+ getCurrentDirectory: () => workspaceRoot,
242
+ getDirectories: ts.sys.getDirectories
243
+ };
244
+ const host = {
245
+ getScriptFileNames: () => Array.from(rootFileNames),
246
+ getScriptVersion: (filePath) => {
247
+ const canonicalFilePath = canonicalPath(filePath);
248
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
249
+ if (inMemory) {
250
+ return String(inMemory.version);
251
+ }
252
+ return getFileMtimeVersion(canonicalFilePath);
253
+ },
254
+ getScriptSnapshot: (filePath) => {
255
+ const canonicalFilePath = canonicalPath(filePath);
256
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
257
+ if (inMemory) {
258
+ return ts.ScriptSnapshot.fromString(inMemory.content);
259
+ }
260
+ const diskContent = ts.sys.readFile(canonicalFilePath);
261
+ if (diskContent === void 0) {
262
+ return void 0;
263
+ }
264
+ return ts.ScriptSnapshot.fromString(diskContent);
265
+ },
266
+ getCurrentDirectory: () => workspaceRoot,
267
+ getCompilationSettings: () => primaryProject.options,
268
+ getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
269
+ fileExists: ts.sys.fileExists,
270
+ readFile: ts.sys.readFile,
271
+ readDirectory: ts.sys.readDirectory,
272
+ directoryExists: ts.sys.directoryExists,
273
+ getDirectories: ts.sys.getDirectories,
274
+ useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
275
+ getProjectVersion: () => String(projectVersion),
276
+ resolveModuleNames: (moduleNames, containingFile) => {
277
+ const owningProject = getOwningProject(containingFile);
278
+ return moduleNames.map((moduleName) => {
279
+ const ownerResolution = ts.resolveModuleName(
280
+ moduleName,
281
+ containingFile,
282
+ owningProject.options,
283
+ moduleResolutionHost,
284
+ owningProject.moduleResolutionCache
285
+ ).resolvedModule;
286
+ if (ownerResolution) {
287
+ return ownerResolution;
288
+ }
289
+ if (owningProject.id === primaryProject.id) {
290
+ return void 0;
291
+ }
292
+ return ts.resolveModuleName(
293
+ moduleName,
294
+ containingFile,
295
+ primaryProject.options,
296
+ moduleResolutionHost,
297
+ primaryProject.moduleResolutionCache
298
+ ).resolvedModule;
299
+ });
300
+ }
301
+ };
302
+ const languageService = ts.createLanguageService(
303
+ host,
304
+ ts.createDocumentRegistry()
305
+ );
306
+ return {
307
+ updateFile(filePath, content) {
308
+ const canonicalFilePath = canonicalPath(filePath);
309
+ const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
310
+ inMemoryFiles.set(canonicalFilePath, {
311
+ version: currentVersion + 1,
312
+ content
313
+ });
314
+ if (!rootFileNames.has(canonicalFilePath)) {
315
+ rootFileNames.add(canonicalFilePath);
316
+ }
317
+ projectVersion += 1;
318
+ },
319
+ closeFile(filePath) {
320
+ const canonicalFilePath = canonicalPath(filePath);
321
+ inMemoryFiles.delete(canonicalFilePath);
322
+ projectVersion += 1;
323
+ },
324
+ getProgram() {
325
+ return languageService.getProgram() ?? null;
326
+ },
327
+ getSemanticDiagnostics(filePath) {
328
+ const canonicalFilePath = canonicalPath(filePath);
329
+ return languageService.getSemanticDiagnostics(canonicalFilePath);
330
+ },
331
+ getDefinition(filePath, position) {
332
+ const canonicalFilePath = canonicalPath(filePath);
333
+ return languageService.getDefinitionAtPosition(
334
+ canonicalFilePath,
335
+ position
336
+ );
337
+ },
338
+ dispose() {
339
+ languageService.dispose();
340
+ }
341
+ };
342
+ }
343
+
344
+ // type-analyzer.ts
345
+ function isCustomComponent(node) {
346
+ const text = node.getText();
347
+ return text.length > 0 && text[0] !== text[0].toLowerCase();
348
+ }
349
+ function canonicalPath2(value) {
350
+ const resolved = path2.resolve(value);
351
+ try {
352
+ return realpathSync3.native(resolved);
353
+ } catch {
354
+ return resolved;
355
+ }
356
+ }
357
+ function parseManagedTsconfigPaths(rawConfig) {
358
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
359
+ return [];
360
+ }
361
+ const metadata = rawConfig.tempobook;
362
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
363
+ return [];
364
+ }
365
+ const managedPaths = metadata.managedTsconfigPaths;
366
+ if (!Array.isArray(managedPaths)) {
367
+ return [];
368
+ }
369
+ return managedPaths.filter(
370
+ (entry) => typeof entry === "string" && entry.trim().length > 0
371
+ );
372
+ }
373
+ function parseProjectReferenceTsconfigPaths(references, configDir) {
374
+ if (!references || references.length === 0) {
375
+ return [];
376
+ }
377
+ const entries = [];
378
+ for (const reference of references) {
379
+ const referencePath = reference.path;
380
+ if (!referencePath) {
381
+ continue;
382
+ }
383
+ const resolvedPath = path2.resolve(configDir, referencePath);
384
+ const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : path2.join(resolvedPath, "tsconfig.json");
385
+ entries.push(tsconfigPath);
386
+ }
387
+ return entries;
388
+ }
389
+ function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
390
+ const configDir = path2.dirname(configPath);
391
+ const projects = [
392
+ {
393
+ id: "root",
394
+ rootDir: root,
395
+ tsconfigPath: configPath,
396
+ priority: 0
397
+ }
398
+ ];
399
+ const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
400
+ const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
401
+ parsedConfig.projectReferences,
402
+ configDir
403
+ );
404
+ const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
405
+ (entry) => path2.resolve(configDir, entry)
406
+ );
407
+ const candidateTsconfigPaths = [
408
+ ...managedTsconfigPaths,
409
+ ...referencedTsconfigPaths
410
+ ];
411
+ for (const candidatePath of candidateTsconfigPaths) {
412
+ const normalizedPath = canonicalPath2(candidatePath);
413
+ if (seenTsconfigPaths.has(normalizedPath)) {
414
+ continue;
415
+ }
416
+ if (!ts2.sys.fileExists(normalizedPath)) {
417
+ continue;
418
+ }
419
+ seenTsconfigPaths.add(normalizedPath);
420
+ projects.push({
421
+ id: `external-${projects.length}`,
422
+ rootDir: path2.dirname(normalizedPath),
423
+ tsconfigPath: normalizedPath,
424
+ priority: 0
425
+ });
426
+ }
427
+ return projects;
428
+ }
429
+ function createTypeAnalyzer(root) {
430
+ const configPath = ts2.findConfigFile(
431
+ root,
432
+ ts2.sys.fileExists,
433
+ "tsconfig.json"
434
+ );
435
+ if (!configPath) return null;
436
+ const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
437
+ if (configFile.error) return null;
438
+ const parsedConfig = ts2.parseJsonConfigFileContent(
439
+ configFile.config,
440
+ ts2.sys,
441
+ root
442
+ );
443
+ const workspaceProjects = buildWorkspaceProjects(
444
+ root,
445
+ configPath,
446
+ parsedConfig,
447
+ configFile.config
448
+ );
449
+ const workspaceProjectRoots = workspaceProjects.map(
450
+ (project) => canonicalPath2(project.rootDir)
451
+ );
452
+ const workspaceService = createTsWorkspaceService({
453
+ workspaceRoot: root,
454
+ primaryProjectId: "root",
455
+ projects: workspaceProjects
456
+ });
457
+ let cssPropertiesType;
458
+ function resolveCSSPropertiesType(checker, sourceFile) {
459
+ if (cssPropertiesType !== void 0) return cssPropertiesType;
460
+ try {
461
+ let jsxNs = checker.resolveName(
462
+ "JSX",
463
+ sourceFile,
464
+ ts2.SymbolFlags.Namespace,
465
+ false
466
+ );
467
+ if (!jsxNs) {
468
+ const program = workspaceService.getProgram();
469
+ const compilerOptions = program?.getCompilerOptions();
470
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
471
+ const resolved = ts2.resolveModuleName(
472
+ `${jsxImportSource}/jsx-runtime`,
473
+ sourceFile.fileName,
474
+ compilerOptions,
475
+ ts2.sys
476
+ );
477
+ if (resolved.resolvedModule) {
478
+ const runtimeFile = program?.getSourceFile(
479
+ resolved.resolvedModule.resolvedFileName
480
+ );
481
+ if (runtimeFile) {
482
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
483
+ if (runtimeSymbol) {
484
+ const exports = checker.getExportsOfModule(runtimeSymbol);
485
+ jsxNs = exports.find((s) => s.name === "JSX");
486
+ }
487
+ }
488
+ }
489
+ }
490
+ if (!jsxNs) {
491
+ cssPropertiesType = null;
492
+ return null;
493
+ }
494
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
495
+ if (!intrinsicSym) {
496
+ cssPropertiesType = null;
497
+ return null;
498
+ }
499
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
500
+ if (!divSym) {
501
+ cssPropertiesType = null;
502
+ return null;
503
+ }
504
+ const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
505
+ if (!styleSym) {
506
+ cssPropertiesType = null;
507
+ return null;
508
+ }
509
+ const styleType = checker.getTypeOfSymbol(styleSym);
510
+ if (styleType.isUnion()) {
511
+ const nonUndefined = styleType.types.find(
512
+ (t) => !(t.flags & ts2.TypeFlags.Undefined)
513
+ );
514
+ cssPropertiesType = nonUndefined ?? null;
515
+ } else {
516
+ cssPropertiesType = styleType;
517
+ }
518
+ } catch {
519
+ cssPropertiesType = null;
520
+ }
521
+ return cssPropertiesType;
522
+ }
523
+ let reactNodeType;
524
+ function resolveReactNodeType(checker, sourceFile) {
525
+ if (reactNodeType !== void 0) return reactNodeType;
526
+ try {
527
+ let jsxNs = checker.resolveName(
528
+ "JSX",
529
+ sourceFile,
530
+ ts2.SymbolFlags.Namespace,
531
+ false
532
+ );
533
+ if (!jsxNs) {
534
+ const program = workspaceService.getProgram();
535
+ const compilerOptions = program?.getCompilerOptions();
536
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
537
+ const resolved = ts2.resolveModuleName(
538
+ `${jsxImportSource}/jsx-runtime`,
539
+ sourceFile.fileName,
540
+ compilerOptions,
541
+ ts2.sys
542
+ );
543
+ if (resolved.resolvedModule) {
544
+ const runtimeFile = program?.getSourceFile(
545
+ resolved.resolvedModule.resolvedFileName
546
+ );
547
+ if (runtimeFile) {
548
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
549
+ if (runtimeSymbol) {
550
+ const exports = checker.getExportsOfModule(runtimeSymbol);
551
+ jsxNs = exports.find((s) => s.name === "JSX");
552
+ }
553
+ }
554
+ }
555
+ }
556
+ if (!jsxNs) {
557
+ reactNodeType = null;
558
+ return null;
559
+ }
560
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
561
+ if (!intrinsicSym) {
562
+ reactNodeType = null;
563
+ return null;
564
+ }
565
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
566
+ if (!divSym) {
567
+ reactNodeType = null;
568
+ return null;
569
+ }
570
+ const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
571
+ if (!childrenSym) {
572
+ reactNodeType = null;
573
+ return null;
574
+ }
575
+ const childrenType = checker.getTypeOfSymbol(childrenSym);
576
+ if (childrenType.isUnion()) {
577
+ const nonUndefined = childrenType.types.find(
578
+ (t) => !(t.flags & ts2.TypeFlags.Undefined)
579
+ );
580
+ reactNodeType = nonUndefined ?? null;
581
+ } else {
582
+ reactNodeType = childrenType;
583
+ }
584
+ } catch {
585
+ reactNodeType = null;
586
+ }
587
+ return reactNodeType;
588
+ }
589
+ return {
590
+ analyzeFileTypes(filePath, source) {
591
+ const canonicalFilePath = canonicalPath2(filePath);
592
+ const belongsToWorkspace = workspaceProjectRoots.some(
593
+ (projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${path2.sep}`)
594
+ );
595
+ if (!belongsToWorkspace) {
596
+ return null;
597
+ }
598
+ workspaceService.updateFile(filePath, source);
599
+ const program = workspaceService.getProgram();
600
+ if (!program) return null;
601
+ const sourceFile = program.getSourceFile(filePath);
602
+ if (!sourceFile) return null;
603
+ const checker = program.getTypeChecker();
604
+ const cssProps = resolveCSSPropertiesType(checker, sourceFile);
605
+ const result = /* @__PURE__ */ new Map();
606
+ function visit(node) {
607
+ if ((ts2.isJsxOpeningElement(node) || ts2.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
608
+ const position = node.getStart(sourceFile);
609
+ const attrsType = checker.getContextualType(node.attributes);
610
+ let supportsStyle = false;
611
+ let supportsClassName = false;
612
+ let supportsChildren = false;
613
+ if (attrsType) {
614
+ const classNameProp = attrsType.getProperty("className");
615
+ if (classNameProp) {
616
+ const propType = checker.getTypeOfSymbol(classNameProp);
617
+ supportsClassName = checker.isTypeAssignableTo(
618
+ checker.getStringType(),
619
+ propType
620
+ );
621
+ }
622
+ const styleProp = attrsType.getProperty("style");
623
+ if (styleProp && cssProps) {
624
+ let propType = checker.getTypeOfSymbol(styleProp);
625
+ if (propType.isUnion()) {
626
+ const nonUndefined = propType.types.find(
627
+ (t) => !(t.flags & ts2.TypeFlags.Undefined)
628
+ );
629
+ if (nonUndefined) propType = nonUndefined;
630
+ }
631
+ supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
632
+ }
633
+ const reactNode = resolveReactNodeType(checker, sourceFile);
634
+ const childrenProp = attrsType.getProperty("children");
635
+ if (childrenProp && reactNode) {
636
+ let propType = checker.getTypeOfSymbol(childrenProp);
637
+ if (propType.isUnion()) {
638
+ const nonUndefined = propType.types.find(
639
+ (t) => !(t.flags & ts2.TypeFlags.Undefined)
640
+ );
641
+ if (nonUndefined) propType = nonUndefined;
642
+ }
643
+ supportsChildren = checker.isTypeAssignableTo(
644
+ reactNode,
645
+ propType
646
+ );
647
+ }
648
+ }
649
+ result.set(position, { supportsStyle, supportsClassName, supportsChildren });
650
+ }
651
+ ts2.forEachChild(node, visit);
652
+ }
653
+ visit(sourceFile);
654
+ return result;
655
+ }
656
+ };
657
+ }
658
+
659
+ // expo-babel-plugin.ts
660
+ var EXPO_DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx", "**/*.js"];
661
+ var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
662
+ var REACT_NATIVE_STYLE_COMPONENTS = /* @__PURE__ */ new Set([
663
+ "ActivityIndicator",
664
+ "Button",
665
+ "FlatList",
666
+ "Image",
667
+ "ImageBackground",
668
+ "KeyboardAvoidingView",
669
+ "Modal",
670
+ "Pressable",
671
+ "RefreshControl",
672
+ "SafeAreaView",
673
+ "ScrollView",
674
+ "SectionList",
675
+ "Switch",
676
+ "Text",
677
+ "TextInput",
678
+ "TouchableHighlight",
679
+ "TouchableNativeFeedback",
680
+ "TouchableOpacity",
681
+ "TouchableWithoutFeedback",
682
+ "View",
683
+ "VirtualizedList"
684
+ ]);
685
+ var REACT_NATIVE_NO_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
686
+ "ActivityIndicator",
687
+ "Image",
688
+ "RefreshControl",
689
+ "Switch"
690
+ ]);
691
+ var REACT_NATIVE_SUPPORT_OVERRIDES = new Map(
692
+ [...REACT_NATIVE_STYLE_COMPONENTS].map((tagName) => [
693
+ tagName,
694
+ {
695
+ supportsStyle: true,
696
+ supportsClassName: false,
697
+ supportsChildren: !REACT_NATIVE_NO_CHILDREN_COMPONENTS.has(tagName)
698
+ }
699
+ ])
700
+ );
701
+ function hasParserPlugin(plugins, name) {
702
+ return plugins.some(
703
+ (plugin) => Array.isArray(plugin) ? plugin[0] === name : plugin === name
704
+ );
705
+ }
706
+ function getBabelTagName(name) {
707
+ switch (name.type) {
708
+ case "JSXIdentifier":
709
+ return name.name;
710
+ case "JSXNamespacedName":
711
+ return `${name.namespace.name}:${name.name.name}`;
712
+ case "JSXMemberExpression":
713
+ return `${getBabelTagName(name.object)}.${name.property.name}`;
714
+ }
715
+ }
716
+ function hasAttribute(node, attrName) {
717
+ return node.attributes.some(
718
+ (attr) => attr.type === "JSXAttribute" && attr.name.name === attrName
719
+ );
720
+ }
721
+ function propValueToExpression(api, value) {
722
+ if (typeof value === "function") {
723
+ return api.template.expression(value.toString())();
724
+ }
725
+ return api.types.valueToNode(value);
726
+ }
727
+ function getSupportOverrides(options) {
728
+ if (!options.reactNativeClassName) {
729
+ return REACT_NATIVE_SUPPORT_OVERRIDES;
730
+ }
731
+ return new Map(
732
+ [...REACT_NATIVE_SUPPORT_OVERRIDES].map(([tagName, support]) => [
733
+ tagName,
734
+ { ...support, supportsClassName: true }
735
+ ])
736
+ );
737
+ }
738
+ function dataAttrToDataSetKey(attrName) {
739
+ return attrName.replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
740
+ }
741
+ function findDataSetAttribute(openingElement) {
742
+ return openingElement.attributes.find(
743
+ (attr) => attr.type === "JSXAttribute" && attr.name.name === "dataSet"
744
+ );
745
+ }
746
+ function addAnnotations(api, tagName, openingElement, props) {
747
+ const t = api.types;
748
+ if (isIntrinsicElement(tagName)) {
749
+ for (const [key, value] of Object.entries(props)) {
750
+ if (value === void 0 || hasAttribute(openingElement, key)) continue;
751
+ openingElement.attributes.push(
752
+ t.jsxAttribute(
753
+ t.jsxIdentifier(key),
754
+ t.jsxExpressionContainer(propValueToExpression(api, value))
755
+ )
756
+ );
757
+ }
758
+ return;
759
+ }
760
+ const dataSetProps = [];
761
+ for (const [key, value] of Object.entries(props)) {
762
+ if (value === void 0) continue;
763
+ dataSetProps.push(
764
+ t.objectProperty(
765
+ t.identifier(dataAttrToDataSetKey(key)),
766
+ propValueToExpression(api, value)
767
+ )
768
+ );
769
+ }
770
+ if (dataSetProps.length === 0) return;
771
+ const existing = findDataSetAttribute(openingElement);
772
+ if (!existing) {
773
+ openingElement.attributes.push(
774
+ t.jsxAttribute(
775
+ t.jsxIdentifier("dataSet"),
776
+ t.jsxExpressionContainer(t.objectExpression(dataSetProps))
777
+ )
778
+ );
779
+ return;
780
+ }
781
+ if (existing.value?.type === "JSXExpressionContainer" && existing.value.expression.type !== "JSXEmptyExpression") {
782
+ existing.value.expression = t.objectExpression([
783
+ t.spreadElement(existing.value.expression),
784
+ ...dataSetProps
785
+ ]);
786
+ }
787
+ }
788
+ var ROOT_META_NAME = "tempo-project-root";
789
+ function injectProjectRootMeta(api, programPath, root) {
790
+ const setter = api.template.statement(`
791
+ if (typeof document !== "undefined") {
792
+ var __tempoRootMeta = document.querySelector('meta[name="${ROOT_META_NAME}"]');
793
+ if (!__tempoRootMeta) {
794
+ __tempoRootMeta = document.createElement("meta");
795
+ __tempoRootMeta.setAttribute("name", "${ROOT_META_NAME}");
796
+ document.head.appendChild(__tempoRootMeta);
797
+ }
798
+ __tempoRootMeta.setAttribute("content", ${JSON.stringify(root)});
799
+ }
800
+ `)();
801
+ programPath.pushContainer("body", setter);
802
+ }
803
+ function resolveBabelRoot(state, options, filename) {
804
+ return resolveCanonicalRoot(
805
+ resolve(
806
+ options.root ?? findNearestPackageRoot(filename) ?? state.cwd ?? state.file.opts.cwd ?? state.file.opts.root ?? process.cwd()
807
+ )
808
+ );
809
+ }
810
+ function findNearestPackageRoot(filename) {
811
+ let current = dirname(filename);
812
+ while (true) {
813
+ if (existsSync(resolve(current, "package.json"))) return current;
814
+ const parent = dirname(current);
815
+ if (parent === current) return null;
816
+ current = parent;
817
+ }
818
+ }
819
+ function resolveFilename(state) {
820
+ const filename = state.filename ?? state.file.opts.filename;
821
+ if (!filename) return null;
822
+ return resolve(cleanModuleId(filename));
823
+ }
824
+ function tempoExpoBabelPlugin(api, rawOptions = {}) {
825
+ api.assertVersion(7);
826
+ const enabled = rawOptions.enabled ?? !!process.env.TEMPO;
827
+ const include = rawOptions.include === void 0 ? EXPO_DEFAULT_INCLUDE : rawOptions.include;
828
+ const exclude = rawOptions.exclude === void 0 ? DEFAULT_EXCLUDE : rawOptions.exclude;
829
+ const filter = createFilter(include, exclude);
830
+ let typeAnalyzerRoot = null;
831
+ let typeAnalyzer = null;
832
+ return {
833
+ name: "tempo-expo-annotate",
834
+ manipulateOptions(opts, parserOpts) {
835
+ parserOpts.plugins ?? (parserOpts.plugins = []);
836
+ if (!hasParserPlugin(parserOpts.plugins, "jsx")) {
837
+ parserOpts.plugins.push("jsx");
838
+ }
839
+ const filename = opts.filename ?? "";
840
+ if (/\.(ts|tsx)$/.test(filename) && !hasParserPlugin(parserOpts.plugins, "typescript")) {
841
+ parserOpts.plugins.push("typescript");
842
+ }
843
+ },
844
+ visitor: {
845
+ Program: {
846
+ enter(path3, state) {
847
+ if (!enabled) return;
848
+ const options = { ...rawOptions, ...state.opts };
849
+ const filename = resolveFilename(state);
850
+ if (!filename || !filter(filename)) return;
851
+ const source = state.file.code;
852
+ const root = resolveBabelRoot(state, options, filename);
853
+ let context;
854
+ try {
855
+ context = getFileAnnotationContext({
856
+ source,
857
+ filename,
858
+ root,
859
+ canonicalizeFilename: true
860
+ });
861
+ } catch {
862
+ return;
863
+ }
864
+ if (context.filepath === "index.js") {
865
+ injectProjectRootMeta(api, path3, root);
866
+ }
867
+ if (options.typeSupport !== false && typeAnalyzerRoot !== root) {
868
+ typeAnalyzerRoot = root;
869
+ typeAnalyzer = createTypeAnalyzer(root);
870
+ }
871
+ const typeInfo = options.typeSupport === false ? null : typeAnalyzer?.analyzeFileTypes(context.cleanFilename, source);
872
+ const supportOverrides = getSupportOverrides(options);
873
+ path3.traverse({
874
+ JSXElement(elementPath) {
875
+ const element = elementPath.node;
876
+ const tagName = getBabelTagName(element.openingElement.name);
877
+ if (FRAGMENT_TAG_NAMES.has(tagName)) return;
878
+ const info = {
879
+ element,
880
+ tagName
881
+ };
882
+ const props = computeTempoAnnotatedProps({
883
+ info,
884
+ filepath: context.filepath,
885
+ modifiedtsMs: context.modifiedtsMs,
886
+ computeAnnotatedProps: options.computeAnnotatedProps,
887
+ typeInfo,
888
+ elementSupportOverrides: supportOverrides
889
+ });
890
+ addAnnotations(api, tagName, element.openingElement, props);
891
+ }
892
+ });
893
+ }
894
+ }
895
+ }
896
+ };
897
+ }
898
+
899
+ export {
900
+ tempoExpoBabelPlugin
901
+ };
902
+ //# sourceMappingURL=chunk-G7M57ARC.js.map