Skip to content

Commit 6b2d1a6

Browse files
refactor(mf2): Move MessageValue definition to its own file
1 parent 8127579 commit 6b2d1a6

File tree

13 files changed

+37
-43
lines changed

13 files changed

+37
-43
lines changed

mf2/messageformat/src/format-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MessageValue } from './functions/index.js';
1+
import type { MessageValue } from './message-value.js';
22
import type { MessageFunctions } from './messageformat.js';
33

44
export interface Context {

mf2/messageformat/src/functions/datetime.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { getLocaleDir } from '../dir-utils.js';
12
import { MessageResolutionError } from '../errors.js';
23
import type { MessageExpressionPart } from '../formatted-parts.js';
3-
import { getLocaleDir } from '../dir-utils.js';
4-
import type { MessageFunctionContext, MessageValue } from './index.js';
4+
import type { MessageValue } from '../message-value.js';
5+
import type { MessageFunctionContext } from '../resolve/function-context.js';
56
import {
67
asBoolean,
78
asPositiveInteger,

mf2/messageformat/src/functions/fallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MessageExpressionPart } from '../formatted-parts.js';
2-
import type { MessageValue } from './index.js';
2+
import type { MessageValue } from '../message-value.js';
33

44
/**
55
* Used to represent runtime/formatting errors.
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
import type { MessageExpressionPart } from '../formatted-parts.js';
2-
1+
export type { MessageValue } from '../message-value.js';
32
export type { MessageFunctionContext } from '../resolve/function-context.js';
43
export { currency } from './currency.js';
5-
export { type MessageDateTime, date, datetime, time } from './datetime.js';
6-
export { type MessageFallback, fallback } from './fallback.js';
4+
export { date, datetime, time, type MessageDateTime } from './datetime.js';
5+
export { fallback, type MessageFallback } from './fallback.js';
76
export { math } from './math.js';
8-
export { type MessageNumber, integer, number } from './number.js';
9-
export { type MessageString, string } from './string.js';
10-
export { type MessageUnknownValue, unknown } from './unknown.js';
11-
12-
export interface MessageValue {
13-
readonly type: string;
14-
readonly source: string;
15-
readonly locale: string;
16-
readonly dir?: 'ltr' | 'rtl' | 'auto';
17-
readonly options?: Readonly<object>;
18-
selectKey?: (keys: Set<string>) => string | null;
19-
toParts?: () => MessageExpressionPart[];
20-
toString?: () => string;
21-
valueOf?: () => unknown;
22-
}
7+
export { integer, number, type MessageNumber } from './number.js';
8+
export { string, type MessageString } from './string.js';
9+
export { unknown, type MessageUnknownValue } from './unknown.js';

mf2/messageformat/src/functions/number.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { getLocaleDir } from '../dir-utils.js';
12
import { MessageResolutionError } from '../errors.js';
23
import type { MessageExpressionPart } from '../formatted-parts.js';
3-
import { getLocaleDir } from '../dir-utils.js';
4-
import type { MessageFunctionContext, MessageValue } from './index.js';
4+
import type { MessageValue } from '../message-value.js';
5+
import type { MessageFunctionContext } from '../resolve/function-context.js';
56
import { asPositiveInteger, asString, mergeLocales } from './utils.js';
67

78
/** @beta */

mf2/messageformat/src/functions/string.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { MessageExpressionPart } from '../formatted-parts.js';
2-
import type { MessageFunctionContext, MessageValue } from './index.js';
2+
import type { MessageValue } from '../message-value.js';
3+
import type { MessageFunctionContext } from '../resolve/function-context.js';
34
import { mergeLocales } from './utils.js';
45

56
/** @beta */

mf2/messageformat/src/functions/test-functions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { MessageResolutionError } from '../errors.js';
9-
import type { MessageFunctionContext, MessageValue } from './index.js';
9+
import type { MessageValue } from '../message-value.js';
10+
import type { MessageFunctionContext } from '../resolve/function-context.js';
1011
import { asPositiveInteger, asString } from './utils.js';
1112

1213
interface TestValue extends MessageValue {

mf2/messageformat/src/functions/unknown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MessageExpressionPart } from '../formatted-parts.js';
2-
import type { MessageValue } from './index.js';
2+
import type { MessageValue } from '../message-value.js';
33

44
/** @beta */
55
export interface MessageUnknownValue extends MessageValue {

mf2/messageformat/src/messageformat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { MessageDataModelError, MessageError } from './errors.js';
66
import type { Context } from './format-context.js';
77
import type { MessagePart } from './formatted-parts.js';
88
import {
9-
MessageValue,
109
currency,
1110
date,
1211
datetime,
@@ -16,6 +15,7 @@ import {
1615
string,
1716
time
1817
} from './functions/index.js';
18+
import type { MessageValue } from './message-value.js';
1919
import { formatMarkup } from './resolve/format-markup.js';
2020
import type { MessageFunctionContext } from './resolve/function-context.js';
2121
import { resolveExpression } from './resolve/resolve-expression.js';

mf2/messageformat/src/mf2-features.test.mts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import {
77
import { parse } from '@messageformat/parser';
88
import { source } from '~/test/utils/source.js';
99

10+
import type {
11+
MessageFunctionContext,
12+
MessageValue
13+
} from './functions/index.js';
1014
import {
15+
MessageBiDiIsolationPart,
1116
MessageExpressionPart,
1217
MessageFormat,
1318
MessageLiteralPart,
1419
SelectMessage
1520
} from './index.js';
16-
import type {
17-
MessageFunctionContext,
18-
MessageValue
19-
} from './functions/index.js';
2021

2122
describe('Plural Range Selectors & Range Formatters (unicode-org/message-format-wg#125)', () => {
2223
function range(
@@ -288,7 +289,9 @@ maybe('List formatting', () => {
288289
describe('Neighbouring text transformations (unicode-org/message-format-wg#160)', () => {
289290
function hackyFixArticles(
290291
locales: string[],
291-
parts: Array<MessageExpressionPart | MessageLiteralPart>
292+
parts: Array<
293+
MessageExpressionPart | MessageLiteralPart | MessageBiDiIsolationPart
294+
>
292295
) {
293296
if (locales[0] !== 'en') throw new Error('Only English supported');
294297
if (!parts) return;

0 commit comments

Comments
 (0)