Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libs/transloco/src/lib/tests/transpiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ describe('TranslocoTranspiler', () => {
);
});

it('should transpile the function params', () => {
const spy = spyOn(transpilerFunctions['upperCase'], 'transpile');
transpiler.transpile(getTranspilerParams('[[ upperCase(lowercase) ]]'));
expect(spy).toHaveBeenCalledWith('lowercase');
spy.calls.reset();
transpiler.transpile(
getTranspilerParams(
'[[ upperCase(lowercase, {{person}}, {{ anotherParson.name }}) ]]',
{
params: { person: 'Shahar', anotherParson: { name: 'Netanel' } },
},
),
);
expect(spy as any).toHaveBeenCalledWith('lowercase', 'Shahar', 'Netanel');
});

it('should work with interpolation params', () => {
const parsed = transpiler.transpile(
getTranspilerParams('[[ testParams(and {{anotherParson}}) ]]', {
Expand Down
6 changes: 5 additions & 1 deletion libs/transloco/src/lib/transloco.transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ export class FunctionalTranspiler
const func: TranslocoTranspilerFunction =
this.injector.get(functionName);

return func.transpile(...getFunctionArgs(args));
const transpiledArgs = this.transpile({
value: getFunctionArgs(args),
...rest,
});
return func.transpile(...transpiledArgs);
} catch (e: unknown) {
let message = `There is an error in: '${value}'.
Check that the you used the right syntax in your translation and that the implementation of ${functionName} is correct.`;
Expand Down