mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +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
|
extractedMeta[key] = property.value.value
|
||||||
}
|
}
|
||||||
|
|
||||||
const extraneousMetaKeys = pageMetaArgument.properties
|
for (const property of pageMetaArgument.properties) {
|
||||||
.filter(property => property.type === 'Property' && property.key.type === 'Identifier' && !(extractionKeys as unknown as string[]).includes(property.key.name))
|
if (property.type !== 'Property') {
|
||||||
// @ts-expect-error inferred types have been filtered out
|
continue
|
||||||
.map(property => property.key.name)
|
}
|
||||||
|
const isIdentifierOrLiteral = property.key.type === 'Literal' || property.key.type === 'Identifier'
|
||||||
if (extraneousMetaKeys.length) {
|
if (!isIdentifierOrLiteral) {
|
||||||
dynamicProperties.add('meta')
|
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) {
|
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', () => {
|
describe('normalizeRoutes', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user