From 919ec8063771970bb8edcaeb4a33701869ca08f1 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 15 May 2024 17:13:06 +0900 Subject: [PATCH 1/3] breaking(unplugin-vue-i18n): drop `jitCompilation` option --- package.json | 2 +- packages/unplugin-vue-i18n/README.md | 11 +- .../examples/vite/vite.config.ts | 3 +- packages/unplugin-vue-i18n/package.json | 2 +- packages/unplugin-vue-i18n/src/index.ts | 42 +- packages/unplugin-vue-i18n/src/types.ts | 1 - packages/unplugin-vue-i18n/test/utils.ts | 2 - .../__snapshots__/custom-block.test.ts.snap | 1384 +++++++++++++++-- .../vite/__snapshots__/sourcemap.test.ts.snap | 14 +- .../test/vite/bundle-import.test.ts | 5 +- .../test/vite/custom-block.test.ts | 111 +- .../test/vite/resource-compilation.test.ts | 35 +- .../__snapshots__/custom-block.test.ts.snap | 1066 ++++++++++++- .../__snapshots__/sourcemap.test.ts.snap | 14 +- .../test/webpack/custom-block.test.ts | 103 +- .../test/webpack/resource-compilation.test.ts | 11 +- yarn.lock | 33 +- 17 files changed, 2536 insertions(+), 303 deletions(-) diff --git a/package.json b/package.json index 3c89faf8..71f98408 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ } }, "devDependencies": { - "@intlify/core-base": "^9.13.1", + "@intlify/core-base": "^10.0.0-alpha.4", "@kazupon/lerna-changelog": "^4.3.0", "@octokit/rest": "^18.6.0", "@rollup/plugin-alias": "^3.1.5", diff --git a/packages/unplugin-vue-i18n/README.md b/packages/unplugin-vue-i18n/README.md index 3eca5e07..0887605e 100644 --- a/packages/unplugin-vue-i18n/README.md +++ b/packages/unplugin-vue-i18n/README.md @@ -353,13 +353,11 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi - **Default:** `true` > [!IMPORTANT] - 'jitCompilation' option now defaults to `true` from 3.0. + 'jitCompilation' option is deprected in v5. + This option will be supported with vue-i18n until v9 latest version. Whether locale mesages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler. -> [!NOTE] - This option works with vue-i18n v9.3 and later. - JIT compilation has been supported since vue-i18n v9.3. This means that since v9 was released until now, the message compiler compiles to executable JavaScript code, however it did not work in the CSP environment. Also, since this was an AOT (Ahead of Time) compilation, it was not possible to dynamically retrieve locale messages from the back-end Database and compose locale mesages with programatic. > [!WARNING] @@ -374,7 +372,10 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi Whether to tree-shake message compiler when we will be bundling. -If you chose to use this option, you will need to enable `jitCompilation` option. +If do you will use this option, you need to enable `jitCompilation` option. + +> [NOTE] +> After v5 or later, this option can be set with or without `jitCompilation`. > [!NOTE] This option works with vue-i18n v9.3 and later. diff --git a/packages/unplugin-vue-i18n/examples/vite/vite.config.ts b/packages/unplugin-vue-i18n/examples/vite/vite.config.ts index f7d34e00..5a8d5fa4 100644 --- a/packages/unplugin-vue-i18n/examples/vite/vite.config.ts +++ b/packages/unplugin-vue-i18n/examples/vite/vite.config.ts @@ -20,8 +20,7 @@ export default defineConfig({ plugins: [ vue(), vueI18n({ - include: path.resolve(__dirname, './src/locales/**'), - jitCompilation: true + include: path.resolve(__dirname, './src/locales/**') }) ] }) diff --git a/packages/unplugin-vue-i18n/package.json b/packages/unplugin-vue-i18n/package.json index de7a4cf9..1479e1d2 100644 --- a/packages/unplugin-vue-i18n/package.json +++ b/packages/unplugin-vue-i18n/package.json @@ -27,7 +27,7 @@ }, "dependencies": { "@intlify/bundle-utils": "^8.0.0", - "@intlify/shared": "^9.4.0", + "@intlify/shared": "^10.0.0-alpha.4", "@rollup/pluginutils": "^5.1.0", "@vue/compiler-sfc": "^3.2.47", "debug": "^4.3.3", diff --git a/packages/unplugin-vue-i18n/src/index.ts b/packages/unplugin-vue-i18n/src/index.ts index c6f82bae..c8b05bf5 100644 --- a/packages/unplugin-vue-i18n/src/index.ts +++ b/packages/unplugin-vue-i18n/src/index.ts @@ -87,14 +87,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { : true debug('runtimeOnly', runtimeOnly) - const jitCompilation = isBoolean(options.jitCompilation) - ? options.jitCompilation - : true - debug('jitCompilation', jitCompilation) - - const dropMessageCompiler = jitCompilation - ? !!options.dropMessageCompiler - : false + const dropMessageCompiler = !!options.dropMessageCompiler debug('dropMessageCompiler', dropMessageCompiler) // prettier-ignore @@ -233,10 +226,6 @@ export const unplugin = createUnplugin((options = {}, meta) => { debug( `set __VUE_I18N_FULL_INSTALL__ is '${config.define['__VUE_I18N_FULL_INSTALL__']}'` ) - config.define['__INTLIFY_JIT_COMPILATION__'] = jitCompilation - debug( - `set __INTLIFY_JIT_COMPILATION__ is '${config.define['__INTLIFY_JIT_COMPILATION__']}'` - ) config.define['__INTLIFY_DROP_MESSAGE_COMPILER__'] = dropMessageCompiler debug( `set __INTLIFY_DROP_MESSAGE_COMPILER__ is '${config.define['__INTLIFY_DROP_MESSAGE_COMPILER__']}'` @@ -327,7 +316,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { allowDynamic, strictMessage, escapeHtml, - jit: jitCompilation, + jit: true, onlyLocales, forceStringify } @@ -342,12 +331,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { return { code: generatedCode, - // prettier-ignore - map: (jitCompilation - ? { mappings: '' } - : sourceMap - ? map - : { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any + map: { mappings: '' } } } else { return result @@ -519,7 +503,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { allowDynamic, strictMessage, escapeHtml, - jit: jitCompilation, + jit: true, onlyLocales, forceStringify } @@ -535,11 +519,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { return { code: generatedCode, // prettier-ignore - map: (jitCompilation - ? { mappings: '' } - : sourceMap - ? map - : { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any + map: { mappings: '' } } } else { // TODO: support virtual import identifier @@ -574,7 +554,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { inSourceMap, isGlobal: globalSFCScope, useClassComponent, - jit: jitCompilation, + jit: true, strictMessage, escapeHtml, onlyLocales, @@ -599,11 +579,7 @@ export const unplugin = createUnplugin((options = {}, meta) => { return { code: generatedCode, // prettier-ignore - map: (jitCompilation - ? { mappings: '' } - : sourceMap - ? map - : { mappings: '' }) as any // eslint-disable-line @typescript-eslint/no-explicit-any + map: { mappings: '' } } } } @@ -669,7 +645,7 @@ async function generateBundleResources( strictMessage = true, escapeHtml = false, useClassComponent = false, - jit = false + jit = true }: { forceStringify?: boolean isGlobal?: boolean @@ -790,7 +766,7 @@ function getOptions( allowDynamic = false, strictMessage = true, escapeHtml = false, - jit = false + jit = true }: { inSourceMap?: RawSourceMap forceStringify?: boolean diff --git a/packages/unplugin-vue-i18n/src/types.ts b/packages/unplugin-vue-i18n/src/types.ts index a6f7a77b..420e0cfe 100644 --- a/packages/unplugin-vue-i18n/src/types.ts +++ b/packages/unplugin-vue-i18n/src/types.ts @@ -3,7 +3,6 @@ export interface PluginOptions { include?: string | string[] onlyLocales?: string | string[] allowDynamic?: boolean - jitCompilation?: boolean dropMessageCompiler?: boolean runtimeOnly?: boolean compositionOnly?: boolean diff --git a/packages/unplugin-vue-i18n/test/utils.ts b/packages/unplugin-vue-i18n/test/utils.ts index 4086aa35..811a4f39 100644 --- a/packages/unplugin-vue-i18n/test/utils.ts +++ b/packages/unplugin-vue-i18n/test/utils.ts @@ -42,7 +42,6 @@ export async function bundleVite( ? options.strictMessage : true options.escapeHtml = !!options.escapeHtml - options.jitCompilation = !!options.jitCompilation const alias: Record = { vue: 'vue/dist/vue.runtime.esm-browser.js' @@ -167,7 +166,6 @@ export async function bundleAndRun( ? options.strictMessage : true options.escapeHtml = !!options.escapeHtml - options.jitCompilation = !!options.jitCompilation const { code, map } = await bundler(fixture, options) diff --git a/packages/unplugin-vue-i18n/test/vite/__snapshots__/custom-block.test.ts.snap b/packages/unplugin-vue-i18n/test/vite/__snapshots__/custom-block.test.ts.snap index 73d3d945..993224ea 100644 --- a/packages/unplugin-vue-i18n/test/vite/__snapshots__/custom-block.test.ts.snap +++ b/packages/unplugin-vue-i18n/test/vite/__snapshots__/custom-block.test.ts.snap @@ -1,5 +1,72 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`AST 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + exports[`array 1`] = ` [ { @@ -8,9 +75,117 @@ exports[`array 1`] = ` "en": { "foo": [ [ - [Function], + { + "body": { + "end": 3, + "items": [ + { + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "bar", + "type": 2, + }, + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "source": "bar", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, ], - [Function], + { + "body": { + "end": 3, + "items": [ + { + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "baz", + "type": 2, + }, + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "source": "baz", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, ], }, }, @@ -18,96 +193,816 @@ exports[`array 1`] = ` ] `; -exports[`basic 1`] = ` +exports[`basic 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`default lang 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 20, + "items": [ + { + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello from defaults!", + "type": 2, + }, + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "source": "hello from defaults!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`default lang and global scope 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 20, + "items": [ + { + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello from defaults!", + "type": 2, + }, + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "source": "hello from defaults!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`global 1`] = ` +[ + { + "locale": "ja", + "resource": { + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello local!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello local!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, +] +`; + +exports[`global 2`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 13, + "items": [ + { + "end": 13, + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello global!", + "type": 2, + }, + "end": 13, + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "source": "hello global!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`global scope and import 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`import 1`] = ` +[ + { + "locale": "", + "resource": { + "en": { + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, + }, + }, + }, +] +`; + +exports[`json: exclude locales 1`] = ` [ { "locale": "", - "resource": { - "en": { - "hello": [Function], - }, - }, + "resource": {}, }, ] `; -exports[`default lang 1`] = ` +exports[`json5 1`] = ` [ { "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, ] `; -exports[`default lang and global scope 1`] = ` +exports[`json5: exclude locales 1`] = ` [ { "locale": "", - "resource": { - "en": { - "hello": [Function], - }, - }, + "resource": {}, }, ] `; -exports[`global 1`] = ` +exports[`locale attr 1`] = ` [ { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] `; -exports[`global 2`] = ` +exports[`locale attr and basic 1`] = ` [ { "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, -] -`; - -exports[`global scope and import 1`] = ` -[ { - "locale": "", + "locale": "ja", "resource": { - "en": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, }, }, }, ] `; -exports[`import 1`] = ` +exports[`locale attr and import 1`] = ` [ { - "locale": "", + "locale": "en", "resource": { - "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, }, }, }, ] `; -exports[`jitCompilation 1`] = ` +exports[`multiple 1`] = ` [ { "locale": "", @@ -171,96 +1066,65 @@ exports[`jitCompilation 1`] = ` }, }, }, -] -`; - -exports[`json: exclude locales 1`] = ` -[ - { - "locale": "", - "resource": {}, - }, -] -`; - -exports[`json5 1`] = ` -[ - { - "locale": "", - "resource": { - "en": { - "hello": [Function], - }, - }, - }, -] -`; - -exports[`json5: exclude locales 1`] = ` -[ - { - "locale": "", - "resource": {}, - }, -] -`; - -exports[`locale attr 1`] = ` -[ - { - "locale": "ja", - "resource": { - "hello": [Function], - }, - }, -] -`; - -exports[`locale attr and basic 1`] = ` -[ - { - "locale": "", - "resource": { - "en": { - "hello": [Function], - }, - }, - }, - { - "locale": "ja", - "resource": { - "hello": [Function], - }, - }, -] -`; - -exports[`locale attr and import 1`] = ` -[ - { - "locale": "en", - "resource": { - "hello": [Function], - }, - }, -] -`; - -exports[`multiple 1`] = ` -[ - { - "locale": "", - "resource": { - "en": { - "hello": [Function], - }, - }, - }, { "locale": "", "resource": { "ja": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -273,7 +1137,63 @@ exports[`special characters 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 19, + "items": [ + { + "end": 19, + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello +great \\"world\\"", + "type": 2, + }, + "end": 19, + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "source": "hello +great \\"world\\"", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -285,13 +1205,121 @@ exports[`yaml 1`] = ` { "locale": "en", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] @@ -302,13 +1330,121 @@ exports[`yaml: exclude locales 1`] = ` { "locale": "en", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] diff --git a/packages/unplugin-vue-i18n/test/vite/__snapshots__/sourcemap.test.ts.snap b/packages/unplugin-vue-i18n/test/vite/__snapshots__/sourcemap.test.ts.snap index 58565b9e..aad5d3e6 100644 --- a/packages/unplugin-vue-i18n/test/vite/__snapshots__/sourcemap.test.ts.snap +++ b/packages/unplugin-vue-i18n/test/vite/__snapshots__/sourcemap.test.ts.snap @@ -1,15 +1,15 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`custom blocks: json 1`] = `";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; +exports[`custom blocks: json 1`] = `";;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`custom blocks: json5 1`] = `";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; +exports[`custom blocks: json5 1`] = `";;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`custom blocks: yaml 1`] = `";AACOA,QAAAA,aAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEP,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASC;AAChB,SAAO,UAAU;AACnB;"`; +exports[`custom blocks: yaml 1`] = `";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`custom blocks: yml 1`] = `";;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; +exports[`custom blocks: yml 1`] = `";;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`resource files: json 1`] = `";;;;iCACYA,CAAAA,QAAAA,aAAAA,QAAAA,KAAAA,CAAAC,CAAAC,GAAAA,WAAAA,CAAAA,aAAAA,MAAAA,CAAAA,CAAAA,GAAAA,QAAAC,CAAAC,GAAAA,WAAAA,CAAAA,aAAAA,OAAAA,GAAAA,CAAAA,GAAAA,SAAAA,CAAAA,CAAAA,CAAAA;AAAAA,IAAAA;AAAAA,OAAAA,SAAAA;AAAAA,WAAAA;AAAAA,EAAAA,GAAAA;AAAAA;IAEAC,UAAAA,MAAAA;AAAAA,YAAAA,KAAAA,CAAAA,QAAAA;AAAAA,cAAAA,EAAAA,WAAAA,YAAAA,aAAAA,cAAAA,OAAAA,OAAAA,IAAAA;AAAAA,eAAAA,WAAAC,CAAAA,UAAAA,aAAAA,OAAAA,MAAAA,CAAAA,GAAAA,GAAAA,CAAAA;AAAAA,MAAAA;AAAAA,SAAAA,SAAAA;AAAAA,aAAAA;AAAAA,IAAAA,GAAAA;AAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAZ,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASC;AAChB,SAAO,UAAU;AACnB;"`; +exports[`resource files: json 1`] = `";;;;;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`resource files: json5 1`] = `";;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; +exports[`resource files: json5 1`] = `";;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; -exports[`resource files: yaml 1`] = `";;;;;;;;;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; +exports[`resource files: yaml 1`] = `";;;;;;;AAGA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,SAASA;AAChB,SAAO,UAAU;AACnB;"`; diff --git a/packages/unplugin-vue-i18n/test/vite/bundle-import.test.ts b/packages/unplugin-vue-i18n/test/vite/bundle-import.test.ts index bfe9f007..d5b8cf88 100644 --- a/packages/unplugin-vue-i18n/test/vite/bundle-import.test.ts +++ b/packages/unplugin-vue-i18n/test/vite/bundle-import.test.ts @@ -1,6 +1,7 @@ import { resolve } from 'pathe' import { bundleVite, bundleAndRun } from '../utils' -import { createMessageContext } from '@intlify/core-base' +import { createMessageContext, compile } from '@intlify/core-base' +import type { MessageCompilerContext } from '@intlify/core-base' ;[ { testcase: 'import', @@ -20,7 +21,7 @@ import { createMessageContext } from '@intlify/core-base' options ) ;['en', 'fr', 'ja', 'ko'].forEach(locale => { - const fn = messages[locale].message + const fn = compile(messages[locale].message, {} as MessageCompilerContext) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) }) diff --git a/packages/unplugin-vue-i18n/test/vite/custom-block.test.ts b/packages/unplugin-vue-i18n/test/vite/custom-block.test.ts index 74eba6c4..6ba4ae3d 100644 --- a/packages/unplugin-vue-i18n/test/vite/custom-block.test.ts +++ b/packages/unplugin-vue-i18n/test/vite/custom-block.test.ts @@ -1,12 +1,15 @@ import { bundleVite, bundleAndRun } from '../utils' -import { createMessageContext, isMessageAST } from '@intlify/core-base' +import { createMessageContext, isMessageAST, compile } from '@intlify/core-base' +import type { MessageCompilerContext } from '@intlify/core-base' test('basic', async () => { const { module } = await bundleAndRun('basic.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('json: exclude locales', async () => { @@ -14,6 +17,7 @@ test('json: exclude locales', async () => { onlyLocales: ['ja'] }) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.resource.en).toBeUndefined() }) @@ -23,6 +27,7 @@ test('yaml: exclude locales', async () => { onlyLocales: ['ja'] }) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.resource.en).toBeUndefined() }) @@ -32,6 +37,7 @@ test('json5: exclude locales', async () => { onlyLocales: ['ja'] }) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.resource.en).toBeUndefined() }) @@ -39,97 +45,125 @@ test('json5: exclude locales', async () => { test('yaml', async () => { const { module } = await bundleAndRun('yaml.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('en') - expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('json5', async () => { const { module } = await bundleAndRun('json5.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('import', async () => { const { module } = await bundleAndRun('import.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('multiple', async () => { const { module } = await bundleAndRun('multiple.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() expect(module.__i18n.length).toEqual(2) + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.ja.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.ja.hello, {} as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('locale attr', async () => { const { module } = await bundleAndRun('locale.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('こんにちは、世界!') }) test('locale attr and basic', async () => { const { module } = await bundleAndRun('locale-mix.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('locale attr and import', async () => { const { module } = await bundleAndRun('locale-import.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('en') - expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('special characters', async () => { const { module } = await bundleAndRun('special-char.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual( - 'hello\ngreat\t"world"' - ) + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello\ngreat\t"world"') }) test('global', async () => { const { module } = await bundleAndRun('global-mix.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() expect(module.__i18nGlobal).toMatchSnapshot() + const l = module.__i18n.pop() expect(l.locale).toEqual('ja') - expect(l.resource.hello(createMessageContext())).toEqual('hello local!') + const fn1 = compile(l.resource.hello, { + locale: l.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('hello local!') + const g = module.__i18nGlobal.pop() expect(g.locale).toEqual('') - expect(g.resource.en.hello(createMessageContext())).toEqual('hello global!') + const fn2 = compile(g.resource.en.hello, {} as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello global!') }) test('default lang', async () => { @@ -137,10 +171,10 @@ test('default lang', async () => { defaultSFCLang: 'yml' }) expect(module.__i18n).toMatchSnapshot() + const l = module.__i18n.pop() - expect(l.resource.en.hello(createMessageContext())).toEqual( - 'hello from defaults!' - ) + const fn = compile(l.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello from defaults!') }) test('default lang and global scope', async () => { @@ -149,10 +183,10 @@ test('default lang and global scope', async () => { globalSFCScope: true }) expect(module.__i18nGlobal).toMatchSnapshot() + const g = module.__i18nGlobal.pop() - expect(g.resource.en.hello(createMessageContext())).toEqual( - 'hello from defaults!' - ) + const fn = compile(g.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello from defaults!') }) test('global scope and import', async () => { @@ -160,25 +194,30 @@ test('global scope and import', async () => { globalSFCScope: true }) expect(module.__i18nGlobal).toMatchSnapshot() + const g = module.__i18nGlobal.pop() - expect(g.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(g.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('array', async () => { const { module } = await bundleAndRun('array.vue', bundleVite) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.foo[0][0](createMessageContext())).toEqual('bar') - expect(i18n.resource.en.foo[1](createMessageContext())).toEqual('baz') + const fn1 = compile(i18n.resource.en.foo[0][0], {} as MessageCompilerContext) + const fn2 = compile(i18n.resource.en.foo[1], {} as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('bar') + expect(fn2(createMessageContext())).toEqual('baz') }) -test('jitCompilation', async () => { +test('AST', async () => { const { module } = await bundleAndRun('basic.vue', bundleVite, { - jitCompilation: true, env: 'production' }) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') expect(isMessageAST(i18n.resource.en.hello)).toBe(true) diff --git a/packages/unplugin-vue-i18n/test/vite/resource-compilation.test.ts b/packages/unplugin-vue-i18n/test/vite/resource-compilation.test.ts index 1a59830f..97f614e1 100644 --- a/packages/unplugin-vue-i18n/test/vite/resource-compilation.test.ts +++ b/packages/unplugin-vue-i18n/test/vite/resource-compilation.test.ts @@ -2,7 +2,8 @@ import { vi } from 'vitest' import { resolve } from 'pathe' import { bundleVite, bundleAndRun } from '../utils' import { isFunction, assign } from '@intlify/shared' -import { createMessageContext } from '@intlify/core-base' +import { createMessageContext, compile } from '@intlify/core-base' +import type { MessageCompilerContext } from '@intlify/core-base' // eslint-disable-next-line @typescript-eslint/no-explicit-any let spyConsoleError: any @@ -24,42 +25,42 @@ const options = { test('json resource', async () => { const { module } = await bundleAndRun('ja.json', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('json5 resource', async () => { const { module } = await bundleAndRun('en.json5', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('yaml resource', async () => { const { module } = await bundleAndRun('ko.yaml', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('yml resource', async () => { const { module } = await bundleAndRun('fr.yml', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('js resource', async () => { const { module } = await bundleAndRun('en-KK.mjs', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('ts resource', async () => { const { module } = await bundleAndRun('en-GB.ts', bundleVite, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) @@ -93,18 +94,10 @@ test('escape message', async () => { escapeHtml: true }) ) - expect(module.hi(createMessageContext())).toBe(`<p>hi there!</p>`) - expect(module.alert(createMessageContext())).toBe( - `<script>window.alert('hi there!')</script>` - ) -}) - -test('jitCompilation', async () => { - const { module } = await bundleAndRun('ja.json', bundleVite, { - jitCompilation: true, - ...options - }) - const fn = module.message - // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) - expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) + expect( + compile(module.hi, {} as MessageCompilerContext)(createMessageContext()) + ).toBe(`<p>hi there!</p>`) + expect( + compile(module.alert, {} as MessageCompilerContext)(createMessageContext()) + ).toBe(`<script>window.alert('hi there!')</script>`) }) diff --git a/packages/unplugin-vue-i18n/test/webpack/__snapshots__/custom-block.test.ts.snap b/packages/unplugin-vue-i18n/test/webpack/__snapshots__/custom-block.test.ts.snap index 8beea3b9..0fa120af 100644 --- a/packages/unplugin-vue-i18n/test/webpack/__snapshots__/custom-block.test.ts.snap +++ b/packages/unplugin-vue-i18n/test/webpack/__snapshots__/custom-block.test.ts.snap @@ -8,9 +8,117 @@ exports[`array 1`] = ` "en": { "foo": [ [ - [Function], + { + "body": { + "end": 3, + "items": [ + { + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "bar", + "type": 2, + }, + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "source": "bar", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, ], - [Function], + { + "body": { + "end": 3, + "items": [ + { + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "baz", + "type": 2, + }, + "end": 3, + "loc": { + "end": { + "column": 4, + "line": 1, + "offset": 3, + }, + "source": "baz", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, ], }, }, @@ -24,7 +132,61 @@ exports[`basic 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -37,7 +199,61 @@ exports[`default lang 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 20, + "items": [ + { + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello from defaults!", + "type": 2, + }, + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "source": "hello from defaults!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -50,7 +266,61 @@ exports[`default lang and global scope 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 20, + "items": [ + { + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello from defaults!", + "type": 2, + }, + "end": 20, + "loc": { + "end": { + "column": 21, + "line": 1, + "offset": 20, + }, + "source": "hello from defaults!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -62,7 +332,61 @@ exports[`global 1`] = ` { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello local!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello local!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] @@ -74,7 +398,61 @@ exports[`global 2`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 13, + "items": [ + { + "end": 13, + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello global!", + "type": 2, + }, + "end": 13, + "loc": { + "end": { + "column": 14, + "line": 1, + "offset": 13, + }, + "source": "hello global!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -87,7 +465,61 @@ exports[`global scope and import 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -100,7 +532,61 @@ exports[`import 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -113,7 +599,61 @@ exports[`json5 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -125,7 +665,61 @@ exports[`locale attr 1`] = ` { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] @@ -137,14 +731,122 @@ exports[`locale attr and basic 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] @@ -155,7 +857,61 @@ exports[`locale attr and import 1`] = ` { "locale": "en", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] @@ -167,7 +923,61 @@ exports[`multiple 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -175,7 +985,61 @@ exports[`multiple 1`] = ` "locale": "", "resource": { "ja": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -188,7 +1052,63 @@ exports[`special characters 1`] = ` "locale": "", "resource": { "en": { - "hello": [Function], + "hello": { + "body": { + "end": 19, + "items": [ + { + "end": 19, + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello +great \\"world\\"", + "type": 2, + }, + "end": 19, + "loc": { + "end": { + "column": 14, + "line": 2, + "offset": 19, + }, + "source": "hello +great \\"world\\"", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, }, @@ -200,13 +1120,121 @@ exports[`yaml 1`] = ` { "locale": "en", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 12, + "items": [ + { + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "hello world!", + "type": 2, + }, + "end": 12, + "loc": { + "end": { + "column": 13, + "line": 1, + "offset": 12, + }, + "source": "hello world!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, { "locale": "ja", "resource": { - "hello": [Function], + "hello": { + "body": { + "end": 9, + "items": [ + { + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 3, + }, + ], + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "static": "こんにちは、世界!", + "type": 2, + }, + "end": 9, + "loc": { + "end": { + "column": 10, + "line": 1, + "offset": 9, + }, + "source": "こんにちは、世界!", + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "start": 0, + "type": 0, + }, }, }, ] diff --git a/packages/unplugin-vue-i18n/test/webpack/__snapshots__/sourcemap.test.ts.snap b/packages/unplugin-vue-i18n/test/webpack/__snapshots__/sourcemap.test.ts.snap index eed8cc85..32f2f6c4 100644 --- a/packages/unplugin-vue-i18n/test/webpack/__snapshots__/sourcemap.test.ts.snap +++ b/packages/unplugin-vue-i18n/test/webpack/__snapshots__/sourcemap.test.ts.snap @@ -1,15 +1,15 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`custom blocks: json 1`] = `";;;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;ACVA;AACA;AACA,CAAuE;AACvE,WAAW,yFAAM,iBAAiB,6FAAM;;;AAGxC,CAAoI;AACpI,iCAAiC,kJAAe;;AAEhD,iEAAe;;;;;;;;;;;;;;ACTf,6BAAe,oCAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,mBAAmB,QAAQ,wBAAwB,MAAM,qCAAqC,yBAAyB,WAAW;AACzJ;AACA;AACA,GAAG;AACH;;;;;;;UCXA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; +exports[`custom blocks: json 1`] = `";;;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;ACVA;AACA;AACA,CAAuE;AACvE,WAAW,yFAAM,iBAAiB,6FAAM;;;AAGxC,CAAoI;AACpI,iCAAiC,kJAAe;;AAEhD,iEAAe;;;;;;;;;;;;;;ACTf,6BAAe,oCAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,mCAAmC,SAAS,+BAA+B,QAAQ,iCAAiC,yBAAyB,SAAS,mCAAmC,SAAS,+BAA+B,QAAQ,kCAAkC,WAAW,mCAAmC,SAAS,+BAA+B,QAAQ,mCAAmC;AAC9Z;AACA;AACA,GAAG;AACH;;;;;;;UCXA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; -exports[`custom blocks: json5 1`] = `";;;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;ACVA;AACA;AACA,CAAkF;AAClF,WAAW,oGAAM,iBAAiB,wGAAM;;;AAGxC,CAAoI;AACpI,iCAAiC,kJAAe;;AAEhD,iEAAe;;;;;;;;;;;;;;ACTf,6BAAe,oCAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,mBAAmB,QAAQ,wBAAwB,MAAM,qCAAqC,yBAAyB,WAAW;AACzJ;AACA;AACA,GAAG;AACH;;;;;;;UCXA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; +exports[`custom blocks: json5 1`] = `";;;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;ACVA;AACA;AACA,CAAkF;AAClF,WAAW,oGAAM,iBAAiB,wGAAM;;;AAGxC,CAAoI;AACpI,iCAAiC,kJAAe;;AAEhD,iEAAe;;;;;;;;;;;;;;ACTf,6BAAe,oCAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,mCAAmC,SAAS,+BAA+B,QAAQ,iCAAiC,yBAAyB,SAAS,mCAAmC,SAAS,+BAA+B,QAAQ,kCAAkC,WAAW,mCAAmC,SAAS,+BAA+B,QAAQ,mCAAmC;AAC9Z;AACA;AACA,GAAG;AACH;;;;;;;UCXA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; -exports[`custom blocks: yaml 1`] = `";;;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACVA;AACA;AACA,CAA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,SAAS,+BAA+B,QAAQ,gCAAgC,WAAW,kCAAkC,SAAS,+BAA+B,QAAQ,iCAAiC;AAC1Y;AACA;AACA;AACA,iEAAe;;;;;;UCbf;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; -exports[`resource files: json5 1`] = `";;;;;;;;;;;;;;AAAA;AACA,mBAAmB,mBAAmB,QAAQ,8HAA8H,MAAM,yKAAyK,mBAAmB,aAAa,GAAG,GAAG,SAAS,GAAG,QAAQ,WAAW;AACha;AACA,iEAAe;;;;;;UCHf;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACN+B;AACG;;AAElC;AACA,kBAAkB,+CAAS;AAC3B,mBAAmB,oCAAO;AAC1B;;AAEA,iEAAe,+CAAS"`; +exports[`resource files: json5 1`] = `";;;;;;;;;;;;;;AAAA;AACA,cAAc,mCAAmC,SAAS,+BAA+B,QAAQ,iCAAiC,mBAAmB,uBAAuB,GAAG,GAAG,SAAS,GAAG,QAAQ,SAAS,mCAAmC,SAAS,+BAA+B,QAAQ,kCAAkC,WAAW,mCAAmC,SAAS,+BAA+B,QAAQ,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AEA,iEAAe,+CAAS"`; diff --git a/packages/unplugin-vue-i18n/test/webpack/custom-block.test.ts b/packages/unplugin-vue-i18n/test/webpack/custom-block.test.ts index 882eab68..aed0c4f4 100644 --- a/packages/unplugin-vue-i18n/test/webpack/custom-block.test.ts +++ b/packages/unplugin-vue-i18n/test/webpack/custom-block.test.ts @@ -1,108 +1,141 @@ import { bundleWebpack, bundleAndRun } from '../utils' -import { createMessageContext } from '@intlify/core-base' +import { createMessageContext, compile } from '@intlify/core-base' +import type { MessageCompilerContext } from '@intlify/core-base' test('basic', async () => { const { module } = await bundleAndRun('basic.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('yaml', async () => { const { module } = await bundleAndRun('yaml.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('en') - expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('json5', async () => { const { module } = await bundleAndRun('json5.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('import', async () => { const { module } = await bundleAndRun('import.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('multiple', async () => { const { module } = await bundleAndRun('multiple.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() expect(module.__i18n.length).toEqual(2) + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.ja.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.ja.hello, {} as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('locale attr', async () => { const { module } = await bundleAndRun('locale.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('こんにちは、世界!') }) test('locale attr and basic', async () => { const { module } = await bundleAndRun('locale-mix.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + let i18n = module.__i18n.pop() expect(i18n.locale).toEqual('ja') - expect(i18n.resource.hello(createMessageContext())).toEqual( - 'こんにちは、世界!' - ) + const fn1 = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('こんにちは、世界!') + i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn2 = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello world!') }) test('locale attr and import', async () => { const { module } = await bundleAndRun('locale-import.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('en') - expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(i18n.resource.hello, { + locale: i18n.locale + } as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('special characters', async () => { const { module } = await bundleAndRun('special-char.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.hello(createMessageContext())).toEqual( - 'hello\ngreat\t"world"' - ) + const fn = compile(i18n.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello\ngreat\t"world"') }) test('global', async () => { const { module } = await bundleAndRun('global-mix.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() expect(module.__i18nGlobal).toMatchSnapshot() + const l = module.__i18n.pop() expect(l.locale).toEqual('ja') - expect(l.resource.hello(createMessageContext())).toEqual('hello local!') + const fn1 = compile(l.resource.hello, { + locale: l.locale + } as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('hello local!') + const g = module.__i18nGlobal.pop() expect(g.locale).toEqual('') - expect(g.resource.en.hello(createMessageContext())).toEqual('hello global!') + const fn2 = compile(g.resource.en.hello, { + locale: g.locale + } as MessageCompilerContext) + expect(fn2(createMessageContext())).toEqual('hello global!') }) test('default lang', async () => { @@ -111,9 +144,8 @@ test('default lang', async () => { }) expect(module.__i18n).toMatchSnapshot() const l = module.__i18n.pop() - expect(l.resource.en.hello(createMessageContext())).toEqual( - 'hello from defaults!' - ) + const fn = compile(l.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello from defaults!') }) test('default lang and global scope', async () => { @@ -123,9 +155,8 @@ test('default lang and global scope', async () => { }) expect(module.__i18nGlobal).toMatchSnapshot() const g = module.__i18nGlobal.pop() - expect(g.resource.en.hello(createMessageContext())).toEqual( - 'hello from defaults!' - ) + const fn = compile(g.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello from defaults!') }) test('global scope and import', async () => { @@ -138,14 +169,18 @@ test('global scope and import', async () => { ) expect(module.__i18nGlobal).toMatchSnapshot() const g = module.__i18nGlobal.pop() - expect(g.resource.en.hello(createMessageContext())).toEqual('hello world!') + const fn = compile(g.resource.en.hello, {} as MessageCompilerContext) + expect(fn(createMessageContext())).toEqual('hello world!') }) test('array', async () => { const { module } = await bundleAndRun('array.vue', bundleWebpack) expect(module.__i18n).toMatchSnapshot() + const i18n = module.__i18n.pop() expect(i18n.locale).toEqual('') - expect(i18n.resource.en.foo[0][0](createMessageContext())).toEqual('bar') - expect(i18n.resource.en.foo[1](createMessageContext())).toEqual('baz') + const fn1 = compile(i18n.resource.en.foo[0][0], {} as MessageCompilerContext) + const fn2 = compile(i18n.resource.en.foo[1], {} as MessageCompilerContext) + expect(fn1(createMessageContext())).toEqual('bar') + expect(fn2(createMessageContext())).toEqual('baz') }) diff --git a/packages/unplugin-vue-i18n/test/webpack/resource-compilation.test.ts b/packages/unplugin-vue-i18n/test/webpack/resource-compilation.test.ts index eddcf166..6f1f5774 100644 --- a/packages/unplugin-vue-i18n/test/webpack/resource-compilation.test.ts +++ b/packages/unplugin-vue-i18n/test/webpack/resource-compilation.test.ts @@ -1,6 +1,7 @@ import { resolve } from 'pathe' import { bundleWebpack, bundleAndRun } from '../utils' -import { createMessageContext } from '@intlify/core-base' +import { createMessageContext, compile } from '@intlify/core-base' +import type { MessageCompilerContext } from '@intlify/core-base' // import { VueLoaderPlugin } from 'vue-loader17' const options = { @@ -15,28 +16,28 @@ const options = { test('json resource', async () => { const { module } = await bundleAndRun('ja.json', bundleWebpack, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('json5 resource', async () => { const { module } = await bundleAndRun('en.json5', bundleWebpack, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('yaml resource', async () => { const { module } = await bundleAndRun('ko.yaml', bundleWebpack, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) test('yml resource', async () => { const { module } = await bundleAndRun('fr.yml', bundleWebpack, options) - const fn = module.message + const fn = compile(module.message, {} as MessageCompilerContext) // expect(fn.source).toEqual(`@.caml:{'no apples'} | {0} apple | {n} apples`) expect(fn(createMessageContext({ named: { n: 3 } }))).toEqual(`3 apples`) }) diff --git a/yarn.lock b/yarn.lock index f0219250..9a4ff2a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1211,7 +1211,7 @@ __metadata: version: 0.0.0-use.local resolution: "@intlify/bundle-tools@workspace:." dependencies: - "@intlify/core-base": ^9.13.1 + "@intlify/core-base": ^10.0.0-alpha.4 "@kazupon/lerna-changelog": ^4.3.0 "@octokit/rest": ^18.6.0 "@rollup/plugin-alias": ^3.1.5 @@ -1309,7 +1309,7 @@ __metadata: languageName: unknown linkType: soft -"@intlify/core-base@npm:9.13.1, @intlify/core-base@npm:^9.13.1": +"@intlify/core-base@npm:9.13.1": version: 9.13.1 resolution: "@intlify/core-base@npm:9.13.1" dependencies: @@ -1319,6 +1319,26 @@ __metadata: languageName: node linkType: hard +"@intlify/core-base@npm:^10.0.0-alpha.4": + version: 10.0.0-alpha.4 + resolution: "@intlify/core-base@npm:10.0.0-alpha.4" + dependencies: + "@intlify/message-compiler": 10.0.0-alpha.4 + "@intlify/shared": 10.0.0-alpha.4 + checksum: 7ef4558ea35c244911477b5e21be69792a4c86876dc28f35b6e68611fd70b6337449b497f955eac750adf43370bf8f6cdcc4af09afeff28b8ee8576edfe8bdb0 + languageName: node + linkType: hard + +"@intlify/message-compiler@npm:10.0.0-alpha.4": + version: 10.0.0-alpha.4 + resolution: "@intlify/message-compiler@npm:10.0.0-alpha.4" + dependencies: + "@intlify/shared": 10.0.0-alpha.4 + source-map-js: ^1.0.2 + checksum: e97c55d478e4837889b9f8dee854196693c7d734e273e94753a961522b8b1932d410fe3fc908ededd38681c13eab0b59fa3385e90ffaa472080480fda4778e30 + languageName: node + linkType: hard + "@intlify/message-compiler@npm:9.13.1": version: 9.13.1 resolution: "@intlify/message-compiler@npm:9.13.1" @@ -1339,6 +1359,13 @@ __metadata: languageName: node linkType: hard +"@intlify/shared@npm:10.0.0-alpha.4, @intlify/shared@npm:^10.0.0-alpha.4": + version: 10.0.0-alpha.4 + resolution: "@intlify/shared@npm:10.0.0-alpha.4" + checksum: 7453a199fa7f0f2be2e14485e376254320ffe130a6608341c94a08eb4a0705edfcabcde82847b5f2c78ad155f1165f3a042a59ad0719d3dda2f4df5c5e16ea60 + languageName: node + linkType: hard + "@intlify/shared@npm:9.13.1": version: 9.13.1 resolution: "@intlify/shared@npm:9.13.1" @@ -1358,7 +1385,7 @@ __metadata: resolution: "@intlify/unplugin-vue-i18n@workspace:packages/unplugin-vue-i18n" dependencies: "@intlify/bundle-utils": ^8.0.0 - "@intlify/shared": ^9.4.0 + "@intlify/shared": ^10.0.0-alpha.4 "@rollup/pluginutils": ^5.1.0 "@vue/compiler-sfc": ^3.2.47 debug: ^4.3.3 From b0acc435f096e77b8d757f32e58744941c3462a8 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 15 May 2024 17:16:47 +0900 Subject: [PATCH 2/3] chore: update test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bc5fa4f..a6d4d53b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node: [18.x] + node: [18, 20, 22] steps: - name: Checkout uses: actions/checkout@v4 From e6912d2d20cc8822c8a24e70bad48b0e9b3ad928 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 15 May 2024 18:12:00 +0900 Subject: [PATCH 3/3] fix: bump --- package.json | 4 +- packages/unplugin-vue-i18n/package.json | 2 +- yarn.lock | 75 ++++++++----------------- 3 files changed, 27 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index 71f98408..4633e2b9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ } }, "devDependencies": { - "@intlify/core-base": "^10.0.0-alpha.4", + "@intlify/core-base": "10.0.0-alpha.5", "@kazupon/lerna-changelog": "^4.3.0", "@octokit/rest": "^18.6.0", "@rollup/plugin-alias": "^3.1.5", @@ -83,7 +83,7 @@ "vite": "^4.4.9", "vitest": "^0.29.8", "vue": "^2.6.14", - "vue-i18n": "9.13.1", + "vue-i18n": "10.0.0-alpha.5", "vue-loader": "^16.3.0", "vue-loader15": "npm:vue-loader@15.11.1", "vue-loader17": "npm:vue-loader@17.4.2", diff --git a/packages/unplugin-vue-i18n/package.json b/packages/unplugin-vue-i18n/package.json index 1479e1d2..bf0cb976 100644 --- a/packages/unplugin-vue-i18n/package.json +++ b/packages/unplugin-vue-i18n/package.json @@ -27,7 +27,7 @@ }, "dependencies": { "@intlify/bundle-utils": "^8.0.0", - "@intlify/shared": "^10.0.0-alpha.4", + "@intlify/shared": "^10.0.0-alpha.5", "@rollup/pluginutils": "^5.1.0", "@vue/compiler-sfc": "^3.2.47", "debug": "^4.3.3", diff --git a/yarn.lock b/yarn.lock index 9a4ff2a6..112060d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1211,7 +1211,7 @@ __metadata: version: 0.0.0-use.local resolution: "@intlify/bundle-tools@workspace:." dependencies: - "@intlify/core-base": ^10.0.0-alpha.4 + "@intlify/core-base": 10.0.0-alpha.5 "@kazupon/lerna-changelog": ^4.3.0 "@octokit/rest": ^18.6.0 "@rollup/plugin-alias": ^3.1.5 @@ -1271,7 +1271,7 @@ __metadata: vite: ^4.4.9 vitest: ^0.29.8 vue: ^2.6.14 - vue-i18n: 9.13.1 + vue-i18n: 10.0.0-alpha.5 vue-loader: ^16.3.0 vue-loader15: "npm:vue-loader@15.11.1" vue-loader17: "npm:vue-loader@17.4.2" @@ -1309,43 +1309,23 @@ __metadata: languageName: unknown linkType: soft -"@intlify/core-base@npm:9.13.1": - version: 9.13.1 - resolution: "@intlify/core-base@npm:9.13.1" +"@intlify/core-base@npm:10.0.0-alpha.5": + version: 10.0.0-alpha.5 + resolution: "@intlify/core-base@npm:10.0.0-alpha.5" dependencies: - "@intlify/message-compiler": 9.13.1 - "@intlify/shared": 9.13.1 - checksum: afca8308829efdadb14555da05c7cb12277a829606236833254f35aac2118912e1b3c20e2e0a86a9af3769975a8d6526dcd30b690843bfb7216817cb3a594c43 + "@intlify/message-compiler": 10.0.0-alpha.5 + "@intlify/shared": 10.0.0-alpha.5 + checksum: fb209c08a7fda9d64e195ae23b3879df3681f8a04e2346b350681d4eb476f684aa0049e93b9046bbbadba71d8c99d56796c6bc448f0f8344150e16eee76acd41 languageName: node linkType: hard -"@intlify/core-base@npm:^10.0.0-alpha.4": - version: 10.0.0-alpha.4 - resolution: "@intlify/core-base@npm:10.0.0-alpha.4" +"@intlify/message-compiler@npm:10.0.0-alpha.5": + version: 10.0.0-alpha.5 + resolution: "@intlify/message-compiler@npm:10.0.0-alpha.5" dependencies: - "@intlify/message-compiler": 10.0.0-alpha.4 - "@intlify/shared": 10.0.0-alpha.4 - checksum: 7ef4558ea35c244911477b5e21be69792a4c86876dc28f35b6e68611fd70b6337449b497f955eac750adf43370bf8f6cdcc4af09afeff28b8ee8576edfe8bdb0 - languageName: node - linkType: hard - -"@intlify/message-compiler@npm:10.0.0-alpha.4": - version: 10.0.0-alpha.4 - resolution: "@intlify/message-compiler@npm:10.0.0-alpha.4" - dependencies: - "@intlify/shared": 10.0.0-alpha.4 - source-map-js: ^1.0.2 - checksum: e97c55d478e4837889b9f8dee854196693c7d734e273e94753a961522b8b1932d410fe3fc908ededd38681c13eab0b59fa3385e90ffaa472080480fda4778e30 - languageName: node - linkType: hard - -"@intlify/message-compiler@npm:9.13.1": - version: 9.13.1 - resolution: "@intlify/message-compiler@npm:9.13.1" - dependencies: - "@intlify/shared": 9.13.1 + "@intlify/shared": 10.0.0-alpha.5 source-map-js: ^1.0.2 - checksum: 75fb8625e5907a799834ade3406774996d219cde9aed6369ccf51f37f87e2ce4a05b5c24c010e67a4fcabc8e9af92a2cb28d8fa8e803efc6826250b56b996cea + checksum: 4f3867e20ae2beead07b21e68409771ecbb7368f8eaed1024b524db10e3a9d8353b57f7dba37b0e396774e78463d1b892282a142921bdf15a21ccf1f21be017d languageName: node linkType: hard @@ -1359,17 +1339,10 @@ __metadata: languageName: node linkType: hard -"@intlify/shared@npm:10.0.0-alpha.4, @intlify/shared@npm:^10.0.0-alpha.4": - version: 10.0.0-alpha.4 - resolution: "@intlify/shared@npm:10.0.0-alpha.4" - checksum: 7453a199fa7f0f2be2e14485e376254320ffe130a6608341c94a08eb4a0705edfcabcde82847b5f2c78ad155f1165f3a042a59ad0719d3dda2f4df5c5e16ea60 - languageName: node - linkType: hard - -"@intlify/shared@npm:9.13.1": - version: 9.13.1 - resolution: "@intlify/shared@npm:9.13.1" - checksum: 27f0e351de1fe57955f27076000bb6103fca593049c315d58e01dece2ebd0e25779de28e5586877fd1596d7377f07784014755cdcb64a345e1efe050afadf911 +"@intlify/shared@npm:10.0.0-alpha.5, @intlify/shared@npm:^10.0.0-alpha.5": + version: 10.0.0-alpha.5 + resolution: "@intlify/shared@npm:10.0.0-alpha.5" + checksum: e70aa77783957b8bd09251eada879afbc71019bb98f94e7c2e4471534019d9ac0a0c6c0a14ae75ba09d38a230d3c9ef67389eb490e158aaa309037e3e863775e languageName: node linkType: hard @@ -1385,7 +1358,7 @@ __metadata: resolution: "@intlify/unplugin-vue-i18n@workspace:packages/unplugin-vue-i18n" dependencies: "@intlify/bundle-utils": ^8.0.0 - "@intlify/shared": ^10.0.0-alpha.4 + "@intlify/shared": ^10.0.0-alpha.5 "@rollup/pluginutils": ^5.1.0 "@vue/compiler-sfc": ^3.2.47 debug: ^4.3.3 @@ -13235,16 +13208,16 @@ __metadata: languageName: node linkType: hard -"vue-i18n@npm:9.13.1": - version: 9.13.1 - resolution: "vue-i18n@npm:9.13.1" +"vue-i18n@npm:10.0.0-alpha.5": + version: 10.0.0-alpha.5 + resolution: "vue-i18n@npm:10.0.0-alpha.5" dependencies: - "@intlify/core-base": 9.13.1 - "@intlify/shared": 9.13.1 + "@intlify/core-base": 10.0.0-alpha.5 + "@intlify/shared": 10.0.0-alpha.5 "@vue/devtools-api": ^6.5.0 peerDependencies: vue: ^3.0.0 - checksum: ec62304958cbff5beac8bbe68798b290c31a44dbc7d06ad2f08c978488fc4e7183f44d8b96e46669dd9920d354de0a157b1cd21db3b6c20337ca68a0c12db028 + checksum: 09fe09f934e4b62c8a1a72fa22c6ff31b694971902bcafe63e8ac68e5248899ec2f6440828b63518e60e89f76461f5c0cd6d4be749b0641fb68e5b933eb7607b languageName: node linkType: hard