@@ -7,6 +7,10 @@ import {
77 TRANSLOCO_CONFIG ,
88 TranslocoConfig ,
99} from './transloco.config' ;
10+ import {
11+ formatTranslocoError ,
12+ TranslocoErrorCode ,
13+ } from './transloco-error-code' ;
1014
1115export const TRANSLOCO_TRANSPILER = new InjectionToken < TranslocoTranspiler > (
1216 typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_TRANSPILER' : '' ,
@@ -164,6 +168,8 @@ export function getFunctionArgs(argsString: string): string[] {
164168 return args ;
165169}
166170
171+ const functionalCallRegExp = / \[ \[ \s * ( \w + ) \( ( .* ?) \) \s * ] ] / g;
172+
167173@Injectable ( )
168174export class FunctionalTranspiler
169175 extends DefaultTranspiler
@@ -175,19 +181,27 @@ export class FunctionalTranspiler
175181 let transpiled = value ;
176182 if ( isString ( value ) ) {
177183 transpiled = value . replace (
178- / \[ \[ \s * ( \w + ) \( ( . * ? ) \) \s * ] ] / g ,
184+ functionalCallRegExp ,
179185 ( match : string , functionName : string , args : string ) => {
180186 try {
181187 const func : TranslocoTranspilerFunction =
182188 this . injector . get ( functionName ) ;
183189
184190 return func . transpile ( ...getFunctionArgs ( args ) ) ;
185191 } catch ( e : unknown ) {
186- let message = `There is an error in: '${ value } '.
192+ let message : string ;
193+ if ( typeof ngDevMode !== 'undefined' && ngDevMode ) {
194+ message = `There is an error in: '${ value } '.
187195 Check that the you used the right syntax in your translation and that the implementation of ${ functionName } is correct.` ;
188- if ( ( e as Error ) . message . includes ( 'NullInjectorError' ) ) {
189- message = `You are using the '${ functionName } ' function in your translation but no provider was found!` ;
196+ if ( ( e as Error ) . message . includes ( 'NullInjectorError' ) ) {
197+ message = `You are using the '${ functionName } ' function in your translation but no provider was found!` ;
198+ }
199+ } else {
200+ message = formatTranslocoError (
201+ TranslocoErrorCode . FunctionalTranspilerInvalidSyntax ,
202+ ) ;
190203 }
204+
191205 throw new Error ( message ) ;
192206 }
193207 } ,
0 commit comments