tempo-sdk 0.0.12 → 0.0.13

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.
@@ -37,9 +37,9 @@ __export(nextjs_loader_exports, {
37
37
  nextjsLoader: () => nextjsLoader
38
38
  });
39
39
  module.exports = __toCommonJS(nextjs_loader_exports);
40
- var import_node_fs2 = require("fs");
40
+ var import_node_fs4 = require("fs");
41
41
  var import_node_module = require("module");
42
- var import_node_path2 = require("path");
42
+ var import_node_path4 = require("path");
43
43
 
44
44
  // ../../modules/annotation/annotate-file.ts
45
45
  var import_oxc_parser2 = require("oxc-parser");
@@ -211,6 +211,7 @@ function computeTempoAnnotatedProps(params) {
211
211
  filepath,
212
212
  modifiedtsMs,
213
213
  computeAnnotatedProps,
214
+ typeInfo,
214
215
  elementSupportOverrides
215
216
  } = params;
216
217
  const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
@@ -235,36 +236,594 @@ function computeTempoAnnotatedProps(params) {
235
236
  ) ? void 0 : override.supportsChildren
236
237
  };
237
238
  }
238
- return userProps;
239
+ const support = typeInfo?.get(info.element.openingElement.start);
240
+ return {
241
+ ...userProps,
242
+ "data-tempo-supports-style": support?.supportsStyle ?? false,
243
+ "data-tempo-supports-classname": support?.supportsClassName ?? false,
244
+ "data-tempo-supports-children": hasJsxAttribute(
245
+ info,
246
+ "data-tempo-supports-children"
247
+ ) ? void 0 : support?.supportsChildren ?? false
248
+ };
249
+ }
250
+
251
+ // type-analyzer.ts
252
+ var import_typescript2 = __toESM(require("typescript"), 1);
253
+ var import_node_path3 = __toESM(require("path"), 1);
254
+ var import_node_fs3 = require("fs");
255
+
256
+ // ../../modules/typescript/workspace-service.ts
257
+ var import_node_fs2 = require("fs");
258
+ var import_node_path2 = __toESM(require("path"), 1);
259
+ var import_typescript = __toESM(require("typescript"), 1);
260
+ function canonicalPath(input) {
261
+ const resolved = import_node_path2.default.resolve(input);
262
+ try {
263
+ return import_node_fs2.realpathSync.native(resolved);
264
+ } catch {
265
+ return resolved;
266
+ }
267
+ }
268
+ function compareProjectPriority(left, right) {
269
+ const depthDelta = right.rootDir.length - left.rootDir.length;
270
+ if (depthDelta !== 0) {
271
+ return depthDelta;
272
+ }
273
+ const priorityDelta = right.priority - left.priority;
274
+ if (priorityDelta !== 0) {
275
+ return priorityDelta;
276
+ }
277
+ return left.id.localeCompare(right.id);
278
+ }
279
+ function isWithinRoot(filePath, rootDir) {
280
+ return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path2.default.sep}`);
281
+ }
282
+ function loadProject(descriptor) {
283
+ const id = descriptor.id.trim();
284
+ if (!id) {
285
+ throw new Error("Project id must be a non-empty string");
286
+ }
287
+ const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
288
+ const rootDir = canonicalPath(descriptor.rootDir);
289
+ const readResult = import_typescript.default.readConfigFile(tsconfigPath, import_typescript.default.sys.readFile);
290
+ if (readResult.error) {
291
+ throw new Error(
292
+ `Failed to read tsconfig at ${tsconfigPath}: ${import_typescript.default.flattenDiagnosticMessageText(
293
+ readResult.error.messageText,
294
+ "\n"
295
+ )}`
296
+ );
297
+ }
298
+ const parsed = import_typescript.default.parseJsonConfigFileContent(
299
+ readResult.config,
300
+ import_typescript.default.sys,
301
+ import_node_path2.default.dirname(tsconfigPath)
302
+ );
303
+ if (parsed.errors.length > 0) {
304
+ const message = parsed.errors.map(
305
+ (diagnostic) => import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
306
+ ).join("; ");
307
+ throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
308
+ }
309
+ const normalizedFiles = parsed.fileNames.map(
310
+ (fileName) => canonicalPath(fileName)
311
+ );
312
+ return {
313
+ id,
314
+ rootDir,
315
+ tsconfigPath,
316
+ priority: descriptor.priority ?? 0,
317
+ options: parsed.options,
318
+ fileNames: normalizedFiles,
319
+ moduleResolutionCache: import_typescript.default.createModuleResolutionCache(
320
+ rootDir,
321
+ (value) => value,
322
+ parsed.options
323
+ )
324
+ };
325
+ }
326
+ function getFileMtimeVersion(filePath) {
327
+ try {
328
+ const stats = (0, import_node_fs2.statSync)(filePath);
329
+ return String(stats.mtimeMs);
330
+ } catch {
331
+ return "0";
332
+ }
333
+ }
334
+ function createTsWorkspaceService(descriptor) {
335
+ if (descriptor.projects.length === 0) {
336
+ throw new Error(
337
+ "TsWorkspaceDescriptor.projects must include at least one project"
338
+ );
339
+ }
340
+ const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
341
+ const loadedProjects = descriptor.projects.map(
342
+ (project) => loadProject(project)
343
+ );
344
+ const projectsById = /* @__PURE__ */ new Map();
345
+ for (const project of loadedProjects) {
346
+ if (projectsById.has(project.id)) {
347
+ throw new Error(`Duplicate project id: ${project.id}`);
348
+ }
349
+ projectsById.set(project.id, project);
350
+ }
351
+ const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
352
+ if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
353
+ throw new Error(
354
+ `Primary project id not found: ${descriptor.primaryProjectId}`
355
+ );
356
+ }
357
+ const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
358
+ const rootFileNames = /* @__PURE__ */ new Set();
359
+ for (const project of loadedProjects) {
360
+ for (const fileName of project.fileNames) {
361
+ rootFileNames.add(fileName);
362
+ }
363
+ }
364
+ const inMemoryFiles = /* @__PURE__ */ new Map();
365
+ let projectVersion = 0;
366
+ function getOwningProject(filePath) {
367
+ const canonicalFilePath = canonicalPath(filePath);
368
+ for (const project of orderedProjects) {
369
+ if (isWithinRoot(canonicalFilePath, project.rootDir)) {
370
+ return project;
371
+ }
372
+ }
373
+ return primaryProject;
374
+ }
375
+ const moduleResolutionHost = {
376
+ fileExists: import_typescript.default.sys.fileExists,
377
+ readFile: import_typescript.default.sys.readFile,
378
+ realpath: import_typescript.default.sys.realpath,
379
+ directoryExists: import_typescript.default.sys.directoryExists,
380
+ getCurrentDirectory: () => workspaceRoot,
381
+ getDirectories: import_typescript.default.sys.getDirectories
382
+ };
383
+ const host = {
384
+ getScriptFileNames: () => Array.from(rootFileNames),
385
+ getScriptVersion: (filePath) => {
386
+ const canonicalFilePath = canonicalPath(filePath);
387
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
388
+ if (inMemory) {
389
+ return String(inMemory.version);
390
+ }
391
+ return getFileMtimeVersion(canonicalFilePath);
392
+ },
393
+ getScriptSnapshot: (filePath) => {
394
+ const canonicalFilePath = canonicalPath(filePath);
395
+ const inMemory = inMemoryFiles.get(canonicalFilePath);
396
+ if (inMemory) {
397
+ return import_typescript.default.ScriptSnapshot.fromString(inMemory.content);
398
+ }
399
+ const diskContent = import_typescript.default.sys.readFile(canonicalFilePath);
400
+ if (diskContent === void 0) {
401
+ return void 0;
402
+ }
403
+ return import_typescript.default.ScriptSnapshot.fromString(diskContent);
404
+ },
405
+ getCurrentDirectory: () => workspaceRoot,
406
+ getCompilationSettings: () => primaryProject.options,
407
+ getDefaultLibFileName: (options) => import_typescript.default.getDefaultLibFilePath(options),
408
+ fileExists: import_typescript.default.sys.fileExists,
409
+ readFile: import_typescript.default.sys.readFile,
410
+ readDirectory: import_typescript.default.sys.readDirectory,
411
+ directoryExists: import_typescript.default.sys.directoryExists,
412
+ getDirectories: import_typescript.default.sys.getDirectories,
413
+ useCaseSensitiveFileNames: () => import_typescript.default.sys.useCaseSensitiveFileNames,
414
+ getProjectVersion: () => String(projectVersion),
415
+ resolveModuleNames: (moduleNames, containingFile) => {
416
+ const owningProject = getOwningProject(containingFile);
417
+ return moduleNames.map((moduleName) => {
418
+ const ownerResolution = import_typescript.default.resolveModuleName(
419
+ moduleName,
420
+ containingFile,
421
+ owningProject.options,
422
+ moduleResolutionHost,
423
+ owningProject.moduleResolutionCache
424
+ ).resolvedModule;
425
+ if (ownerResolution) {
426
+ return ownerResolution;
427
+ }
428
+ if (owningProject.id === primaryProject.id) {
429
+ return void 0;
430
+ }
431
+ return import_typescript.default.resolveModuleName(
432
+ moduleName,
433
+ containingFile,
434
+ primaryProject.options,
435
+ moduleResolutionHost,
436
+ primaryProject.moduleResolutionCache
437
+ ).resolvedModule;
438
+ });
439
+ }
440
+ };
441
+ const languageService = import_typescript.default.createLanguageService(
442
+ host,
443
+ import_typescript.default.createDocumentRegistry()
444
+ );
445
+ return {
446
+ updateFile(filePath, content) {
447
+ const canonicalFilePath = canonicalPath(filePath);
448
+ const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
449
+ inMemoryFiles.set(canonicalFilePath, {
450
+ version: currentVersion + 1,
451
+ content
452
+ });
453
+ if (!rootFileNames.has(canonicalFilePath)) {
454
+ rootFileNames.add(canonicalFilePath);
455
+ }
456
+ projectVersion += 1;
457
+ },
458
+ closeFile(filePath) {
459
+ const canonicalFilePath = canonicalPath(filePath);
460
+ inMemoryFiles.delete(canonicalFilePath);
461
+ projectVersion += 1;
462
+ },
463
+ getProgram() {
464
+ return languageService.getProgram() ?? null;
465
+ },
466
+ getSemanticDiagnostics(filePath) {
467
+ const canonicalFilePath = canonicalPath(filePath);
468
+ return languageService.getSemanticDiagnostics(canonicalFilePath);
469
+ },
470
+ getDefinition(filePath, position) {
471
+ const canonicalFilePath = canonicalPath(filePath);
472
+ return languageService.getDefinitionAtPosition(
473
+ canonicalFilePath,
474
+ position
475
+ );
476
+ },
477
+ dispose() {
478
+ languageService.dispose();
479
+ }
480
+ };
481
+ }
482
+
483
+ // type-analyzer.ts
484
+ function isCustomComponent(node) {
485
+ const text = node.getText();
486
+ return text.length > 0 && text[0] !== text[0].toLowerCase();
487
+ }
488
+ function canonicalPath2(value) {
489
+ const resolved = import_node_path3.default.resolve(value);
490
+ try {
491
+ return import_node_fs3.realpathSync.native(resolved);
492
+ } catch {
493
+ return resolved;
494
+ }
495
+ }
496
+ function parseManagedTsconfigPaths(rawConfig) {
497
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
498
+ return [];
499
+ }
500
+ const metadata = rawConfig.tempobook;
501
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
502
+ return [];
503
+ }
504
+ const managedPaths = metadata.managedTsconfigPaths;
505
+ if (!Array.isArray(managedPaths)) {
506
+ return [];
507
+ }
508
+ return managedPaths.filter(
509
+ (entry) => typeof entry === "string" && entry.trim().length > 0
510
+ );
511
+ }
512
+ function parseProjectReferenceTsconfigPaths(references, configDir) {
513
+ if (!references || references.length === 0) {
514
+ return [];
515
+ }
516
+ const entries = [];
517
+ for (const reference of references) {
518
+ const referencePath = reference.path;
519
+ if (!referencePath) {
520
+ continue;
521
+ }
522
+ const resolvedPath = import_node_path3.default.resolve(configDir, referencePath);
523
+ const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path3.default.join(resolvedPath, "tsconfig.json");
524
+ entries.push(tsconfigPath);
525
+ }
526
+ return entries;
527
+ }
528
+ function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
529
+ const configDir = import_node_path3.default.dirname(configPath);
530
+ const projects = [
531
+ {
532
+ id: "root",
533
+ rootDir: root,
534
+ tsconfigPath: configPath,
535
+ priority: 0
536
+ }
537
+ ];
538
+ const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
539
+ const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
540
+ parsedConfig.projectReferences,
541
+ configDir
542
+ );
543
+ const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
544
+ (entry) => import_node_path3.default.resolve(configDir, entry)
545
+ );
546
+ const candidateTsconfigPaths = [
547
+ ...managedTsconfigPaths,
548
+ ...referencedTsconfigPaths
549
+ ];
550
+ for (const candidatePath of candidateTsconfigPaths) {
551
+ const normalizedPath = canonicalPath2(candidatePath);
552
+ if (seenTsconfigPaths.has(normalizedPath)) {
553
+ continue;
554
+ }
555
+ if (!import_typescript2.default.sys.fileExists(normalizedPath)) {
556
+ continue;
557
+ }
558
+ seenTsconfigPaths.add(normalizedPath);
559
+ projects.push({
560
+ id: `external-${projects.length}`,
561
+ rootDir: import_node_path3.default.dirname(normalizedPath),
562
+ tsconfigPath: normalizedPath,
563
+ priority: 0
564
+ });
565
+ }
566
+ return projects;
567
+ }
568
+ function createTypeAnalyzer(root) {
569
+ const configPath = import_typescript2.default.findConfigFile(
570
+ root,
571
+ import_typescript2.default.sys.fileExists,
572
+ "tsconfig.json"
573
+ );
574
+ if (!configPath) return null;
575
+ const configFile = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
576
+ if (configFile.error) return null;
577
+ const parsedConfig = import_typescript2.default.parseJsonConfigFileContent(
578
+ configFile.config,
579
+ import_typescript2.default.sys,
580
+ root
581
+ );
582
+ const workspaceProjects = buildWorkspaceProjects(
583
+ root,
584
+ configPath,
585
+ parsedConfig,
586
+ configFile.config
587
+ );
588
+ const workspaceProjectRoots = workspaceProjects.map(
589
+ (project) => canonicalPath2(project.rootDir)
590
+ );
591
+ const workspaceService = createTsWorkspaceService({
592
+ workspaceRoot: root,
593
+ primaryProjectId: "root",
594
+ projects: workspaceProjects
595
+ });
596
+ let cssPropertiesType;
597
+ function resolveCSSPropertiesType(checker, sourceFile) {
598
+ if (cssPropertiesType !== void 0) return cssPropertiesType;
599
+ try {
600
+ let jsxNs = checker.resolveName(
601
+ "JSX",
602
+ sourceFile,
603
+ import_typescript2.default.SymbolFlags.Namespace,
604
+ false
605
+ );
606
+ if (!jsxNs) {
607
+ const program = workspaceService.getProgram();
608
+ const compilerOptions = program?.getCompilerOptions();
609
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
610
+ const resolved = import_typescript2.default.resolveModuleName(
611
+ `${jsxImportSource}/jsx-runtime`,
612
+ sourceFile.fileName,
613
+ compilerOptions,
614
+ import_typescript2.default.sys
615
+ );
616
+ if (resolved.resolvedModule) {
617
+ const runtimeFile = program?.getSourceFile(
618
+ resolved.resolvedModule.resolvedFileName
619
+ );
620
+ if (runtimeFile) {
621
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
622
+ if (runtimeSymbol) {
623
+ const exports2 = checker.getExportsOfModule(runtimeSymbol);
624
+ jsxNs = exports2.find((s) => s.name === "JSX");
625
+ }
626
+ }
627
+ }
628
+ }
629
+ if (!jsxNs) {
630
+ cssPropertiesType = null;
631
+ return null;
632
+ }
633
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
634
+ if (!intrinsicSym) {
635
+ cssPropertiesType = null;
636
+ return null;
637
+ }
638
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
639
+ if (!divSym) {
640
+ cssPropertiesType = null;
641
+ return null;
642
+ }
643
+ const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
644
+ if (!styleSym) {
645
+ cssPropertiesType = null;
646
+ return null;
647
+ }
648
+ const styleType = checker.getTypeOfSymbol(styleSym);
649
+ if (styleType.isUnion()) {
650
+ const nonUndefined = styleType.types.find(
651
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
652
+ );
653
+ cssPropertiesType = nonUndefined ?? null;
654
+ } else {
655
+ cssPropertiesType = styleType;
656
+ }
657
+ } catch {
658
+ cssPropertiesType = null;
659
+ }
660
+ return cssPropertiesType;
661
+ }
662
+ let reactNodeType;
663
+ function resolveReactNodeType(checker, sourceFile) {
664
+ if (reactNodeType !== void 0) return reactNodeType;
665
+ try {
666
+ let jsxNs = checker.resolveName(
667
+ "JSX",
668
+ sourceFile,
669
+ import_typescript2.default.SymbolFlags.Namespace,
670
+ false
671
+ );
672
+ if (!jsxNs) {
673
+ const program = workspaceService.getProgram();
674
+ const compilerOptions = program?.getCompilerOptions();
675
+ const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
676
+ const resolved = import_typescript2.default.resolveModuleName(
677
+ `${jsxImportSource}/jsx-runtime`,
678
+ sourceFile.fileName,
679
+ compilerOptions,
680
+ import_typescript2.default.sys
681
+ );
682
+ if (resolved.resolvedModule) {
683
+ const runtimeFile = program?.getSourceFile(
684
+ resolved.resolvedModule.resolvedFileName
685
+ );
686
+ if (runtimeFile) {
687
+ const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
688
+ if (runtimeSymbol) {
689
+ const exports2 = checker.getExportsOfModule(runtimeSymbol);
690
+ jsxNs = exports2.find((s) => s.name === "JSX");
691
+ }
692
+ }
693
+ }
694
+ }
695
+ if (!jsxNs) {
696
+ reactNodeType = null;
697
+ return null;
698
+ }
699
+ const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
700
+ if (!intrinsicSym) {
701
+ reactNodeType = null;
702
+ return null;
703
+ }
704
+ const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
705
+ if (!divSym) {
706
+ reactNodeType = null;
707
+ return null;
708
+ }
709
+ const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
710
+ if (!childrenSym) {
711
+ reactNodeType = null;
712
+ return null;
713
+ }
714
+ const childrenType = checker.getTypeOfSymbol(childrenSym);
715
+ if (childrenType.isUnion()) {
716
+ const nonUndefined = childrenType.types.find(
717
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
718
+ );
719
+ reactNodeType = nonUndefined ?? null;
720
+ } else {
721
+ reactNodeType = childrenType;
722
+ }
723
+ } catch {
724
+ reactNodeType = null;
725
+ }
726
+ return reactNodeType;
727
+ }
728
+ return {
729
+ analyzeFileTypes(filePath, source) {
730
+ const canonicalFilePath = canonicalPath2(filePath);
731
+ const belongsToWorkspace = workspaceProjectRoots.some(
732
+ (projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path3.default.sep}`)
733
+ );
734
+ if (!belongsToWorkspace) {
735
+ return null;
736
+ }
737
+ workspaceService.updateFile(filePath, source);
738
+ const program = workspaceService.getProgram();
739
+ if (!program) return null;
740
+ const sourceFile = program.getSourceFile(filePath);
741
+ if (!sourceFile) return null;
742
+ const checker = program.getTypeChecker();
743
+ const cssProps = resolveCSSPropertiesType(checker, sourceFile);
744
+ const result = /* @__PURE__ */ new Map();
745
+ function visit(node) {
746
+ if ((import_typescript2.default.isJsxOpeningElement(node) || import_typescript2.default.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
747
+ const position = node.getStart(sourceFile);
748
+ const attrsType = checker.getContextualType(node.attributes);
749
+ let supportsStyle = false;
750
+ let supportsClassName = false;
751
+ let supportsChildren = false;
752
+ if (attrsType) {
753
+ const classNameProp = attrsType.getProperty("className");
754
+ if (classNameProp) {
755
+ const propType = checker.getTypeOfSymbol(classNameProp);
756
+ supportsClassName = checker.isTypeAssignableTo(
757
+ checker.getStringType(),
758
+ propType
759
+ );
760
+ }
761
+ const styleProp = attrsType.getProperty("style");
762
+ if (styleProp && cssProps) {
763
+ let propType = checker.getTypeOfSymbol(styleProp);
764
+ if (propType.isUnion()) {
765
+ const nonUndefined = propType.types.find(
766
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
767
+ );
768
+ if (nonUndefined) propType = nonUndefined;
769
+ }
770
+ supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
771
+ }
772
+ const reactNode = resolveReactNodeType(checker, sourceFile);
773
+ const childrenProp = attrsType.getProperty("children");
774
+ if (childrenProp && reactNode) {
775
+ let propType = checker.getTypeOfSymbol(childrenProp);
776
+ if (propType.isUnion()) {
777
+ const nonUndefined = propType.types.find(
778
+ (t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
779
+ );
780
+ if (nonUndefined) propType = nonUndefined;
781
+ }
782
+ supportsChildren = checker.isTypeAssignableTo(
783
+ reactNode,
784
+ propType
785
+ );
786
+ }
787
+ }
788
+ result.set(position, { supportsStyle, supportsClassName, supportsChildren });
789
+ }
790
+ import_typescript2.default.forEachChild(node, visit);
791
+ }
792
+ visit(sourceFile);
793
+ return result;
794
+ }
795
+ };
239
796
  }
