mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt): use original escapes/quotes in page re-exports (#23191)
This commit is contained in:
parent
16e40f899e
commit
e729406805
@ -65,8 +65,10 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) =>
|
||||
// [vite] Re-export any script imports
|
||||
const scriptImport = imports.find(i => parseMacroQuery(i.specifier).type === 'script')
|
||||
if (scriptImport) {
|
||||
const specifier = rewriteQuery(scriptImport.specifier)
|
||||
s.overwrite(0, code.length, `export { default } from ${JSON.stringify(specifier)}`)
|
||||
const reorderedQuery = rewriteQuery(scriptImport.specifier)
|
||||
// Avoid using JSON.stringify which can add extra escapes to paths with non-ASCII characters
|
||||
const quotedSpecifier = getQuotedSpecifier(scriptImport.code)?.replace(scriptImport.specifier, reorderedQuery) ?? JSON.stringify(reorderedQuery)
|
||||
s.overwrite(0, code.length, `export { default } from ${quotedSpecifier}`)
|
||||
return result()
|
||||
}
|
||||
|
||||
@ -77,8 +79,10 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) =>
|
||||
continue
|
||||
}
|
||||
|
||||
const specifier = rewriteQuery(match.specifier)
|
||||
s.overwrite(0, code.length, `export { default } from ${JSON.stringify(specifier)}`)
|
||||
const reorderedQuery = rewriteQuery(match.specifier)
|
||||
// Avoid using JSON.stringify which can add extra escapes to paths with non-ASCII characters
|
||||
const quotedSpecifier = getQuotedSpecifier(match.code)?.replace(match.specifier, reorderedQuery) ?? JSON.stringify(reorderedQuery)
|
||||
s.overwrite(0, code.length, `export { default } from ${quotedSpecifier}`)
|
||||
return result()
|
||||
}
|
||||
|
||||
@ -183,3 +187,7 @@ function parseMacroQuery (id: string) {
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
function getQuotedSpecifier (id: string) {
|
||||
return id.match(/(["']).*\1/)?.[0]
|
||||
}
|
||||
|
8
test/fixtures/basic/pages/non-ascii/ç.vue
vendored
Normal file
8
test/fixtures/basic/pages/non-ascii/ç.vue
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- -->
|
||||
</div>
|
||||
</template>
|
Loading…
Reference in New Issue
Block a user