mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: "ownPropertyOnly" not respected when passed via "renderOptions"
This commit is contained in:
@@ -32,12 +32,14 @@ export class Context {
|
|||||||
* Throw when accessing undefined variable?
|
* Throw when accessing undefined variable?
|
||||||
*/
|
*/
|
||||||
public strictVariables: boolean;
|
public strictVariables: boolean;
|
||||||
|
public ownPropertyOnly: boolean;
|
||||||
public constructor (env: object = {}, opts: NormalizedFullOptions = defaultOptions, renderOptions: RenderOptions = {}) {
|
public constructor (env: object = {}, opts: NormalizedFullOptions = defaultOptions, renderOptions: RenderOptions = {}) {
|
||||||
this.sync = !!renderOptions.sync
|
this.sync = !!renderOptions.sync
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.globals = renderOptions.globals ?? opts.globals
|
this.globals = renderOptions.globals ?? opts.globals
|
||||||
this.environments = env
|
this.environments = env
|
||||||
this.strictVariables = renderOptions.strictVariables ?? this.opts.strictVariables
|
this.strictVariables = renderOptions.strictVariables ?? this.opts.strictVariables
|
||||||
|
this.ownPropertyOnly = renderOptions.ownPropertyOnly ?? opts.ownPropertyOnly
|
||||||
}
|
}
|
||||||
public getRegister (key: string) {
|
public getRegister (key: string) {
|
||||||
return (this.registers[key] = this.registers[key] || {})
|
return (this.registers[key] = this.registers[key] || {})
|
||||||
@@ -74,7 +76,7 @@ export class Context {
|
|||||||
public * _getFromScope (scope: unknown, paths: PropertyKey[] | string): IterableIterator<unknown> {
|
public * _getFromScope (scope: unknown, paths: PropertyKey[] | string): IterableIterator<unknown> {
|
||||||
if (isString(paths)) paths = paths.split('.')
|
if (isString(paths)) paths = paths.split('.')
|
||||||
for (let i = 0; i < paths.length; i++) {
|
for (let i = 0; i < paths.length; i++) {
|
||||||
scope = yield readProperty(scope as object, paths[i], this.opts.ownPropertyOnly)
|
scope = yield readProperty(scope as object, paths[i], this.ownPropertyOnly)
|
||||||
if (isNil(scope) && this.strictVariables) {
|
if (isNil(scope) && this.strictVariables) {
|
||||||
throw new InternalUndefinedVariableError((paths as string[]).slice(0, i + 1).join!('.'))
|
throw new InternalUndefinedVariableError((paths as string[]).slice(0, i + 1).join!('.'))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user