Skip to content

Commit 02f3854

Browse files
committed
Fix wrong helper selection on multiple occurances
1 parent 0f0af92 commit 02f3854

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const builders = Object.entries({
172172
).join(',') + ')values' +
173173
valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options)
174174
}
175-
}).map(([x, fn]) => ([new RegExp('(^|[\\s(])' + x + '($|[\\s(])', 'i'), fn]))
175+
}).map(([x, fn]) => ([new RegExp('((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)', 'i'), fn]))
176176

177177
function notTagged() {
178178
throw Errors.generic('NOT_TAGGED_CALL', 'Query not called as a tagged template literal')

tests/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,3 +2140,16 @@ t('Does not try rollback when commit errors', async() => {
21402140
await sql`drop table test`
21412141
]
21422142
})
2143+
2144+
t('Last keyword used even with duplicate keywords', async() => {
2145+
await sql`create table test (x int);`
2146+
await sql`insert into test values(1)`
2147+
const [{ x }] = await sql`
2148+
select
2149+
1 in (1) as x
2150+
from test
2151+
where x in ${ sql([1, 2]) }
2152+
`
2153+
2154+
return [x, true]
2155+
})

0 commit comments

Comments
 (0)