@@ -47,16 +47,6 @@ const FSI = "\u2068";
47
47
const PDI = "\u2069" ;
48
48
49
49
50
- // Helper: Report an error.
51
- function report ( scope , error ) {
52
- if ( scope . errors ) {
53
- scope . errors . push ( error ) ;
54
- } else {
55
- throw error ;
56
- }
57
- }
58
-
59
-
60
50
// Helper: match a variant key to the given selector.
61
51
function match ( bundle , selector , key ) {
62
52
if ( key === selector ) {
@@ -89,7 +79,7 @@ function getDefault(scope, variants, star) {
89
79
return resolvePattern ( scope , variants [ star ] . value ) ;
90
80
}
91
81
92
- report ( scope , new RangeError ( "No default" ) ) ;
82
+ scope . reportError ( new RangeError ( "No default" ) ) ;
93
83
return new FluentNone ( ) ;
94
84
}
95
85
@@ -137,7 +127,7 @@ function resolveExpression(scope, expr) {
137
127
function VariableReference ( scope , { name} ) {
138
128
if ( ! scope . args || ! scope . args . hasOwnProperty ( name ) ) {
139
129
if ( scope . insideTermReference === false ) {
140
- report ( scope , new ReferenceError ( `Unknown variable: ${ name } ` ) ) ;
130
+ scope . reportError ( new ReferenceError ( `Unknown variable: ${ name } ` ) ) ;
141
131
}
142
132
return new FluentNone ( `$${ name } ` ) ;
143
133
}
@@ -160,7 +150,7 @@ function VariableReference(scope, {name}) {
160
150
return new FluentDateTime ( arg ) ;
161
151
}
162
152
default :
163
- report ( scope ,
153
+ scope . reportError (
164
154
new TypeError ( `Unsupported variable type: ${ name } , ${ typeof arg } ` )
165
155
) ;
166
156
return new FluentNone ( `$${ name } ` ) ;
@@ -171,7 +161,7 @@ function VariableReference(scope, {name}) {
171
161
function MessageReference ( scope , { name, attr} ) {
172
162
const message = scope . bundle . _messages . get ( name ) ;
173
163
if ( ! message ) {
174
- report ( scope , new ReferenceError ( `Unknown message: ${ name } ` ) ) ;
164
+ scope . reportError ( new ReferenceError ( `Unknown message: ${ name } ` ) ) ;
175
165
return new FluentNone ( name ) ;
176
166
}
177
167
@@ -180,15 +170,15 @@ function MessageReference(scope, {name, attr}) {
180
170
if ( attribute ) {
181
171
return resolvePattern ( scope , attribute ) ;
182
172
}
183
- report ( scope , new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
173
+ scope . reportError ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
184
174
return new FluentNone ( `${ name } .${ attr } ` ) ;
185
175
}
186
176
187
177
if ( message . value ) {
188
178
return resolvePattern ( scope , message . value ) ;
189
179
}
190
180
191
- report ( scope , new ReferenceError ( `No value: ${ name } ` ) ) ;
181
+ scope . reportError ( new ReferenceError ( `No value: ${ name } ` ) ) ;
192
182
return new FluentNone ( name ) ;
193
183
}
194
184
@@ -197,20 +187,20 @@ function TermReference(scope, {name, attr, args}) {
197
187
const id = `-${ name } ` ;
198
188
const term = scope . bundle . _terms . get ( id ) ;
199
189
if ( ! term ) {
200
- report ( scope , new ReferenceError ( `Unknown term: ${ id } ` ) ) ;
190
+ scope . reportError ( new ReferenceError ( `Unknown term: ${ id } ` ) ) ;
201
191
return new FluentNone ( id ) ;
202
192
}
203
193
204
194
// Every TermReference has its own args.
205
195
const [ , keyargs ] = getArguments ( scope , args ) ;
206
- const local = { ... scope , args : keyargs , insideTermReference : true } ;
196
+ const local = scope . clone ( keyargs ) ;
207
197
208
198
if ( attr ) {
209
199
const attribute = term . attributes [ attr ] ;
210
200
if ( attribute ) {
211
201
return resolvePattern ( local , attribute ) ;
212
202
}
213
- report ( scope , new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
203
+ scope . reportError ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
214
204
return new FluentNone ( `${ id } .${ attr } ` ) ;
215
205
}
216
206
@@ -223,12 +213,12 @@ function FunctionReference(scope, {name, args}) {
223
213
// the `FluentBundle` constructor.
224
214
const func = scope . bundle . _functions [ name ] || builtins [ name ] ;
225
215
if ( ! func ) {
226
- report ( scope , new ReferenceError ( `Unknown function: ${ name } ()` ) ) ;
216
+ scope . reportError ( new ReferenceError ( `Unknown function: ${ name } ()` ) ) ;
227
217
return new FluentNone ( `${ name } ()` ) ;
228
218
}
229
219
230
220
if ( typeof func !== "function" ) {
231
- report ( scope , new TypeError ( `Function ${ name } () is not callable` ) ) ;
221
+ scope . reportError ( new TypeError ( `Function ${ name } () is not callable` ) ) ;
232
222
return new FluentNone ( `${ name } ()` ) ;
233
223
}
234
224
@@ -261,7 +251,7 @@ function SelectExpression(scope, {selector, variants, star}) {
261
251
// Resolve a pattern (a complex string with placeables).
262
252
export function resolveComplexPattern ( scope , ptn ) {
263
253
if ( scope . dirty . has ( ptn ) ) {
264
- report ( scope , new RangeError ( "Cyclic reference" ) ) ;
254
+ scope . reportError ( new RangeError ( "Cyclic reference" ) ) ;
265
255
return new FluentNone ( ) ;
266
256
}
267
257
0 commit comments