|
1 | | -import { warn, format, isBoolean, isString } from '@intlify/shared' |
| 1 | +import { warn, format, isObject, isBoolean, isString } from '@intlify/shared' |
2 | 2 | import { |
3 | 3 | baseCompile as baseCompileCore, |
4 | 4 | defaultOnError, |
@@ -31,6 +31,11 @@ export function clearCompileCache(): void { |
31 | 31 | compileCache = Object.create(null) |
32 | 32 | } |
33 | 33 |
|
| 34 | +export const isMessageAST = (val: unknown): val is ResourceNode => |
| 35 | + isObject(val) && |
| 36 | + (val.t === 0 || val.type === 0) && |
| 37 | + ('b' in val || 'body' in val) |
| 38 | + |
34 | 39 | function baseCompile( |
35 | 40 | message: string, |
36 | 41 | options: CompileOptions = {} |
@@ -101,7 +106,11 @@ export function compile< |
101 | 106 | message: MessageSource, |
102 | 107 | context: MessageCompilerContext |
103 | 108 | ): MessageFunction<Message> { |
104 | | - if (isString(message)) { |
| 109 | + if ( |
| 110 | + __FEATURE_JIT_COMPILATION__ && |
| 111 | + !__FEATURE_DROP_MESSAGE_COMPILER__ && |
| 112 | + isString(message) |
| 113 | + ) { |
105 | 114 | // check HTML message |
106 | 115 | const warnHtmlMessage = isBoolean(context.warnHtmlMessage) |
107 | 116 | ? context.warnHtmlMessage |
@@ -131,6 +140,13 @@ export function compile< |
131 | 140 | ? ((compileCache as MessageFunctions<Message>)[cacheKey] = msg) |
132 | 141 | : msg |
133 | 142 | } else { |
| 143 | + if (__DEV__ && !isMessageAST(message)) { |
| 144 | + warn( |
| 145 | + `the message that is resolve with key '${context.key}') is not supported for jit compilation` |
| 146 | + ) |
| 147 | + return (() => message) as MessageFunction<Message> |
| 148 | + } |
| 149 | + |
134 | 150 | // AST case (passed from bundler) |
135 | 151 | const cacheKey = (message as unknown as ResourceNode).cacheKey |
136 | 152 | if (cacheKey) { |
|
0 commit comments