Skip to content

Commit ef54e72

Browse files
fixed issue with calling functions in templates (#32)
1 parent 9493fb8 commit ef54e72

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

CHANGELOG.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to the "@qavajs/memory" will be documented in this file.
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## [1.10.2]
8+
- :beetle: fixed issue with calling functions in templates
9+
710
## [1.10.1]
811
- :beetle: fixed issue with parsing json
912

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/memory",
3-
"version": "1.10.1",
3+
"version": "1.10.2",
44
"description": "memory package for @qavajs framework",
55
"main": "index.js",
66
"scripts": {

src/memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Memory {
6565
@readonly
6666
getString(str: string): any {
6767
const getFunction = new Function(
68-
`return \`${str.replaceAll(`{$`, '${this.')}\``
68+
`return \`${str.replaceAll('$', 'this.').replaceAll('{this.', '${this.')}\``
6969
.replace(UNESCAPE_DOLLAR_REGEXP, '$')
7070
);
7171
try {

tests/memory.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ test('resolve json', () => {
338338
expect(memory.getValue(json)).to.equal('{"email": "random+random"}');
339339
});
340340

341+
test('resolve template with function', () => {
342+
memory.setValue('x', (text: string) => text);
343+
memory.setValue('y', 42);
344+
const expression = 'text {$x($y)}';
345+
expect(memory.getValue(expression)).to.equal('text 42');
346+
});
347+
348+
341349

342350

343351

0 commit comments

Comments
 (0)