pgtyped
pgtyped copied to clipboard
bug: comments cannot contain colon
Steps to reproduce
- Create the following SQL file (assuming the schema contains a table named
transaction)
/* @name findTransaction */
SELECT
*
FROM
-- NOTE: this is important
transaction;
- Run the code generation with
pgtyped
Expected output
No error
Actual output
(Modified slightly to remove the name of my computer)
Processing transaction.sql
Error processing file: TypeError: Cannot read properties of undefined (reading 'name')
at TypeAllocator.use (./node_modules/@pgtyped/cli/lib/types.js:135:24)
at ./node_modules/@pgtyped/cli/lib/generator.js:78:40
at Generator.next (<anonymous>)
at fulfilled (./node_modules/@pgtyped/cli/lib/generator.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Diagnosis
I realize that if I remove the colon from NOTE:, then this error does not happens again. So I suspect that this is because the generator is using naive text search algorithm to search for variables (which are prefixed with colon) instead of using proper parsing technique.
I frequently use TODO: syntax which is widely recognized by editors.
No longer reproduceable. Closing.