Skip to content

Commit

Permalink
fix(transloco): 🐛 allow multiple functions functional transpiler (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielDHH authored and shaharkazaz committed Aug 2, 2023
1 parent ddebbff commit 5095f96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions libs/transloco/src/lib/tests/transpiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe('TranslocoTranspiler', () => {
expect(parsed).toEqual('LOWERCASE');
});

it('should work with multiple functions', () => {
const parsed = parser.transpile('first [[ upperCase(second) ]] third [[ upperCase(fourth) ]] fifth', {}, {}, 'key');
expect(parsed).toEqual('first SECOND third FOURTH fifth');
});

it('should pass the function params', () => {
const spy = spyOn(transpilerFunctions['upperCase'], 'transpile');
parser.transpile('[[ upperCase(lowercase) ]]', {}, {}, 'key');
Expand Down
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco.transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class FunctionalTranspiler
let transpiled = value;
if (isString(value)) {
transpiled = value.replace(
/\[\[\s*(\w+)\((.*)\)\s*]]/g,
/\[\[\s*(\w+)\((.*?)\)\s*]]/g,
(match: string, functionName: string, args: string) => {
try {
const func: TranslocoTranspilerFunction =
Expand Down

0 comments on commit 5095f96

Please sign in to comment.