@@ -79,7 +79,7 @@ function getDefault(scope, variants, star) {
7979 return resolvePattern ( scope , variants [ star ] . value ) ;
8080 }
8181
82- scope . errors . push ( new RangeError ( "No default" ) ) ;
82+ scope . reportError ( new RangeError ( "No default" ) ) ;
8383 return new FluentNone ( ) ;
8484}
8585
@@ -127,7 +127,7 @@ function resolveExpression(scope, expr) {
127127function VariableReference ( scope , { name} ) {
128128 if ( ! scope . args || ! scope . args . hasOwnProperty ( name ) ) {
129129 if ( scope . insideTermReference === false ) {
130- scope . errors . push ( new ReferenceError ( `Unknown variable: ${ name } ` ) ) ;
130+ scope . reportError ( new ReferenceError ( `Unknown variable: ${ name } ` ) ) ;
131131 }
132132 return new FluentNone ( `$${ name } ` ) ;
133133 }
@@ -150,7 +150,7 @@ function VariableReference(scope, {name}) {
150150 return new FluentDateTime ( arg ) ;
151151 }
152152 default :
153- scope . errors . push (
153+ scope . reportError (
154154 new TypeError ( `Unsupported variable type: ${ name } , ${ typeof arg } ` )
155155 ) ;
156156 return new FluentNone ( `$${ name } ` ) ;
@@ -161,7 +161,7 @@ function VariableReference(scope, {name}) {
161161function MessageReference ( scope , { name, attr} ) {
162162 const message = scope . bundle . _messages . get ( name ) ;
163163 if ( ! message ) {
164- scope . errors . push ( new ReferenceError ( `Unknown message: ${ name } ` ) ) ;
164+ scope . reportError ( new ReferenceError ( `Unknown message: ${ name } ` ) ) ;
165165 return new FluentNone ( name ) ;
166166 }
167167
@@ -170,15 +170,15 @@ function MessageReference(scope, {name, attr}) {
170170 if ( attribute ) {
171171 return resolvePattern ( scope , attribute ) ;
172172 }
173- scope . errors . push ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
173+ scope . reportError ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
174174 return new FluentNone ( `${ name } .${ attr } ` ) ;
175175 }
176176
177177 if ( message . value ) {
178178 return resolvePattern ( scope , message . value ) ;
179179 }
180180
181- scope . errors . push ( new ReferenceError ( `No value: ${ name } ` ) ) ;
181+ scope . reportError ( new ReferenceError ( `No value: ${ name } ` ) ) ;
182182 return new FluentNone ( name ) ;
183183}
184184
@@ -187,21 +187,20 @@ function TermReference(scope, {name, attr, args}) {
187187 const id = `-${ name } ` ;
188188 const term = scope . bundle . _terms . get ( id ) ;
189189 if ( ! term ) {
190- const err = new ReferenceError ( `Unknown term: ${ id } ` ) ;
191- scope . errors . push ( err ) ;
190+ scope . reportError ( new ReferenceError ( `Unknown term: ${ id } ` ) ) ;
192191 return new FluentNone ( id ) ;
193192 }
194193
195- // Every TermReference has its own args .
196- const [ , keyargs ] = getArguments ( scope , args ) ;
197- const local = { ... scope , args : keyargs , insideTermReference : true } ;
194+ // Every TermReference has its own variables .
195+ const [ , params ] = getArguments ( scope , args ) ;
196+ const local = scope . cloneForTermReference ( params ) ;
198197
199198 if ( attr ) {
200199 const attribute = term . attributes [ attr ] ;
201200 if ( attribute ) {
202201 return resolvePattern ( local , attribute ) ;
203202 }
204- scope . errors . push ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
203+ scope . reportError ( new ReferenceError ( `Unknown attribute: ${ attr } ` ) ) ;
205204 return new FluentNone ( `${ id } .${ attr } ` ) ;
206205 }
207206
@@ -214,12 +213,12 @@ function FunctionReference(scope, {name, args}) {
214213 // the `FluentBundle` constructor.
215214 const func = scope . bundle . _functions [ name ] || builtins [ name ] ;
216215 if ( ! func ) {
217- scope . errors . push ( new ReferenceError ( `Unknown function: ${ name } ()` ) ) ;
216+ scope . reportError ( new ReferenceError ( `Unknown function: ${ name } ()` ) ) ;
218217 return new FluentNone ( `${ name } ()` ) ;
219218 }
220219
221220 if ( typeof func !== "function" ) {
222- scope . errors . push ( new TypeError ( `Function ${ name } () is not callable` ) ) ;
221+ scope . reportError ( new TypeError ( `Function ${ name } () is not callable` ) ) ;
223222 return new FluentNone ( `${ name } ()` ) ;
224223 }
225224
@@ -252,7 +251,7 @@ function SelectExpression(scope, {selector, variants, star}) {
252251// Resolve a pattern (a complex string with placeables).
253252export function resolveComplexPattern ( scope , ptn ) {
254253 if ( scope . dirty . has ( ptn ) ) {
255- scope . errors . push ( new RangeError ( "Cyclic reference" ) ) ;
254+ scope . reportError ( new RangeError ( "Cyclic reference" ) ) ;
256255 return new FluentNone ( ) ;
257256 }
258257
0 commit comments