Skip to content

Commit 02324a5

Browse files
authored
Merge pull request #155 from effigies/fix/set-columns
fix: Allow TSV files to have column names matching Map instance methods
2 parents 3a66a21 + 6b522ff commit 02324a5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/types/columns.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Deno.test('ColumnsMap', async (t) => {
3737
// @ts-expect-error ibid
3838
assertEquals(columns.size, ['0'])
3939
})
40+
await t.step('set columns are permissible', () => {
41+
const columns = new ColumnsMap()
42+
// @ts-expect-error ts thinks size is protected property
43+
columns['set'] = ['0']
44+
// @ts-expect-error ibid
45+
assertEquals(columns.set, ['0'])
46+
})
4047
await t.step('missing columns are undefined', () => {
4148
const columns = new ColumnsMap()
4249
columns['a'] = ['0']

src/types/columns.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ const columnMapAccessorProxy = {
1515
prop: symbol | string,
1616
receiver: ColumnsMap,
1717
) {
18-
// Map.size exists, so we need to shadow it with the column contents
19-
if (prop === 'size') return target.get('size')
18+
// Map instance methods/properties that could plasubily be column names:
19+
if (
20+
['clear', 'delete', 'keys', 'set', 'values', 'size'].includes(
21+
prop as string,
22+
)
23+
) {
24+
return target.get(prop as string)
25+
}
2026
const value = Reflect.get(target, prop, receiver)
2127
if (typeof value === 'function') return value.bind(target)
2228
if (prop === Symbol.iterator) return target[Symbol.iterator].bind(target)

0 commit comments

Comments
 (0)