Skip to content

Commit

Permalink
fix: make is* method not throw
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed May 13, 2024
1 parent 2c120c2 commit 0378001
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-cooks-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slonik/sql-tag": patch
---

is\* method must not throw
10 changes: 3 additions & 7 deletions packages/sql-tag/src/utilities/isSqlToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,19 @@ export const isSqlToken = (subject: unknown): subject is SqlTokenType => {
}

if (!hasOwnProperty(subject, 'type')) {
throw new UnexpectedStateError(
'Expected token to include "type" property.',
);
return false;
}

const tokenType = subject.type;

if (typeof tokenType !== 'symbol') {
throw new UnexpectedStateError('Expected type to be symbol.');
return false;
}

const tokenTypeName = Symbol.keyFor(tokenType);

if (typeof tokenTypeName !== 'string') {
throw new UnexpectedStateError(
'Expected token type to be a symbol with inferrable key',
);
return false;
}

// It is worth clarifying that we don't care if symbols match.
Expand Down

0 comments on commit 0378001

Please sign in to comment.