Skip to content

Commit

Permalink
Merge pull request #1855 from effigies/fix/shadow-columns-size
Browse files Browse the repository at this point in the history
FIX: Shadow size property of columns object, so it acts as a column
  • Loading branch information
rwblair authored Dec 14, 2023
2 parents 3501e79 + ac49a6e commit f52eec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bids-validator/src/types/columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ Deno.test('ColumnsMap', async (t) => {
assertEquals(Object.keys(columns), ['a', 'b', '0'])
assertEquals(Object.getOwnPropertyNames(columns), ['a', 'b', '0'])
})
await t.step('size columns are permissible', () => {
const columns = new ColumnsMap()
// @ts-expect-error
columns['size'] = ['0']
// @ts-expect-error
assertEquals(columns.size, ['0'])
})
await t.step('missing columns are undefined', () => {
const columns = new ColumnsMap()
columns['a'] = ['0']
assertEquals(columns.b, undefined)
assertEquals(columns.size, undefined)
})
})
2 changes: 2 additions & 0 deletions bids-validator/src/types/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const columnMapAccessorProxy = {
prop: symbol | string,
receiver: ColumnsMap,
) {
// Map.size exists, so we need to shadow it with the column contents
if (prop === 'size') return target.get('size')
const value = Reflect.get(target, prop, receiver)
if (typeof value === 'function') return value.bind(target)
if (prop === Symbol.iterator) return target[Symbol.iterator].bind(target)
Expand Down

0 comments on commit f52eec4

Please sign in to comment.