@@ -86,7 +86,7 @@ export class Context {
8686 public * _getFromScope ( scope : unknown , paths : ( PropertyKey | Drop ) [ ] | string , strictVariables = this . strictVariables ) : IterableIterator < unknown > {
8787 if ( isString ( paths ) ) paths = paths . split ( '.' )
8888 for ( let i = 0 ; i < paths . length ; i ++ ) {
89- scope = yield readProperty ( scope as object , paths [ i ] , this . ownPropertyOnly )
89+ scope = yield this . readProperty ( scope as object , paths [ i ] )
9090 if ( strictVariables && isUndefined ( scope ) ) {
9191 throw new InternalUndefinedVariableError ( ( paths as string [ ] ) . slice ( 0 , i + 1 ) . join ! ( '.' ) )
9292 }
@@ -120,21 +120,21 @@ export class Context {
120120 if ( key in this . environments ) return this . environments
121121 return this . globals
122122 }
123+ readProperty ( obj : Scope , key : ( PropertyKey | Drop ) ) {
124+ obj = toLiquid ( obj )
125+ key = toValue ( key ) as PropertyKey
126+ if ( isNil ( obj ) ) return obj
127+ if ( isArray ( obj ) && ( key as number ) < 0 ) return obj [ obj . length + + key ]
128+ const value = readJSProperty ( obj , key , this . ownPropertyOnly )
129+ if ( value === undefined && obj instanceof Drop ) return obj . liquidMethodMissing ( key , this )
130+ if ( isFunction ( value ) ) return value . call ( obj )
131+ if ( key === 'size' ) return readSize ( obj )
132+ else if ( key === 'first' ) return readFirst ( obj )
133+ else if ( key === 'last' ) return readLast ( obj )
134+ return value
135+ }
123136}
124137
125- export function readProperty ( obj : Scope , key : ( PropertyKey | Drop ) , ownPropertyOnly : boolean ) {
126- obj = toLiquid ( obj )
127- key = toValue ( key ) as PropertyKey
128- if ( isNil ( obj ) ) return obj
129- if ( isArray ( obj ) && ( key as number ) < 0 ) return obj [ obj . length + + key ]
130- const value = readJSProperty ( obj , key , ownPropertyOnly )
131- if ( value === undefined && obj instanceof Drop ) return obj . liquidMethodMissing ( key )
132- if ( isFunction ( value ) ) return value . call ( obj )
133- if ( key === 'size' ) return readSize ( obj )
134- else if ( key === 'first' ) return readFirst ( obj )
135- else if ( key === 'last' ) return readLast ( obj )
136- return value
137- }
138138export function readJSProperty ( obj : Scope , key : PropertyKey , ownPropertyOnly : boolean ) {
139139 if ( ownPropertyOnly && ! hasOwnProperty . call ( obj , key ) && ! ( obj instanceof Drop ) ) return undefined
140140 return obj [ key ]
0 commit comments