Skip to content

Commit

Permalink
refactor: change ownPropertyOnly default value to true
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ownPropertyOnly` default value changed to `true`
  • Loading branch information
harttle committed Nov 27, 2022
1 parent ffefd91 commit 7eb6216
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ export class Context {
}

export function readProperty (obj: Scope, key: PropertyKey, ownPropertyOnly: boolean) {
if (isNil(obj)) return obj
obj = toLiquid(obj)
if (isNil(obj)) return obj
if (isArray(obj) && key < 0) return obj[obj.length + +key]
const jsProperty = readJSProperty(obj, key, ownPropertyOnly)
if (jsProperty === undefined && obj instanceof Drop) return obj.liquidMethodMissing(key)
if (isFunction(jsProperty)) return jsProperty.call(obj)
const value = readJSProperty(obj, key, ownPropertyOnly)
if (value === undefined && obj instanceof Drop) return obj.liquidMethodMissing(key)
if (isFunction(value)) return value.call(obj)
if (key === 'size') return readSize(obj)
else if (key === 'first') return readFirst(obj)
else if (key === 'last') return readLast(obj)
return jsProperty
return value
}
export function readJSProperty (obj: Scope, key: PropertyKey, ownPropertyOnly: boolean) {
if (ownPropertyOnly && !Object.hasOwnProperty.call(obj, key)) return undefined
if (ownPropertyOnly && !Object.hasOwnProperty.call(obj, key) && !(obj instanceof Drop)) return undefined
return obj[key]
}

Expand Down
2 changes: 1 addition & 1 deletion src/liquid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const defaultOptions: NormalizedFullOptions = {
preserveTimezones: false,
strictFilters: false,
strictVariables: false,
ownPropertyOnly: false,
ownPropertyOnly: true,
lenientIf: false,
globals: {},
keepOutputType: false,
Expand Down

0 comments on commit 7eb6216

Please sign in to comment.