diff --git a/packages/core-base/src/compilation.ts b/packages/core-base/src/compilation.ts index b4cc80e17..dd8a79736 100644 --- a/packages/core-base/src/compilation.ts +++ b/packages/core-base/src/compilation.ts @@ -52,13 +52,13 @@ function baseCompile( return { ...baseCompileCore(message, options), detectError } } -export function compileToFunction< +export const compileToFunction = /* #__PURE__*/ < Message = string, MessageSource = string | ResourceNode >( message: MessageSource, context: MessageCompilerContext -): MessageFunction { +): MessageFunction => { if (!isString(message)) { throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE) } @@ -107,8 +107,10 @@ export function compile< context: MessageCompilerContext ): MessageFunction { if ( - __FEATURE_JIT_COMPILATION__ && - !__FEATURE_DROP_MESSAGE_COMPILER__ && + (__ESM_BROWSER__ || + __NODE_JS__ || + __GLOBAL__ || + (__FEATURE_JIT_COMPILATION__ && !__FEATURE_DROP_MESSAGE_COMPILER__)) && isString(message) ) { // check HTML message diff --git a/packages/core/package.json b/packages/core/package.json index 95409d695..1d26f597f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -66,8 +66,8 @@ "default": "./index.js" } }, - "import": "./dist/core.mjs", - "browser": "./dist/core.esm-browser.js" + "browser": "./dist/core.esm-browser.js", + "import": "./dist/core.mjs" }, "./dist/*": "./dist/*", "./package.json": "./package.json" diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 48f252050..d7f7450ad 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -14,10 +14,15 @@ if (__ESM_BUNDLER__ && !__TEST__) { } // register message compiler at @intlify/core -if (!__FEATURE_JIT_COMPILATION__) { - registerMessageCompiler(compileToFunction) -} else { +if ( + __ESM_BROWSER__ || + __NODE_JS__ || + __GLOBAL__ || + __FEATURE_JIT_COMPILATION__ +) { registerMessageCompiler(compile) +} else { + registerMessageCompiler(compileToFunction) } // register message resolver at @intlify/core diff --git a/packages/global.d.ts b/packages/global.d.ts index 1ad88252f..3c474c2a8 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -5,6 +5,7 @@ declare let __BROWSER__: boolean declare let __GLOBAL__: boolean declare let __RUNTIME__: boolean declare let __ESM_BUNDLER__: boolean +declare let __ESM_BROWSER__: boolean declare let __NODE_JS__: boolean declare let __LITE__: boolean declare let __BRIDGE__: boolean diff --git a/packages/petite-vue-i18n/src/index.ts b/packages/petite-vue-i18n/src/index.ts index 75a6c7a3a..75e376e12 100644 --- a/packages/petite-vue-i18n/src/index.ts +++ b/packages/petite-vue-i18n/src/index.ts @@ -12,10 +12,15 @@ if (__ESM_BUNDLER__ && !__TEST__) { } // register message compiler at petite-vue-i18n -if (!__FEATURE_JIT_COMPILATION__) { - registerMessageCompiler(compileToFunction) -} else { +if ( + __ESM_BROWSER__ || + __NODE_JS__ || + __GLOBAL__ || + __FEATURE_JIT_COMPILATION__ +) { registerMessageCompiler(compile) +} else { + registerMessageCompiler(compileToFunction) } export { diff --git a/packages/vue-i18n-bridge/src/index.ts b/packages/vue-i18n-bridge/src/index.ts index 438f929eb..ba7d9d37b 100644 --- a/packages/vue-i18n-bridge/src/index.ts +++ b/packages/vue-i18n-bridge/src/index.ts @@ -16,10 +16,15 @@ if (__ESM_BUNDLER__ && !__TEST__) { } // register message compiler at vue-i18n -if (!__FEATURE_JIT_COMPILATION__) { - registerMessageCompiler(compileToFunction) -} else { +if ( + __ESM_BROWSER__ || + __NODE_JS__ || + __GLOBAL__ || + __FEATURE_JIT_COMPILATION__ +) { registerMessageCompiler(compile) +} else { + registerMessageCompiler(compileToFunction) } // register message resolver at vue-i18n diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index 5e1f2870d..7eca5d985 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -16,10 +16,15 @@ if (__ESM_BUNDLER__ && !__TEST__) { } // register message compiler at vue-i18n -if (!__FEATURE_JIT_COMPILATION__) { - registerMessageCompiler(compileToFunction) -} else { +if ( + __ESM_BROWSER__ || + __NODE_JS__ || + __GLOBAL__ || + __FEATURE_JIT_COMPILATION__ +) { registerMessageCompiler(compile) +} else { + registerMessageCompiler(compileToFunction) } // register message resolver at vue-i18n