-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.0.0-beta-3 - Nuxt 3 RC13] Uncaught SyntaxError: Unexpected token '{' #1616
Comments
Thank you for reporting and contributing as always! :) Related as here.
|
Sorry, I could not still understand this issue. customFunctions: {
greeting({ name }) {
return `Hello ${name}.`
},
}, I don't understand the use case for specifying The That schema can do by the completion if we are using typescript. In fact, the type of options expected by nuxtjs/i18n are defined here |
Hi @kazupon,
The problem is that at the moment, as a result of the object being defined in this way, export const resolveNuxtI18nOptions = async (context) => {
const nuxtI18nOptions = Object({});
const vueI18nOptionsLoader = async (context) =>
Object({ legacy: false, locale: 'en' });
nuxtI18nOptions.vueI18n = await vueI18nOptionsLoader(context);
nuxtI18nOptions.locales = [
Object({
code: 'en',
name: 'English',
file: 'en.json',
customFunctions: Object({
greeting: greeting({ name }) { // SYNTAX ERROR
return `Hello ${name}.`;
},
// ... That is because right now, (the line number changed, I should've copied permalink earlier)
which would give export const resolveNuxtI18nOptions = async (context) => {
const nuxtI18nOptions = Object({});
const vueI18nOptionsLoader = async (context) =>
Object({ legacy: false, locale: 'en' });
nuxtI18nOptions.vueI18n = await vueI18nOptionsLoader(context);
nuxtI18nOptions.locales = [
Object({
code: 'en',
name: 'English',
file: 'en.json',
customFunctions: Object({
greeting: ({ name }) => { // OK
return `Hello ${name}.`;
},
// ... Please note that both definitions of a property as function as valid in JS. Since this is just a high-level abstraction of my current issue, I'm not defining these functions but importing from another module that has defined it in the non-arrow function way, and those need to be considered, and so at the moment what #1617 is doing is checking if the function is named, and replacing it with export const resolveNuxtI18nOptions = async (context) => {
const nuxtI18nOptions = Object({});
const vueI18nOptionsLoader = async (context) =>
Object({ legacy: false, locale: 'en' });
nuxtI18nOptions.vueI18n = await vueI18nOptionsLoader(context);
nuxtI18nOptions.locales = [
Object({
code: 'en',
name: 'English',
file: 'en.json',
customFunctions: Object({
greeting: function ({ name }) { // OK
return `Hello ${name}.`;
},
// ... Here is a replication link: https://stackblitz.com/edit/github-azrltz-ryxlbu?file=.nuxt/i18n.options.mjs (please check file |
Or option 2 (not ideal) would be to refactor and only pick out properties the module is interested in const { code, name, file, ...meta } = locale
normalized.push({ code, name, file }) |
Thank you for your kind explation! Sorry, I confused confuse the |
…1617) * fix(gen): consider named functions (nuxt-modules#1616) * fix(gen): added tests for function to code * fix: linted the new tests for gen
Version
@nuxtjs/i18n: 8.0.0-beta.3
nuxt: 3.0.0-rc.12
@nuxtjs/i18n configuration
Description
i18n.locales[0].customFunctions
will break https://github.com/nuxt-community/i18n-module/blob/next/src/gen.ts#L193 resulting inIt needs to distinguish between arrow functions and named functions - I'll open a PR!
The text was updated successfully, but these errors were encountered: