diff --git a/.changeset/tough-cooks-accept.md b/.changeset/tough-cooks-accept.md new file mode 100644 index 00000000..04500f9e --- /dev/null +++ b/.changeset/tough-cooks-accept.md @@ -0,0 +1,5 @@ +--- +"@slonik/sql-tag": patch +--- + +is\* method must not throw diff --git a/packages/sql-tag/src/utilities/isSqlToken.ts b/packages/sql-tag/src/utilities/isSqlToken.ts index 7bef4549..d39a3938 100644 --- a/packages/sql-tag/src/utilities/isSqlToken.ts +++ b/packages/sql-tag/src/utilities/isSqlToken.ts @@ -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.