Skip to content

Commit e53b83c

Browse files
aslakhellesoymattbaileyuk
authored andcommitted
Await array elements
1 parent 9e1523d commit e53b83c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/jsonata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ var jsonata = (function() {
397397
// count in from end of array
398398
index = input.length + index;
399399
}
400-
var item = input[index];
400+
var item = await input[index];
401401
if(typeof item !== 'undefined') {
402402
if(Array.isArray(item)) {
403403
results = item;

test/async-function.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,13 @@ describe('Handle chained functions that end in promises', function() {
176176
});
177177

178178
});
179+
180+
describe('Async array', function() {
181+
it('should revaluate array items', async function() {
182+
var data = {
183+
list: [Promise.resolve({name: 'hello'})]
184+
};
185+
var expr = jsonata('list[0].name');
186+
return expect(expr.evaluate(data)).to.eventually.equal('hello');
187+
});
188+
});

0 commit comments

Comments
 (0)