mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): extract all-literal page meta (#27821)
This commit is contained in:
parent
9d3b43a6c8
commit
d23c79f395
@ -256,13 +256,19 @@ export async function getRouteMeta (contents: string, absolutePath: string): Pro
|
||||
extractedMeta[key] = property.value.value
|
||||
}
|
||||
|
||||
const extraneousMetaKeys = pageMetaArgument.properties
|
||||
.filter(property => property.type === 'Property' && property.key.type === 'Identifier' && !(extractionKeys as unknown as string[]).includes(property.key.name))
|
||||
// @ts-expect-error inferred types have been filtered out
|
||||
.map(property => property.key.name)
|
||||
|
||||
if (extraneousMetaKeys.length) {
|
||||
dynamicProperties.add('meta')
|
||||
for (const property of pageMetaArgument.properties) {
|
||||
if (property.type !== 'Property') {
|
||||
continue
|
||||
}
|
||||
const isIdentifierOrLiteral = property.key.type === 'Literal' || property.key.type === 'Identifier'
|
||||
if (!isIdentifierOrLiteral) {
|
||||
continue
|
||||
}
|
||||
const name = property.key.type === 'Identifier' ? property.key.name : String(property.value)
|
||||
if (!(extractionKeys as unknown as string[]).includes(name)) {
|
||||
dynamicProperties.add('meta')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamicProperties.size) {
|
||||
|
@ -75,6 +75,28 @@ describe('page metadata', () => {
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('should extract serialisable metadata all quoted', async () => {
|
||||
const meta = await getRouteMeta(`
|
||||
<script setup>
|
||||
definePageMeta({
|
||||
"otherValue": {
|
||||
foo: 'bar',
|
||||
},
|
||||
})
|
||||
</script>
|
||||
`, filePath)
|
||||
|
||||
expect(meta).toMatchInlineSnapshot(`
|
||||
{
|
||||
"meta": {
|
||||
"__nuxt_dynamic_meta_key": Set {
|
||||
"meta",
|
||||
},
|
||||
},
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeRoutes', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user