mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user