Skip to content

Commit 7c3e629

Browse files
authored
fix(core-base): isMessageAST more strictly (#1509)
1 parent 3846acd commit 7c3e629

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/core-base/src/translate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const isMessageFunction = <T>(val: unknown): val is MessageFunction<T> =>
5555
isFunction(val)
5656

5757
export const isMessageAST = (val: unknown): val is ResourceNode =>
58-
isObject(val) && val.type === 0 && 'body' in val
58+
isObject(val) && val.type === 0 && ('body' in val || 'b' in val)
5959

6060
/**
6161
* # translate

packages/core-base/test/translate.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vi.mock('@intlify/shared', async () => {
1313
})
1414

1515
import { createCoreContext as context, NOT_REOSLVED } from '../src/context'
16-
import { translate } from '../src/translate'
16+
import { translate, isMessageAST } from '../src/translate'
1717
import { CoreErrorCodes, errorMessages } from '../src/errors'
1818
import {
1919
registerMessageCompiler,
@@ -992,4 +992,24 @@ describe('AST passing', () => {
992992
})
993993
})
994994

995+
describe('isMessageAST', () => {
996+
describe('basic AST', () => {
997+
test('should be true', () => {
998+
expect(isMessageAST({ type: 0, body: '' })).toBe(true)
999+
})
1000+
})
1001+
1002+
describe('minify AST', () => {
1003+
test('should be true', () => {
1004+
expect(isMessageAST({ type: 0, b: '' })).toBe(true)
1005+
})
1006+
})
1007+
1008+
describe('not message compiler AST format', () => {
1009+
test('should be false', () => {
1010+
expect(isMessageAST({ b: '' })).toBe(false)
1011+
})
1012+
})
1013+
})
1014+
9951015
/* eslint-enable @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any */

0 commit comments

Comments
 (0)