240
797
 
241
798
  // nextjs-loader.ts
242
799
  var ROOT_META_NAME = "tempo-project-root";
243
800
  var cachedCanonicalRoot = null;
801
+ var cachedTypeAnalyzer = null;
244
802
  var cachedUserComputeProps;
245
803
  var cachedComputeModulePath = null;
246
804
  function _resetLoaderState() {
247
805
  cachedCanonicalRoot = null;
806
+ cachedTypeAnalyzer = null;
248
807
  cachedUserComputeProps = void 0;
249
808
  cachedComputeModulePath = null;
250
809
  }
251
- function stripQueryAndHash(path) {
252
- const queryIdx = path.indexOf("?");
253
- const hashIdx = path.indexOf("#");
254
- let end = path.length;
810
+ function stripQueryAndHash(path3) {
811
+ const queryIdx = path3.indexOf("?");
812
+ const hashIdx = path3.indexOf("#");
813
+ let end = path3.length;
255
814
  if (queryIdx !== -1) end = Math.min(end, queryIdx);
256
815
  if (hashIdx !== -1) end = Math.min(end, hashIdx);
257
- return path.slice(0, end);
816
+ return path3.slice(0, end);
258
817
  }
259
818
  function resolveCanonicalRoot(rootContext) {
260
819
  try {
261
- return import_node_fs2.realpathSync.native(rootContext);
820
+ return import_node_fs4.realpathSync.native(rootContext);
262
821
  } catch {
263
822
  return rootContext;
264
823
  }
265
824
  }
266
- function isInNodeModules(path) {
267
- return path.includes(`${import_node_path2.sep}node_modules${import_node_path2.sep}`);
825
+ function isInNodeModules(path3) {
826
+ return path3.includes(`${import_node_path4.sep}node_modules${import_node_path4.sep}`);
268
827
  }
269
828
  function findFirstJSXElement(program, tagName) {
270
829
  let result = null;
@@ -332,7 +891,7 @@ function injectRootMetaIntoAnnotatedSource(annotatedSource, filename, root) {
332
891
  return injectRootMetaIntoSource(annotatedSource, filename, root);
333
892
  }
334
893
  function loadUserComputeProps(modulePath, canonicalRoot) {
335
- const resolved = (0, import_node_path2.resolve)(canonicalRoot, modulePath);
894
+ const resolved = (0, import_node_path4.resolve)(canonicalRoot, modulePath);
336
895
  const requireFromRoot = (0, import_node_module.createRequire)(`${canonicalRoot}/__tempo_loader__.js`);
337
896
  const mod = requireFromRoot(resolved);
338
897
  const fn = mod && (mod.default ?? mod);
@@ -362,6 +921,13 @@ function nextjsLoader(source) {
362
921
  cachedCanonicalRoot = resolveCanonicalRoot(this.rootContext);
363
922
  }
364
923
  const canonicalRoot = cachedCanonicalRoot;
924
+ if (cachedTypeAnalyzer === null) {
925
+ try {
926
+ cachedTypeAnalyzer = createTypeAnalyzer(canonicalRoot);
927
+ } catch {
928
+ cachedTypeAnalyzer = { analyzeFileTypes: () => null };
929
+ }
930
+ }
365
931
  const userModule = options.computeAnnotatedPropsModule;
366
932
  if (userModule && userModule !== cachedComputeModulePath) {
367
933
  try {
@@ -374,8 +940,12 @@ function nextjsLoader(source) {
374
940
  cachedUserComputeProps = null;
375
941
  }
376
942
  const userComputeProps = cachedUserComputeProps;
377
- const filepath = (0, import_node_path2.relative)(canonicalRoot, cleanPath);
378
- const modifiedtsMs = Math.trunc((0, import_node_fs2.statSync)(cleanPath).mtimeMs);
943
+ const filepath = (0, import_node_path4.relative)(canonicalRoot, cleanPath);
944
+ const modifiedtsMs = Math.trunc((0, import_node_fs4.statSync)(cleanPath).mtimeMs);
945
+ const typeInfo = cachedTypeAnalyzer?.analyzeFileTypes(
946
+ cleanPath,
947
+ source
948
+ ) ?? null;
379
949
  const annotated = annotateFile(
380
950
  source,
381
951
  cleanPath,
@@ -383,7 +953,8 @@ function nextjsLoader(source) {
383
953
  info,
384
954
  filepath,
385
955
  modifiedtsMs,
386
- computeAnnotatedProps: userComputeProps ?? void 0
956
+ computeAnnotatedProps: userComputeProps ?? void 0,
957
+ typeInfo
387
958
  })
388
959
  );
389
960
  let finalSource = annotated.annotatedSource;