Skip to content

Commit

Permalink
fix: skip node for which definePageMeta does not exist (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
wattanx authored May 24, 2024
1 parent 61e7f46 commit 8d7c5f0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/bridge/src/page-meta/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export const PageMetaPlugin = createUnplugin(
}
})

if (!contents) {
return
}

s.prependLeft(exportDeclaration.start, contents)

if (code.includes('__nuxt_page_meta')) {
Expand Down
50 changes: 48 additions & 2 deletions packages/bridge/test/page-meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ import { defineComponent as _defineComponent } from 'vue';
export default /*#__PURE__*/_defineComponent({
__name: 'redirect',
setup: function setup(__props) {
const route = useRoute()
var route = useRoute()
definePageMeta({
middleware: ['redirect'],
layout: 'custom'
});
var obj = {
setup: {
test: 'test'
}
}
return {
__sfc: true
};
Expand All @@ -54,8 +60,14 @@ export default /*#__PURE__*/_defineComponent({
export default /*#__PURE__*/_defineComponent({
...__nuxt_page_meta,__name: 'redirect',
setup: function setup(__props) {
const route = useRoute()
var route = useRoute()
;
var obj = {
setup: {
test: 'test'
}
}
return {
__sfc: true
};
Expand All @@ -73,6 +85,12 @@ export default {
definePageMeta({
layout: 'custom'
});
var obj = {
setup: {
test: 'test'
}
}
return {
__sfc: true,
message: message
Expand All @@ -88,6 +106,12 @@ export default {
setup: function setup(__props) {
var message;
;
var obj = {
setup: {
test: 'test'
}
}
return {
__sfc: true,
message: message
Expand Down Expand Up @@ -141,6 +165,11 @@ const _sfc_main = /* @__PURE__ */ _defineComponent({
definePageMeta({
middleware: ["redirect"]
});
const obj = {
setup: {
test: "test"
}
}
return { __sfc: true };
}
});`)).toMatchInlineSnapshot(`
Expand All @@ -153,6 +182,11 @@ const _sfc_main = /* @__PURE__ */ _defineComponent({
...__nuxt_page_meta,__name: "redirect",
setup(__props) {
;
const obj = {
setup: {
test: "test"
}
}
return { __sfc: true };
}
});"
Expand All @@ -169,6 +203,12 @@ const _sfc_main = /* @__PURE__ */ _defineComponent({
definePageMeta({
layout: 'custom'
})
const obj = {
setup: {
test: 'test'
}
}
return { __sfc: true,message }
}
Expand All @@ -183,6 +223,12 @@ const _sfc_main = /* @__PURE__ */ _defineComponent({
let message
const obj = {
setup: {
test: 'test'
}
}
return { __sfc: true,message }
}
Expand Down

0 comments on commit 8d7c5f0

Please sign in to comment.