fix: enumerate Promises (e.g. in for & tablerow) (#237)

* fix: enumerate Promise<array> (e.g. in {% for ... %})

Previously, a Promise of an array was not being enumerated in
{% for %}, for example. This is misleading since the library
handles promises elsewhere (e.g. if you {% assign x = promiseArray %}
and then {% for v in x %}, it worked just fine.

This PR makes Promises of arrays handled by changing toEnumerable
to handle then-ables. This affects other iterators, too, e.g. tablerow,
so I put in a test for that as well.
This commit is contained in:
Tejas Manohar
2020-06-28 09:55:56 +08:00
committed by GitHub
parent 11ffd65503
commit 941dd668fe
4 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ export default {
},
render: function * (ctx: Context, emitter: Emitter) {
const r = this.liquid.renderer
let collection = toEnumerable(evalToken(this.collection, ctx))
let collection = toEnumerable(yield evalToken(this.collection, ctx))
if (!collection.length) {
yield r.renderTemplates(this.elseTemplates, ctx, emitter)
+1 -1
View File
@@ -30,7 +30,7 @@ export default {
},
render: function * (ctx: Context, emitter: Emitter) {
let collection = toEnumerable(evalToken(this.collection, ctx))
let collection = toEnumerable(yield evalToken(this.collection, ctx))
const hash = yield this.hash.render(ctx)
const offset = hash.offset || 0
const limit = (hash.limit === undefined) ? collection.length : hash.limit