Skip to content
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

improvement: tweak compler registration and message condition on compile function #1532

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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