@@ -3,7 +3,7 @@ import { Drop } from '../drop/drop'
3
3
import { __assign } from 'tslib'
4
4
import { NormalizedFullOptions , defaultOptions , RenderOptions } from '../liquid-options'
5
5
import { Scope } from './scope'
6
- import { hasOwnProperty , isArray , isNil , isUndefined , isString , isFunction , toLiquid , InternalUndefinedVariableError , toValueSync , isObject , Limiter } from '../util'
6
+ import { hasOwnProperty , isArray , isNil , isUndefined , isString , isFunction , toLiquid , InternalUndefinedVariableError , toValueSync , isObject , Limiter , toValue } from '../util'
7
7
8
8
type PropertyKey = string | number ;
9
9
@@ -71,8 +71,8 @@ export class Context {
71
71
public getSync ( paths : PropertyKey [ ] ) : unknown {
72
72
return toValueSync ( this . _get ( paths ) )
73
73
}
74
- public * _get ( paths : PropertyKey [ ] ) : IterableIterator < unknown > {
75
- const scope = this . findScope ( paths [ 0 ] )
74
+ public * _get ( paths : ( PropertyKey | Drop ) [ ] ) : IterableIterator < unknown > {
75
+ const scope = this . findScope ( paths [ 0 ] as string ) // first prop should always be a string
76
76
return yield this . _getFromScope ( scope , paths )
77
77
}
78
78
/**
@@ -81,7 +81,7 @@ export class Context {
81
81
public getFromScope ( scope : unknown , paths : PropertyKey [ ] | string ) : IterableIterator < unknown > {
82
82
return toValueSync ( this . _getFromScope ( scope , paths ) )
83
83
}
84
- public * _getFromScope ( scope : unknown , paths : PropertyKey [ ] | string , strictVariables = this . strictVariables ) : IterableIterator < unknown > {
84
+ public * _getFromScope ( scope : unknown , paths : ( PropertyKey | Drop ) [ ] | string , strictVariables = this . strictVariables ) : IterableIterator < unknown > {
85
85
if ( isString ( paths ) ) paths = paths . split ( '.' )
86
86
for ( let i = 0 ; i < paths . length ; i ++ ) {
87
87
scope = yield readProperty ( scope as object , paths [ i ] , this . ownPropertyOnly )
@@ -120,8 +120,9 @@ export class Context {
120
120
}
121
121
}
122
122
123
- export function readProperty ( obj : Scope , key : PropertyKey , ownPropertyOnly : boolean ) {
123
+ export function readProperty ( obj : Scope , key : ( PropertyKey | Drop ) , ownPropertyOnly : boolean ) {
124
124
obj = toLiquid ( obj )
125
+ key = toValue ( key ) as PropertyKey
125
126
if ( isNil ( obj ) ) return obj
126
127
if ( isArray ( obj ) && ( key as number ) < 0 ) return obj [ obj . length + + key ]
127
128
const value = readJSProperty ( obj , key , ownPropertyOnly )
0 commit comments