File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Scope } from "./scope.js";
3
3
import { FluentResource } from "./resource.js" ;
4
4
import { FluentValue , FluentNone , FluentFunction } from "./types.js" ;
5
5
import { Message , Term , Pattern } from "./ast.js" ;
6
+ import { NUMBER , DATETIME } from "./builtins.js" ;
6
7
7
8
export type TextTransform = ( text : string ) => string ;
8
9
@@ -54,7 +55,7 @@ export class FluentBundle {
54
55
constructor (
55
56
locales : string | Array < string > ,
56
57
{
57
- functions = { } ,
58
+ functions,
58
59
useIsolating = true ,
59
60
transform = ( v : string ) : string => v
60
61
} : {
@@ -64,7 +65,11 @@ export class FluentBundle {
64
65
} = { }
65
66
) {
66
67
this . locales = Array . isArray ( locales ) ? locales : [ locales ] ;
67
- this . _functions = functions ;
68
+ this . _functions = {
69
+ NUMBER ,
70
+ DATETIME ,
71
+ ...functions
72
+ } ;
68
73
this . _useIsolating = useIsolating ;
69
74
this . _transform = transform ;
70
75
}
Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ import {
31
31
FluentNumber ,
32
32
FluentDateTime
33
33
} from "./types.js" ;
34
- import { NUMBER , DATETIME } from "./builtins.js" ;
35
34
import { Scope } from "./scope.js" ;
36
35
import {
37
36
Variant ,
@@ -266,17 +265,8 @@ function resolveFunctionReference(
266
265
// the `FluentBundle` constructor.
267
266
let func = scope . bundle . _functions [ name ] ;
268
267
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 } ()` ) ;
280
270
}
281
271
282
272
if ( typeof func !== "function" ) {
You can’t perform that action at this time.
0 commit comments