Repository navigation
fix(mapper): keep diagnostics inside the file - #20
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
I reviewed both commits. They fix the TS100025 transform rejection for .sql files that end inside an open quote or comment.
- Lexer offsets (
engine/core/src/lex.rs): unterminated strings,E''strings, quoted identifiers and both block comment forms now report the offset of their opening token. They used to reportb.len()or the scan position, andanalysis.rs/mysql.rsthen turned that into alength: 1diagnostic one byte past the end of the file. The oldE'…\case could even land atlen + 1. That case is covered now too. - Mapper clamp (
src/mapper.ts,withinFileinsrc/module-types.ts): every diagnostic's range is clamped toBuffer.byteLength(sql). That matches the mapper'spositionEncoding: "utf-8", so no future engine diagnostic can invalidate a transform. - Tests (
tests/unterminated.test.ts, lexer unit tests): these run realtsc --runExternalCodeand use@ts-expect-errorto prove each module stays typed. I rannode --test tests/unterminated.test.tslocally: the SQLite case and thewithinFileunit test pass, and the Postgres case was skipped because no server was available. No other copy of the old(at byte N)text exists in the oracle or test fixtures.
claude-opus-5-5 | 𝕏
5bb6ffa to
3620d0b
Compare
There was a problem hiding this comment.
✅ No new issues found. The push since the last review rebases onto
mainand rebuilds the engine artifacts.
Reviewed changes
Since the prior review, the branch has been rebased onto main (237e417) and the three engine binaries have been rebuilt.
- Rebased the two commits unchanged:
git range-diffshows both commits as identical.lex.rs,mapper.ts,module-types.tsandtests/unterminated.test.tshave the same blob hashes as at5bb6ffa. - Rebuilt
packages/{mysql,postgres,sqlite}/engine.wasmon top of #7: these are the only changed blobs. I checked that each binary carries both sets of changes:- #7's engine code: the
odd_pairsmessage ("takes keys and values in pairs") is in the postgres and sqlite wasm. MySQL never callsodd_pairs, so it is correctly absent there. - This PR's lexer offsets: I loaded each wasm through
Engineand rananalyzeonselect 1, 'abc, a quoted name, a block comment and anE''string. Every one returnsstart: 10on all three dialects. - End-to-end test:
node --test tests/unterminated.test.tsstill passes on SQLite, together with thewithinFileunit test. The Postgres case was skipped because no server was available.
- #7's engine code: the
claude-opus-5-5 | 𝕏
3620d0b to
0beb0c8
Compare
There was a problem hiding this comment.
ℹ️ The rebase has no code issues. But
maingained #15 after this push, and #15 rebuiltpackages/postgres/engine.wasm, so that binary will conflict.
Reviewed changes
Since the prior review, the branch was rebased onto cb43f3e (#17, #21), and the wasm rebuild moved into its own commit.
- Rebased the lexer and mapper commits.
lex.rs,module-types.tsandtests/unterminated.test.tshave the same blobs as at3620d0b. Inmapper.tsthe only change is the context from #17. All threediag(call sites still passsize, including the no-project path, which now emits #17's doc comment. - Rebuilt
packages/mysql/engine.wasmon top of #21. The new binary is 1683423 bytes. #21's build was 1683085 bytes and the one before it 1678775, so the new binary includes #21's growth. The postgres and sqlite binaries were left alone, which is correct againstcb43f3e. - Re-checked the offsets in every committed wasm. I loaded each binary through
Engineand rananalyzeon each unterminated form: strings, quoted names,E'',$x$and both block-comment forms. Every one returnsstart: 10on all three dialects.
ℹ️ packages/postgres/engine.wasm predates #15 on main
The branch is based on cb43f3e, but main is now at 0ac13f3 (#15). #15 changed the Postgres engine (infer.rs, postgres.rs, jsonshape.rs) and rebuilt packages/postgres/engine.wasm. This PR's Postgres binary was built without #15. Both sides changed that binary since cb43f3e, so the merge will conflict. Taking either side alone would drop either #15's inference or this PR's lexer offsets.
Technical details
# Postgres engine.wasm must be rebuilt on top of #15
## Affected sites
- packages/postgres/engine.wasm — PR blob `48edfa8` (3788645 bytes) has this PR's lexer offsets but not #15; main's blob `cfb89a4` (3803745 bytes) has #15 but not this PR's lexer offsets.
## Required outcome
- Rebase onto `0ac13f3` and rebuild `packages/postgres/engine.wasm` (mysql and sqlite are unaffected by #15) so the binary carries both #15's `infer.rs`/`postgres.rs`/`jsonshape.rs` changes and the `lex.rs` offsets.
- An `analyze` of `select 1, 'abc` on the rebuilt Postgres wasm should still return a diagnostic with `start: 10`.claude-opus-5-5 | 𝕏
0beb0c8 to
13e2c82
Compare
There was a problem hiding this comment.
✅ No new issues found. The rebase onto
d450564clears thepackages/postgres/engine.wasmconflict with #15 that the last review flagged.
Reviewed changes
Since the prior review, the branch was rebased onto main at d450564 (#10), and the engine artifacts were rebuilt again.
- Rebased the lexer, mapper and test commits.
git range-diffshows all three commits as identical patches. - Rebuilt
packages/{postgres,sqlite,mysql}/engine.wasmonmain. Each binary ismain's build plus this PR'slex.rschange:- The Postgres binary is the same size as
main's (3808259 bytes) and only 71 bytes differ. So it carries #15, #18 and #10. - The SQLite binary is the same size as
main's and only 35 bytes differ. - The MySQL binary is 338 bytes larger than
main's, which includes #29. The rebuild before this one added the same 338 bytes on top of #21.
- The Postgres binary is the same size as
- Re-checked the offsets in every committed wasm. I loaded each binary through
Engineand rananalyzeon every unterminated form. Every one returnsstart: 10on all three dialects. As a control,main's Postgres binary still returnsstart: 14forselect 1, 'abc.
claude-opus-5-5 | 𝕏
13e2c82 to
c928b6f
Compare
There was a problem hiding this comment.
ℹ️ The rebase has no code issues. But
maingained #39 after this push. #39 rebuiltpackages/postgres/engine.wasm, so that binary conflicts again.
Reviewed changes
Since the prior review, the branch was rebased onto b9b2e05 (#32, #36, #37), and the SQLite engine was rebuilt.
- Rebased the lexer, mapper and test commits.
git range-diffshows all three commits as identical patches. - Rebuilt
packages/sqlite/engine.wasmon top of #32. The new binary is 2446062 bytes andmain's atb9b2e05is 2445740. It includes #32's full-text search functions (bm25,highlight,snippet). The Postgres and MySQL binaries are the same as at13e2c82. That is correct, because nothing betweend450564andb9b2e05touched them. - Checked the binaries against their sources.
tests/fingerprint.test.ts(added in #36) passes for all three binaries atc928b6f. I also loaded the SQLite binary throughEngineand rananalyzeon each unterminated form. Every one returnsstart: 10.
ℹ️ packages/postgres/engine.wasm predates #39 on main
main is now at 8486b5c (#39). #39 moved the pg_query pins into engine/postgres/vendor/pg_query-source.sh, which the Postgres fingerprint hashes, and rebuilt packages/postgres/engine.wasm. git merge-tree against origin/main reports a binary conflict on that file.
Whichever side the merge keeps, the result is wrong. Keeping main's binary drops this PR's lexer offsets. Keeping this PR's binary fails tests/fingerprint.test.ts: I checked this by putting the PR's lex.rs and Postgres wasm on top of 8486b5c.
Technical details
# Postgres engine.wasm must be rebuilt on top of #39
## Affected sites
- packages/postgres/engine.wasm — PR blob `641b73d` (3808259 bytes) has this PR's `lex.rs` offsets but was built without `engine/postgres/vendor/pg_query-source.sh`; main's blob `bf881e4` (3809553 bytes) has #39 but not the offsets.
## Required outcome
- Rebase onto `8486b5c` and rebuild `packages/postgres/engine.wasm` with `engine/build.sh postgres`. #39 does not affect the SQLite and MySQL binaries.
- `node --experimental-strip-types --test tests/fingerprint.test.ts` passes for all three binaries.
- An `analyze` of `select 1, 'abc` on the rebuilt Postgres wasm still returns a diagnostic with `start: 10`.claude-opus-5-5 | 𝕏
c928b6f to
a980394
Compare
There was a problem hiding this comment.
ℹ️ The rebase onto
8486b5cclears thepackages/postgres/engine.wasmconflict with #39. Butmaingained #33 after this push. #33 rebuiltpackages/mysql/engine.wasm, so that binary conflicts now.
Reviewed changes
Since the prior review, the branch was rebased onto 8486b5c (#39 and two docs commits), and the Postgres engine was rebuilt.
- Rebased the lexer, mapper and test commits.
git range-diffshows all three commits as identical patches. - Rebuilt
packages/postgres/engine.wasmon top of #39. The new blob is039a174. The SQLite and MySQL binaries are the same as atc928b6f. That is correct, because #39 changed only the Postgres engine. - Checked the binaries against their sources.
tests/fingerprint.test.tspasses for all three binaries ata980394. I loaded the new Postgres binary throughEngineand rananalyzeon'abc,"abc,/* abc,E'ab\and$x$abc. Every one returnsstart: 10.
ℹ️ packages/mysql/engine.wasm predates #33 on main
main is now at 1b16b35, which includes 09da440 (#33). #33 changed the MySQL engine (engine/mysql/src/mysql.rs, the new mysql_derived.rs, mysql_shape.rs) and rebuilt packages/mysql/engine.wasm. git merge-tree HEAD origin/main reports a binary conflict on that file.
Neither side of the conflict is right on its own. main's binary has #33 but not this PR's lexer offsets. This PR's binary has the offsets but was built without #33's sources, so it would fail tests/fingerprint.test.ts after the merge. #33 does not touch engine/core or the path that turns a LexError into a diagnostic, so a rebuild is all this needs.
Technical details
# MySQL engine.wasm must be rebuilt on top of #33
## Affected sites
- packages/mysql/engine.wasm — PR blob `0964cd4` (1687886 bytes) has this PR's `lex.rs` offsets but not #33; main's blob `2c2bb64` (1700223 bytes) has #33 but not the offsets.
## Required outcome
- Rebase onto `origin/main` (`1b16b35`) and rebuild `packages/mysql/engine.wasm` with `engine/build.sh mysql`. #33 does not affect the Postgres and SQLite binaries.
- `node --experimental-strip-types --test tests/fingerprint.test.ts` passes for all three binaries.
- An `analyze` of `select 1, 'abc` on the rebuilt MySQL wasm still returns a diagnostic with `start: 10`.claude-opus-5-5 | 𝕏
a980394 to
b9498ca
Compare
There was a problem hiding this comment.
✅ No new issues found. The rebase onto
1b16b35clears thepackages/mysql/engine.wasmconflict with #33 that the last review flagged.
Reviewed changes
Since the prior review, the branch was rebased onto 1b16b35 (#33 and two docs commits), and the MySQL engine was rebuilt.
- Rebased the lexer, mapper and test commits.
git range-diffshows all three commits as identical patches. - Rebuilt
packages/mysql/engine.wasmon top of #33. The new blob isef78280at 1700561 bytes.main's binary is 1700223 bytes, so the new one is 338 bytes larger, the same difference every earlier MySQL rebuild added. The Postgres and SQLite binaries are unchanged froma980394. That is correct, because #33 changed only the MySQL engine. - Checked the binaries against their sources.
tests/fingerprint.test.tspasses for all three binaries atb9498ca. I loaded the new MySQL binary throughEngineand rananalyzeon'abc,`abcand/* abc. Every one returnsstart: 10. - Checked the merge against the current
main.mainhas since moved to299f6e6(#38), which changes only.github/files.git merge-tree --write-tree HEAD origin/mainmerges cleanly.
claude-opus-5-5 | 𝕏

A
.sqlfile that ends inside a string, a quoted identifier or a block comment lost its types:tscreportedand the import became
any.Cause
The engine's lexer reported these errors at the end of the text (
offset: b.len()). The analysis turned that into a diagnostic withstartequal to the file's length andlength: 1, which runs one byte past the end of the file, and TypeScript refuses a transform holding such a diagnostic. With the mapper's range clamped (and no engine change),tscgivesq.sql(1,10): error reylo1: unterminated string literalforselect 'a, which confirms the range as the only problem.Fix
engine/core/src/lex.rs): each unterminated error now points at the opening quote or the comment's start, as Postgres itself does. This covers a string, anE''string, a quoted name, a MySQL block comment, and a nested Postgres one. A dollar quote already pointed at its start. The error now underlines what was left open, and its range lies inside the text. The threeengine.wasmartifacts are rebuilt.src/mapper.ts,withinFileinsrc/module-types.ts): every diagnostic the mapper returns is cut at the end of the file, so no engine diagnostic can invalidate a transform again.Before / after (SQLite,
tsc --runExternalCode)select 'aq.sql(1,1): error TS100025 …, import isanyq.sql(1,8): error reylo1: unterminated string literalselect `aq.sql(1,1): error TS100025 …q.sql(1,8): error reylo1: unterminated quoted identifierselect 1 /* xq.sql(1,1): error TS100025 …q.sql(1,10): error reylo1: unterminated block commentVerified
tests/unterminated.test.tsrunstscover the three files on SQLite and on Postgres. It checks each error's position and that every module is typed: an@ts-expect-erroron a missing property would go unused if the import wereany. It also unit-testswithinFile.engine/core/src/lex.rstests the offset of every unterminated form.cargo-build,engine-tests,oracle-tests,wasm,oracle,typecheck,loader-tests(0 skipped) andpackageall pass.