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:
Steve Stedman
2021-09-30 22:15:09 +08:00
committed by Jun Yang
co-authored by harttle
parent 9012133e07
commit fb787e8847
3 changed files with 39 additions and 9 deletions
+5 -2
View File
@@ -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)