moduleFile

tcmts.loader.moduleFile · #jdw4h5b6 · term · runs anywhere

A component's module: .tsx when it uses JSX (TypeScript only parses JSX there), .ts otherwise. Its first JSX member's runtime is named in a pragma, so every compiler (tcm's module hook, Vite, the type checker) compiles the elements to the pinned version.

import type { DefSource } from "#codebase/tcmts/loader";

export function moduleFile(componentHash: string, src: Pick<DefSource, "members">): string {
  return `${componentHash}${src.members(componentHash).some((m) => m.jsx) ? ".tsx" : ".ts"}`;
}

uses

used by