Home / Function/ transformWithOxc() — vite Function Reference

transformWithOxc() — vite Function Reference

Architecture documentation for the transformWithOxc() function in oxc.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  047aa0d5_25bc_9eb0_8c41_99a2be202642["transformWithOxc()"]
  16dc8750_0d4e_ed3e_3844_b80096ed2e0b["oxc.ts"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|defined in| 16dc8750_0d4e_ed3e_3844_b80096ed2e0b
  60451d3e_8c58_53f5_26c6_c17035d9a884["extractExportsData()"]
  60451d3e_8c58_53f5_26c6_c17035d9a884 -->|calls| 047aa0d5_25bc_9eb0_8c41_99a2be202642
  d06e795b_d030_62c2_8aca_d422635f9891["oxcPlugin()"]
  d06e795b_d030_62c2_8aca_d422635f9891 -->|calls| 047aa0d5_25bc_9eb0_8c41_99a2be202642
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  bf7f9c91_a198_bc30_3101_285b2049912d["loadTsconfigJsonForFile()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| bf7f9c91_a198_bc30_3101_285b2049912d
  0a6fbb70_77d3_9873_8417_b1e4ffba2651["ensureWatchedFile()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| 0a6fbb70_77d3_9873_8417_b1e4ffba2651
  c8312997_27e4_3bcf_c2e8_f08d25fffcbe["setOxcTransformOptionsFromTsconfigOptions()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| c8312997_27e4_3bcf_c2e8_f08d25fffcbe
  310ed049_c1b4_c917_b399_81bab290e5a2["generateCodeFrame()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| 310ed049_c1b4_c917_b399_81bab290e5a2
  cb1210e8_03e9_2eec_ef04_aa15d44d4c08["combineSourcemaps()"]
  047aa0d5_25bc_9eb0_8c41_99a2be202642 -->|calls| cb1210e8_03e9_2eec_ef04_aa15d44d4c08
  style 047aa0d5_25bc_9eb0_8c41_99a2be202642 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/oxc.ts lines 215–310

export async function transformWithOxc(
  code: string,
  filename: string,
  options?: OxcTransformOptions,
  inMap?: object,
  config?: ResolvedConfig,
  watcher?: FSWatcher,
): Promise<Omit<OxcTransformResult, 'errors'> & { warnings: string[] }> {
  const warnings: string[] = []
  let lang = options?.lang

  if (!lang) {
    // if the id ends with a valid ext, use it (e.g. vue blocks)
    // otherwise, cleanup the query before checking the ext
    const ext = path
      .extname(validExtensionRE.test(filename) ? filename : cleanUrl(filename))
      .slice(1)

    if (ext === 'cjs' || ext === 'mjs') {
      lang = 'js'
    } else if (ext === 'cts' || ext === 'mts') {
      lang = 'ts'
    } else {
      lang = ext as 'js' | 'jsx' | 'ts' | 'tsx'
    }
  }

  const resolvedOptions = {
    sourcemap: true,
    ...options,
    lang,
  }

  if (lang === 'ts' || lang === 'tsx') {
    try {
      const { tsconfig: loadedTsconfig, tsconfigFile } =
        await loadTsconfigJsonForFile(filename, config)
      // tsconfig could be out of root, make sure it is watched on dev
      if (watcher && tsconfigFile && config) {
        ensureWatchedFile(watcher, tsconfigFile, config.root)
      }
      setOxcTransformOptionsFromTsconfigOptions(
        resolvedOptions,
        loadedTsconfig.compilerOptions,
        warnings,
      )
    } catch (e) {
      if (e instanceof TSConfckParseError) {
        // tsconfig could be out of root, make sure it is watched on dev
        if (watcher && e.tsconfigFile && config) {
          ensureWatchedFile(watcher, e.tsconfigFile, config.root)
        }
      }
      throw e
    }
  }

  const result = transformSync(filename, code, resolvedOptions)

  if (result.errors.length > 0) {
    const firstError = result.errors[0]
    const error: RollupError = new Error(firstError.message)
    let frame = ''
    frame += firstError.labels
      .map(
        (l) =>
          (l.message ? `${l.message}\n` : '') +
          generateCodeFrame(code, l.start, l.end),
      )
      .join('\n')
    if (firstError.helpMessage) {
      frame += '\n' + firstError.helpMessage
    }
    error.frame = frame
    error.pos =
      firstError.labels.length > 0 ? firstError.labels[0].start : undefined
    throw error
  }

  let map: SourceMap
  if (inMap && result.map) {

Domain

Subdomains

Frequently Asked Questions

What does transformWithOxc() do?
transformWithOxc() is a function in the vite codebase, defined in packages/vite/src/node/plugins/oxc.ts.
Where is transformWithOxc() defined?
transformWithOxc() is defined in packages/vite/src/node/plugins/oxc.ts at line 215.
What does transformWithOxc() call?
transformWithOxc() calls 6 function(s): cleanUrl, combineSourcemaps, ensureWatchedFile, generateCodeFrame, loadTsconfigJsonForFile, setOxcTransformOptionsFromTsconfigOptions.
What calls transformWithOxc()?
transformWithOxc() is called by 2 function(s): extractExportsData, oxcPlugin.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free