Repository navigation
Fix database.table.column references throwing to close #2186 - #2578
Open
joshuablac wants to merge 1 commit into
Open
joshuablac wants to merge 1 commit into
joshuablac wants to merge 1 commit into
Conversation
A reference like db.table.column was parsed as (db.table)->column, so the compiled code read p['db']['table'] and threw "Cannot read properties of undefined" in ON, WHERE, ORDER BY and the SELECT list. When compiling the -> operator, a left side "a.b" where "a" is a database and not a source alias, and "b" is a source table, is now compiled as the column a.b.column. alias.column.property keeps working as a property lookup, so the grammar is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #2186
Problem
A three-part
database.table.columnreference throwsCannot read properties of undefined (reading '<table>')wherever it is used, not only inON:Cause
As the issue describes,
db.t1.idis parsed as(db.t1) -> id: a two-part column (tableid: 'db',columnid: 't1') followed by a property access. The compiled code readsp['db']['t1'], which is undefined.Why this doesn't use the grammar change from the issue
I tried the change the issue proposes (
%nonassoc LOW_PRECplusLiteral DOT Literal %prec LOW_PREC). It fixesdb.table.column, and the existing suite still passes. But it breaksalias.column.property, which works ondevelopand has no test:The parser can't tell
db.table.colfromalias.col.prop, because the difference depends on what the names refer to. So I resolve it at compile time instead.Fix
In
Op.toJSfor->, a left sidea.bis compiled as the columna.b.<right>only when all of these hold:ais not a source alias of the queryais an existing databasebis a source of the queryEvery other
->compiles exactly as before. The only expressions whose behavior changes are ones that throw today. No grammar change.Note: an unaliased
SELECT db.t1.id FROM db.t1gets the keydb.t1->id, the same automatic naming any->expression gets. UseASfor a clean name.Tests
test/test2186.js(named after theA_2186/B_2186tables from the issue):database.table.columninON, in theSELECTlist,WHEREandORDER BY, and withUSE <db>alias.column.property(t.obj.x,t.obj.y.z, and thet.obj->xkey name) behaves as beforedevelopand pass with this change.bun test, same command asyarn test-only): 2253 pass, 213 skip. The only failures are the 2 CLI tests intest2149.js, which fail the same way on unmodifieddevelopin my local setup (a space in my checkout path, and the version-injection step ofbuild.shnot running).This fix was written with AI assistance (Claude Code) and verified locally as described above.
🤖 Generated with Claude Code