Skip to content

Commit 4d48ced

Browse files
committed
_functions = {NUMBER, DATETIME, ...functions}
1 parent 03ea7a0 commit 4d48ced

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

fluent-bundle/src/bundle.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Scope } from "./scope.js";
33
import { FluentResource } from "./resource.js";
44
import { FluentValue, FluentNone, FluentFunction } from "./types.js";
55
import { Message, Term, Pattern } from "./ast.js";
6+
import { NUMBER, DATETIME } from "./builtins.js";
67

78
export type TextTransform = (text: string) => string;
89

@@ -54,7 +55,7 @@ export class FluentBundle {
5455
constructor(
5556
locales: string | Array<string>,
5657
{
57-
functions = {},
58+
functions,
5859
useIsolating = true,
5960
transform = (v: string): string => v
6061
}: {
@@ -64,7 +65,11 @@ export class FluentBundle {
6465
} = {}
6566
) {
6667
this.locales = Array.isArray(locales) ? locales : [locales];
67-
this._functions = functions;
68+
this._functions = {
69+
NUMBER,
70+
DATETIME,
71+
...functions
72+
};
6873
this._useIsolating = useIsolating;
6974
this._transform = transform;
7075
}

fluent-bundle/src/resolver.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
FluentNumber,
3232
FluentDateTime
3333
} from "./types.js";
34-
import { NUMBER, DATETIME } from "./builtins.js";
3534
import { Scope } from "./scope.js";
3635
import {
3736
Variant,
@@ -266,17 +265,8 @@ function resolveFunctionReference(
266265
// the `FluentBundle` constructor.
267266
let func = scope.bundle._functions[name];
268267
if (!func) {
269-
switch (name) {
270-
case "NUMBER":
271-
func = NUMBER;
272-
break;
273-
case "DATETIME":
274-
func = DATETIME;
275-
break;
276-
default:
277-
scope.reportError(new ReferenceError(`Unknown function: ${name}()`));
278-
return new FluentNone(`${name}()`);
279-
}
268+
scope.reportError(new ReferenceError(`Unknown function: ${name}()`));
269+
return new FluentNone(`${name}()`);
280270
}
281271

282272
if (typeof func !== "function") {

0 commit comments

Comments
 (0)