fix(string): keep a quoted identifier out of the comment scan - #345
Merged
Conversation
// DB has a column literally named a--b
StrictRow<DB, 'select "a--b" from users'>
// was QueryTypeError<'no FROM clause: cannot resolve column ""a"'>
StripCommentsAndMaskLiterals had no double-quote awareness, so the `--`
inside a quoted name was taken as a line comment and swallowed the rest of
the query, and the `'` in `"it's"` opened a string-literal mask. Quoted
identifiers are the library's documented escape hatch for special names, and
these are exactly the names that need it. MaskQuotedIdentifiers already
exists to protect `;` from the same class of scan; this extends that
treatment to the comment/literal pass, which runs first.
The scan now destructures the leading character once and dispatches on it,
instead of matching the whole string against one pattern per case. Written
the original way, the three new quote cases measured +15,778 instantiations;
keyed on the character the step already read, the whole scan comes in at
184,737 against master's 192,486 - 7,749 cheaper than before the fix.
Fixes #287
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/287-quoted-identifier-comments
branch
from
August 2, 2026 13:04
9aac309 to
80838cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #287.
The bug
The
--inside the quotes was taken as a line comment and ate the rest of the query; the'opened a string-literal mask. Quoted identifiers are the documented escape hatch for special names, and these are exactly the names that need it.The fix
StripCommentsAndMaskLiteralsnow recognizes the three identifier quotes and copies the body through verbatim — nothing inside a quoted name opens a comment or a literal.MaskQuotedIdentifiersalready exists to protect;from the same class of scan (#232); this extends that treatment to the pass that runs before it.The structure of the scan changed with it, and it is the reason this is not expensive. Written as three more whole-string pattern matches per step, the fix measured 208,264 instantiations — over the 200,000 budget. Destructuring the leading character once and dispatching on it (
Opener extends "'",Opener extends '-', …) makes every case a character comparison instead of a pattern match:So the fix lands 7,749 below master.
Verification
tests/quoted-identifier-punctuation.test-d.ts, eleven cases. Six red on master:"a--b"in both modes,"it's","a/*b","a$b", and one among ordinary columns--comment and a real'x'literal in the same query as a quoted name still workControls: plain
"id",[weird-table]and`id`are unchanged.tsc --noEmitclean, 192 runtime tests pass.