fix(nuxt): use tsx loader for jsx blocks as well (#31014)

This commit is contained in:
Ryota Watanabe 2025-02-18 03:14:12 +09:00 committed by GitHub
parent 0f0a822208
commit b0729241bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -192,7 +192,7 @@ export function extractScriptContent (sfc: string) {
for (const match of sfc.matchAll(SFC_SCRIPT_RE)) {
if (match?.groups?.content) {
contents.push({
loader: match.groups.attrs?.includes('tsx') ? 'tsx' : 'ts',
loader: match.groups.attrs && /[tj]sx/.test(match.groups.attrs) ? 'tsx' : 'ts',
code: match.groups.content.trim(),
})
}

View File

@ -42,6 +42,19 @@ export default {
})
})
it('should parse lang="jsx" from vue files', async () => {
const fileContents = `
<script setup lang="jsx">
const foo = <></>;
definePageMeta({ name: 'bar' })
</script>`
const meta = await getRouteMeta(fileContents, `/app/pages/index.vue`)
expect(meta).toStrictEqual({
name: 'bar',
})
})
// TODO: https://github.com/nuxt/nuxt/pull/30066
it.todo('should handle experimental decorators', async () => {
const fileContents = `