Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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));
return func.transpile(
...getFunctionArgs(args).map((arg) =>
this.transpile({ value: arg, ...rest }),
),
Copy link
Collaborator

@shaharkazaz shaharkazaz Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question here do we want to support nested function transpilations? I'm not sure that would actually work.
Add a test case, if that works, cool. otherwise let's skip directly to the parent transpiler

const transpiledArgs = super.transpile({value: getFunctionArgs(args), ...rest});
return func.transpile(...transpiledArgs);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. As far as I can tell, this PR doesn't implements nesting function because getFunctionArgs use a simple pattern to separate the args, namely on comma. A regexp engine with support of nesting would be needed. I sure can look into that, but I could also live with this limitation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the changes and test the pkg-pr-new release

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure what do you want me to do / change? I think the original code with the map call should do it... Thks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call the super like in the code I suggested

);
} 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
Loading