Skip to content

Commit ec8ff1c

Browse files
author
isc-auf
committed
feat(transloco): transpile function arguments in FunctionalTranspiler (#829)
Signed-off-by: isc-auf <[email protected]>
1 parent a16c3ab commit ec8ff1c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

libs/transloco/src/lib/tests/transpiler.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ describe('TranslocoTranspiler', () => {
114114
);
115115
});
116116

117+
it('should transpile the function params', () => {
118+
const spy = spyOn(transpilerFunctions['upperCase'], 'transpile');
119+
transpiler.transpile(getTranspilerParams('[[ upperCase(lowercase) ]]'));
120+
expect(spy).toHaveBeenCalledWith('lowercase');
121+
spy.calls.reset();
122+
transpiler.transpile(
123+
getTranspilerParams(
124+
'[[ upperCase(lowercase, {{person}}, {{ anotherParson.name }}) ]]',
125+
{
126+
params: { person: 'Shahar', anotherParson: { name: 'Netanel' } },
127+
},
128+
),
129+
);
130+
expect(spy as any).toHaveBeenCalledWith('lowercase', 'Shahar', 'Netanel');
131+
});
132+
117133
it('should work with interpolation params', () => {
118134
const parsed = transpiler.transpile(
119135
getTranspilerParams('[[ testParams(and {{anotherParson}}) ]]', {

libs/transloco/src/lib/transloco.transpiler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ export class FunctionalTranspiler
181181
const func: TranslocoTranspilerFunction =
182182
this.injector.get(functionName);
183183

184-
return func.transpile(...getFunctionArgs(args));
184+
return func.transpile(
185+
...getFunctionArgs(args).map((arg) =>
186+
this.transpile({ value: arg, ...rest }),
187+
),
188+
);
185189
} catch (e: unknown) {
186190
let message = `There is an error in: '${value}'.
187191
Check that the you used the right syntax in your translation and that the implementation of ${functionName} is correct.`;

0 commit comments

Comments
 (0)