Skip to content

Commit 832167e

Browse files
committed
Add .raw property to tagged template fn call
1 parent 8e68fed commit 832167e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/query-builder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type FragmentBuilder = {
4949
* This is intended to take a tagged template tag function.
5050
*/
5151
toTaggedTemplate: <T>(
52-
tag: (strings: string[], ...bindings: string[]) => T,
52+
tag: (strings: TemplateStringsArray, ...bindings: string[]) => T,
5353
) => T;
5454
toRaw: () => RawFragment;
5555
};
@@ -114,11 +114,14 @@ export class QueryBuilder {
114114
};
115115
},
116116
toTaggedTemplate: <T>(
117-
tag: (strings: string[], ..._bindings: string[]) => T,
117+
tag: (strings: TemplateStringsArray, ..._bindings: string[]) => T,
118118
) => {
119119
onUsage();
120120

121-
return tag(buildStrings(), ...bindings);
121+
const raw = buildStrings();
122+
const strings = [...raw] as string[] & { raw: string[] };
123+
strings.raw = raw;
124+
return tag(strings, ...bindings);
122125
},
123126
withArrayBindings: ({ placeholder: userPlaceholder = '?' } = {}) => {
124127
if (typeof userPlaceholder !== 'function') {

src/sql-cursor-pagination.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ describe('SqlCursorPagination', () => {
112112
}),
113113
).toMatchSnapshot();
114114
expect(
115-
builder.toTaggedTemplate((strings, ...bindings) => ({
116-
bindings,
117-
strings,
118-
})),
115+
builder.toTaggedTemplate((strings, ...bindings) => {
116+
expect(Array.isArray(strings)).toBe(true);
117+
expect(strings.raw).toStrictEqual([...strings]);
118+
return {
119+
bindings,
120+
strings,
121+
};
122+
}),
119123
).toMatchSnapshot();
120124
};
121125

0 commit comments

Comments
 (0)