tempo-sdk 0.0.7 → 0.0.9

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