mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
Fix: respect parameter order when using "for ... reversed" (#231)
* fix: spelling * fix: respect param order for reversed * docs: add for-reversed order details * perf: improve performance by 4x by simplified parseFile BREAKING CHANGES: - previously deprecated `getTemplate()` and `getTemplateSync()` not no longer supported - `opts` no longer support dynamic set in `parseFile()`, `renderFile()` arguments * perf: parse filenames in parse() insteadof render() * docs: update description of LiquidJS Co-authored-by: harttle <[email protected]>
This commit is contained in:
committed by
Jun Yang
co-authored by
harttle
parent
9012133e07
commit
fb787e8847
@@ -18,7 +18,7 @@ export default {
|
||||
|
||||
this.variable = variable.content
|
||||
this.collection = collection
|
||||
this.hash = new Hash(toknenizer.remaining())
|
||||
this.hash = new Hash(tokenizer.remaining())
|
||||
this.templates = []
|
||||
this.elseTemplates = []
|
||||
|
||||
@@ -46,9 +46,12 @@ export default {
|
||||
const hash = yield this.hash.render(ctx)
|
||||
const offset = hash.offset || 0
|
||||
const limit = (hash.limit === undefined) ? collection.length : hash.limit
|
||||
const reversedIndex = Reflect.ownKeys(hash).indexOf('reversed')
|
||||
|
||||
// reverse collection before slicing if 'reversed' is 1st parameter
|
||||
if (reversedIndex === 0) collection.reverse()
|
||||
collection = collection.slice(offset, offset + limit)
|
||||
if ('reversed' in hash) collection.reverse()
|
||||
if (reversedIndex > 0) collection.reverse()
|
||||
|
||||
const scope = { forloop: new ForloopDrop(collection.length) }
|
||||
ctx.push(scope)
|
||||
|
||||
Reference in New Issue
Block a user