MCPcopy
hub / github.com/vitejs/vite / getModifiedOxcTransformOptions

Function getModifiedOxcTransformOptions

packages/vite/src/node/plugins/oxc.ts:234–271  ·  view source on GitHub ↗
(
    oxcTransformOptions: OxcTransformOptions,
    id: string,
    code: string,
    environment: Environment,
  )

Source from the content-addressed store, hash-verified

232 const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`
233
234 const getModifiedOxcTransformOptions = (
235 oxcTransformOptions: OxcTransformOptions,
236 id: string,
237 code: string,
238 environment: Environment,
239 ): OxcTransformOptions => {
240 const result: OxcTransformOptions = {
241 ...oxcTransformOptions,
242 sourcemap:
243 environment.mode !== 'build' || !!environment.config.build.sourcemap,
244 }
245
246 const jsxOptions = result.jsx
247
248 // disable refresh based by the same condition as @vitejs/plugin-react
249 // https://github.com/vitejs/vite-plugin-react/blob/c8ecad052001b6fc42e508f18433e6b305bca641/packages/plugin-react/src/index.ts#L261-L269
250 const [filepath] = id.split('?')
251 const isJSX = filepath.endsWith('x')
252
253 if (
254 typeof jsxOptions === 'object' &&
255 jsxOptions.refresh &&
256 (environment.config.consumer === 'server' ||
257 (jsxRefreshFilter && !jsxRefreshFilter(id)) ||
258 !(
259 isJSX ||
260 code.includes(jsxImportRuntime) ||
261 code.includes(jsxImportDevRuntime)
262 ))
263 ) {
264 result.jsx = { ...jsxOptions, refresh: false }
265 }
266 if (jsxRefreshFilter?.(id) && !JS_TYPES_RE.test(cleanUrl(id))) {
267 result.lang = 'js'
268 }
269
270 return result
271 }
272
273 let server: ViteDevServer
274

Callers 1

transformFunction · 0.85

Calls 1

cleanUrlFunction · 0.90

Tested by

no test coverage detected