Quotation marks can't be used within `definePageMeta` comments
Environment
- Operating System:
Linux - Node Version:
v16.14.2 - Nuxt Version:
3.0.0-rc.6 - Package Manager:
[email protected] - Builder:
vite - User Config:
- - Runtime Modules:
- - Build Modules:
-
Reproduction
A minimal reproduction of this issue can be found on StackBlitz here.
After using npx nuxi init ., the only step required to reproduce this bug is to create pages/index.vue with the following content:
<script setup>
definePageMeta({
foo: "" // '
});
</script>
Describe the bug
Including any quotation marks (single or double) aside from those around a string within definePageMeta causes Nuxt to throw an Internal server error. This includes quotation marks in comments in addition to those within strings.
Additional context
This bug is reproducible with the same steps on Windows 11 and Linux (the Linux environment is above). The bug does not occur if nuxt.config.js is not present. The bug does not occur if the quotation marks are balanced (present in an even amount within each string and/or comment and ordered properly so as to resolve a string; i.e. "" or '""', but not '"'" or """).
Logs
WARN [SSR] Error transforming /pages/index.vue?macro=true: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
at formatError (node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39080:46)
at TransformContext.error (node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39076:19)
at TransformContext.transform (node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58294:22)
at async Object.transform (node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39317:30)
at async doTransform (node_modules/vite/dist/node/chunks/dep-c9998dc6.js:50037:29)
ERROR 1:16:55 PM [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
Plugin: vite:import-analysis
File: /home/projects/nuxt-6312/pages/index.vue?macro=true
33 | });
34 |
35 | const __returned__ = { }
| ^
36 | Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })
37 | return __returned__
at formatError (/home/projects/nuxt-6312/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39080:46)
at TransformContext.error (/home/projects/nuxt-6312/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39076:19)
at TransformContext.transform (/home/projects/nuxt-6312/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58294:22)
at async Object.transform (/home/projects/nuxt-6312/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39317:30)
at async doTransform (/home/projects/nuxt-6312/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:50037:29)
A recently merged PR handles quotation marks within strings - it's only comments that are still wrongly parsed.
A workaround is to move the comment to its own line:
definePageMeta({
// '
foo: ""
})