Skip to content

Commit fcb6f12

Browse files
authored
fix: don't treat modules ending with js-like query as js (#23687)
1 parent 8579189 commit fcb6f12

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎packages/vite/src/node/__tests__/plugins/oxc.spec.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
import path from 'node:path'
22
import { describe, expect, test } from 'vitest'
3+
import { PartialEnvironment } from '../../baseEnvironment'
34
import { resolveConfig } from '../../config'
4-
import { transformWithOxc } from '../../plugins/oxc'
5+
import { oxcPlugin, transformWithOxc } from '../../plugins/oxc'
6+
7+
describe('oxcPlugin', () => {
8+
test('preserves the language of modules with extensions in queries', async () => {
9+
const config = await resolveConfig(
10+
{
11+
configFile: false,
12+
oxc: { jsxRefreshInclude: /\.tsx$/ },
13+
},
14+
'serve',
15+
)
16+
const plugin = oxcPlugin(config)
17+
const environment = new PartialEnvironment('client', config)
18+
const transform = plugin.transform as any
19+
const result = await transform.call(
20+
{ environment },
21+
'const value: string = "hello"',
22+
'/project/App.vue?vue&type=script&setup=true&lang.tsx',
23+
)
24+
25+
expect(result.code).toMatchInlineSnapshot(`
26+
"const value = "hello";
27+
"
28+
`)
29+
})
30+
})
531

632
describe('transformWithOxc', () => {
733
test('correctly overrides TS configuration and applies automatic transform', async () => {

‎packages/vite/src/node/plugins/oxc.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
265265
) {
266266
result.jsx = { ...jsxOptions, refresh: false }
267267
}
268-
if (jsxRefreshFilter?.(id) && !JS_TYPES_RE.test(cleanUrl(id))) {
268+
if (
269+
jsxRefreshFilter?.(id) &&
270+
!JS_TYPES_RE.test(id) &&
271+
!JS_TYPES_RE.test(cleanUrl(id))
272+
) {
269273
result.lang = 'js'
270274
}
271275

0 commit comments

Comments
 (0)