@@ -28,6 +28,13 @@ const ALLOW_ANNOTATION = '// sql-date-bound:'
2828const DRIZZLE_MODULE = 'drizzle-orm'
2929const STATEMENT_TYPE = / ( S t a t e m e n t | D e c l a r a t i o n ) $ /
3030
31+ function isDrizzleModule ( value : unknown ) : value is string {
32+ return (
33+ typeof value === 'string' &&
34+ ( value === DRIZZLE_MODULE || value . startsWith ( `${ DRIZZLE_MODULE } /` ) )
35+ )
36+ }
37+
3138interface Violation {
3239 file : string
3340 line : number
@@ -223,10 +230,7 @@ function collectSqlBindings(program: SyntaxNode): SqlBindings {
223230 const visit = ( node : SyntaxNode ) => {
224231 if ( node . type === 'ImportDeclaration' && isSyntaxNode ( node . source ) ) {
225232 const source = node . source . value
226- const isDrizzle =
227- typeof source === 'string' &&
228- ( source === DRIZZLE_MODULE || source . startsWith ( `${ DRIZZLE_MODULE } /` ) )
229- if ( isDrizzle && Array . isArray ( node . specifiers ) ) {
233+ if ( isDrizzleModule ( source ) && Array . isArray ( node . specifiers ) ) {
230234 for ( const specifier of node . specifiers ) {
231235 if ( ! isSyntaxNode ( specifier ) || ! isSyntaxNode ( specifier . local ) ) continue
232236 const local = specifier . local . name
@@ -270,10 +274,7 @@ function isDrizzleImportCall(node: unknown): boolean {
270274 const args = Array . isArray ( current . arguments ) ? current . arguments : [ ]
271275 const source = isSyntaxNode ( current . source ) ? current . source : args . find ( isSyntaxNode )
272276 const value = source ?. value
273- return (
274- typeof value === 'string' &&
275- ( value === DRIZZLE_MODULE || value . startsWith ( `${ DRIZZLE_MODULE } /` ) )
276- )
277+ return isDrizzleModule ( value )
277278}
278279
279280const unwrapAwait = ( node : SyntaxNode ) : unknown =>
@@ -562,7 +563,7 @@ export function mayBindDrizzleSql(source: string): boolean {
562563 if (
563564 ( token === ts . SyntaxKind . StringLiteral ||
564565 token === ts . SyntaxKind . NoSubstitutionTemplateLiteral ) &&
565- value === DRIZZLE_MODULE
566+ isDrizzleModule ( value )
566567 ) {
567568 hasDrizzleModule = true
568569 }
0 commit comments