Skip to content

Commit

Permalink
improvement: tweak compilation register and message condition on comp…
Browse files Browse the repository at this point in the history
…ile function (#1532)
  • Loading branch information
kazupon authored Sep 8, 2023
1 parent f2e38ac commit 6e294c7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
10 changes: 6 additions & 4 deletions packages/core-base/src/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> {
): MessageFunction<Message> => {
if (!isString(message)) {
throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE)
}
Expand Down Expand Up @@ -107,8 +107,10 @@ export function compile<
context: MessageCompilerContext
): MessageFunction<Message> {
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
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions packages/petite-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions packages/vue-i18n-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions packages/vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e294c7

Please sign in to comment.