mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: allow {%render%} to reassign argument, #404
This commit is contained in:
committed by
Harttle
parent
432d1c7ccb
commit
124f4c4485
@@ -1,3 +1,4 @@
|
||||
import { __assign } from 'tslib'
|
||||
import { assert } from '../../util/assert'
|
||||
import { ForloopDrop } from '../../drop/forloop-drop'
|
||||
import { toEnumerable } from '../../util/collection'
|
||||
@@ -51,12 +52,12 @@ export default {
|
||||
assert(filepath, () => `illegal filename "${filepath}"`)
|
||||
|
||||
const childCtx = new Context({}, ctx.opts, ctx.sync)
|
||||
const scope = yield hash.render(ctx)
|
||||
const scope = childCtx.bottom()
|
||||
__assign(scope, yield hash.render(ctx))
|
||||
if (this['with']) {
|
||||
const { value, alias } = this['with']
|
||||
scope[alias || filepath] = evalToken(value, ctx)
|
||||
}
|
||||
childCtx.push(scope)
|
||||
|
||||
if (this['for']) {
|
||||
const { value, alias } = this['for']
|
||||
@@ -67,7 +68,7 @@ export default {
|
||||
scope[alias] = item
|
||||
const templates = yield liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile'])
|
||||
yield liquid.renderer.renderTemplates(templates, childCtx, emitter)
|
||||
scope.forloop.next()
|
||||
scope['forloop'].next()
|
||||
}
|
||||
} else {
|
||||
const templates = yield liquid._parsePartialFile(filepath, childCtx.sync, this['currentFile'])
|
||||
|
||||
@@ -6,9 +6,21 @@ import { isArray, isNil, isString, isFunction, toLiquid } from '../util/undersco
|
||||
import { InternalUndefinedVariableError } from '../util/error'
|
||||
|
||||
export class Context {
|
||||
/**
|
||||
* insert a Context-level empty scope,
|
||||
* for tags like {% capture %} {% assign %} to operate
|
||||
*/
|
||||
private scopes: Scope[] = [{}]
|
||||
private registers = {}
|
||||
/**
|
||||
* user passed in scope
|
||||
* {% increment %}, {% decrement %} changes this scope,
|
||||
* whereas {% capture %}, {% assign %} only hide this scope
|
||||
*/
|
||||
public environments: Scope
|
||||
/**
|
||||
* global scope used as fallback for missing variables
|
||||
*/
|
||||
public globals: Scope
|
||||
public sync: boolean
|
||||
public opts: NormalizedFullOptions
|
||||
|
||||
@@ -55,7 +55,7 @@ export interface LiquidOptions {
|
||||
greedy?: boolean;
|
||||
/** `fs` is used to override the default file-system module with a custom implementation. */
|
||||
fs?: FS;
|
||||
/** the global environment passed down to all partial templates, i.e. templates included by `include`, `layout` and `render` tags. */
|
||||
/** the global scope passed down to all partial and layout templates, i.e. templates included by `include`, `layout` and `render` tags. */
|
||||
globals?: object;
|
||||
/** Whether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to `false`. */
|
||||
keepOutputType?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user