Skip to content

Commit

Permalink
Merge pull request #155 from effigies/fix/set-columns
Browse files Browse the repository at this point in the history
fix: Allow TSV files to have column names matching Map instance methods
  • Loading branch information
effigies authored Feb 9, 2025
2 parents 3a66a21 + 6b522ff commit 02324a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/types/columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Deno.test('ColumnsMap', async (t) => {
// @ts-expect-error ibid
assertEquals(columns.size, ['0'])
})
await t.step('set columns are permissible', () => {
const columns = new ColumnsMap()
// @ts-expect-error ts thinks size is protected property
columns['set'] = ['0']
// @ts-expect-error ibid
assertEquals(columns.set, ['0'])
})
await t.step('missing columns are undefined', () => {
const columns = new ColumnsMap()
columns['a'] = ['0']
Expand Down
10 changes: 8 additions & 2 deletions src/types/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ 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')
// Map instance methods/properties that could plasubily be column names:
if (
['clear', 'delete', 'keys', 'set', 'values', 'size'].includes(
prop as string,
)
) {
return target.get(prop as string)
}
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 02324a5

Please sign in to comment.