mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: inconsistent continue behaviour, fixes #779
This commit is contained in:
@@ -25,6 +25,8 @@ export class Context {
|
||||
*/
|
||||
public globals: Scope
|
||||
public sync: boolean
|
||||
public breakCalled = false
|
||||
public continueCalled = false
|
||||
/**
|
||||
* The normalized liquid options object
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ export class Render {
|
||||
const html = yield tpl.render(ctx, emitter)
|
||||
// if not, it'll return an `html`, write to the emitter for it
|
||||
html && emitter.write(html)
|
||||
if (emitter['break'] || emitter['continue']) break
|
||||
if (ctx.breakCalled || ctx.continueCalled) break
|
||||
} catch (e) {
|
||||
const err = LiquidError.is(e) ? e : new RenderError(e as Error, tpl)
|
||||
if (ctx.opts.catchAllErrors) errors.push(err)
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { Context, Emitter, Tag } from '..'
|
||||
|
||||
export default class extends Tag {
|
||||
render (ctx: Context, emitter: Emitter) {
|
||||
emitter['break'] = true
|
||||
render (ctx: Context, _emitter: Emitter) {
|
||||
ctx.breakCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Tag, Emitter, Context } from '..'
|
||||
|
||||
export default class extends Tag {
|
||||
render (ctx: Context, emitter: Emitter) {
|
||||
emitter['continue'] = true
|
||||
render (ctx: Context, _emitter: Emitter) {
|
||||
ctx.continueCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -68,12 +68,9 @@ export default class extends Tag {
|
||||
ctx.push(scope)
|
||||
for (const item of collection) {
|
||||
scope[this.variable] = item
|
||||
ctx.continueCalled = ctx.breakCalled = false
|
||||
yield r.renderTemplates(this.templates, ctx, emitter)
|
||||
if (emitter['break']) {
|
||||
emitter['break'] = false
|
||||
break
|
||||
}
|
||||
emitter['continue'] = false
|
||||
if (ctx.breakCalled) break
|
||||
scope.forloop.next()
|
||||
}
|
||||
ctx.pop()
|
||||
|
||||
Reference in New Issue
Block a user