pgtyped icon indicating copy to clipboard operation
pgtyped copied to clipboard

bug: comments cannot contain colon

Open wongjiahau opened this issue 3 years ago • 1 comments

Steps to reproduce

  1. Create the following SQL file (assuming the schema contains a table named transaction)
/* @name findTransaction */
SELECT
  *
FROM
  -- NOTE: this is important
  transaction;
  1. 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.

wongjiahau avatar Mar 11 '22 07:03 wongjiahau

I frequently use TODO: syntax which is widely recognized by editors.

benlongo avatar May 20 '22 17:05 benlongo

No longer reproduceable. Closing.

adelsz avatar Jan 29 '23 00:01 adelsz