Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/vite/src/node/__tests__/plugins/oxc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { PartialEnvironment } from '../../baseEnvironment'
import { resolveConfig } from '../../config'
import { transformWithOxc } from '../../plugins/oxc'
import { oxcPlugin, transformWithOxc } from '../../plugins/oxc'

describe('oxcPlugin', () => {
test('preserves the language of modules with extensions in queries', async () => {
const config = await resolveConfig(
{
configFile: false,
oxc: { jsxRefreshInclude: /\.tsx$/ },
},
'serve',
)
const plugin = oxcPlugin(config)
const environment = new PartialEnvironment('client', config)
const transform = plugin.transform as any
const result = await transform.call(
{ environment },
'const value: string = "hello"',
'/project/App.vue?vue&type=script&setup=true&lang.tsx',
)

expect(result.code).toMatchInlineSnapshot(`
"const value = "hello";
"
`)
})
})

describe('transformWithOxc', () => {
test('correctly overrides TS configuration and applies automatic transform', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
) {
result.jsx = { ...jsxOptions, refresh: false }
}
if (jsxRefreshFilter?.(id) && !JS_TYPES_RE.test(cleanUrl(id))) {
if (
jsxRefreshFilter?.(id) &&
!JS_TYPES_RE.test(id) &&
!JS_TYPES_RE.test(cleanUrl(id))
) {
result.lang = 'js'
}

Expand Down
Loading